![]() |
ProvSQL C/C++ API
Adding support for provenance and uncertainty management to PostgreSQL databases
|
Tree decomposition of a Boolean circuit's primal graph. More...
#include "TreeDecomposition.h"
Public Types | |
| template<class T> | |
| using | small_vector = boost::container::static_vector<T, MAX_TREEWIDTH+1> |
Stack-allocated vector type bounded by MAX_TREEWIDTH+1 elements. | |
| using | Bag = flat_set<gate_t, small_vector> |
| The type of a bag: a small flat set of gate IDs. | |
Public Member Functions | |
| TreeDecomposition (const BooleanCircuit &bc) | |
Compute a tree decomposition of the primal graph of bc. | |
| TreeDecomposition (Graph graph, std::unordered_map< unsigned long, bag_t > *elimination_bag=nullptr) | |
| Compute a tree decomposition of an arbitrary undirected graph. | |
| const Bag & | getBag (bag_t b) const |
Const access to bag b. | |
| const std::vector< bag_t > & | getChildren (bag_t b) const |
Const access to the children of bag b. | |
| bag_t | getParent (bag_t b) const |
Return the parent of bag b. | |
| bag_t | getRoot () const |
| Return the root bag of the decomposition. | |
| std::size_t | getNbBags () const |
| Return the number of bags in the decomposition. | |
| TreeDecomposition (std::istream &in) | |
| Parse a tree decomposition from a stream (PACE challenge format). | |
| TreeDecomposition (const TreeDecomposition &td) | |
| Copy constructor. | |
| TreeDecomposition & | operator= (const TreeDecomposition &td) |
| Copy assignment. | |
| unsigned | getTreewidth () const |
| Return the treewidth of this decomposition. | |
| void | makeFriendly (gate_t root) |
| Restructure the tree into the friendly normal form. | |
| std::string | toDot () const |
| Render the tree decomposition as a GraphViz DOT string. | |
Static Public Member Functions | |
| static unsigned | degeneracyLowerBound (const BooleanCircuit &bc, unsigned &max_degree) |
Cheap degeneracy lower bound on the treewidth of bc's primal graph. | |
| static unsigned | degeneracyLowerBound (const Graph &graph, unsigned &max_degree) |
| Degeneracy lower bound over an arbitrary graph. | |
Static Public Attributes | |
| static constexpr int | MAX_TREEWIDTH = 10 |
| Maximum supported treewidth. | |
| static constexpr int | OPTIMAL_ARITY = 2 |
| Preferred maximum arity of bags in the friendly form. | |
Private Member Functions | |
| TreeDecomposition ()=default | |
| bag_t | findGateConnection (gate_t v) const |
Find the bag whose gate set is closest to gate v (for rooting). | |
| void | reroot (bag_t bag) |
Re-root the tree so that bag becomes the root. | |
| 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. | |
| void | addGateToBag (gate_t g, bag_t b) |
Add gate g to the contents of bag b. | |
| Bag & | getBag (bag_t b) |
Mutable access to bag b. | |
| std::vector< bag_t > & | getChildren (bag_t b) |
Mutable access to the children of bag b. | |
| void | setParent (bag_t b, bag_t p) |
Set the parent of bag b to p. | |
Private Attributes | |
| std::vector< Bag > | bags |
Bag contents, indexed by bag_t. | |
| std::vector< bag_t > | parent |
| Parent of each bag (root points to itself). | |
| std::vector< std::vector< bag_t > > | children |
| Children of each bag. | |
| bag_t | root |
| Identifier of the root bag. | |
| unsigned | treewidth |
| Treewidth of the decomposition. | |
Friends | |
| class | dDNNFTreeDecompositionBuilder |
| std::istream & | operator>> (std::istream &in, TreeDecomposition &td) |
| Read a tree decomposition in PACE challenge format. | |
Tree decomposition of a Boolean circuit's primal graph.
Provides constructors that compute the decomposition from a BooleanCircuit using the min-fill heuristic, or parse it from an input stream. After construction, makeFriendly() restructures the tree into the "friendly" normal form required by dDNNFTreeDecompositionBuilder.
Definition at line 58 of file TreeDecomposition.h.
| using TreeDecomposition::Bag = flat_set<gate_t, small_vector> |
The type of a bag: a small flat set of gate IDs.
Definition at line 74 of file TreeDecomposition.h.
| using TreeDecomposition::small_vector = boost::container::static_vector<T, MAX_TREEWIDTH+1> |
Stack-allocated vector type bounded by MAX_TREEWIDTH+1 elements.
Used for bag contents to avoid heap allocation for small, bounded sets.
Definition at line 71 of file TreeDecomposition.h.
|
privatedefault |

| TreeDecomposition::TreeDecomposition | ( | const BooleanCircuit & | bc | ) |
Compute a tree decomposition of the primal graph of bc.
Uses the min-fill elimination ordering heuristic. Throws TreeDecompositionException if the computed treewidth exceeds MAX_TREEWIDTH.
| bc | The Boolean circuit to decompose. |
Definition at line 381 of file TreeDecomposition.cpp.

| TreeDecomposition::TreeDecomposition | ( | Graph | graph, |
| std::unordered_map< unsigned long, bag_t > * | elimination_bag = nullptr ) |
Compute a tree decomposition of an arbitrary undirected graph.
Same min-fill elimination ordering heuristic as the BooleanCircuit constructor (which delegates here), but over a caller-supplied Graph – e.g. the Gaifman graph of a relational instance, when exploiting bounded-treewidth data rather than a bounded-treewidth circuit. Bag elements are then the graph's node IDs (wrapped in gate_t). Throws TreeDecompositionException if the computed treewidth exceeds MAX_TREEWIDTH.
| graph | The graph to decompose (consumed: the elimination process empties it). |
| elimination_bag | If non-null, receives for every node the bag created when that node was eliminated (nodes remaining after the elimination loop map to the final root bag). By the elimination invariant, for every edge (u,v) of the graph the earlier-eliminated endpoint's bag contains both u and v, which gives a constant-time edge-to-bag assignment. |
Definition at line 387 of file TreeDecomposition.cpp.

| TreeDecomposition::TreeDecomposition | ( | std::istream & | in | ) |
Parse a tree decomposition from a stream (PACE challenge format).
| in | Input stream containing the decomposition. |
Definition at line 131 of file TreeDecomposition.cpp.
| TreeDecomposition::TreeDecomposition | ( | const TreeDecomposition & | td | ) |
Copy constructor.
| td | Source decomposition. |

|
private |
Insert a new empty bag as a child of parent.
| parent | Parent bag of the new empty bag. |
| children | Children to transfer from parent to the new bag. |
Definition at line 256 of file TreeDecomposition.cpp.


Add gate g to the contents of bag b.
| g | Gate to add. |
| b | Destination bag. |
Definition at line 276 of file TreeDecomposition.cpp.


|
static |
Cheap degeneracy lower bound on the treewidth of bc's primal graph.
Computes the degeneracy \(\delta D(G)\) (Maximum Minimum Degree) by a linear-time min-degree peel (Matula-Beck): repeatedly remove a minimum-degree node, the bound being the largest degree any node has at its own removal. \(\delta D(G) \le \mathrm{tw}(G)\) (Maniu, Senellart, Jog, ICDT 2019, the fastest and best-behaved cheap lower bound there), so a value above MAX_TREEWIDTH proves the full min-fill build would fail – letting a caller skip the (costlier) attempt. O(V+E), no decomposition built.
The maximum degree \(\Delta\) falls out of the same single pass (it bounds the per-step fill-in work of the min-fill build), so it is returned alongside.
| bc | The Boolean circuit. |
| max_degree | Output: the maximum degree of the primal graph. |
Definition at line 58 of file TreeDecomposition.cpp.


|
static |
Degeneracy lower bound over an arbitrary graph.
Core of the BooleanCircuit overload (which builds the primal graph and delegates), usable directly on a data graph – e.g. the reachability compiler probes the edge relation's graph with it before paying for the min-fill construction. The graph is not mutated.
| graph | The graph. |
| max_degree | Output: the maximum degree. |
Definition at line 65 of file TreeDecomposition.cpp.

Find the bag whose gate set is closest to gate v (for rooting).
| v | Gate to search for. |
v. Definition at line 138 of file TreeDecomposition.cpp.


Mutable access to bag b.
| b | Bag identifier. |
Definition at line 115 of file TreeDecomposition.h.

Const access to bag b.
| b | Bag identifier. |
Definition at line 180 of file TreeDecomposition.h.
Mutable access to the children of bag b.
| b | Bag identifier. |
Definition at line 124 of file TreeDecomposition.h.

Const access to the children of bag b.
| b | Bag identifier. |
Definition at line 189 of file TreeDecomposition.h.
|
inline |
Return the number of bags in the decomposition.
Definition at line 214 of file TreeDecomposition.h.

Return the parent of bag b.
| b | Bag identifier. |
Definition at line 198 of file TreeDecomposition.h.

|
inline |
Return the root bag of the decomposition.
Definition at line 206 of file TreeDecomposition.h.

|
inline |
Return the treewidth of this decomposition.
Definition at line 239 of file TreeDecomposition.h.

| void TreeDecomposition::makeFriendly | ( | gate_t | root | ) |
Restructure the tree into the friendly normal form.
Reroots the tree at the bag that covers the circuit's root gate and splits/merges bags so that dDNNFTreeDecompositionBuilder can process them efficiently.
| root | The gate that should be covered by the root bag. |
Definition at line 156 of file TreeDecomposition.cpp.

| TreeDecomposition & TreeDecomposition::operator= | ( | const TreeDecomposition & | td | ) |
Copy assignment.
| td | Source decomposition. |

|
private |
Re-root the tree so that bag becomes the root.
| bag | The bag to use as the new root. |
Definition at line 281 of file TreeDecomposition.cpp.


Set the parent of bag b to p.
| b | Bag whose parent is to be set. |
| p | New parent bag. |
Definition at line 133 of file TreeDecomposition.h.

| std::string TreeDecomposition::toDot | ( | ) | const |
Render the tree decomposition as a GraphViz DOT string.
digraph string for visualisation. Definition at line 303 of file TreeDecomposition.cpp.


|
friend |
Definition at line 297 of file TreeDecomposition.h.
|
friend |
Read a tree decomposition in PACE challenge format.
| in | Input stream. |
| td | Tree decomposition to populate. |
in. Definition at line 329 of file TreeDecomposition.cpp.
|
private |
Bag contents, indexed by bag_t.
Definition at line 77 of file TreeDecomposition.h.
|
private |
Children of each bag.
Definition at line 79 of file TreeDecomposition.h.
|
staticconstexpr |
Maximum supported treewidth.
Circuits exceeding this cause an error.
Definition at line 61 of file TreeDecomposition.h.
|
staticconstexpr |
Preferred maximum arity of bags in the friendly form.
Definition at line 63 of file TreeDecomposition.h.
|
private |
Parent of each bag (root points to itself).
Definition at line 78 of file TreeDecomposition.h.
|
private |
Identifier of the root bag.
Definition at line 80 of file TreeDecomposition.h.
|
private |
Treewidth of the decomposition.
Definition at line 81 of file TreeDecomposition.h.