26#ifndef TREE_DECOMPOSITION_H
27#define TREE_DECOMPOSITION_H
33#include <boost/container/static_vector.hpp>
70using small_vector = boost::container::static_vector<T, MAX_TREEWIDTH+1>;
116 return bags[
static_cast<std::underlying_type<bag_t>::type
>(b)];
125 return bags[
static_cast<std::underlying_type<bag_t>::type
>(b)];
134 return children[
static_cast<std::underlying_type<bag_t>::type
>(b)];
143 return children[
static_cast<std::underlying_type<bag_t>::type
>(b)];
152 return parent[
static_cast<std::underlying_type<bag_t>::type
>(b)];
161 parent[
static_cast<std::underlying_type<bag_t>::type
>(b)]=p;
215std::string
toDot()
const;
235 return b=
bag_t{
static_cast<std::underlying_type<bag_t>::type
>(b)+1};
244 b=
bag_t{
static_cast<std::underlying_type<bag_t>::type
>(b)+1};
256 return static_cast<std::underlying_type<bag_t>::type
>(t)<u;
265 return std::to_string(
static_cast<std::underlying_type<bag_t>::type
>(b));
276 std::underlying_type<bag_t>::type u;
Boolean provenance circuit with support for knowledge compilation.
gate_t
Strongly-typed gate identifier.
std::istream & operator>>(std::istream &in, TreeDecomposition &td)
Read a tree decomposition in PACE challenge format.
std::string to_string(bag_t b)
Convert a bag_t to its decimal string representation.
bag_t
Strongly-typed bag identifier for a tree decomposition.
bool operator<(bag_t t, std::vector< bag_t >::size_type u)
Compare a bag_t against a std::vector size type.
bag_t & operator++(bag_t &b)
Pre-increment operator for bag_t.
Boolean circuit for provenance formula evaluation.
Exception thrown when a tree decomposition cannot be constructed.
Tree decomposition of a Boolean circuit's primal graph.
friend std::istream & operator>>(std::istream &in, TreeDecomposition &td)
Read a tree decomposition in PACE challenge format.
bag_t findGateConnection(gate_t v) const
Find the bag whose gate set is closest to gate v (for rooting).
bag_t addEmptyBag(bag_t parent, const std::vector< bag_t > &children=std::vector< bag_t >())
Insert a new empty bag as a child of parent.
const std::vector< bag_t > & getChildren(bag_t b) const
Const access to the children of bag b.
std::vector< Bag > bags
Bag contents, indexed by bag_t.
TreeDecomposition(const TreeDecomposition &td)
Copy constructor.
void addGateToBag(gate_t g, bag_t b)
Add gate g to the contents of bag b.
void setParent(bag_t b, bag_t p)
Set the parent of bag b to p.
unsigned getTreewidth() const
Return the treewidth of this decomposition.
TreeDecomposition()=default
std::string toDot() const
Render the tree decomposition as a GraphViz DOT string.
void reroot(bag_t bag)
Re-root the tree so that bag becomes the root.
static constexpr int OPTIMAL_ARITY
Preferred maximum arity of bags in the friendly form.
const Bag & getBag(bag_t b) const
Const access to bag b.
std::vector< bag_t > parent
Parent of each bag (root points to itself)
boost::container::static_vector< T, MAX_TREEWIDTH+1 > small_vector
Stack-allocated vector type bounded by MAX_TREEWIDTH+1 elements.
unsigned treewidth
Treewidth of the decomposition.
bag_t getParent(bag_t b) const
Return the parent of bag b.
static constexpr int MAX_TREEWIDTH
Maximum supported treewidth.
std::vector< std::vector< bag_t > > children
Children of each bag.
bag_t root
Identifier of the root bag.
Bag & getBag(bag_t b)
Mutable access to bag b.
TreeDecomposition & operator=(const TreeDecomposition &td)
Copy assignment.
void makeFriendly(gate_t root)
Restructure the tree into the friendly normal form.
std::vector< bag_t > & getChildren(bag_t b)
Mutable access to the children of bag b.
Builds a d-DNNF from a Boolean circuit using a tree decomposition.
TreeDecomposition & td
Tree decomposition of the circuit's primal graph.
Flat (unsorted, contiguous-storage) set template.