51 std::vector< NodeId > nodes_to_inspect;
58 nodes_to_inspect.push_back(root);
60 while (!nodes_to_inspect.empty()) {
62 NodeId current_node = nodes_to_inspect.back();
63 nodes_to_inspect.pop_back();
68 if (!mark[current_node]) {
69 mark[current_node] =
true;
72 for (
const auto neigh : JT.
neighbours(current_node))
73 if (!mark[neigh]) nodes_to_inspect.push_back(neigh);
85 for (
const auto node : nodes1)
86 result *= domain_sizes[node];
88 for (
const auto node : nodes2)
89 if (!nodes1.exists(node)) result *= domain_sizes[node];
107 if (neighbors.
size() <= 2)
return;
109 if ((neighbors.
size() == 3) && (clique != from))
return;
113 std::vector< NodeId > cliques;
114 cliques.reserve(neighbors.
size());
116 for (
const auto nei : neighbors)
117 if (nei != from) cliques.push_back(nei);
123 std::vector< bool > is_cliques_relevant(cliques.size(),
true);
129 std::pair< NodeId, NodeId > pair;
133 for (
NodeId i = 0; i < cliques.size(); ++i) {
137 for (
NodeId j = i + 1; j < cliques.size(); ++j) {
150 for (
NodeId k = 2; k < cliques.size(); ++k) {
161 JT.
addEdge(cliques[ti], new_node);
162 JT.
addEdge(cliques[tj], new_node);
168 cliques[ti] = new_node;
169 is_cliques_relevant[tj] =
false;
173 for (
NodeId ind = 0; ind < tj; ++ind) {
174 if (is_cliques_relevant[ind]) {
182 for (
NodeId ind = tj + 1; ind < cliques.size(); ++ind) {
183 if (is_cliques_relevant[ind]) {
195 for (
NodeId ind = 0; ind < ti; ++ind) {
196 if (is_cliques_relevant[ind]) {
199 nodes1, JT.
separator(cliques[ind], clique), domain_sizes);
206 for (
NodeId ind = ti + 1; ind < cliques.size(); ++ind) {
207 if (is_cliques_relevant[ind]) {
210 nodes1, JT.
separator(cliques[ind], clique), domain_sizes);
227 mark[current_node] =
true;
230 for (
const auto neigh : JT.
neighbours(current_node)) {
244 const NodeSet& specified_roots) {
257 for (
const auto root : specified_roots) {
263 "several roots have been specified for a given " 264 "connected component");
271 for (
const auto& elt : mark)
283 for (
const auto root :
__roots)
NodeId addNode(const NodeSet &clique)
adds a new clique to the graph
Val pop()
Removes the top element from the priority queue and return it.
BinaryJoinTreeConverterDefault()
default constructor
CliqueGraph convert(const CliqueGraph &JT, const NodeProperty< Size > &domain_sizes, const NodeSet &roots)
returns a binary join tree corresponding to clique graph JT
const NodeSet & separator(const Edge &edge) const
returns the separator included in a given edge
NodeProperty< VAL > nodesProperty(VAL(*f)(const NodeId &), Size size=0) const
a method to create a HashTable with key:NodeId and value:VAL
void __markConnectedComponent(const CliqueGraph &JT, NodeId root, NodeProperty< bool > &mark) const
a function used to mark the nodes belonging to a given connected component
gum is the global namespace for all aGrUM entities
The class for generic Hash Tables.
void erase(const Val &val)
Removes a given element from the priority queue (but does not return it).
const NodeSet & neighbours(const NodeId id) const
returns the set of edges adjacent to a given node
void setPriority(const Val &elt, const Priority &new_priority)
Modifies the priority of each instance of a given element.
const NodeSet & roots() const
returns all the roots considered for all the connected components
A priorityQueue is a heap in which each element has a mutable priorityA priority queue is quite simil...
void __convertClique(CliqueGraph &JT, NodeId clique, NodeId from, const NodeProperty< Size > &domain_sizes) const
convert a clique and its adjacent cliques into a binary join tree
virtual ~BinaryJoinTreeConverterDefault()
destructor
virtual void eraseEdge(const Edge &edge)
removes an edge (and its separator) from the clique graph
void __convertConnectedComponent(CliqueGraph &JT, NodeId current_node, NodeId from, const NodeProperty< Size > &domain_sizes, NodeProperty< bool > &mark) const
convert a whole connected component into a binary join tree
virtual void addEdge(const NodeId first, const NodeId second)
inserts a new edge between two cliques
Size insert(const Val &val, const Priority &priority)
Inserts a new (a copy) element in the priority queue.
priority queues (in which an element cannot appear more than once)
Size sizeNodes() const
returns the number of nodes in the NodeGraphPart
The base class for all undirected edges.
NodeSet __roots
the new roots that have been created to compute the last query
An algorithm for converting a join tree into a binary join tree.
Size size() const noexcept
Returns the number of elements in the set.
float __combinedSize(const NodeSet &nodes1, const NodeSet &nodes2, const NodeProperty< Size > &domain_sizes) const
returns the domain size of the union of two cliques
Size NodeId
Type for node ids.
#define GUM_ERROR(type, msg)