35#include <unordered_set>
59 return std::hash<typename std::underlying_type<gate_t>::type>()(
60 static_cast<typename std::underlying_type<gate_t>::type
>(g));
84std::unordered_map<gate_t, std::vector<double> >
shapley_delta()
const;
111std::vector<gate_t>
topological_order(
const std::vector<std::vector<gate_t> > &reversedWires)
const;
255std::string
toDot()
const;
281 const std::function<
int(
const std::string &)> &var_of_uuid = {})
const;
Boolean provenance circuit with support for knowledge compilation.
BooleanGate
Gate types for a Boolean provenance circuit.
gate_t
Strongly-typed gate identifier.
dDNNF compilation(gate_t g, std::string compiler, std::string *resolved=nullptr) const
Compile the sub-circuit rooted at g to a dDNNF via an external tool.
BooleanCircuit()
Construct an empty Boolean circuit.
Top-down structured-d-DNNF builder over a query-derived variable order.
Builds a d-DNNF from a Boolean circuit using a tree decomposition.
A d-DNNF circuit supporting exact probabilistic and game-theoretic evaluation.
dDNNF conditionAndSimplify(gate_t var, bool value) const
Condition on variable var having value value and simplify.
std::string toNNF(const std::function< int(const std::string &)> &var_of_uuid={}) const
Serialise the d-DNNF in the c2d / d4 ".nnf" text format.
gate_t root
The root gate of the d-DNNF.
dDNNF condition(gate_t var, bool value) const
Condition on variable var having value value (no simplification).
double banzhaf_internal() const
Compute the unnormalised Banzhaf value for the whole circuit.
Stats nodeStats() const
Compute structural statistics over the gates reachable from root.
double probabilityEvaluation() const
Compute the exact probability of the d-DNNF being true.
void setRoot(gate_t g)
Set the root gate.
void simplify()
Simplify the d-DNNF by removing redundant constants.
void makeSmooth()
Make the d-DNNF smooth.
void makeGatesBinary(BooleanGate type)
Rewrite all n-ary AND/OR gates into binary trees.
std::vector< std::vector< double > > shapley_alpha() const
Compute the α table used in the Shapley algorithm.
friend StructuredDNNFBuilder
Inversion-free structured builder: constructs and populates this d-DNNF.
double shapley(gate_t var) const
Compute the Shapley value of input gate var.
double banzhaf(gate_t var) const
Compute the Banzhaf power index of input gate var.
std::vector< gate_t > topological_order(const std::vector< std::vector< gate_t > > &reversedWires) const
Compute a topological ordering of the circuit.
friend dDNNFTreeDecompositionBuilder
Allowed to construct and populate this d-DNNF.
std::unordered_set< gate_t > vars(gate_t root) const
Return the set of all variable (IN) gates reachable from root.
std::unordered_map< gate_t, double, hash_gate_t > probability_cache
Memoisation cache mapping gates to their probability values.
gate_t getRoot() const
Return the root gate of this d-DNNF.
std::unordered_map< gate_t, std::vector< double > > shapley_delta() const
Compute the δ table used in the Shapley algorithm.
std::string toDot() const
Return a GraphViz DOT representation of the d-DNNF.
Structural statistics of a compiled d-DNNF.
bool smooth
Every OR gate's children share their variable set.
int depth
Longest path (in gates) from the root.
std::size_t nodes
Total reachable gates.
std::size_t or_gates
OR (decision) gates.
std::size_t edges
Total wires among reachable gates.
std::size_t not_gates
NOT gates.
std::size_t inputs
IN (variable) leaves.
std::size_t and_gates
AND (decomposition) gates.
std::hash functor for gate_t.
size_t operator()(gate_t g) const
Compute the hash of a gate identifier.