aGrUM  0.14.2
gum::StaticTriangulation Class Referenceabstract

base class for all non-incremental triangulation methods More...

#include <staticTriangulation.h>

+ Inheritance diagram for gum::StaticTriangulation:
+ Collaboration diagram for gum::StaticTriangulation:

Public Member Functions

Accessors / Modifiers
double maxLog10CliqueDomainSize ()
 returns the max of log10DomainSize of the cliques in the junction tree. More...
 
const NodeProperty< Size > * domainSizes () const
 returns the domain sizes of the variables of the graph to be triangulated More...
 

Protected Attributes

EliminationSequenceStrategy_elimination_sequence_strategy {nullptr}
 the elimination sequence strategy used by the triangulation More...
 
JunctionTreeStrategy_junction_tree_strategy {nullptr}
 the junction tree strategy used by the triangulation More...
 
const NodeProperty< Size > * _domain_sizes {nullptr}
 the domain sizes of the variables/nodes of the graph More...
 

Constructors / Destructors

virtual StaticTriangulationnewFactory () const =0
 returns a fresh triangulation of the same type as the current object but over an empty graph More...
 
virtual StaticTriangulationcopyFactory () const =0
 virtual copy constructor More...
 
virtual ~StaticTriangulation ()
 destructor More...
 
 StaticTriangulation (const EliminationSequenceStrategy &elimSeq, const JunctionTreeStrategy &JTStrategy, bool minimality=false)
 default constructor: without any graph More...
 
 StaticTriangulation (const UndiGraph *graph, const NodeProperty< Size > *dom_sizes, const EliminationSequenceStrategy &elimSeq, const JunctionTreeStrategy &JTStrategy, bool minimality=false)
 constructor with a given graph More...
 
 StaticTriangulation (const StaticTriangulation &)
 forbid copy constructor except in newfactory More...
 
 StaticTriangulation (StaticTriangulation &&)
 forbid move constructor except in children's constructors More...
 

Accessors / Modifiers

virtual void setGraph (const UndiGraph *graph, const NodeProperty< Size > *domsizes)
 initialize the triangulation data structures for a new graph More...
 
const EdgeSetfillIns ()
 returns the fill-ins added by the triangulation algorithm More...
 
const std::vector< NodeId > & eliminationOrder ()
 returns an elimination ordering compatible with the triangulated graph More...
 
Idx eliminationOrder (const NodeId)
 returns the index of a given node in the elimination order (0 = first node eliminated) More...
 
const NodeProperty< NodeId > & reverseEliminationOrder ()
 returns a table indicating, for each node, at which step it was deleted by the triangulation process More...
 
const UndiGraphtriangulatedGraph ()
 returns the triangulated graph More...
 
const CliqueGrapheliminationTree ()
 returns the elimination tree of a compatible ordering More...
 
const CliqueGraphjunctionTree ()
 returns a compatible junction tree More...
 
NodeId createdJunctionTreeClique (const NodeId id)
 returns the Id of the clique of the junction tree created by the elimination of a given node during the triangulation process More...
 
const NodeProperty< NodeId > & createdJunctionTreeCliques ()
 returns the Ids of the cliques of the junction tree created by the elimination of the nodes More...
 
const CliqueGraphmaxPrimeSubgraphTree ()
 returns a junction tree of maximal prime subgraphs More...
 
NodeId createdMaxPrimeSubgraph (const NodeId id)
 returns the Id of the maximal prime subgraph created by the elimination of a given node during the triangulation process More...
 
void clear ()
 reinitialize the graph to be triangulated to an empty graph More...
 
void setMinimalRequirement (bool)
 sets/unset the minimality requirement More...
 
virtual bool isMinimalityRequired () const final
 indicates wether minimality is required More...
 
void setFillIns (bool)
 sets/unsets the record of the fill-ins in the standard triangulation procedure More...
 
const UndiGraphoriginalGraph () const
 returns the graph to be triangulated More...
 
EliminationSequenceStrategyeliminationSequenceStrategy () const
 returns the elimination sequence strategy used by the triangulation More...
 
JunctionTreeStrategyjunctionTreeStrategy () const
 returns the junction tree strategy used by the triangulation More...
 
virtual void _initTriangulation (UndiGraph &graph)
 the function called to initialize the triangulation process More...
 

Detailed Description

base class for all non-incremental triangulation methods

Definition at line 47 of file staticTriangulation.h.

Constructor & Destructor Documentation

◆ ~StaticTriangulation()

gum::StaticTriangulation::~StaticTriangulation ( )
virtual

destructor

Definition at line 150 of file staticTriangulation.cpp.

References _elimination_sequence_strategy, and _junction_tree_strategy.

150  {
151  // for debugging purposes
152  GUM_DESTRUCTOR(StaticTriangulation);
153 
156 
157  // no need to deallocate __original_graph nor __junction_tree because
158  // they are not owned by the static triangulation class
159  }
EliminationSequenceStrategy * _elimination_sequence_strategy
the elimination sequence strategy used by the triangulation
JunctionTreeStrategy * _junction_tree_strategy
the junction tree strategy used by the triangulation
StaticTriangulation(const EliminationSequenceStrategy &elimSeq, const JunctionTreeStrategy &JTStrategy, bool minimality=false)
default constructor: without any graph

◆ StaticTriangulation() [1/4]

gum::StaticTriangulation::StaticTriangulation ( const EliminationSequenceStrategy elimSeq,
const JunctionTreeStrategy JTStrategy,
bool  minimality = false 
)
protected

default constructor: without any graph

Parameters
elimSeqthe elimination sequence used to triangulate the graph
JTStrategythe junction tree strategy used to create junction trees from elimination trees
minimalitya Boolean indicating whether we should enforce that the triangulation is minimal w.r.t. inclusion

Definition at line 66 of file staticTriangulation.cpp.

References _junction_tree_strategy, and gum::JunctionTreeStrategy::setTriangulation().

69  :
70  _elimination_sequence_strategy(elimSeq.newFactory()),
71  _junction_tree_strategy(JTStrategy.newFactory()),
72  __minimality_required(minimality) {
73  // for debugging purposes
74  GUM_CONSTRUCTOR(StaticTriangulation);
75 
76  // register the triangulation to its junction tree strategy
78  }
EliminationSequenceStrategy * _elimination_sequence_strategy
the elimination sequence strategy used by the triangulation
JunctionTreeStrategy * _junction_tree_strategy
the junction tree strategy used by the triangulation
virtual void setTriangulation(StaticTriangulation *triangulation)=0
assigns the triangulation to the junction tree strategy
bool __minimality_required
indicates whether the triangulation must be minimal
StaticTriangulation(const EliminationSequenceStrategy &elimSeq, const JunctionTreeStrategy &JTStrategy, bool minimality=false)
default constructor: without any graph
+ Here is the call graph for this function:

◆ StaticTriangulation() [2/4]

gum::StaticTriangulation::StaticTriangulation ( const UndiGraph graph,
const NodeProperty< Size > *  dom_sizes,
const EliminationSequenceStrategy elimSeq,
const JunctionTreeStrategy JTStrategy,
bool  minimality = false 
)
protected

constructor with a given graph

Parameters
graphthe graph to be triangulated, i.e., the nodes of which will be eliminated
dom_sizesthe domain sizes of the nodes to be eliminated
elimSeqthe elimination sequence used to triangulate the graph
JTStrategythe junction tree strategy used to create junction trees
Warning
Note that we allow dom_sizes to be defined over nodes/variables that do not belong to graph. These sizes will simply be ignored. However, it is compulsory that all the nodes of graph belong to dom_sizes
Parameters
minimalitya Boolean indicating whether we should enforce that the triangulation is minimal w.r.t. inclusion
Warning
note that, by aGrUM's rule, the graph is not copied but only referenced by the triangulation algorithm.

Definition at line 38 of file staticTriangulation.cpp.

References __added_fill_ins, __elim_cliques, __elim_order, __node_2_max_prime_clique, __reverse_elim_order, _junction_tree_strategy, gum::JunctionTreeStrategy::setTriangulation(), and gum::NodeGraphPart::size().

43  :
44  Triangulation(domsizes),
45  _elimination_sequence_strategy(elimSeq.newFactory()),
46  _junction_tree_strategy(JTStrategy.newFactory()), __original_graph(theGraph),
47  __minimality_required(minimality) {
48  // for debugging purposes
49  GUM_CONSTRUCTOR(StaticTriangulation);
50 
51  // if the graph is not empty, resize several structures in order to speed-up
52  // their fillings.
53  if (theGraph != nullptr) {
54  __elim_order.resize(theGraph->size());
55  __reverse_elim_order.resize(theGraph->size());
56  __elim_cliques.resize(theGraph->size());
57  __node_2_max_prime_clique.resize(theGraph->size());
58  __added_fill_ins.resize(theGraph->size());
59  }
60 
61  // register the triangulation to its junction tree strategy
63  }
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 (...
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)
JunctionTreeStrategy * _junction_tree_strategy
the junction tree strategy used by the triangulation
NodeProperty< NodeId > __reverse_elim_order
the elimination order (access by NodeId)
std::vector< EdgeSet > __added_fill_ins
a vector containing the set of fill-ins added after each node elimination (used by recursive thinning...
virtual void setTriangulation(StaticTriangulation *triangulation)=0
assigns the triangulation to the junction tree strategy
NodeProperty< NodeSet > __elim_cliques
the cliques formed by the elimination of the nodes
Triangulation()
default constructor
bool __minimality_required
indicates whether the triangulation must be minimal
std::vector< NodeId > __elim_order
the order in which nodes are eliminated by the algorithm
StaticTriangulation(const EliminationSequenceStrategy &elimSeq, const JunctionTreeStrategy &JTStrategy, bool minimality=false)
default constructor: without any graph
+ Here is the call graph for this function:

◆ StaticTriangulation() [3/4]

gum::StaticTriangulation::StaticTriangulation ( const StaticTriangulation from)
protected

forbid copy constructor except in newfactory

Definition at line 81 of file staticTriangulation.cpp.

References __junction_tree, _elimination_sequence_strategy, _junction_tree_strategy, gum::JunctionTreeStrategy::copyFactory(), gum::EliminationSequenceStrategy::copyFactory(), and gum::JunctionTreeStrategy::junctionTree().

81  :
82  Triangulation(from), __original_graph(from.__original_graph),
83  __triangulated_graph(from.__triangulated_graph), __fill_ins(from.__fill_ins),
84  __elim_order(from.__elim_order),
85  __reverse_elim_order(from.__reverse_elim_order),
86  __elim_cliques(from.__elim_cliques), __elim_tree(from.__elim_tree),
87  __max_prime_junction_tree(from.__max_prime_junction_tree),
88  __node_2_max_prime_clique(from.__node_2_max_prime_clique),
89  __has_triangulation(from.__has_triangulation),
90  __has_triangulated_graph(from.__has_triangulated_graph),
91  __has_elimination_tree(from.__has_elimination_tree),
92  __has_junction_tree(from.__has_junction_tree),
93  __has_max_prime_junction_tree(from.__has_max_prime_junction_tree),
94  __has_fill_ins(from.__has_fill_ins),
95  __minimality_required(from.__minimality_required),
96  __added_fill_ins(from.__added_fill_ins),
97  __we_want_fill_ins(from.__we_want_fill_ins) {
98  // copy the strategies
100  from._elimination_sequence_strategy->copyFactory();
101  _junction_tree_strategy = from._junction_tree_strategy->copyFactory(this);
102 
103  // if from has a junction tree, copy it
104  if (from.__junction_tree != nullptr) {
106  }
107 
108  // for debugging purposes
109  GUM_CONS_CPY(StaticTriangulation);
110  }
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 (...
bool __has_max_prime_junction_tree
indicates whether a maximal prime subgraph junction tree has been constructed
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)
bool __has_triangulated_graph
a boolean indicating whether we have constructed the triangulated graph
JunctionTreeStrategy * _junction_tree_strategy
the junction tree strategy used by the triangulation
UndiGraph __triangulated_graph
the triangulated graph
NodeProperty< NodeId > __reverse_elim_order
the elimination order (access by NodeId)
std::vector< EdgeSet > __added_fill_ins
a vector containing the set of fill-ins added after each node elimination (used by recursive thinning...
bool __has_triangulation
a boolean indicating whether we have parformed a triangulation
virtual JunctionTreeStrategy * copyFactory(StaticTriangulation *triangulation=nullptr) const =0
virtual copy constructor
bool __has_junction_tree
a boolean indicating whether the junction tree has been constructed
CliqueGraph __max_prime_junction_tree
the maximal prime subgraph junction tree computed from the junction tree
NodeProperty< NodeSet > __elim_cliques
the cliques formed by the elimination of the nodes
Triangulation()
default constructor
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
const CliqueGraph * __junction_tree
the junction tree computed by the algorithm
bool __has_elimination_tree
a boolean indicating whether the elimination tree has been computed
EdgeSet __fill_ins
the fill-ins added during the whole triangulation process
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
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
+ Here is the call graph for this function:

◆ StaticTriangulation() [4/4]

gum::StaticTriangulation::StaticTriangulation ( StaticTriangulation &&  from)
protected

forbid move constructor except in children's constructors

Definition at line 113 of file staticTriangulation.cpp.

References __junction_tree, _junction_tree_strategy, gum::JunctionTreeStrategy::junctionTree(), and gum::JunctionTreeStrategy::moveTriangulation().

113  :
114  Triangulation(std::move(from)),
115  _elimination_sequence_strategy(from._elimination_sequence_strategy),
116  _junction_tree_strategy(from._junction_tree_strategy),
117  __original_graph(from.__original_graph),
118  __triangulated_graph(std::move(from.__triangulated_graph)),
119  __fill_ins(std::move(from.__fill_ins)),
120  __elim_order(std::move(from.__elim_order)),
121  __reverse_elim_order(std::move(from.__reverse_elim_order)),
122  __elim_cliques(std::move(from.__elim_cliques)),
123  __elim_tree(std::move(from.__elim_tree)),
124  __max_prime_junction_tree(std::move(from.__max_prime_junction_tree)),
125  __node_2_max_prime_clique(std::move(from.__node_2_max_prime_clique)),
126  __has_triangulation(from.__has_triangulation),
127  __has_triangulated_graph(from.__has_triangulated_graph),
128  __has_elimination_tree(from.__has_elimination_tree),
129  __has_junction_tree(from.__has_junction_tree),
130  __has_max_prime_junction_tree(from.__has_max_prime_junction_tree),
131  __has_fill_ins(from.__has_fill_ins),
132  __minimality_required(from.__minimality_required),
133  __added_fill_ins(std::move(from.__added_fill_ins)),
134  __we_want_fill_ins(from.__we_want_fill_ins) {
135  // move the factories contained in from
136  from._elimination_sequence_strategy = new DefaultEliminationSequenceStrategy;
137  from._junction_tree_strategy = new DefaultJunctionTreeStrategy;
139 
140  // if from has a junction tree, copy it
141  if (from.__junction_tree != nullptr) {
143  }
144 
145  // for debugging purposes
146  GUM_CONS_MOV(StaticTriangulation);
147  }
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 (...
bool __has_max_prime_junction_tree
indicates whether a maximal prime subgraph junction tree has been constructed
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)
bool __has_triangulated_graph
a boolean indicating whether we have constructed the triangulated graph
JunctionTreeStrategy * _junction_tree_strategy
the junction tree strategy used by the triangulation
UndiGraph __triangulated_graph
the triangulated graph
NodeProperty< NodeId > __reverse_elim_order
the elimination order (access by NodeId)
std::vector< EdgeSet > __added_fill_ins
a vector containing the set of fill-ins added after each node elimination (used by recursive thinning...
bool __has_triangulation
a boolean indicating whether we have parformed a triangulation
bool __has_junction_tree
a boolean indicating whether the junction tree has been constructed
CliqueGraph __max_prime_junction_tree
the maximal prime subgraph junction tree computed from the junction tree
NodeProperty< NodeSet > __elim_cliques
the cliques formed by the elimination of the nodes
Triangulation()
default constructor
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
const CliqueGraph * __junction_tree
the junction tree computed by the algorithm
bool __has_elimination_tree
a boolean indicating whether the elimination tree has been computed
EdgeSet __fill_ins
the fill-ins added during the whole triangulation process
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 ...
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
+ Here is the call graph for this function:

Member Function Documentation

◆ __computeEliminationTree()

void gum::StaticTriangulation::__computeEliminationTree ( )
private

returns an elimination tree from a triangulated graph

Definition at line 334 of file staticTriangulation.cpp.

References __elim_cliques, __elim_order, __elim_tree, __has_elimination_tree, __has_triangulation, __original_graph, __reverse_elim_order, __triangulate(), gum::CliqueGraph::addEdge(), gum::CliqueGraph::addNode(), gum::NodeGraphPart::bound(), and gum::CliqueGraph::clear().

334  {
335  // if there already exists an elimination tree, no need to compute it again
336  if (__has_elimination_tree) return;
337 
338  // if the graph is not triangulated, triangulate it
340 
341  // create the nodes of the elimination tree
342  __elim_tree.clear();
343 
344  Size size = Size(__elim_order.size());
345  for (NodeId i = NodeId(0); i < size; ++i)
347 
348  // create the edges of the elimination tree: join a node to the one in
349  // its clique that is eliminated first
350  for (NodeId i = NodeId(0); i < size; ++i) {
351  NodeId clique_i_creator = __elim_order[i];
352  const NodeSet& list_of_nodes = __elim_cliques[clique_i_creator];
353  Idx child = __original_graph->bound() + 1;
354 
355  for (const auto node : list_of_nodes) {
356  Idx it_elim_step = __reverse_elim_order[node];
357 
358  if ((node != clique_i_creator) && (child > it_elim_step))
359  child = it_elim_step;
360  }
361 
362  if (child <= __original_graph->bound()) {
363  // WARNING: here, we assume that the nodes of the elimination tree are
364  // indexed from 0 to n-1
365  __elim_tree.addEdge(i, child);
366  }
367  }
368 
369  __has_elimination_tree = true;
370  }
NodeId addNode(const NodeSet &clique)
adds a new clique to the graph
void __triangulate()
the function that performs the triangulation
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
const UndiGraph * __original_graph
a pointer to the (external) original graph (which will be triangulated)
virtual void clear()
removes all the cliques and separators from the graph (as well as their adjacent edges) ...
NodeProperty< NodeId > __reverse_elim_order
the elimination order (access by NodeId)
bool __has_triangulation
a boolean indicating whether we have parformed a triangulation
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
NodeId bound() const
returns a number n such that all node ids are strictly lower than n
bool __has_elimination_tree
a boolean indicating whether the elimination tree has been computed
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:45
std::vector< NodeId > __elim_order
the order in which nodes are eliminated by the algorithm
Size NodeId
Type for node ids.
Definition: graphElements.h:97
CliqueGraph __elim_tree
the elimination tree computed by the algorithm
+ Here is the call graph for this function:

◆ __computeMaxPrimeJunctionTree()

void gum::StaticTriangulation::__computeMaxPrimeJunctionTree ( )
private

computes the junction tree of the maximal prime subgraphs

Definition at line 407 of file staticTriangulation.cpp.

References __computeMaxPrimeMergings(), __has_junction_tree, __has_max_prime_junction_tree, __junction_tree, __max_prime_junction_tree, __node_2_max_prime_clique, _junction_tree_strategy, gum::CliqueGraph::addEdge(), gum::CliqueGraph::addNode(), gum::CliqueGraph::addToClique(), gum::CliqueGraph::clique(), gum::Set< Key, Alloc >::contains(), gum::JunctionTreeStrategy::createdCliques(), gum::EdgeGraphPart::edges(), gum::HashTable< Key, Val, Alloc >::insert(), junctionTree(), gum::NodeGraphPart::nodes(), and gum::NodeGraphPart::size().

407  {
408  // if there already exists a max prime junction tree, no need
409  // to recompute it
410  if (__has_max_prime_junction_tree) return;
411 
412  // if there is no junction tree, create it
414 
415  // the maximal prime subgraph join tree is created by aggregation of some
416  // cliques. More precisely, when the separator between 2 cliques is not
417  // complete in the original graph, then the two cliques must be merged.
418  // Create a hashtable indicating which clique has been absorbed by some
419  // other
420  // clique.
421  NodeProperty< NodeId > T_mpd_cliques(__junction_tree->size());
422 
423  for (const auto clik : __junction_tree->nodes())
424  T_mpd_cliques.insert(clik, clik);
425 
426  // parse all the separators of the junction tree and test those that are not
427  // complete in the orginal graph
428  std::vector< Arc > merged_cliques;
429 
430  NodeSet mark;
431 
432  for (const auto clik : __junction_tree->nodes())
433  if (!mark.contains(clik))
434  __computeMaxPrimeMergings(clik, clik, merged_cliques, mark);
435 
436  // compute the transitive closure of merged_cliques. This one will contain
437  // pairs (X,Y) indicating that clique X must be merged with clique Y.
438  // Actually clique X will be inserted into clique Y.
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()];
442  }
443 
444  // now we can create the max prime junction tree. First, create the cliques
445  for (const auto& elt : T_mpd_cliques)
446  if (elt.first == elt.second)
448  __junction_tree->clique(elt.second));
449 
450  // add to the cliques previously created the nodes of the cliques that were
451  // merged into them
452  for (const auto& elt : T_mpd_cliques)
453  if (elt.first != elt.second)
454  for (const auto node : __junction_tree->clique(elt.first)) {
455  try {
456  __max_prime_junction_tree.addToClique(elt.second, node);
457  } catch (DuplicateElement&) {}
458  }
459 
460  // add the edges to the graph
461  for (const auto& edge : __junction_tree->edges()) {
462  NodeId node1 = T_mpd_cliques[edge.first()];
463  NodeId node2 = T_mpd_cliques[edge.second()];
464 
465  if (node1 != node2) {
466  try {
467  __max_prime_junction_tree.addEdge(node1, node2);
468  } catch (DuplicateElement&) {}
469  }
470  }
471 
472  // compute for each node which clique of the max prime junction tree was
473  // created by the elimination of the node
474  const NodeProperty< NodeId >& node_2_junction_clique =
476 
477  for (const auto& elt : node_2_junction_clique)
478  __node_2_max_prime_clique.insert(elt.first, T_mpd_cliques[elt.second]);
479 
481  }
const CliqueGraph & junctionTree()
returns a compatible junction tree
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 ...
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 (...
bool __has_max_prime_junction_tree
indicates whether a maximal prime subgraph junction tree has been constructed
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
Size size() const
alias for sizeNodes
JunctionTreeStrategy * _junction_tree_strategy
the junction tree strategy used by the triangulation
const EdgeSet & edges() const
returns the set of edges stored within the EdgeGraphPart
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
CliqueGraph __max_prime_junction_tree
the maximal prime subgraph junction tree computed from the junction tree
const NodeGraphPart & nodes() const
return *this as a NodeGraphPart
virtual void addEdge(const NodeId first, const NodeId second)
inserts a new edge between two cliques
const NodeSet & clique(const NodeId idClique) const
returns the set of nodes included into a given clique
const CliqueGraph * __junction_tree
the junction tree computed by the algorithm
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
Size NodeId
Type for node ids.
Definition: graphElements.h:97
+ Here is the call graph for this function:

◆ __computeMaxPrimeMergings()

void gum::StaticTriangulation::__computeMaxPrimeMergings ( const NodeId  node,
const NodeId  from,
std::vector< Arc > &  merged_cliques,
NodeSet mark 
) const
private

used for computing the junction tree of the maximal prime subgraphs

Definition at line 373 of file staticTriangulation.cpp.

References __junction_tree, __original_graph, gum::Set< Key, Alloc >::begin(), gum::Set< Key, Alloc >::end(), gum::EdgeGraphPart::existsEdge(), gum::EdgeGraphPart::neighbours(), and gum::CliqueGraph::separator().

Referenced by __computeMaxPrimeJunctionTree().

377  {
378  mark << node;
379 
380  for (const auto other_node : __junction_tree->neighbours(node))
381  if (other_node != from) {
382  const NodeSet& separator = __junction_tree->separator(node, other_node);
383  // check that the separator between node and other_node is complete
384  bool complete = true;
385 
386  for (auto iter_sep1 = separator.begin();
387  iter_sep1 != separator.end() && complete;
388  ++iter_sep1) {
389  auto iter_sep2 = iter_sep1;
390 
391  for (++iter_sep2; iter_sep2 != separator.end(); ++iter_sep2) {
392  if (!__original_graph->existsEdge(*iter_sep1, *iter_sep2)) {
393  complete = false;
394  break;
395  }
396  }
397  }
398 
399  // here complete indicates whether the separator is complete or not
400  if (!complete) merged_cliques.push_back(Arc(other_node, node));
401 
402  __computeMaxPrimeMergings(other_node, node, merged_cliques, mark);
403  }
404  }
const NodeSet & separator(const Edge &edge) const
returns the separator included in a given edge
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
const UndiGraph * __original_graph
a pointer to the (external) original graph (which will be triangulated)
const NodeSet & neighbours(const NodeId id) const
returns the set of edges adjacent to a given node
bool existsEdge(const Edge &edge) const
indicates whether a given edge exists
const CliqueGraph * __junction_tree
the junction tree computed by the algorithm
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
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __computeRecursiveThinning()

void gum::StaticTriangulation::__computeRecursiveThinning ( )
private

removes redondant fill-ins and compute proper elimination cliques and order

Definition at line 192 of file staticTriangulation.cpp.

References __added_fill_ins, __elim_cliques, __elim_order, __fill_ins, __has_fill_ins, __reverse_elim_order, __triangulated_graph, gum::Set< Key, Alloc >::erase(), gum::PriorityQueueImplementation< Val, Priority, Cmp, Alloc, Gen >::insert(), gum::Set< Key, Alloc >::insert(), gum::HashTable< Key, Val, Alloc >::insert(), and gum::NodeGraphPart::size().

Referenced by __triangulate().

192  {
193  // apply recursive thinning (fmint, see Kjaerulff (90), "triangulation of
194  // graphs - algorithms giving small total state space")
195  NodeId node1, node2;
196  bool incomplete;
197  std::vector< NodeId > adj;
198  EdgeSet T_prime;
199  NodeProperty< unsigned int > R(__triangulated_graph.size());
200 
201  for (const auto node : __triangulated_graph)
202  R.insert(node, 0);
203 
204  // the FMINT loop
205  if (__added_fill_ins.size() > 0) {
206  for (auto iter = __added_fill_ins.rbegin(); iter != __added_fill_ins.rend();
207  ++iter) {
208  if (iter->size()) {
209  // here apply MINT to T_i = __added_fill_ins[i]
210  EdgeSet& T = *iter;
211 
212  // compute R: by default, R is equal to all the nodes in the graph
213  // when R[...] >= j (see the j in the loop below), this means that the
214  // node belongs to an extremal edge in R
215  for (std::size_t k = 0; k < __elim_order.size(); ++k)
216  R[__elim_order[k]] =
217  0; // WARNING: do not replace R[__elim_order[k]] by
218 
219  // R[k] because the node ids may not be
220  // consecutive numbers
221 
222  // apply MINT while some edges can possibly be deleted
223  bool require_mint = true;
224 
225  for (unsigned int j = 0; require_mint; ++j) {
226  // find T' (it is equal to the edges (v,w) of T such that
227  // the intersection of adj(v,G) and adj(w,G) is complete and such
228  // that
229  // v and/or w belongs to an extremal node in R
230  for (const auto& edge : T) {
231  node1 = edge.first();
232  node2 = edge.second();
233 
234  // check if at least one extremal node belongs to R
235  if ((R[node1] < j) && (R[node2] < j)) continue;
236 
237  // check if the intersection of adj(v,G) and adj(w,G) is a
238  // complete subgraph
239  if (__triangulated_graph.neighbours(node2).size()
240  < __triangulated_graph.neighbours(node1).size()) {
241  NodeId tmp = node1;
242  node1 = node2;
243  node2 = tmp;
244  }
245 
246  incomplete = false;
247 
248  // find the nodes belonging to the intersection of adj(v,G)
249  // and adj(w,G)
250  for (const auto adjnode : __triangulated_graph.neighbours(node1))
251  if (__triangulated_graph.existsEdge(node2, adjnode))
252  adj.push_back(adjnode);
253 
254  // check if the intersection is complete
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])) {
258  incomplete = true;
259  break;
260  }
261  }
262  }
263 
264  adj.clear();
265 
266  if (!incomplete) {
267  T_prime.insert(edge);
268  R[node1] = j + 1;
269  R[node2] = j + 1;
270  }
271  }
272 
273  // compute the new value of T (i.e. T\T') and update the
274  // triangulated graph
275  for (const auto& edge : T_prime) {
276  T.erase(edge);
277  __triangulated_graph.eraseEdge(edge);
278 
279  if (__has_fill_ins) __fill_ins.erase(edge);
280  }
281 
282  if (T_prime.size() == 0) require_mint = false;
283 
284  T_prime.clear();
285  }
286  }
287  }
288  }
289 
290  // here, the recursive thinning has removed all the superfluous edges.
291  // Hence some cliques have been split and, as a result, the elimination
292  // order has changed. We should thus compute a new perfect ordering. To
293  // do so, we use a Maximal Cardinality Search: it has indeed the nice
294  // property that, when the graph is already triangulated, it finds a
295  // compatible order of elimination that does not require any edge addition
296 
297  // a structure storing the number of neighbours previously processed
298  PriorityQueue< NodeId, unsigned int, std::greater< unsigned int > >
299  numbered_neighbours(std::greater< unsigned int >(),
300  __triangulated_graph.size());
301 
302  for (Size i = 0; i < __elim_order.size(); ++i)
303  numbered_neighbours.insert(__elim_order[i], 0);
304 
305  // perform the maximum cardinality search
306  if (__elim_order.size() > 0) {
307  for (Size i = Size(__elim_order.size()); i >= 1; --i) {
308  NodeId ni = NodeId(i - 1);
309  NodeId node = numbered_neighbours.pop();
310  __elim_order[ni] = node;
311  __reverse_elim_order[node] = ni;
312 
313  for (const auto neighbour : __triangulated_graph.neighbours(node)) {
314  try {
315  numbered_neighbours.setPriority(
316  neighbour, 1 + numbered_neighbours.priority(neighbour));
317  } catch (NotFound&) {}
318  }
319  }
320  }
321 
322  // here the elimination order is ok. We now need to update the
323  // __elim_cliques
324  for (Size i = 0; i < __elim_order.size(); ++i) {
325  NodeSet& cliques = __elim_cliques.insert(__elim_order[i], NodeSet()).second;
326  cliques << __elim_order[i];
327 
328  for (const auto neighbour : __triangulated_graph.neighbours(__elim_order[i]))
329  if (__reverse_elim_order[neighbour] > i) cliques << neighbour;
330  }
331  }
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
Size size() const
alias for sizeNodes
void erase(const Key &k)
Erases an element from the set.
Definition: set_tpl.h:653
UndiGraph __triangulated_graph
the triangulated graph
NodeProperty< NodeId > __reverse_elim_order
the elimination order (access by NodeId)
std::vector< EdgeSet > __added_fill_ins
a vector containing the set of fill-ins added after each node elimination (used by recursive thinning...
Set< Edge > EdgeSet
Some typdefs and define for shortcuts ...
NodeProperty< NodeSet > __elim_cliques
the cliques formed by the elimination of the nodes
bool __has_fill_ins
indicates whether we actually computed fill-ins
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:45
EdgeSet __fill_ins
the fill-ins added during the whole triangulation process
std::vector< NodeId > __elim_order
the order in which nodes are eliminated by the algorithm
Size NodeId
Type for node ids.
Definition: graphElements.h:97
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:610
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __triangulate()

void gum::StaticTriangulation::__triangulate ( )
private

the function that performs the triangulation

Definition at line 551 of file staticTriangulation.cpp.

References __added_fill_ins, __computeRecursiveThinning(), __elim_cliques, __elim_order, __fill_ins, __has_fill_ins, __has_triangulated_graph, __has_triangulation, __minimality_required, __original_graph, __reverse_elim_order, __triangulated_graph, __we_want_fill_ins, _elimination_sequence_strategy, _initTriangulation(), gum::UndiGraph::addEdge(), gum::EliminationSequenceStrategy::askFillIns(), gum::Set< Key, Alloc >::begin(), gum::EliminationSequenceStrategy::eliminationUpdate(), gum::Set< Key, Alloc >::end(), gum::UndiGraph::eraseNode(), gum::EdgeGraphPart::existsEdge(), gum::Set< Key, Alloc >::insert(), gum::EdgeGraphPart::neighbours(), gum::EliminationSequenceStrategy::nextNodeToEliminate(), gum::EliminationSequenceStrategy::providesFillIns(), gum::EliminationSequenceStrategy::providesGraphUpdate(), gum::Set< Key, Alloc >::resize(), gum::NodeGraphPart::size(), and gum::Set< Key, Alloc >::size().

Referenced by __computeEliminationTree(), fillIns(), and triangulatedGraph().

551  {
552  // if the graph is already triangulated, no need to triangulate it again
553  if (__has_triangulation) return;
554 
555  // copy the graph to be triangulated, so that we can modify it
556  UndiGraph tmp_graph = *__original_graph;
557 
558  _initTriangulation(tmp_graph);
560 
561  // if we are to do recursive thinning, we will have to add fill-ins to the
562  // triangulated graph each time we eliminate a node. Hence, we shall
563  // initialize the triangulated graph by a copy of the original graph
564  if (__minimality_required) {
567  }
568 
569  // perform the triangulation
570  NodeId removable_node = 0;
571 
572  for (unsigned int nb_elim = 0; tmp_graph.size() != 0; ++nb_elim) {
574 
575  // when minimality is not required, i.e., we won't apply recursive
576  // thinning, the cliques sets can be computed
577  if (!__minimality_required) {
578  NodeSet& cliques = __elim_cliques.insert(removable_node, NodeSet()).second;
579  cliques.resize(tmp_graph.neighbours(removable_node).size() / 2);
580  cliques << removable_node;
581  for (const auto clik : tmp_graph.neighbours(removable_node))
582  cliques << clik;
583  } else {
584  // here recursive thinning will be applied, hence we need store the
585  // fill-ins added by the current node removal
586  EdgeSet& current_fill = __added_fill_ins[nb_elim];
587  NodeId node1, node2;
588 
589  const NodeSet& nei = tmp_graph.neighbours(removable_node);
590 
591  for (auto iter_edges1 = nei.begin(); iter_edges1 != nei.end();
592  ++iter_edges1) {
593  node1 = *iter_edges1;
594  auto iter_edges2 = iter_edges1;
595 
596  for (++iter_edges2; iter_edges2 != nei.end(); ++iter_edges2) {
597  node2 = *iter_edges2;
598  Edge edge(node1, node2);
599 
600  if (!tmp_graph.existsEdge(edge)) {
601  current_fill.insert(edge);
602  __triangulated_graph.addEdge(node1, node2);
603  }
604  }
605  }
606  }
607 
608  // if we want fill-ins but the elimination sequence strategy does not
609  // compute them, we shall compute them here
612  NodeId node1, node2;
613 
614  // add edges between removable_node's neighbours in order to create
615  // a clique
616  const NodeSet& nei = tmp_graph.neighbours(removable_node);
617 
618  for (auto iter_edges1 = nei.begin(); iter_edges1 != nei.end();
619  ++iter_edges1) {
620  node1 = *iter_edges1;
621  auto iter_edges2 = iter_edges1;
622 
623  for (++iter_edges2; iter_edges2 != nei.end(); ++iter_edges2) {
624  node2 = *iter_edges2;
625  Edge edge(node1, node2);
626 
627  if (!tmp_graph.existsEdge(edge)) { __fill_ins.insert(edge); }
628  }
629  }
630 
631  // delete removable_node and its adjacent edges
632  tmp_graph.eraseNode(removable_node);
633  }
634 
635  // inform the elimination sequence that we are actually removing
636  // removable_node (this enables, for instance, to update the weights of
637  // the nodes in the graph)
639 
641  NodeId node1, node2;
642 
643  const NodeSet& nei = tmp_graph.neighbours(removable_node);
644 
645  for (auto iter_edges1 = nei.begin(); iter_edges1 != nei.end();
646  ++iter_edges1) {
647  node1 = *iter_edges1;
648  auto iter_edges2 = iter_edges1;
649 
650  for (++iter_edges2; iter_edges2 != nei.end(); ++iter_edges2) {
651  node2 = *iter_edges2;
652  Edge edge(node1, node2);
653 
654  if (!tmp_graph.existsEdge(edge)) { tmp_graph.addEdge(node1, node2); }
655  }
656  }
657 
658  tmp_graph.eraseNode(removable_node);
659  }
660 
661  // update the elimination order
662  __elim_order[nb_elim] = removable_node;
663  __reverse_elim_order.insert(removable_node, nb_elim);
664  }
665 
666  // indicate whether we actually computed fill-ins
668 
669  // if minimality is required, remove the redondant edges
671 
672  __has_triangulation = true;
673  }
virtual void eliminationUpdate(const NodeId node)
performs all the graph/fill-ins updates provided (if any)
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
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
virtual void addEdge(const NodeId first, const NodeId second)
insert a new edge into the undirected graph
Definition: undiGraph_inl.h:32
bool __has_triangulated_graph
a boolean indicating whether we have constructed the triangulated graph
UndiGraph __triangulated_graph
the triangulated graph
NodeProperty< NodeId > __reverse_elim_order
the elimination order (access by NodeId)
std::vector< EdgeSet > __added_fill_ins
a vector containing the set of fill-ins added after each node elimination (used by recursive thinning...
Set< Edge > EdgeSet
Some typdefs and define for shortcuts ...
bool __has_triangulation
a boolean indicating whether we have parformed a triangulation
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
NodeProperty< NodeSet > __elim_cliques
the cliques formed by the elimination of the nodes
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
EdgeSet __fill_ins
the fill-ins added during the whole triangulation process
void __computeRecursiveThinning()
removes redondant fill-ins and compute proper elimination cliques and order
std::vector< NodeId > __elim_order
the order in which nodes are eliminated by the algorithm
Size NodeId
Type for node ids.
Definition: graphElements.h:97
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:610
virtual bool providesFillIns() const =0
indicates whether the fill-ins generated by the eliminated nodes, if needed, will be computed by the ...
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 ...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _initTriangulation()

void gum::StaticTriangulation::_initTriangulation ( UndiGraph graph)
protectedvirtual

the function called to initialize the triangulation process

This function is called when the triangulation process starts and is used to initialize the elimination sequence strategy. Actually, the graph that is modified by the triangulation algorithm is a copy of the original graph, and this copy needs be known by the elimination sequence strategy. _initTriangulation is used to transmit this knowledge to the elimination sequence (through method setGraph of the elimination sequence class).

Parameters
graphthe very graph that is triangulated (this is a copy of __original_graph)

Reimplemented in gum::PartialOrderedTriangulation, and gum::OrderedTriangulation.

Definition at line 730 of file staticTriangulation.cpp.

References gum::Triangulation::_domain_sizes, _elimination_sequence_strategy, and gum::EliminationSequenceStrategy::setGraph().

Referenced by __triangulate().

730  {
732  }
EliminationSequenceStrategy * _elimination_sequence_strategy
the elimination sequence strategy used by the triangulation
const NodeProperty< Size > * _domain_sizes
the domain sizes of the variables/nodes of the graph
virtual bool setGraph(UndiGraph *graph, const NodeProperty< Size > *dom_sizes)
sets a new graph to be triangulated
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ clear()

void gum::StaticTriangulation::clear ( )
virtual

reinitialize the graph to be triangulated to an empty graph

Implements gum::Triangulation.

Definition at line 162 of file staticTriangulation.cpp.

References __added_fill_ins, __elim_cliques, __elim_order, __elim_tree, __fill_ins, __has_elimination_tree, __has_fill_ins, __has_junction_tree, __has_max_prime_junction_tree, __has_triangulated_graph, __has_triangulation, __junction_tree, __max_prime_junction_tree, __node_2_max_prime_clique, __original_graph, __reverse_elim_order, __triangulated_graph, _elimination_sequence_strategy, _junction_tree_strategy, gum::JunctionTreeStrategy::clear(), gum::CliqueGraph::clear(), gum::EliminationSequenceStrategy::clear(), gum::UndiGraph::clear(), and gum::Set< Key, Alloc >::clear().

Referenced by setGraph().

162  {
163  // clear the factories
166 
167  // remove the current graphs
168  __original_graph = nullptr;
169  __junction_tree = nullptr;
171  __elim_tree.clear();
173  __elim_cliques.clear();
175 
176  // remove all fill-ins and orderings
177  __fill_ins.clear();
178  __added_fill_ins.clear();
179  __elim_order.clear();
180  __reverse_elim_order.clear();
181 
182  // indicates that the junction tree, the max prime tree, etc, are updated
183  __has_triangulation = true;
185  __has_elimination_tree = true;
186  __has_junction_tree = true;
188  __has_fill_ins = true;
189  }
virtual void clear()
clears the sequence (to prepare, for instance, a new elimination sequence)
virtual void clear()
removes all the nodes and edges from the graph
Definition: undiGraph_inl.h:40
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 (...
bool __has_max_prime_junction_tree
indicates whether a maximal prime subgraph junction tree has been constructed
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)
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
UndiGraph __triangulated_graph
the triangulated graph
NodeProperty< NodeId > __reverse_elim_order
the elimination order (access by NodeId)
std::vector< EdgeSet > __added_fill_ins
a vector containing the set of fill-ins added after each node elimination (used by recursive thinning...
bool __has_triangulation
a boolean indicating whether we have parformed a triangulation
virtual void clear()=0
resets the current junction tree strategy data structures
bool __has_junction_tree
a boolean indicating whether the junction tree has been constructed
CliqueGraph __max_prime_junction_tree
the maximal prime subgraph junction tree computed from the junction tree
NodeProperty< NodeSet > __elim_cliques
the cliques formed by the elimination of the nodes
bool __has_fill_ins
indicates whether we actually computed fill-ins
const CliqueGraph * __junction_tree
the junction tree computed by the algorithm
bool __has_elimination_tree
a boolean indicating whether the elimination tree has been computed
void clear()
Removes all the elements, if any, from the set.
Definition: set_tpl.h:372
EdgeSet __fill_ins
the fill-ins added during the whole triangulation process
std::vector< NodeId > __elim_order
the order in which nodes are eliminated by the algorithm
CliqueGraph __elim_tree
the elimination tree computed by the algorithm
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ copyFactory()

virtual StaticTriangulation* gum::StaticTriangulation::copyFactory ( ) const
pure virtual

virtual copy constructor

note that we return a pointer as it enables subclasses to return pointers to their types, not Triangulation pointers. See item 25 of the more effective C++.

Implements gum::Triangulation.

Implemented in gum::PartialOrderedTriangulation, gum::OrderedTriangulation, gum::DefaultTriangulation, and gum::UnconstrainedTriangulation.

◆ createdJunctionTreeClique()

NodeId gum::StaticTriangulation::createdJunctionTreeClique ( const NodeId  id)
virtual

returns the Id of the clique of the junction tree created by the elimination of a given node during the triangulation process

Implements gum::Triangulation.

◆ createdJunctionTreeCliques()

const NodeProperty< NodeId >& gum::StaticTriangulation::createdJunctionTreeCliques ( )
virtual

returns the Ids of the cliques of the junction tree created by the elimination of the nodes

Implements gum::Triangulation.

◆ createdMaxPrimeSubgraph()

NodeId gum::StaticTriangulation::createdMaxPrimeSubgraph ( const NodeId  id)
virtual

returns the Id of the maximal prime subgraph created by the elimination of a given node during the triangulation process

Implements gum::Triangulation.

◆ domainSizes()

const NodeProperty< Size >* gum::Triangulation::domainSizes ( ) const
inherited

returns the domain sizes of the variables of the graph to be triangulated

◆ eliminationOrder() [1/2]

◆ eliminationOrder() [2/2]

Idx gum::StaticTriangulation::eliminationOrder ( const NodeId  )
virtual

returns the index of a given node in the elimination order (0 = first node eliminated)

Implements gum::Triangulation.

◆ eliminationSequenceStrategy()

EliminationSequenceStrategy& gum::StaticTriangulation::eliminationSequenceStrategy ( ) const

returns the elimination sequence strategy used by the triangulation

◆ eliminationTree()

const CliqueGraph& gum::StaticTriangulation::eliminationTree ( )
virtual

returns the elimination tree of a compatible ordering

Implements gum::Triangulation.

Referenced by gum::DefaultJunctionTreeStrategy::__computeJunctionTree().

+ Here is the caller graph for this function:

◆ fillIns()

const EdgeSet & gum::StaticTriangulation::fillIns ( )
virtual

returns the fill-ins added by the triangulation algorithm

Implements gum::Triangulation.

Definition at line 676 of file staticTriangulation.cpp.

References __fill_ins, __has_fill_ins, __has_junction_tree, __has_triangulation, __junction_tree, __original_graph, __triangulate(), __we_want_fill_ins, _elimination_sequence_strategy, gum::CliqueGraph::clique(), gum::EdgeGraphPart::existsEdge(), gum::EliminationSequenceStrategy::fillIns(), gum::Set< Key, Alloc >::insert(), junctionTree(), gum::NodeGraphPart::nodes(), gum::EliminationSequenceStrategy::providesFillIns(), and gum::Set< Key, Alloc >::size().

676  {
677  // if we did not compute the triangulation yet, do it and commpute
678  // the fill-ins at the same time
679  if (!__has_triangulation) {
680  bool want_fill_ins = __we_want_fill_ins;
681  __we_want_fill_ins = true;
682  __triangulate();
683  __we_want_fill_ins = want_fill_ins;
684  __has_fill_ins = true;
685  }
686 
687  // here, we already computed a triangulation and we already computed
688  // the fill-ins, so return them
689  if (__has_fill_ins) {
692  else
693  return __fill_ins;
694  } else {
695  // ok, here, we shall compute the fill-ins as they were not precomputed
696  if (!__original_graph) return __fill_ins;
697 
698  // just in case, be sure that the junction tree has been constructed
700 
701  for (const auto clik_id : __junction_tree->nodes()) {
702  // for each clique, add the edges necessary to make it complete
703  const NodeSet& clique = __junction_tree->clique(clik_id);
704  std::vector< NodeId > clique_nodes(clique.size());
705  unsigned int i = 0;
706 
707  for (const auto node : clique) {
708  clique_nodes[i] = node;
709  i += 1;
710  }
711 
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]);
715 
716  if (!__original_graph->existsEdge(edge)) {
717  try {
718  __fill_ins.insert(edge);
719  } catch (DuplicateElement&) {}
720  }
721  }
722  }
723  }
724 
725  return __fill_ins;
726  }
727  }
const CliqueGraph & junctionTree()
returns a compatible junction tree
virtual const EdgeSet & fillIns()
in case fill-ins are provided, this function returns the fill-ins due to all the nodes eliminated so ...
void __triangulate()
the function that performs the triangulation
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
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)
bool __has_triangulation
a boolean indicating whether we have parformed a triangulation
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
const NodeGraphPart & nodes() const
return *this as a NodeGraphPart
const NodeSet & clique(const NodeId idClique) const
returns the set of nodes included into a given clique
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
const CliqueGraph * __junction_tree
the junction tree computed by the algorithm
EdgeSet __fill_ins
the fill-ins added during the whole triangulation process
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:610
virtual bool providesFillIns() const =0
indicates whether the fill-ins generated by the eliminated nodes, if needed, will be computed by the ...
+ Here is the call graph for this function:

◆ isMinimalityRequired()

virtual bool gum::StaticTriangulation::isMinimalityRequired ( ) const
finalvirtual

indicates wether minimality is required

◆ junctionTree()

const CliqueGraph& gum::StaticTriangulation::junctionTree ( )
virtual

returns a compatible junction tree

Implements gum::Triangulation.

Referenced by __computeMaxPrimeJunctionTree(), fillIns(), and triangulatedGraph().

+ Here is the caller graph for this function:

◆ junctionTreeStrategy()

JunctionTreeStrategy& gum::StaticTriangulation::junctionTreeStrategy ( ) const

returns the junction tree strategy used by the triangulation

◆ maxLog10CliqueDomainSize()

double gum::Triangulation::maxLog10CliqueDomainSize ( )
inherited

returns the max of log10DomainSize of the cliques in the junction tree.

This is usefull for instance to estimate the complexity (both in space and in time) of the inference that will use the junction tree.

This method is not 'const' since it can be called before building any junction tree and hence it needs to build it...

Definition at line 67 of file triangulation.cpp.

References gum::Triangulation::_domain_sizes, and gum::Triangulation::junctionTree().

Referenced by gum::MaxInducedWidthMCBayesNetGenerator< GUM_SCALAR, ICPTGenerator, ICPTDisturber >::__checkConditions().

67  {
68  double res = 0.0;
69  double dSize;
70  const JunctionTree& jt = junctionTree(); // here, the fact that we get
71  // a junction tree ensures that _domain_sizes is different from nullptr
72 
73  for (const NodeId cl : jt) {
74  dSize = 0.0;
75 
76  for (const auto node : jt.clique(cl))
77  dSize += std::log10((*_domain_sizes)[node]);
78 
79  if (res < dSize) res = dSize;
80  }
81 
82  return res;
83  }
const NodeProperty< Size > * _domain_sizes
the domain sizes of the variables/nodes of the graph
CliqueGraph JunctionTree
a junction tree is a clique graph satisfying the running intersection property and such that no cliqu...
Definition: cliqueGraph.h:299
virtual const CliqueGraph & junctionTree()=0
returns a compatible junction tree
Size NodeId
Type for node ids.
Definition: graphElements.h:97
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ maxPrimeSubgraphTree()

const CliqueGraph& gum::StaticTriangulation::maxPrimeSubgraphTree ( )
virtual

returns a junction tree of maximal prime subgraphs

Warning
Actually, the cliques of the junction tree are guarranteed to be maximal prime subgraph of the original graph that was triangulated only if the triangulation performed is minimal (in the sense that removing any edge in the triangulated graph results in a nontriangulated graph). This can be ensured by requiring minimality of the triangulation.

Implements gum::Triangulation.

◆ newFactory()

virtual StaticTriangulation* gum::StaticTriangulation::newFactory ( ) const
pure virtual

returns a fresh triangulation of the same type as the current object but over an empty graph

note that we return a pointer as it enables subclasses to return pointers to their types, not Triangulation pointers. See item 25 of the more effective C++.

Implements gum::Triangulation.

Implemented in gum::PartialOrderedTriangulation, gum::OrderedTriangulation, gum::DefaultTriangulation, and gum::UnconstrainedTriangulation.

◆ operator=()

StaticTriangulation& gum::StaticTriangulation::operator= ( const StaticTriangulation )
private

forbid copy operator

◆ originalGraph()

const UndiGraph* gum::StaticTriangulation::originalGraph ( ) const

returns the graph to be triangulated

Warning
if we have not set yet a graph, then originalGraph () will return a nullptr.

Referenced by gum::DefaultJunctionTreeStrategy::copyFactory().

+ Here is the caller graph for this function:

◆ reverseEliminationOrder()

const NodeProperty< NodeId >& gum::StaticTriangulation::reverseEliminationOrder ( )

returns a table indicating, for each node, at which step it was deleted by the triangulation process

◆ setFillIns()

void gum::StaticTriangulation::setFillIns ( bool  )

sets/unsets the record of the fill-ins in the standard triangulation procedure

◆ setGraph()

void gum::StaticTriangulation::setGraph ( const UndiGraph graph,
const NodeProperty< Size > *  domsizes 
)
virtual

initialize the triangulation data structures for a new graph

Parameters
graphthe graph to be triangulated, i.e., the nodes of which will be eliminated
domsizesthe domain sizes of the nodes to be eliminated
Warning
Note that we allow domsizes to be defined over nodes/variables that do not belong to graph. These sizes will simply be ignored. However, it is compulsory that all the nodes of graph belong to dom_sizes
the graph is not copied but only referenced by the elimination sequence algorithm.

Implements gum::Triangulation.

Reimplemented in gum::PartialOrderedTriangulation, and gum::OrderedTriangulation.

Definition at line 523 of file staticTriangulation.cpp.

References __added_fill_ins, __elim_cliques, __elim_order, __has_elimination_tree, __has_fill_ins, __has_junction_tree, __has_max_prime_junction_tree, __has_triangulated_graph, __has_triangulation, __node_2_max_prime_clique, __original_graph, __reverse_elim_order, gum::Triangulation::_domain_sizes, clear(), and gum::NodeGraphPart::size().

Referenced by gum::OrderedTriangulation::setGraph(), and gum::PartialOrderedTriangulation::setGraph().

524  {
525  // remove the old graph
526  clear();
527 
528  if (graph != nullptr) {
529  // prepare the size of the data for the new graph
530  __elim_order.resize(graph->size());
531  __reverse_elim_order.resize(graph->size());
532  __elim_cliques.resize(graph->size());
533  __added_fill_ins.resize(graph->size());
534  __node_2_max_prime_clique.resize(graph->size());
535  }
536 
537  // keep track of the variables passed in argument
538  __original_graph = graph;
539  _domain_sizes = domsizes;
540 
541  // indicate that no triangulation was performed for this graph
542  __has_triangulation = false;
543  __has_triangulated_graph = false;
544  __has_elimination_tree = false;
545  __has_junction_tree = false;
547  __has_fill_ins = false;
548  }
void clear()
reinitialize the graph to be triangulated to an empty graph
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 (...
bool __has_max_prime_junction_tree
indicates whether a maximal prime subgraph junction tree has been constructed
const UndiGraph * __original_graph
a pointer to the (external) original graph (which will be triangulated)
bool __has_triangulated_graph
a boolean indicating whether we have constructed the triangulated graph
NodeProperty< NodeId > __reverse_elim_order
the elimination order (access by NodeId)
std::vector< EdgeSet > __added_fill_ins
a vector containing the set of fill-ins added after each node elimination (used by recursive thinning...
const NodeProperty< Size > * _domain_sizes
the domain sizes of the variables/nodes of the graph
bool __has_triangulation
a boolean indicating whether we have parformed a triangulation
bool __has_junction_tree
a boolean indicating whether the junction tree has been constructed
NodeProperty< NodeSet > __elim_cliques
the cliques formed by the elimination of the nodes
bool __has_fill_ins
indicates whether we actually computed fill-ins
bool __has_elimination_tree
a boolean indicating whether the elimination tree has been computed
std::vector< NodeId > __elim_order
the order in which nodes are eliminated by the algorithm
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setMinimalRequirement()

void gum::StaticTriangulation::setMinimalRequirement ( bool  )

sets/unset the minimality requirement

◆ triangulatedGraph()

const UndiGraph & gum::StaticTriangulation::triangulatedGraph ( )
virtual

returns the triangulated graph

Implements gum::Triangulation.

Definition at line 484 of file staticTriangulation.cpp.

References __has_junction_tree, __has_triangulated_graph, __has_triangulation, __junction_tree, __original_graph, __triangulate(), __triangulated_graph, gum::UndiGraph::addEdge(), junctionTree(), and gum::Set< Key, Alloc >::size().

484  {
486 
487  // if we did not construct the triangulated graph during the triangulation,
488  // that is, we just constructed the junction tree, we shall construct it now
490  // just in case, be sure that the junction tree has been constructed
492 
493  // copy the original graph
495 
496  for (const auto clik_id : *__junction_tree) {
497  // for each clique, add the edges necessary to make it complete
498  const NodeSet& clique = __junction_tree->clique(clik_id);
499  std::vector< NodeId > clique_nodes(clique.size());
500  unsigned int i = 0;
501 
502  for (const auto node : clique) {
503  clique_nodes[i] = node;
504  i += 1;
505  }
506 
507  for (i = 0; i < clique_nodes.size(); ++i) {
508  for (unsigned int j = i + 1; j < clique_nodes.size(); ++j) {
509  try {
510  __triangulated_graph.addEdge(clique_nodes[i], clique_nodes[j]);
511  } catch (DuplicateElement&) {}
512  }
513  }
514  }
515 
517  }
518 
519  return __triangulated_graph;
520  }
const CliqueGraph & junctionTree()
returns a compatible junction tree
void __triangulate()
the function that performs the triangulation
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
const UndiGraph * __original_graph
a pointer to the (external) original graph (which will be triangulated)
virtual void addEdge(const NodeId first, const NodeId second)
insert a new edge into the undirected graph
Definition: undiGraph_inl.h:32
bool __has_triangulated_graph
a boolean indicating whether we have constructed the triangulated graph
UndiGraph __triangulated_graph
the triangulated graph
bool __has_triangulation
a boolean indicating whether we have parformed a triangulation
bool __has_junction_tree
a boolean indicating whether the junction tree has been constructed
const CliqueGraph * __junction_tree
the junction tree computed by the algorithm
+ Here is the call graph for this function:

Member Data Documentation

◆ __added_fill_ins

std::vector< EdgeSet > gum::StaticTriangulation::__added_fill_ins
private

a vector containing the set of fill-ins added after each node elimination (used by recursive thinning)

Definition at line 293 of file staticTriangulation.h.

Referenced by __computeRecursiveThinning(), __triangulate(), clear(), setGraph(), and StaticTriangulation().

◆ __elim_cliques

NodeProperty< NodeSet > gum::StaticTriangulation::__elim_cliques
private

the cliques formed by the elimination of the nodes

Definition at line 251 of file staticTriangulation.h.

Referenced by __computeEliminationTree(), __computeRecursiveThinning(), __triangulate(), clear(), setGraph(), and StaticTriangulation().

◆ __elim_order

std::vector< NodeId > gum::StaticTriangulation::__elim_order
private

the order in which nodes are eliminated by the algorithm

Definition at line 245 of file staticTriangulation.h.

Referenced by __computeEliminationTree(), __computeRecursiveThinning(), __triangulate(), clear(), setGraph(), and StaticTriangulation().

◆ __elim_tree

CliqueGraph gum::StaticTriangulation::__elim_tree
private

the elimination tree computed by the algorithm

Definition at line 254 of file staticTriangulation.h.

Referenced by __computeEliminationTree(), and clear().

◆ __fill_ins

EdgeSet gum::StaticTriangulation::__fill_ins
private

the fill-ins added during the whole triangulation process

Definition at line 242 of file staticTriangulation.h.

Referenced by __computeRecursiveThinning(), __triangulate(), clear(), and fillIns().

◆ __has_elimination_tree

bool gum::StaticTriangulation::__has_elimination_tree {false}
private

a boolean indicating whether the elimination tree has been computed

Definition at line 276 of file staticTriangulation.h.

Referenced by __computeEliminationTree(), clear(), and setGraph().

◆ __has_fill_ins

bool gum::StaticTriangulation::__has_fill_ins {false}
private

indicates whether we actually computed fill-ins

Definition at line 286 of file staticTriangulation.h.

Referenced by __computeRecursiveThinning(), __triangulate(), clear(), fillIns(), and setGraph().

◆ __has_junction_tree

bool gum::StaticTriangulation::__has_junction_tree {false}
private

a boolean indicating whether the junction tree has been constructed

Definition at line 279 of file staticTriangulation.h.

Referenced by __computeMaxPrimeJunctionTree(), clear(), fillIns(), setGraph(), and triangulatedGraph().

◆ __has_max_prime_junction_tree

bool gum::StaticTriangulation::__has_max_prime_junction_tree {false}
private

indicates whether a maximal prime subgraph junction tree has been constructed

Definition at line 283 of file staticTriangulation.h.

Referenced by __computeMaxPrimeJunctionTree(), clear(), and setGraph().

◆ __has_triangulated_graph

bool gum::StaticTriangulation::__has_triangulated_graph {false}
private

a boolean indicating whether we have constructed the triangulated graph

Definition at line 273 of file staticTriangulation.h.

Referenced by __triangulate(), clear(), setGraph(), and triangulatedGraph().

◆ __has_triangulation

bool gum::StaticTriangulation::__has_triangulation {false}
private

a boolean indicating whether we have parformed a triangulation

Definition at line 270 of file staticTriangulation.h.

Referenced by __computeEliminationTree(), __triangulate(), clear(), fillIns(), setGraph(), and triangulatedGraph().

◆ __junction_tree

const CliqueGraph* gum::StaticTriangulation::__junction_tree {nullptr}
private

the junction tree computed by the algorithm

note that the junction tree is owned by the junctionTreeStrategy and, therefore, its deletion from memory is not handled by the static triangulation class.

Definition at line 260 of file staticTriangulation.h.

Referenced by __computeMaxPrimeJunctionTree(), __computeMaxPrimeMergings(), clear(), fillIns(), StaticTriangulation(), and triangulatedGraph().

◆ __max_prime_junction_tree

CliqueGraph gum::StaticTriangulation::__max_prime_junction_tree
private

the maximal prime subgraph junction tree computed from the junction tree

Definition at line 263 of file staticTriangulation.h.

Referenced by __computeMaxPrimeJunctionTree(), and clear().

◆ __minimality_required

bool gum::StaticTriangulation::__minimality_required {false}
private

indicates whether the triangulation must be minimal

Definition at line 289 of file staticTriangulation.h.

Referenced by __triangulate().

◆ __node_2_max_prime_clique

NodeProperty< NodeId > gum::StaticTriangulation::__node_2_max_prime_clique
private

indicates which clique of the max prime junction tree was created by the elmination of a given node (the key of the table)

Definition at line 267 of file staticTriangulation.h.

Referenced by __computeMaxPrimeJunctionTree(), clear(), setGraph(), and StaticTriangulation().

◆ __original_graph

const UndiGraph* gum::StaticTriangulation::__original_graph {nullptr}
private

a pointer to the (external) original graph (which will be triangulated)

Definition at line 236 of file staticTriangulation.h.

Referenced by __computeEliminationTree(), __computeMaxPrimeMergings(), __triangulate(), clear(), fillIns(), setGraph(), and triangulatedGraph().

◆ __reverse_elim_order

NodeProperty< NodeId > gum::StaticTriangulation::__reverse_elim_order
private

the elimination order (access by NodeId)

Definition at line 248 of file staticTriangulation.h.

Referenced by __computeEliminationTree(), __computeRecursiveThinning(), __triangulate(), clear(), setGraph(), and StaticTriangulation().

◆ __triangulated_graph

UndiGraph gum::StaticTriangulation::__triangulated_graph
private

the triangulated graph

Definition at line 239 of file staticTriangulation.h.

Referenced by __computeRecursiveThinning(), __triangulate(), clear(), and triangulatedGraph().

◆ __we_want_fill_ins

bool gum::StaticTriangulation::__we_want_fill_ins {false}
private

a boolean indicating if we want fill-ins list with the standard triangulation method

Definition at line 297 of file staticTriangulation.h.

Referenced by __triangulate(), and fillIns().

◆ _domain_sizes

const NodeProperty< Size >* gum::Triangulation::_domain_sizes {nullptr}
protectedinherited

◆ _elimination_sequence_strategy

◆ _junction_tree_strategy

JunctionTreeStrategy* gum::StaticTriangulation::_junction_tree_strategy {nullptr}
protected

The documentation for this class was generated from the following files: