27#ifndef BOOLEAN_CIRCUIT_H
28#define BOOLEAN_CIRCUIT_H
30#include <unordered_map>
31#include <unordered_set>
36#include <boost/archive/binary_oarchive.hpp>
37#include <boost/serialization/unordered_map.hpp>
38#include <boost/serialization/map.hpp>
39#include <boost/serialization/set.hpp>
40#include <boost/serialization/vector.hpp>
85bool evaluate(
gate_t g,
const std::unordered_set<gate_t> &sampled)
const;
123 const std::vector<gate_t> &muls,
124 const std::vector<double> &cumulated_probs,
127 std::vector<gate_t> &prefix);
133std::map<gate_t, unsigned>
info;
183 prob[
static_cast<std::underlying_type<gate_t>::type
>(g)]=p;
192 return prob[
static_cast<std::underlying_type<gate_t>::type
>(g)];
321template<
class Archive>
322void serialize (Archive & ar,
const unsigned int version)
BooleanGate
Gate types for a Boolean provenance circuit.
@ MULVAR
Auxiliary gate grouping all MULIN siblings.
@ NOT
Logical negation of a single child gate.
@ OR
Logical disjunction of child gates.
@ AND
Logical conjunction of child gates.
@ IN
Input (variable) gate representing a base tuple.
@ UNDETERMINED
Placeholder gate whose type has not been set yet.
@ MULIN
Multivalued-input gate (one of several options)
gate_t
Strongly-typed gate identifier.
Out-of-line template method implementations for Circuit<gateType>.
Boolean circuit for provenance formula evaluation.
std::vector< double > prob
Per-gate probability (for IN gates)
virtual ~BooleanCircuit()
double WeightMC(gate_t g, std::string opt) const
Compute the probability using the weightmc model counter.
bool evaluate(gate_t g, const std::unordered_set< gate_t > &sampled) const
Evaluate the sub-circuit at g on one sampled world.
dDNNF interpretAsDD(gate_t g) const
Build a dDNNF directly from the Boolean circuit's structure.
double possibleWorlds(gate_t g) const
Compute the probability by exact enumeration of all possible worlds.
bool probabilistic
true if any gate has a non-unit probability
void setProb(gate_t g, double p)
Set the probability for gate g and mark the circuit as probabilistic.
std::set< gate_t > inputs
Set of IN (input) gate IDs.
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().
double independentEvaluationInternal(gate_t g, std::set< gate_t > &seen) const
Recursive helper for independentEvaluation().
std::string exportCircuit(gate_t g) const
Export the circuit in the textual format expected by external compilers.
const std::set< gate_t > & getInputs() const
Return the set of input (IN) gate IDs.
std::string Tseytin(gate_t g, bool display_prob) const
Generate a Tseytin transformation of the sub-circuit at g.
dDNNF makeDD(gate_t g, const std::string &method, const std::string &args) const
Dispatch to the appropriate d-DNNF construction method.
gate_t setGate(BooleanGate type) override
Allocate a new gate with type type and no UUID.
unsigned getInfo(gate_t g) const
Return the integer annotation for gate g.
gate_t addGate() override
Allocate a new gate with a default-initialised type.
double monteCarlo(gate_t g, unsigned samples) const
Estimate the probability via Monte Carlo sampling.
void rewriteMultivaluedGates()
Rewrite all MULVAR/MULIN gate clusters into standard AND/OR/NOT circuits.
double getProb(gate_t g) const
Return the probability stored for gate g.
void setInfo(gate_t g, unsigned info)
Store an integer annotation on gate g.
virtual std::string toString(gate_t g) const override
Return a textual description of gate g for debugging.
BooleanCircuit()
Construct an empty Boolean circuit.
void serialize(Archive &ar, const unsigned int version)
Boost serialisation support.
std::map< gate_t, unsigned > info
Per-gate integer info (for MULIN gates)
friend class boost::serialization::access
dDNNF compilation(gate_t g, std::string compiler) const
Compile the sub-circuit rooted at g to a dDNNF via an external tool.
bool isProbabilistic() const
Return true if any gate has a non-trivial (< 1) probability.
gate_t interpretAsDDInternal(gate_t g, std::set< gate_t > &seen, dDNNF &dd) const
Recursive helper for interpretAsDD().
double independentEvaluation(gate_t g) const
Compute the probability exactly when inputs are independent.
std::set< gate_t > mulinputs
Set of MULVAR gate IDs.
Generic template base class for provenance circuits.
std::string uuid
UUID type used in this circuit (always std::string).
std::unordered_map< gate_t, uuid > id2uuid
Gate index → UUID string.
std::unordered_map< uuid, gate_t > uuid2id
UUID string → gate index.
std::vector< BooleanGate > gates
Gate type for each gate.
std::vector< std::vector< gate_t > > wires
Child wire lists for each gate.
Builds a d-DNNF from a Boolean circuit using a tree decomposition.
A d-DNNF circuit supporting exact probabilistic and game-theoretic evaluation.