73 std::vector< NodeId > nodes_to_inspect;
80 nodes_to_inspect.push_back(root);
82 while (!nodes_to_inspect.empty()) {
84 NodeId current_node = nodes_to_inspect.back();
85 nodes_to_inspect.pop_back();
90 if (!mark[current_node]) {
91 mark[current_node] =
true;
94 for (
const auto neigh: JT.
neighbours(current_node))
95 if (!mark[neigh]) nodes_to_inspect.push_back(neigh);
107 for (
const auto node: nodes1)
108 result *= domain_sizes[node];
110 for (
const auto node: nodes2)
111 if (!nodes1.
exists(node)) result *= domain_sizes[node];
129 if (neighbors.
size() <= 2)
return;
131 if ((neighbors.
size() == 3) && (clique != from))
return;
135 std::vector< NodeId > cliques;
136 cliques.reserve(neighbors.
size());
138 for (
const auto nei: neighbors)
139 if (nei != from) cliques.push_back(nei);
145 std::vector< bool > is_cliques_relevant(cliques.size(),
true);
151 std::pair< NodeId, NodeId > pair;
155 for (
NodeId i = 0; i < cliques.size(); ++i) {
159 for (
NodeId j = i + 1; j < cliques.size(); ++j) {
170 for (
NodeId k = 2; k < cliques.size(); ++k) {
181 JT.
addEdge(cliques[ti], new_node);
182 JT.
addEdge(cliques[tj], new_node);
188 cliques[ti] = new_node;
189 is_cliques_relevant[tj] =
false;
193 for (
NodeId ind = 0; ind < tj; ++ind) {
194 if (is_cliques_relevant[ind]) {
202 for (
NodeId ind = tj + 1; ind < cliques.size(); ++ind) {
203 if (is_cliques_relevant[ind]) {
215 for (
NodeId ind = 0; ind < ti; ++ind) {
216 if (is_cliques_relevant[ind]) {
225 for (
NodeId ind = ti + 1; ind < cliques.size(); ++ind) {
226 if (is_cliques_relevant[ind]) {
245 mark[current_node] =
true;
248 for (
const auto neigh: JT.
neighbours(current_node)) {
261 const NodeSet& specified_roots) {
274 for (
const auto root: specified_roots) {
280 "several roots have been specified for a given "
281 "connected component (last : "
289 for (
const auto& elt: mark)
An algorithm for converting a join tree into a binary join tree.
virtual ~BinaryJoinTreeConverterDefault()
destructor
BinaryJoinTreeConverterDefault()
default constructor
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
NodeSet _roots_
the new roots that have been created to compute the last query
const NodeSet & roots() const
returns all the roots considered for all the connected components
void _markConnectedComponent_(const CliqueGraph &JT, NodeId root, NodeProperty< bool > &mark) const
a function used to mark the nodes belonging to a given connected component
float _combinedSize_(const NodeSet &nodes1, const NodeSet &nodes2, const NodeProperty< Size > &domain_sizes) const
returns the domain size of the union of two cliques
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
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
virtual void addEdge(NodeId first, NodeId second)
inserts a new edge between two cliques
NodeId addNode(const NodeSet &clique)
adds a new clique to the graph
virtual void eraseEdge(const Edge &edge)
removes an edge (and its separator) from the clique graph
const NodeSet & neighbours(NodeId id) const
returns the set of node neighbours to a given node
The base class for all undirected edges.
Exception : node does not exist.
Size sizeNodes() const
returns the number of nodes in the NodeGraphPart
NodeProperty< VAL > nodesPropertyFromVal(const VAL &a, Size size=0) const
a method to create a hashMap with key:NodeId and value:VAL
void erase(const Val &val)
Removes a given element from the priority queue (but does not return it).
void setPriority(const Val &elt, const Priority &new_priority)
Modifies the priority of each instance of a given element.
Val pop()
Removes the top element from the priority queue and return it.
Size insert(const Val &val, const Priority &priority)
Inserts a new (a copy) element in the priority queue.
A priorityQueue is a heap in which each element has a mutable priority.
Size size() const noexcept
Returns the number of elements in the set.
bool exists(const Key &k) const
Indicates whether a given elements belong to the set.
#define GUM_ERROR(type, msg)
Size NodeId
Type for node ids.
HashTable< NodeId, VAL > NodeProperty
Property on graph elements.
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
gum is the global namespace for all aGrUM entities
priority queues (in which an element cannot appear more than once)