ProvSQL C/C++ API
Adding support for provenance and uncertainty management to PostgreSQL databases
Loading...
Searching...
No Matches
GenericCircuit Class Reference

In-memory provenance circuit with semiring-generic evaluation. More...

#include "GenericCircuit.h"

Inheritance diagram for GenericCircuit:
Collaboration diagram for GenericCircuit:

Public Member Functions

virtual std::string toString (gate_t g) const override
 Return a placeholder debug string (not intended for display).
 
void setInfos (gate_t g, unsigned info1, unsigned info2)
 Set the integer annotation pair for gate g.
 
std::pair< unsigned, unsigned > getInfos (gate_t g) const
 Return the integer annotation pair for gate g.
 
void setExtra (gate_t g, const std::string &ex)
 Attach a string extra to gate g.
 
std::string getExtra (gate_t g) const
 Return the string extra for gate g.
 
gate_t addGate () override
 Allocate a new gate with a default-initialised type.
 
gate_t setGate (gate_type type) override
 Allocate a new gate with type type and no UUID.
 
gate_t setGate (const uuid &u, gate_type type) override
 Create or update the gate associated with UUID u.
 
const std::set< gate_t > & getInputs () const
 Return the set of input (leaf) gates.
 
void setProb (gate_t g, double p)
 Set the probability for gate g.
 
double getProb (gate_t g) const
 Return the probability for gate g.
 
template<class Archive >
void serialize (Archive &ar, const unsigned int version)
 Boost serialisation support.
 
template<typename S , std::enable_if_t< std::is_base_of_v< semiring::Semiring< typename S::value_type >, S >, int > = 0>
S::value_type evaluate (gate_t g, std::unordered_map< gate_t, typename S::value_type > &provenance_mapping, S semiring) const
 Evaluate the sub-circuit rooted at gate g over semiring semiring.
 
- Public Member Functions inherited from Circuit< gate_type >
virtual ~Circuit ()
 
std::vector< gate_t >::size_type getNbGates () const
 Return the total number of gates in the circuit.
 
gate_t getGate (const uuid &u)
 Return (or create) the gate associated with UUID u.
 
uuid getUUID (gate_t g) const
 Return the UUID string associated with gate g.
 
gate_type getGateType (gate_t g) const
 Return the type of gate g.
 
std::vector< gate_t > & getWires (gate_t g)
 Return a mutable reference to the child-wire list of gate g.
 
const std::vector< gate_t > & getWires (gate_t g) const
 Return a const reference to the child-wire list of gate g.
 
virtual gate_t setGate (const uuid &u, gate_type type)
 Create or update the gate associated with UUID u.
 
virtual gate_t setGate (gate_type type)
 Allocate a new gate with type type and no UUID.
 
bool hasGate (const uuid &u) const
 Test whether a gate with UUID u exists.
 
void addWire (gate_t f, gate_t t)
 Add a directed wire from gate f (parent) to gate t (child).
 

Private Attributes

std::map< gate_t, std::pair< unsigned, unsigned > > infos
 Per-gate (info1, info2) annotations.
 
std::map< gate_t, std::string > extra
 Per-gate string extras.
 
std::set< gate_tinputs
 Set of input (leaf) gate IDs.
 
std::vector< double > prob
 Per-gate probability values.
 

Friends

class dDNNFTreeDecompositionBuilder
 
class boost::serialization::access
 

Additional Inherited Members

- Public Types inherited from Circuit< gate_type >
using uuid = std::string
 UUID type used in this circuit (always std::string).
 
- Protected Member Functions inherited from Circuit< gate_type >
void setGateType (gate_t g, gate_type t)
 Update the type of an existing gate.
 
- Protected Attributes inherited from Circuit< gate_type >
std::unordered_map< uuid, gate_tuuid2id
 UUID string → gate index.
 
std::unordered_map< gate_t, uuidid2uuid
 Gate index → UUID string.
 
std::vector< gate_typegates
 Gate type for each gate.
 
std::vector< std::vector< gate_t > > wires
 Child wire lists for each gate.
 

Detailed Description

In-memory provenance circuit with semiring-generic evaluation.

Gate types are the PostgreSQL gate_type values. The circuit is constructed from the persistent mmap store and then evaluated in-memory.

Definition at line 48 of file GenericCircuit.h.

Member Function Documentation

◆ addGate()

gate_t GenericCircuit::addGate ( )
overridevirtual

Allocate a new gate with a default-initialised type.

Derived classes override this to perform additional initialisation (e.g. resizing auxiliary vectors).

Returns
The gate_t identifier of the newly created gate.

Reimplemented from Circuit< gate_type >.

Definition at line 34 of file GenericCircuit.cpp.

Here is the call graph for this function:

◆ evaluate()

template<typename S , std::enable_if_t< std::is_base_of_v< semiring::Semiring< typename S::value_type >, S >, int > >
S::value_type GenericCircuit::evaluate ( gate_t  g,
std::unordered_map< gate_t, typename S::value_type > &  provenance_mapping,
semiring 
) const

Evaluate the sub-circuit rooted at gate g over semiring semiring.

Performs a post-order traversal from g, mapping each input gate to its semiring value via provenance_mapping, and combining the results using the semiring operations.

Template Parameters
SA concrete semiring::Semiring subclass.
Parameters
gRoot gate of the sub-circuit to evaluate.
provenance_mappingMap from input gate IDs to semiring values.
semiringSemiring instance providing zero(), one(), plus(), times(), etc.
Returns
The semiring value of the circuit at gate g.

Definition at line 35 of file GenericCircuit.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getExtra()

std::string GenericCircuit::getExtra ( gate_t  g) const
inline

Return the string extra for gate g.

Parameters
gGate identifier.
Returns
The stored string, or empty if not set.

Definition at line 105 of file GenericCircuit.h.

Here is the caller graph for this function:

◆ getInfos()

std::pair< unsigned, unsigned > GenericCircuit::getInfos ( gate_t  g) const
inline

Return the integer annotation pair for gate g.

Parameters
gGate identifier.
Returns
{info1, info2}, or {-1,-1} if not set.

Definition at line 82 of file GenericCircuit.h.

Here is the caller graph for this function:

◆ getInputs()

const std::set< gate_t > & GenericCircuit::getInputs ( ) const
inline

Return the set of input (leaf) gates.

Returns
Const reference to the set of input gate identifiers.

Definition at line 125 of file GenericCircuit.h.

Here is the caller graph for this function:

◆ getProb()

double GenericCircuit::getProb ( gate_t  g) const
inline

Return the probability for gate g.

Parameters
gGate identifier.
Returns
The stored probability.

Definition at line 143 of file GenericCircuit.h.

Here is the caller graph for this function:

◆ serialize()

template<class Archive >
void GenericCircuit::serialize ( Archive &  ar,
const unsigned int  version 
)
inline

Boost serialisation support.

Parameters
arBoost archive (input or output).
versionArchive version (unused).

Definition at line 153 of file GenericCircuit.h.

◆ setExtra()

void GenericCircuit::setExtra ( gate_t  g,
const std::string &  ex 
)
inline

Attach a string extra to gate g.

Parameters
gGate identifier.
exString to store.

Definition at line 95 of file GenericCircuit.h.

Here is the caller graph for this function:

◆ setGate() [1/2]

gate_t GenericCircuit::setGate ( const uuid u,
gate_type  type 
)
override

Create or update the gate associated with UUID u.

If the UUID is already mapped the existing gate's type is updated. Otherwise a new gate is allocated.

Parameters
uUUID string to associate with the gate.
typeGate type.
Returns
Gate identifier.

Definition at line 25 of file GenericCircuit.cpp.

Here is the call graph for this function:

◆ setGate() [2/2]

gate_t GenericCircuit::setGate ( gate_type  type)
override

Allocate a new gate with type type and no UUID.

Parameters
typeGate type.
Returns
Gate identifier.

Definition at line 16 of file GenericCircuit.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setInfos()

void GenericCircuit::setInfos ( gate_t  g,
unsigned  info1,
unsigned  info2 
)
inline

Set the integer annotation pair for gate g.

Parameters
gGate identifier.
info1First annotation integer.
info2Second annotation integer.

Definition at line 72 of file GenericCircuit.h.

Here is the caller graph for this function:

◆ setProb()

void GenericCircuit::setProb ( gate_t  g,
double  p 
)
inline

Set the probability for gate g.

Parameters
gGate identifier.
pProbability in [0, 1].

Definition at line 134 of file GenericCircuit.h.

Here is the caller graph for this function:

◆ toString()

virtual std::string GenericCircuit::toString ( gate_t  g) const
inlineoverridevirtual

Return a placeholder debug string (not intended for display).

Parameters
gGate identifier (unused).
Returns
Fixed placeholder string "<GenericCircuit>".

Implements Circuit< gate_type >.

Definition at line 62 of file GenericCircuit.h.

Friends And Related Symbol Documentation

◆ boost::serialization::access

friend class boost::serialization::access
friend

Definition at line 166 of file GenericCircuit.h.

◆ dDNNFTreeDecompositionBuilder

friend class dDNNFTreeDecompositionBuilder
friend

Definition at line 165 of file GenericCircuit.h.

Member Data Documentation

◆ extra

std::map<gate_t, std::string> GenericCircuit::extra
private

Per-gate string extras.

Definition at line 52 of file GenericCircuit.h.

◆ infos

std::map<gate_t, std::pair<unsigned,unsigned> > GenericCircuit::infos
private

Per-gate (info1, info2) annotations.

Definition at line 51 of file GenericCircuit.h.

◆ inputs

std::set<gate_t> GenericCircuit::inputs
private

Set of input (leaf) gate IDs.

Definition at line 53 of file GenericCircuit.h.

◆ prob

std::vector<double> GenericCircuit::prob
private

Per-gate probability values.

Definition at line 54 of file GenericCircuit.h.


The documentation for this class was generated from the following files: