![]() |
ProvSQL C/C++ API
Adding support for provenance and uncertainty management to PostgreSQL databases
|
Boolean circuit for provenance formula evaluation. More...
#include "BooleanCircuit.h"


Public Member Functions | |
| BooleanCircuit () | |
| Construct an empty Boolean circuit. | |
| virtual | ~BooleanCircuit () |
| gate_t | addGate () override |
| Allocate a new gate with a default-initialised type. | |
| gate_t | setGate (BooleanGate type) override |
Allocate a new gate with type type and no UUID. | |
| gate_t | setGate (const uuid &u, BooleanGate type) override |
Create or update the gate associated with UUID u. | |
| gate_t | setGate (BooleanGate t, double p) |
| Create a new gate with a probability annotation. | |
| gate_t | setGate (const uuid &u, BooleanGate t, double p) |
| Create (or update) a gate with a UUID and probability. | |
| const std::set< gate_t > & | getInputs () const |
| Return the set of input (IN) gate IDs. | |
| void | setProb (gate_t g, double p) |
Set the probability for gate g and mark the circuit as probabilistic. | |
| double | getProb (gate_t g) const |
Return the probability stored for gate g. | |
| bool | isProbabilistic () const |
Return true if any gate has a non-trivial (< 1) probability. | |
| void | setInfo (gate_t g, unsigned info) |
Store an integer annotation on gate g. | |
| unsigned | getInfo (gate_t g) const |
Return the integer annotation for gate g. | |
| double | possibleWorlds (gate_t g) const |
| Compute the probability by exact enumeration of all possible worlds. | |
| dDNNF | compilation (gate_t g, std::string compiler) const |
Compile the sub-circuit rooted at g to a dDNNF via an external tool. | |
| double | monteCarlo (gate_t g, unsigned samples) const |
| Estimate the probability via Monte Carlo sampling. | |
| double | WeightMC (gate_t g, std::string opt) const |
Compute the probability using the weightmc model counter. | |
| double | independentEvaluation (gate_t g) const |
| Compute the probability exactly when inputs are independent. | |
| void | rewriteMultivaluedGates () |
| Rewrite all MULVAR/MULIN gate clusters into standard AND/OR/NOT circuits. | |
| dDNNF | interpretAsDD (gate_t g) const |
Build a dDNNF directly from the Boolean circuit's structure. | |
| dDNNF | makeDD (gate_t g, const std::string &method, const std::string &args) const |
| Dispatch to the appropriate d-DNNF construction method. | |
| virtual std::string | toString (gate_t g) const override |
Return a textual description of gate g for debugging. | |
| std::string | exportCircuit (gate_t g) const |
| Export the circuit in the textual format expected by external compilers. | |
| template<class Archive > | |
| void | serialize (Archive &ar, const unsigned int version) |
| Boost serialisation support. | |
Public Member Functions inherited from Circuit< BooleanGate > | |
| 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. | |
| BooleanGate | 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, BooleanGate type) |
Create or update the gate associated with UUID u. | |
| virtual gate_t | setGate (BooleanGate 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). | |
Protected Attributes | |
| std::set< gate_t > | inputs |
| Set of IN (input) gate IDs. | |
| std::set< gate_t > | mulinputs |
| Set of MULVAR gate IDs. | |
| std::vector< double > | prob |
| Per-gate probability (for IN gates) | |
| std::map< gate_t, unsigned > | info |
| Per-gate integer info (for MULIN gates) | |
| bool | probabilistic =false |
true if any gate has a non-unit probability | |
Protected Attributes inherited from Circuit< BooleanGate > | |
| std::unordered_map< uuid, gate_t > | uuid2id |
| UUID string → gate index. | |
| std::unordered_map< gate_t, uuid > | id2uuid |
| Gate index → UUID string. | |
| std::vector< BooleanGate > | gates |
| Gate type for each gate. | |
| std::vector< std::vector< gate_t > > | wires |
| Child wire lists for each gate. | |
Private Member Functions | |
| bool | evaluate (gate_t g, const std::unordered_set< gate_t > &sampled) const |
Evaluate the sub-circuit at g on one sampled world. | |
| std::string | Tseytin (gate_t g, bool display_prob) const |
Generate a Tseytin transformation of the sub-circuit at g. | |
| gate_t | interpretAsDDInternal (gate_t g, std::set< gate_t > &seen, dDNNF &dd) const |
Recursive helper for interpretAsDD(). | |
| double | independentEvaluationInternal (gate_t g, std::set< gate_t > &seen) const |
Recursive helper for independentEvaluation(). | |
| void | rewriteMultivaluedGatesRec (const std::vector< gate_t > &muls, const std::vector< double > &cumulated_probs, unsigned start, unsigned end, std::vector< gate_t > &prefix) |
Recursive helper for rewriteMultivaluedGates(). | |
Friends | |
| class | dDNNFTreeDecompositionBuilder |
| class | boost::serialization::access |
Additional Inherited Members | |
Public Types inherited from Circuit< BooleanGate > | |
| using | uuid = std::string |
UUID type used in this circuit (always std::string). | |
Protected Member Functions inherited from Circuit< BooleanGate > | |
| void | setGateType (gate_t g, BooleanGate t) |
| Update the type of an existing gate. | |
Boolean circuit for provenance formula evaluation.
Inherits the gate/wire infrastructure from Circuit<BooleanGate> and adds probability annotation, info integers (for multivalued inputs), and a rich set of evaluation algorithms.
Definition at line 73 of file BooleanCircuit.h.
|
inline |
Construct an empty Boolean circuit.
Definition at line 138 of file BooleanCircuit.h.
|
inlinevirtual |
Definition at line 140 of file BooleanCircuit.h.
|
overridevirtual |
Allocate a new gate with a default-initialised type.
Derived classes override this to perform additional initialisation (e.g. resizing auxiliary vectors).
gate_t identifier of the newly created gate. Reimplemented from Circuit< BooleanGate >.
Definition at line 100 of file BooleanCircuit.cpp.

Compile the sub-circuit rooted at g to a dDNNF via an external tool.
Writes the circuit in DIMACS/DNNF format, invokes compiler as a subprocess, and parses the resulting d-DNNF.
| g | Root gate. |
| compiler | Command to invoke (e.g. "d4", "c2d", "minic2d"). |
dDNNF. Definition at line 379 of file BooleanCircuit.cpp.


|
private |
Evaluate the sub-circuit at g on one sampled world.
Each gate in sampled is treated as true; all other IN gates are false.
| g | Root gate to evaluate. |
| sampled | Set of input gates that are true in this world. |
g. Definition at line 211 of file BooleanCircuit.cpp.


| std::string BooleanCircuit::exportCircuit | ( | gate_t | g | ) | const |
Export the circuit in the textual format expected by external compilers.
Produces a multi-line string encoding all gates reachable from the circuit in the format used by the standalone tdkc tool and external model counters.
| g | Root gate. |
Definition at line 152 of file BooleanCircuit.cpp.

| unsigned BooleanCircuit::getInfo | ( | gate_t | g | ) | const |
Return the integer annotation for gate g.
| g | Gate identifier. |
Definition at line 708 of file BooleanCircuit.cpp.

|
inline |
Return the set of input (IN) gate IDs.
Definition at line 171 of file BooleanCircuit.h.

|
inline |
Return the probability stored for gate g.
| g | Gate identifier. |
Definition at line 191 of file BooleanCircuit.h.

| double BooleanCircuit::independentEvaluation | ( | gate_t | g | ) | const |
Compute the probability exactly when inputs are independent.
Applicable when the circuit has no shared input gate (i.e., each input appears at most once).
| g | Root gate. |
Definition at line 697 of file BooleanCircuit.cpp.


|
private |
Recursive helper for independentEvaluation().
| g | Current gate to evaluate. |
| seen | Set of gates already evaluated (for memoisation). |
g. Definition at line 622 of file BooleanCircuit.cpp.


Build a dDNNF directly from the Boolean circuit's structure.
Used as a fallback when no external compiler is available and the circuit is already in a form that can be interpreted as a d-DNNF.
| g | Root gate. |
dDNNF wrapping the same structure. Definition at line 842 of file BooleanCircuit.cpp.


|
private |
Recursive helper for interpretAsDD().
| g | Current gate to process. |
| seen | Set of gates already visited (prevents re-processing). |
| dd | The d-DNNF being constructed. |
dd corresponding to g. Definition at line 790 of file BooleanCircuit.cpp.


|
inline |
Return true if any gate has a non-trivial (< 1) probability.
true iff at least one gate has a probability strictly less than 1. Definition at line 199 of file BooleanCircuit.h.

| dDNNF BooleanCircuit::makeDD | ( | gate_t | g, |
| const std::string & | method, | ||
| const std::string & | args | ||
| ) | const |
Dispatch to the appropriate d-DNNF construction method.
| g | Root gate. |
| method | Compilation method name (e.g. "tree-decomposition", "d4", "c2d", …). |
| args | Additional arguments forwarded to the chosen method. |
dDNNF. Definition at line 852 of file BooleanCircuit.cpp.


| double BooleanCircuit::monteCarlo | ( | gate_t | g, |
| unsigned | samples | ||
| ) | const |
Estimate the probability via Monte Carlo sampling.
| g | Root gate. |
| samples | Number of independent worlds to sample. |
Definition at line 247 of file BooleanCircuit.cpp.


| double BooleanCircuit::possibleWorlds | ( | gate_t | g | ) | const |
Compute the probability by exact enumeration of all possible worlds.
Only tractable for circuits with a small number of input gates.
| g | Root gate. |
Definition at line 269 of file BooleanCircuit.cpp.


| void BooleanCircuit::rewriteMultivaluedGates | ( | ) |
Rewrite all MULVAR/MULIN gate clusters into standard AND/OR/NOT circuits.
Must be called before any evaluation method when the circuit contains multivalued input gates.
Definition at line 760 of file BooleanCircuit.cpp.


|
private |
Recursive helper for rewriteMultivaluedGates().
| muls | Gates in the MULVAR group being rewritten. |
| cumulated_probs | Cumulative probability thresholds for each MULIN. |
| start | First index in muls to process. |
| end | One past the last index in muls to process. |
| prefix | Current AND-chain prefix being built. |
Definition at line 718 of file BooleanCircuit.cpp.


|
inline |
Boost serialisation support.
| ar | Boost archive (input or output). |
| version | Archive version (unused). |
Definition at line 322 of file BooleanCircuit.h.
| gate_t BooleanCircuit::setGate | ( | BooleanGate | t, |
| double | p | ||
| ) |
Create a new gate with a probability annotation.
| t | Gate type (typically BooleanGate::IN). |
| p | Probability of this gate being true. |
Definition at line 91 of file BooleanCircuit.cpp.

|
override |
Allocate a new gate with type type and no UUID.
| type | Gate type. |
Definition at line 58 of file BooleanCircuit.cpp.


| gate_t BooleanCircuit::setGate | ( | const uuid & | u, |
| BooleanGate | t, | ||
| double | p | ||
| ) |
Create (or update) a gate with a UUID and probability.
| u | UUID string. |
| t | Gate type. |
| p | Probability of this gate being true. |
Definition at line 82 of file BooleanCircuit.cpp.

|
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.
| u | UUID string to associate with the gate. |
| type | Gate type. |
Definition at line 70 of file BooleanCircuit.cpp.

| void BooleanCircuit::setInfo | ( | gate_t | g, |
| unsigned | info | ||
| ) |
Store an integer annotation on gate g.
Used to record the index of a MULIN gate within its MULVAR group.
| g | Gate identifier. |
| info | Integer to store. |
Definition at line 703 of file BooleanCircuit.cpp.

|
inline |
Set the probability for gate g and mark the circuit as probabilistic.
| g | Gate identifier. |
| p | Probability value in [0, 1]. |
Definition at line 180 of file BooleanCircuit.h.

|
overridevirtual |
Return a textual description of gate g for debugging.
Pure virtual; each concrete circuit class provides its own formatting.
| g | Gate to describe. |
Implements Circuit< BooleanGate >.
Definition at line 107 of file BooleanCircuit.cpp.


|
private |
Generate a Tseytin transformation of the sub-circuit at g.
Produces a CNF/DIMACS-style encoding suitable for input to model counters such as weightmc or d4.
| g | Root gate. |
| display_prob | Include probability weights in the output. |
Definition at line 302 of file BooleanCircuit.cpp.


| double BooleanCircuit::WeightMC | ( | gate_t | g, |
| std::string | opt | ||
| ) | const |
Compute the probability using the weightmc model counter.
| g | Root gate. |
| opt | Additional command-line options forwarded to weightmc. |
weightmc. Definition at line 556 of file BooleanCircuit.cpp.


|
friend |
Definition at line 336 of file BooleanCircuit.h.
|
friend |
Definition at line 335 of file BooleanCircuit.h.
|
protected |
Per-gate integer info (for MULIN gates)
Definition at line 133 of file BooleanCircuit.h.
|
protected |
Set of IN (input) gate IDs.
Definition at line 130 of file BooleanCircuit.h.
|
protected |
Set of MULVAR gate IDs.
Definition at line 131 of file BooleanCircuit.h.
|
protected |
Per-gate probability (for IN gates)
Definition at line 132 of file BooleanCircuit.h.
|
protected |
true if any gate has a non-unit probability
Definition at line 134 of file BooleanCircuit.h.