33 #endif // GUM_NO_INLINE 45 _elimination_sequence_strategy(elimSeq.newFactory()),
46 _junction_tree_strategy(JTStrategy.newFactory()), __original_graph(theGraph),
47 __minimality_required(minimality) {
53 if (theGraph !=
nullptr) {
141 if (from.__junction_tree !=
nullptr) {
197 std::vector< NodeId > adj;
223 bool require_mint =
true;
225 for (
unsigned int j = 0; require_mint; ++j) {
230 for (
const auto& edge : T) {
231 node1 = edge.first();
232 node2 = edge.second();
235 if ((R[node1] < j) && (R[node2] < j))
continue;
239 if (__triangulated_graph.neighbours(node2).size()
240 < __triangulated_graph.neighbours(node1).size()) {
250 for (
const auto adjnode : __triangulated_graph.neighbours(node1))
251 if (__triangulated_graph.existsEdge(node2, adjnode))
252 adj.push_back(adjnode);
255 for (
unsigned int k = 0; k < adj.size() && !incomplete; ++k) {
256 for (
unsigned int m = k + 1; m < adj.size(); ++m) {
257 if (!__triangulated_graph.existsEdge(adj[k], adj[m])) {
275 for (
const auto& edge : T_prime) {
277 __triangulated_graph.eraseEdge(edge);
282 if (T_prime.size() == 0) require_mint =
false;
299 numbered_neighbours(std::greater< unsigned int >(),
300 __triangulated_graph.size());
309 NodeId node = numbered_neighbours.pop();
313 for (
const auto neighbour : __triangulated_graph.neighbours(node)) {
315 numbered_neighbours.setPriority(
316 neighbour, 1 + numbered_neighbours.priority(neighbour));
328 for (
const auto neighbour : __triangulated_graph.neighbours(__elim_order[i]))
355 for (
const auto node : list_of_nodes) {
358 if ((node != clique_i_creator) && (child > it_elim_step))
359 child = it_elim_step;
362 if (child <= __original_graph->bound()) {
376 std::vector< Arc >& merged_cliques,
381 if (other_node != from) {
384 bool complete =
true;
386 for (
auto iter_sep1 = separator.
begin();
387 iter_sep1 != separator.
end() && complete;
389 auto iter_sep2 = iter_sep1;
391 for (++iter_sep2; iter_sep2 != separator.
end(); ++iter_sep2) {
400 if (!complete) merged_cliques.push_back(
Arc(other_node, node));
424 T_mpd_cliques.
insert(clik, clik);
428 std::vector< Arc > merged_cliques;
439 for (
unsigned int i = 0; i < merged_cliques.size(); ++i) {
440 T_mpd_cliques[merged_cliques[i].tail()] =
441 T_mpd_cliques[merged_cliques[i].head()];
445 for (
const auto& elt : T_mpd_cliques)
446 if (elt.first == elt.second)
452 for (
const auto& elt : T_mpd_cliques)
453 if (elt.first != elt.second)
462 NodeId node1 = T_mpd_cliques[edge.first()];
463 NodeId node2 = T_mpd_cliques[edge.second()];
465 if (node1 != node2) {
477 for (
const auto& elt : node_2_junction_clique)
498 const NodeSet& clique = __junction_tree->clique(clik_id);
499 std::vector< NodeId > clique_nodes(clique.
size());
502 for (
const auto node : clique) {
503 clique_nodes[i] = node;
507 for (i = 0; i < clique_nodes.size(); ++i) {
508 for (
unsigned int j = i + 1; j < clique_nodes.size(); ++j) {
528 if (graph !=
nullptr) {
570 NodeId removable_node = 0;
572 for (
unsigned int nb_elim = 0; tmp_graph.
size() != 0; ++nb_elim) {
580 cliques << removable_node;
581 for (
const auto clik : tmp_graph.
neighbours(removable_node))
591 for (
auto iter_edges1 = nei.
begin(); iter_edges1 != nei.
end();
593 node1 = *iter_edges1;
594 auto iter_edges2 = iter_edges1;
596 for (++iter_edges2; iter_edges2 != nei.
end(); ++iter_edges2) {
597 node2 = *iter_edges2;
598 Edge edge(node1, node2);
601 current_fill.
insert(edge);
618 for (
auto iter_edges1 = nei.
begin(); iter_edges1 != nei.
end();
620 node1 = *iter_edges1;
621 auto iter_edges2 = iter_edges1;
623 for (++iter_edges2; iter_edges2 != nei.
end(); ++iter_edges2) {
624 node2 = *iter_edges2;
625 Edge edge(node1, node2);
645 for (
auto iter_edges1 = nei.
begin(); iter_edges1 != nei.
end();
647 node1 = *iter_edges1;
648 auto iter_edges2 = iter_edges1;
650 for (++iter_edges2; iter_edges2 != nei.
end(); ++iter_edges2) {
651 node2 = *iter_edges2;
652 Edge edge(node1, node2);
704 std::vector< NodeId > clique_nodes(clique.
size());
707 for (
const auto node : clique) {
708 clique_nodes[i] = node;
712 for (i = 0; i < clique_nodes.size(); ++i) {
713 for (
unsigned int j = i + 1; j < clique_nodes.size(); ++j) {
714 Edge edge(clique_nodes[i], clique_nodes[j]);
const CliqueGraph & junctionTree()
returns a compatible junction tree
bool contains(const Key &k) const
Indicates whether a given elements belong to the set.
virtual void clear()
clears the sequence (to prepare, for instance, a new elimination sequence)
const UndiGraph & triangulatedGraph()
returns the triangulated graph
virtual void eliminationUpdate(const NodeId node)
performs all the graph/fill-ins updates provided (if any)
virtual const EdgeSet & fillIns()
in case fill-ins are provided, this function returns the fill-ins due to all the nodes eliminated so ...
NodeId addNode(const NodeSet &clique)
adds a new clique to the graph
virtual const NodeProperty< NodeId > & createdCliques()=0
returns, for each node, the clique of the junction tree which was created by its deletion ...
virtual void clear()
removes all the nodes and edges from the graph
void clear()
reinitialize the graph to be triangulated to an empty graph
virtual EliminationSequenceStrategy * copyFactory() const =0
virtual copy constructor
NodeProperty< NodeId > __node_2_max_prime_clique
indicates which clique of the max prime junction tree was created by the elmination of a given node (...
void __triangulate()
the function that performs the triangulation
bool __has_max_prime_junction_tree
indicates whether a maximal prime subgraph junction tree has been constructed
const NodeSet & separator(const Edge &edge) const
returns the separator included in a given edge
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
virtual ~StaticTriangulation()
destructor
EliminationSequenceStrategy * _elimination_sequence_strategy
the elimination sequence strategy used by the triangulation
const UndiGraph * __original_graph
a pointer to the (external) original graph (which will be triangulated)
virtual void _initTriangulation(UndiGraph &graph)
the function called to initialize the triangulation process
Size size() const
alias for sizeNodes
virtual void addEdge(const NodeId first, const NodeId second)
insert a new edge into the undirected graph
const EdgeSet & fillIns()
returns the fill-ins added by the triangulation algorithm
void __computeMaxPrimeJunctionTree()
computes the junction tree of the maximal prime subgraphs
bool __has_triangulated_graph
a boolean indicating whether we have constructed the triangulated graph
virtual void clear()
removes all the cliques and separators from the graph (as well as their adjacent edges) ...
JunctionTreeStrategy * _junction_tree_strategy
the junction tree strategy used by the triangulation
void erase(const Key &k)
Erases an element from the set.
UndiGraph __triangulated_graph
the triangulated graph
gum is the global namespace for all aGrUM entities
NodeProperty< NodeId > __reverse_elim_order
the elimination order (access by NodeId)
const iterator & end() const noexcept
The usual unsafe end iterator to parse the set.
iterator begin() const
The usual unsafe begin iterator to parse the set.
std::vector< EdgeSet > __added_fill_ins
a vector containing the set of fill-ins added after each node elimination (used by recursive thinning...
The class for generic Hash Tables.
An efficient unconstrained elimination sequence algorithm.
const NodeProperty< Size > * _domain_sizes
the domain sizes of the variables/nodes of the graph
const NodeSet & neighbours(const NodeId id) const
returns the set of edges adjacent to a given node
virtual void eraseNode(const NodeId id)
remove a node and its adjacent edges from the graph
bool __has_triangulation
a boolean indicating whether we have parformed a triangulation
virtual void clear()=0
resets the current junction tree strategy data structures
const EdgeSet & edges() const
returns the set of edges stored within the EdgeGraphPart
A priorityQueue is a heap in which each element has a mutable priorityA priority queue is quite simil...
virtual JunctionTreeStrategy * copyFactory(StaticTriangulation *triangulation=nullptr) const =0
virtual copy constructor
virtual void addToClique(const NodeId clique_id, const NodeId node_id)
changes the set of nodes included into a given clique and returns the new set
bool __has_junction_tree
a boolean indicating whether the junction tree has been constructed
bool existsEdge(const Edge &edge) const
indicates whether a given edge exists
void resize(Size new_capacity)
Changes the size of the underlying hash table containing the set.
virtual void setTriangulation(StaticTriangulation *triangulation)=0
assigns the triangulation to the junction tree strategy
The base class for all directed edgesThis class is used as a basis for manipulating all directed edge...
CliqueGraph __max_prime_junction_tree
the maximal prime subgraph junction tree computed from the junction tree
Base Class for all the algorithms producing a junction given a set of cliques/subcliques resulting fr...
const NodeGraphPart & nodes() const
return *this as a NodeGraphPart
base class for all non-incremental triangulations.
virtual bool providesGraphUpdate() const =0
indicates whether the elimination sequence updates by itself the graph after a node has been eliminat...
virtual NodeId nextNodeToEliminate()=0
returns the new node to be eliminated within the triangulation algorithm
virtual void addEdge(const NodeId first, const NodeId second)
inserts a new edge between two cliques
NodeProperty< NodeSet > __elim_cliques
the cliques formed by the elimination of the nodes
Size insert(const Val &val, const Priority &priority)
Inserts a new (a copy) element in the priority queue.
const NodeSet & clique(const NodeId idClique) const
returns the set of nodes included into a given clique
priority queues (in which an element cannot appear more than once)
An algorithms producing a junction given the elimination tree produced by the triangulation algorithm...
virtual StaticTriangulation * newFactory() const =0
returns a fresh triangulation of the same type as the current object but over an empty graph ...
virtual bool setGraph(UndiGraph *graph, const NodeProperty< Size > *dom_sizes)
sets a new graph to be triangulated
The base class for all elimination sequence algorithms used by triangulation algorithms.
The base class for all undirected edges.
bool __we_want_fill_ins
a boolean indicating if we want fill-ins list with the standard triangulation method ...
bool __has_fill_ins
indicates whether we actually computed fill-ins
bool __minimality_required
indicates whether the triangulation must be minimal
NodeId bound() const
returns a number n such that all node ids are strictly lower than n
base class for all non-incremental triangulation methods
const CliqueGraph * __junction_tree
the junction tree computed by the algorithm
void __computeEliminationTree()
returns an elimination tree from a triangulated graph
Base class for undirected graphs.
Size Idx
Type for indexes.
bool __has_elimination_tree
a boolean indicating whether the elimination tree has been computed
An efficient unconstrained elimination sequence algorithm.
virtual void setGraph(const UndiGraph *graph, const NodeProperty< Size > *domsizes)
initialize the triangulation data structures for a new graph
void clear()
Removes all the elements, if any, from the set.
void __computeMaxPrimeMergings(const NodeId node, const NodeId from, std::vector< Arc > &merged_cliques, NodeSet &mark) const
used for computing the junction tree of the maximal prime subgraphs
std::size_t Size
In aGrUM, hashed values are unsigned long int.
EdgeSet __fill_ins
the fill-ins added during the whole triangulation process
Interface for all the triangulation methods.
Size size() const noexcept
Returns the number of elements in the set.
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
void __computeRecursiveThinning()
removes redondant fill-ins and compute proper elimination cliques and order
virtual const CliqueGraph & junctionTree()=0
returns the junction tree computed
std::vector< NodeId > __elim_order
the order in which nodes are eliminated by the algorithm
virtual void moveTriangulation(StaticTriangulation *triangulation)
assigns a new triangulation to the junction tree strategy during a move construction ...
Size NodeId
Type for node ids.
void insert(const Key &k)
Inserts a new element into the set.
virtual bool providesFillIns() const =0
indicates whether the fill-ins generated by the eliminated nodes, if needed, will be computed by the ...
CliqueGraph __elim_tree
the elimination tree computed by the algorithm
StaticTriangulation(const EliminationSequenceStrategy &elimSeq, const JunctionTreeStrategy &JTStrategy, bool minimality=false)
default constructor: without any graph
Inline implementations for computing default triangulations of graphs.
virtual void askFillIns(bool do_it)=0
if the elimination sequence is able to compute fill-ins, we indicate whether we want this feature to ...
An algorithm producing a junction given the elimination tree produced by a triangulation algorithm...