aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
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

EliminationSequenceStrategyelimination_sequence_strategy_ {nullptr}
 the elimination sequence strategy used by the triangulation More...
 
JunctionTreeStrategyjunction_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 49 of file staticTriangulation.h.

Constructor & Destructor Documentation

◆ ~StaticTriangulation()

gum::StaticTriangulation::~StaticTriangulation ( )
virtual

destructor

Definition at line 142 of file staticTriangulation.cpp.

References gum::Set< Key, Alloc >::emplace().

142  {
143  // for debugging purposes
144  GUM_DESTRUCTOR(StaticTriangulation);
145 
148 
149  // no need to deallocate _original_graph_ nor _junction_tree_ because
150  // they are not owned by the static triangulation class
151  }
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
+ Here is the call graph for this function:

◆ 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 67 of file staticTriangulation.cpp.

References gum::Set< Key, Alloc >::emplace().

69  :
70  elimination_sequence_strategy_(elimSeq.newFactory()),
71  junction_tree_strategy_(JTStrategy.newFactory()), _minimality_required_(minimality) {
72  // for debugging purposes
73  GUM_CONSTRUCTOR(StaticTriangulation);
74 
75  // register the triangulation to its junction tree strategy
77  }
EliminationSequenceStrategy * elimination_sequence_strategy_
the elimination sequence strategy used by the triangulation
bool _minimality_required_
indicates whether the triangulation must be minimal
virtual void setTriangulation(StaticTriangulation *triangulation)=0
assigns the triangulation to the junction tree strategy
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
+ 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 40 of file staticTriangulation.cpp.

References gum::Set< Key, Alloc >::emplace().

44  :
45  Triangulation(domsizes),
46  elimination_sequence_strategy_(elimSeq.newFactory()),
47  junction_tree_strategy_(JTStrategy.newFactory()), _original_graph_(theGraph),
48  _minimality_required_(minimality) {
49  // for debugging purposes
50  GUM_CONSTRUCTOR(StaticTriangulation);
51 
52  // if the graph is not empty, resize several structures in order to speed-up
53  // their fillings.
54  if (theGraph != nullptr) {
55  _elim_order_.resize(theGraph->size());
56  _reverse_elim_order_.resize(theGraph->size());
57  _elim_cliques_.resize(theGraph->size());
58  _node_2_max_prime_clique_.resize(theGraph->size());
59  _added_fill_ins_.resize(theGraph->size());
60  }
61 
62  // register the triangulation to its junction tree strategy
64  }
EliminationSequenceStrategy * elimination_sequence_strategy_
the elimination sequence strategy used by the triangulation
bool _minimality_required_
indicates whether the triangulation must be minimal
std::vector< EdgeSet > _added_fill_ins_
a vector containing the set of fill-ins added after each node elimination (used by recursive thinning...
NodeProperty< NodeId > _reverse_elim_order_
the elimination order (access by NodeId)
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
std::vector< NodeId > _elim_order_
the order in which nodes are eliminated by the algorithm
Triangulation()
default constructor
JunctionTreeStrategy * junction_tree_strategy_
the junction tree strategy used by the triangulation
const UndiGraph * _original_graph_
a pointer to the (external) original graph (which will be triangulated)
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 (...
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 80 of file staticTriangulation.cpp.

References gum::Set< Key, Alloc >::emplace().

80  :
81  Triangulation(from), _original_graph_(from._original_graph_),
82  _triangulated_graph_(from._triangulated_graph_), _fill_ins_(from._fill_ins_),
83  _elim_order_(from._elim_order_), _reverse_elim_order_(from._reverse_elim_order_),
84  _elim_cliques_(from._elim_cliques_), _elim_tree_(from._elim_tree_),
85  _max_prime_junction_tree_(from._max_prime_junction_tree_),
86  _node_2_max_prime_clique_(from._node_2_max_prime_clique_),
87  _has_triangulation_(from._has_triangulation_),
88  _has_triangulated_graph_(from._has_triangulated_graph_),
89  _has_elimination_tree_(from._has_elimination_tree_),
90  _has_junction_tree_(from._has_junction_tree_),
91  _has_max_prime_junction_tree_(from._has_max_prime_junction_tree_),
92  _has_fill_ins_(from._has_fill_ins_), _minimality_required_(from._minimality_required_),
93  _added_fill_ins_(from._added_fill_ins_), _we_want_fill_ins_(from._we_want_fill_ins_) {
94  // copy the strategies
95  elimination_sequence_strategy_ = from.elimination_sequence_strategy_->copyFactory();
96  junction_tree_strategy_ = from.junction_tree_strategy_->copyFactory(this);
97 
98  // if from has a junction tree, copy it
99  if (from._junction_tree_ != nullptr) {
101  }
102 
103  // for debugging purposes
104  GUM_CONS_CPY(StaticTriangulation);
105  }
bool _has_triangulated_graph_
a boolean indicating whether we have constructed the triangulated graph
bool _has_max_prime_junction_tree_
indicates whether a maximal prime subgraph junction tree has been constructed
CliqueGraph _elim_tree_
the elimination tree computed by the algorithm
virtual EliminationSequenceStrategy * copyFactory() const =0
virtual copy constructor
EliminationSequenceStrategy * elimination_sequence_strategy_
the elimination sequence strategy used by the triangulation
CliqueGraph _max_prime_junction_tree_
the maximal prime subgraph junction tree computed from the junction tree
bool _minimality_required_
indicates whether the triangulation must be minimal
std::vector< EdgeSet > _added_fill_ins_
a vector containing the set of fill-ins added after each node elimination (used by recursive thinning...
bool _we_want_fill_ins_
a boolean indicating if we want fill-ins list with the standard triangulation method ...
NodeProperty< NodeId > _reverse_elim_order_
the elimination order (access by NodeId)
EdgeSet _fill_ins_
the fill-ins added during the whole triangulation process
UndiGraph _triangulated_graph_
the triangulated graph
bool _has_junction_tree_
a boolean indicating whether the junction tree has been constructed
virtual JunctionTreeStrategy * copyFactory(StaticTriangulation *triangulation=nullptr) const =0
virtual copy constructor
bool _has_triangulation_
a boolean indicating whether we have parformed a triangulation
bool _has_fill_ins_
indicates whether we actually computed fill-ins
NodeProperty< NodeSet > _elim_cliques_
the cliques formed by the elimination of the nodes
const CliqueGraph * _junction_tree_
the junction tree computed by the algorithm
std::vector< NodeId > _elim_order_
the order in which nodes are eliminated by the algorithm
Triangulation()
default constructor
JunctionTreeStrategy * junction_tree_strategy_
the junction tree strategy used by the triangulation
const UndiGraph * _original_graph_
a pointer to the (external) original graph (which will be triangulated)
virtual const CliqueGraph & junctionTree()=0
returns the junction tree computed
bool _has_elimination_tree_
a boolean indicating whether the elimination tree has been computed
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 (...
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 108 of file staticTriangulation.cpp.

References gum::Set< Key, Alloc >::emplace().

108  :
109  Triangulation(std::move(from)),
110  elimination_sequence_strategy_(from.elimination_sequence_strategy_),
111  junction_tree_strategy_(from.junction_tree_strategy_),
112  _original_graph_(from._original_graph_),
113  _triangulated_graph_(std::move(from._triangulated_graph_)),
114  _fill_ins_(std::move(from._fill_ins_)), _elim_order_(std::move(from._elim_order_)),
115  _reverse_elim_order_(std::move(from._reverse_elim_order_)),
116  _elim_cliques_(std::move(from._elim_cliques_)), _elim_tree_(std::move(from._elim_tree_)),
117  _max_prime_junction_tree_(std::move(from._max_prime_junction_tree_)),
118  _node_2_max_prime_clique_(std::move(from._node_2_max_prime_clique_)),
119  _has_triangulation_(from._has_triangulation_),
120  _has_triangulated_graph_(from._has_triangulated_graph_),
121  _has_elimination_tree_(from._has_elimination_tree_),
122  _has_junction_tree_(from._has_junction_tree_),
123  _has_max_prime_junction_tree_(from._has_max_prime_junction_tree_),
124  _has_fill_ins_(from._has_fill_ins_), _minimality_required_(from._minimality_required_),
125  _added_fill_ins_(std::move(from._added_fill_ins_)),
126  _we_want_fill_ins_(from._we_want_fill_ins_) {
127  // move the factories contained in from
128  from.elimination_sequence_strategy_ = new DefaultEliminationSequenceStrategy;
129  from.junction_tree_strategy_ = new DefaultJunctionTreeStrategy;
131 
132  // if from has a junction tree, copy it
133  if (from._junction_tree_ != nullptr) {
135  }
136 
137  // for debugging purposes
138  GUM_CONS_MOV(StaticTriangulation);
139  }
bool _has_triangulated_graph_
a boolean indicating whether we have constructed the triangulated graph
bool _has_max_prime_junction_tree_
indicates whether a maximal prime subgraph junction tree has been constructed
CliqueGraph _elim_tree_
the elimination tree computed by the algorithm
EliminationSequenceStrategy * elimination_sequence_strategy_
the elimination sequence strategy used by the triangulation
CliqueGraph _max_prime_junction_tree_
the maximal prime subgraph junction tree computed from the junction tree
bool _minimality_required_
indicates whether the triangulation must be minimal
std::vector< EdgeSet > _added_fill_ins_
a vector containing the set of fill-ins added after each node elimination (used by recursive thinning...
bool _we_want_fill_ins_
a boolean indicating if we want fill-ins list with the standard triangulation method ...
NodeProperty< NodeId > _reverse_elim_order_
the elimination order (access by NodeId)
EdgeSet _fill_ins_
the fill-ins added during the whole triangulation process
UndiGraph _triangulated_graph_
the triangulated graph
bool _has_junction_tree_
a boolean indicating whether the junction tree has been constructed
bool _has_triangulation_
a boolean indicating whether we have parformed a triangulation
bool _has_fill_ins_
indicates whether we actually computed fill-ins
NodeProperty< NodeSet > _elim_cliques_
the cliques formed by the elimination of the nodes
const CliqueGraph * _junction_tree_
the junction tree computed by the algorithm
std::vector< NodeId > _elim_order_
the order in which nodes are eliminated by the algorithm
Triangulation()
default constructor
JunctionTreeStrategy * junction_tree_strategy_
the junction tree strategy used by the triangulation
const UndiGraph * _original_graph_
a pointer to the (external) original graph (which will be triangulated)
virtual const CliqueGraph & junctionTree()=0
returns the junction tree computed
virtual void moveTriangulation(StaticTriangulation *triangulation)
assigns a new triangulation to the junction tree strategy during a move construction ...
bool _has_elimination_tree_
a boolean indicating whether the elimination tree has been computed
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 (...
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 322 of file staticTriangulation.cpp.

References gum::Set< Key, Alloc >::emplace().

322  {
323  // if there already exists an elimination tree, no need to compute it again
324  if (_has_elimination_tree_) return;
325 
326  // if the graph is not triangulated, triangulate it
328 
329  // create the nodes of the elimination tree
330  _elim_tree_.clear();
331 
332  Size size = Size(_elim_order_.size());
333  for (NodeId i = NodeId(0); i < size; ++i)
335 
336  // create the edges of the elimination tree: join a node to the one in
337  // its clique that is eliminated first
338  for (NodeId i = NodeId(0); i < size; ++i) {
339  NodeId clique_i_creator = _elim_order_[i];
340  const NodeSet& list_of_nodes = _elim_cliques_[clique_i_creator];
341  Idx child = _original_graph_->bound() + 1;
342 
343  for (const auto node: list_of_nodes) {
344  Idx it_elim_step = _reverse_elim_order_[node];
345 
346  if ((node != clique_i_creator) && (child > it_elim_step)) child = it_elim_step;
347  }
348 
349  if (child <= _original_graph_->bound()) {
350  // WARNING: here, we assume that the nodes of the elimination tree are
351  // indexed from 0 to n-1
352  _elim_tree_.addEdge(i, child);
353  }
354  }
355 
356  _has_elimination_tree_ = true;
357  }
NodeId addNode(const NodeSet &clique)
adds a new clique to the graph
CliqueGraph _elim_tree_
the elimination tree computed by the algorithm
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
void _triangulate_()
the function that performs the triangulation
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
NodeProperty< NodeSet > _elim_cliques_
the cliques formed by the elimination of the nodes
virtual void addEdge(const NodeId first, const NodeId second)
inserts a new edge between two cliques
std::vector< NodeId > _elim_order_
the order in which nodes are eliminated by the algorithm
NodeId bound() const
returns a number n such that all node ids are strictly lower than n
const UndiGraph * _original_graph_
a pointer to the (external) original graph (which will be triangulated)
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:47
bool _has_elimination_tree_
a boolean indicating whether the elimination tree has been computed
Size NodeId
Type for node ids.
Definition: graphElements.h:97
+ 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 392 of file staticTriangulation.cpp.

References gum::Set< Key, Alloc >::emplace().

392  {
393  // if there already exists a max prime junction tree, no need
394  // to recompute it
395  if (_has_max_prime_junction_tree_) return;
396 
397  // if there is no junction tree, create it
399 
400  // the maximal prime subgraph join tree is created by aggregation of some
401  // cliques. More precisely, when the separator between 2 cliques is not
402  // complete in the original graph, then the two cliques must be merged.
403  // Create a hashtable indicating which clique has been absorbed by some
404  // other
405  // clique.
406  NodeProperty< NodeId > T_mpd_cliques(_junction_tree_->size());
407 
408  for (const auto clik: _junction_tree_->nodes())
409  T_mpd_cliques.insert(clik, clik);
410 
411  // parse all the separators of the junction tree and test those that are not
412  // complete in the orginal graph
413  std::vector< Arc > merged_cliques;
414 
415  NodeSet mark;
416 
417  for (const auto clik: _junction_tree_->nodes())
418  if (!mark.contains(clik)) _computeMaxPrimeMergings_(clik, clik, merged_cliques, mark);
419 
420  // compute the transitive closure of merged_cliques. This one will contain
421  // pairs (X,Y) indicating that clique X must be merged with clique Y.
422  // Actually clique X will be inserted into clique Y.
423  for (unsigned int i = 0; i < merged_cliques.size(); ++i) {
424  T_mpd_cliques[merged_cliques[i].tail()] = T_mpd_cliques[merged_cliques[i].head()];
425  }
426 
427  // now we can create the max prime junction tree. First, create the cliques
428  for (const auto& elt: T_mpd_cliques)
429  if (elt.first == elt.second)
430  _max_prime_junction_tree_.addNode(elt.second, _junction_tree_->clique(elt.second));
431 
432  // add to the cliques previously created the nodes of the cliques that were
433  // merged into them
434  for (const auto& elt: T_mpd_cliques)
435  if (elt.first != elt.second)
436  for (const auto node: _junction_tree_->clique(elt.first)) {
437  try {
438  _max_prime_junction_tree_.addToClique(elt.second, node);
439  } catch (DuplicateElement&) {}
440  }
441 
442  // add the edges to the graph
443  for (const auto& edge: _junction_tree_->edges()) {
444  NodeId node1 = T_mpd_cliques[edge.first()];
445  NodeId node2 = T_mpd_cliques[edge.second()];
446 
447  if (node1 != node2) {
448  try {
449  _max_prime_junction_tree_.addEdge(node1, node2);
450  } catch (DuplicateElement&) {}
451  }
452  }
453 
454  // compute for each node which clique of the max prime junction tree was
455  // created by the elimination of the node
456  const NodeProperty< NodeId >& node_2_junction_clique
458 
459  for (const auto& elt: node_2_junction_clique)
460  _node_2_max_prime_clique_.insert(elt.first, T_mpd_cliques[elt.second]);
461 
463  }
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 ...
bool _has_max_prime_junction_tree_
indicates whether a maximal prime subgraph junction tree has been constructed
CliqueGraph _max_prime_junction_tree_
the maximal prime subgraph junction tree computed from the junction tree
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
Size size() const
alias for sizeNodes
bool _has_junction_tree_
a boolean indicating whether the junction tree has been constructed
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
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
const NodeGraphPart & nodes() const
return *this as a NodeGraphPart
const CliqueGraph * _junction_tree_
the junction tree computed by the algorithm
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
JunctionTreeStrategy * junction_tree_strategy_
the junction tree strategy used by the triangulation
Size NodeId
Type for node ids.
Definition: graphElements.h:97
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 (...
+ 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 360 of file staticTriangulation.cpp.

References gum::Set< Key, Alloc >::emplace().

363  {
364  mark << node;
365 
366  for (const auto other_node: _junction_tree_->neighbours(node))
367  if (other_node != from) {
368  const NodeSet& separator = _junction_tree_->separator(node, other_node);
369  // check that the separator between node and other_node is complete
370  bool complete = true;
371 
372  for (auto iter_sep1 = separator.begin(); iter_sep1 != separator.end() && complete;
373  ++iter_sep1) {
374  auto iter_sep2 = iter_sep1;
375 
376  for (++iter_sep2; iter_sep2 != separator.end(); ++iter_sep2) {
377  if (!_original_graph_->existsEdge(*iter_sep1, *iter_sep2)) {
378  complete = false;
379  break;
380  }
381  }
382  }
383 
384  // here complete indicates whether the separator is complete or not
385  if (!complete) merged_cliques.push_back(Arc(other_node, node));
386 
387  _computeMaxPrimeMergings_(other_node, node, merged_cliques, mark);
388  }
389  }
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 NodeSet & neighbours(const NodeId id) const
returns the set of node neighbours to a given node
bool existsEdge(const Edge &edge) const
indicates whether a given edge exists
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
const CliqueGraph * _junction_tree_
the junction tree computed by the algorithm
const UndiGraph * _original_graph_
a pointer to the (external) original graph (which will be triangulated)
+ Here is the call graph for this function:

◆ _computeRecursiveThinning_()

void gum::StaticTriangulation::_computeRecursiveThinning_ ( )
private

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

Definition at line 184 of file staticTriangulation.cpp.

References gum::Set< Key, Alloc >::emplace().

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

◆ _triangulate_()

void gum::StaticTriangulation::_triangulate_ ( )
private

the function that performs the triangulation

Definition at line 532 of file staticTriangulation.cpp.

References gum::Set< Key, Alloc >::emplace().

532  {
533  // if the graph is already triangulated, no need to triangulate it again
534  if (_has_triangulation_) return;
535 
536  // copy the graph to be triangulated, so that we can modify it
537  UndiGraph tmp_graph = *_original_graph_;
538 
539  initTriangulation_(tmp_graph);
541 
542  // if we are to do recursive thinning, we will have to add fill-ins to the
543  // triangulated graph each time we eliminate a node. Hence, we shall
544  // initialize the triangulated graph by a copy of the original graph
545  if (_minimality_required_) {
548  }
549 
550  // perform the triangulation
551  NodeId removable_node = 0;
552 
553  for (unsigned int nb_elim = 0; tmp_graph.size() != 0; ++nb_elim) {
555 
556  // when minimality is not required, i.e., we won't apply recursive
557  // thinning, the cliques sets can be computed
558  if (!_minimality_required_) {
559  NodeSet& cliques = _elim_cliques_.insert(removable_node, NodeSet()).second;
560  cliques.resize(tmp_graph.neighbours(removable_node).size() / 2);
561  cliques << removable_node;
562  for (const auto clik: tmp_graph.neighbours(removable_node))
563  cliques << clik;
564  } else {
565  // here recursive thinning will be applied, hence we need store the
566  // fill-ins added by the current node removal
567  EdgeSet& current_fill = _added_fill_ins_[nb_elim];
568  NodeId node1, node2;
569 
570  const NodeSet& nei = tmp_graph.neighbours(removable_node);
571 
572  for (auto iter_edges1 = nei.begin(); iter_edges1 != nei.end(); ++iter_edges1) {
573  node1 = *iter_edges1;
574  auto iter_edges2 = iter_edges1;
575 
576  for (++iter_edges2; iter_edges2 != nei.end(); ++iter_edges2) {
577  node2 = *iter_edges2;
578  Edge edge(node1, node2);
579 
580  if (!tmp_graph.existsEdge(edge)) {
581  current_fill.insert(edge);
582  _triangulated_graph_.addEdge(node1, node2);
583  }
584  }
585  }
586  }
587 
588  // if we want fill-ins but the elimination sequence strategy does not
589  // compute them, we shall compute them here
591  NodeId node1, node2;
592 
593  // add edges between removable_node's neighbours in order to create
594  // a clique
595  const NodeSet& nei = tmp_graph.neighbours(removable_node);
596 
597  for (auto iter_edges1 = nei.begin(); iter_edges1 != nei.end(); ++iter_edges1) {
598  node1 = *iter_edges1;
599  auto iter_edges2 = iter_edges1;
600 
601  for (++iter_edges2; iter_edges2 != nei.end(); ++iter_edges2) {
602  node2 = *iter_edges2;
603  Edge edge(node1, node2);
604 
605  if (!tmp_graph.existsEdge(edge)) { _fill_ins_.insert(edge); }
606  }
607  }
608 
609  // delete removable_node and its adjacent edges
610  tmp_graph.eraseNode(removable_node);
611  }
612 
613  // inform the elimination sequence that we are actually removing
614  // removable_node (this enables, for instance, to update the weights of
615  // the nodes in the graph)
617 
619  NodeId node1, node2;
620 
621  const NodeSet& nei = tmp_graph.neighbours(removable_node);
622 
623  for (auto iter_edges1 = nei.begin(); iter_edges1 != nei.end(); ++iter_edges1) {
624  node1 = *iter_edges1;
625  auto iter_edges2 = iter_edges1;
626 
627  for (++iter_edges2; iter_edges2 != nei.end(); ++iter_edges2) {
628  node2 = *iter_edges2;
629  Edge edge(node1, node2);
630 
631  if (!tmp_graph.existsEdge(edge)) { tmp_graph.addEdge(node1, node2); }
632  }
633  }
634 
635  tmp_graph.eraseNode(removable_node);
636  }
637 
638  // update the elimination order
639  _elim_order_[nb_elim] = removable_node;
640  _reverse_elim_order_.insert(removable_node, nb_elim);
641  }
642 
643  // indicate whether we actually computed fill-ins
645 
646  // if minimality is required, remove the redondant edges
648 
649  _has_triangulation_ = true;
650  }
bool _has_triangulated_graph_
a boolean indicating whether we have constructed the triangulated graph
virtual void eliminationUpdate(const NodeId node)
performs all the graph/fill-ins updates provided (if any)
EliminationSequenceStrategy * elimination_sequence_strategy_
the elimination sequence strategy used by the triangulation
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
bool _minimality_required_
indicates whether the triangulation must be minimal
std::vector< EdgeSet > _added_fill_ins_
a vector containing the set of fill-ins added after each node elimination (used by recursive thinning...
bool _we_want_fill_ins_
a boolean indicating if we want fill-ins list with the standard triangulation method ...
NodeProperty< NodeId > _reverse_elim_order_
the elimination order (access by NodeId)
EdgeSet _fill_ins_
the fill-ins added during the whole triangulation process
Set< Edge > EdgeSet
Some typdefs and define for shortcuts ...
UndiGraph _triangulated_graph_
the triangulated graph
bool _has_triangulation_
a boolean indicating whether we have parformed a triangulation
bool _has_fill_ins_
indicates whether we actually computed fill-ins
NodeProperty< NodeSet > _elim_cliques_
the cliques formed by the elimination of the nodes
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 initTriangulation_(UndiGraph &graph)
the function called to initialize the triangulation process
std::vector< NodeId > _elim_order_
the order in which nodes are eliminated by the algorithm
const UndiGraph * _original_graph_
a pointer to the (external) original graph (which will be triangulated)
void addEdge(NodeId first, NodeId second) override
insert a new edge into the undirected graph
Definition: undiGraph_inl.h:34
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:606
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 ...
void _computeRecursiveThinning_()
removes redondant fill-ins and compute proper elimination cliques and order
+ Here is the call 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 154 of file staticTriangulation.cpp.

References gum::Set< Key, Alloc >::emplace().

154  {
155  // clear the factories
158 
159  // remove the current graphs
160  _original_graph_ = nullptr;
161  _junction_tree_ = nullptr;
163  _elim_tree_.clear();
165  _elim_cliques_.clear();
167 
168  // remove all fill-ins and orderings
169  _fill_ins_.clear();
170  _added_fill_ins_.clear();
171  _elim_order_.clear();
172  _reverse_elim_order_.clear();
173 
174  // indicates that the junction tree, the max prime tree, etc, are updated
175  _has_triangulation_ = true;
177  _has_elimination_tree_ = true;
178  _has_junction_tree_ = true;
180  _has_fill_ins_ = true;
181  }
virtual void clear()
clears the sequence (to prepare, for instance, a new elimination sequence)
bool _has_triangulated_graph_
a boolean indicating whether we have constructed the triangulated graph
bool _has_max_prime_junction_tree_
indicates whether a maximal prime subgraph junction tree has been constructed
CliqueGraph _elim_tree_
the elimination tree computed by the algorithm
EliminationSequenceStrategy * elimination_sequence_strategy_
the elimination sequence strategy used by the triangulation
void clear() override
removes all the nodes and edges from the graph
Definition: undiGraph_inl.h:42
CliqueGraph _max_prime_junction_tree_
the maximal prime subgraph junction tree computed from the junction tree
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 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)
EdgeSet _fill_ins_
the fill-ins added during the whole triangulation process
UndiGraph _triangulated_graph_
the triangulated graph
bool _has_junction_tree_
a boolean indicating whether the junction tree has been constructed
virtual void clear()=0
resets the current junction tree strategy data structures
bool _has_triangulation_
a boolean indicating whether we have parformed a triangulation
bool _has_fill_ins_
indicates whether we actually computed fill-ins
NodeProperty< NodeSet > _elim_cliques_
the cliques formed by the elimination of the nodes
const CliqueGraph * _junction_tree_
the junction tree computed by the algorithm
std::vector< NodeId > _elim_order_
the order in which nodes are eliminated by the algorithm
JunctionTreeStrategy * junction_tree_strategy_
the junction tree strategy used by the triangulation
const UndiGraph * _original_graph_
a pointer to the (external) original graph (which will be triangulated)
void clear()
Removes all the elements, if any, from the set.
Definition: set_tpl.h:361
bool _has_elimination_tree_
a boolean indicating whether the elimination tree has been computed
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 (...
+ Here is the call 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]

const std::vector< NodeId >& gum::StaticTriangulation::eliminationOrder ( )
virtual

returns an elimination ordering compatible with the triangulated graph

Implements gum::Triangulation.

◆ 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.

◆ fillIns()

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

returns the fill-ins added by the triangulation algorithm

Implements gum::Triangulation.

Definition at line 653 of file staticTriangulation.cpp.

References gum::Set< Key, Alloc >::emplace().

653  {
654  // if we did not compute the triangulation yet, do it and commpute
655  // the fill-ins at the same time
656  if (!_has_triangulation_) {
657  bool want_fill_ins = _we_want_fill_ins_;
658  _we_want_fill_ins_ = true;
659  _triangulate_();
660  _we_want_fill_ins_ = want_fill_ins;
661  _has_fill_ins_ = true;
662  }
663 
664  // here, we already computed a triangulation and we already computed
665  // the fill-ins, so return them
666  if (_has_fill_ins_) {
669  else
670  return _fill_ins_;
671  } else {
672  // ok, here, we shall compute the fill-ins as they were not precomputed
673  if (!_original_graph_) return _fill_ins_;
674 
675  // just in case, be sure that the junction tree has been constructed
677 
678  for (const auto clik_id: _junction_tree_->nodes()) {
679  // for each clique, add the edges necessary to make it complete
680  const NodeSet& clique = _junction_tree_->clique(clik_id);
681  std::vector< NodeId > clique_nodes(clique.size());
682  unsigned int i = 0;
683 
684  for (const auto node: clique) {
685  clique_nodes[i] = node;
686  i += 1;
687  }
688 
689  for (i = 0; i < clique_nodes.size(); ++i) {
690  for (unsigned int j = i + 1; j < clique_nodes.size(); ++j) {
691  Edge edge(clique_nodes[i], clique_nodes[j]);
692 
693  if (!_original_graph_->existsEdge(edge)) {
694  try {
695  _fill_ins_.insert(edge);
696  } catch (DuplicateElement&) {}
697  }
698  }
699  }
700  }
701 
702  return _fill_ins_;
703  }
704  }
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 ...
EliminationSequenceStrategy * elimination_sequence_strategy_
the elimination sequence strategy used by the triangulation
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
void _triangulate_()
the function that performs the triangulation
bool _we_want_fill_ins_
a boolean indicating if we want fill-ins list with the standard triangulation method ...
EdgeSet _fill_ins_
the fill-ins added during the whole triangulation process
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
bool _has_triangulation_
a boolean indicating whether we have parformed a triangulation
bool _has_fill_ins_
indicates whether we actually computed fill-ins
const NodeGraphPart & nodes() const
return *this as a NodeGraphPart
const CliqueGraph * _junction_tree_
the junction tree computed by the algorithm
const NodeSet & clique(const NodeId idClique) const
returns the set of nodes included into a given clique
const UndiGraph * _original_graph_
a pointer to the (external) original graph (which will be triangulated)
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:606
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:

◆ 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 707 of file staticTriangulation.cpp.

References gum::Set< Key, Alloc >::emplace().

707  {
709  }
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:

◆ 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.

◆ 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 64 of file triangulation.cpp.

References gum::Set< Key, Alloc >::emplace().

64  {
65  double res = 0.0;
66  double dSize;
67  const JunctionTree& jt = junctionTree(); // here, the fact that we get
68  // a junction tree ensures that domain_sizes_ is different from nullptr
69 
70  for (const NodeId cl: jt) {
71  dSize = 0.0;
72 
73  for (const auto node: jt.clique(cl))
74  dSize += std::log10((*domain_sizes_)[node]);
75 
76  if (res < dSize) res = dSize;
77  }
78 
79  return res;
80  }
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:300
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:

◆ 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.

◆ 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 505 of file staticTriangulation.cpp.

References gum::Set< Key, Alloc >::emplace().

505  {
506  // remove the old graph
507  clear();
508 
509  if (graph != nullptr) {
510  // prepare the size of the data for the new graph
511  _elim_order_.resize(graph->size());
512  _reverse_elim_order_.resize(graph->size());
513  _elim_cliques_.resize(graph->size());
514  _added_fill_ins_.resize(graph->size());
515  _node_2_max_prime_clique_.resize(graph->size());
516  }
517 
518  // keep track of the variables passed in argument
519  _original_graph_ = graph;
520  domain_sizes_ = domsizes;
521 
522  // indicate that no triangulation was performed for this graph
523  _has_triangulation_ = false;
524  _has_triangulated_graph_ = false;
525  _has_elimination_tree_ = false;
526  _has_junction_tree_ = false;
528  _has_fill_ins_ = false;
529  }
bool _has_triangulated_graph_
a boolean indicating whether we have constructed the triangulated graph
bool _has_max_prime_junction_tree_
indicates whether a maximal prime subgraph junction tree has been constructed
void clear()
reinitialize the graph to be triangulated to an empty graph
const NodeProperty< Size > * domain_sizes_
the domain sizes of the variables/nodes of the graph
std::vector< EdgeSet > _added_fill_ins_
a vector containing the set of fill-ins added after each node elimination (used by recursive thinning...
NodeProperty< NodeId > _reverse_elim_order_
the elimination order (access by NodeId)
bool _has_junction_tree_
a boolean indicating whether the junction tree has been constructed
bool _has_triangulation_
a boolean indicating whether we have parformed a triangulation
bool _has_fill_ins_
indicates whether we actually computed fill-ins
NodeProperty< NodeSet > _elim_cliques_
the cliques formed by the elimination of the nodes
std::vector< NodeId > _elim_order_
the order in which nodes are eliminated by the algorithm
const UndiGraph * _original_graph_
a pointer to the (external) original graph (which will be triangulated)
bool _has_elimination_tree_
a boolean indicating whether the elimination tree has been computed
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 (...
+ Here is the call 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 466 of file staticTriangulation.cpp.

References gum::Set< Key, Alloc >::emplace().

466  {
468 
469  // if we did not construct the triangulated graph during the triangulation,
470  // that is, we just constructed the junction tree, we shall construct it now
472  // just in case, be sure that the junction tree has been constructed
474 
475  // copy the original graph
477 
478  for (const auto clik_id: *_junction_tree_) {
479  // for each clique, add the edges necessary to make it complete
480  const NodeSet& clique = _junction_tree_->clique(clik_id);
481  std::vector< NodeId > clique_nodes(clique.size());
482  unsigned int i = 0;
483 
484  for (const auto node: clique) {
485  clique_nodes[i] = node;
486  i += 1;
487  }
488 
489  for (i = 0; i < clique_nodes.size(); ++i) {
490  for (unsigned int j = i + 1; j < clique_nodes.size(); ++j) {
491  try {
492  _triangulated_graph_.addEdge(clique_nodes[i], clique_nodes[j]);
493  } catch (DuplicateElement&) {}
494  }
495  }
496  }
497 
499  }
500 
501  return _triangulated_graph_;
502  }
const CliqueGraph & junctionTree()
returns a compatible junction tree
bool _has_triangulated_graph_
a boolean indicating whether we have constructed the triangulated graph
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
void _triangulate_()
the function that performs the triangulation
UndiGraph _triangulated_graph_
the triangulated graph
bool _has_junction_tree_
a boolean indicating whether the junction tree has been constructed
bool _has_triangulation_
a boolean indicating whether we have parformed a triangulation
const CliqueGraph * _junction_tree_
the junction tree computed by the algorithm
const UndiGraph * _original_graph_
a pointer to the (external) original graph (which will be triangulated)
void addEdge(NodeId first, NodeId second) override
insert a new edge into the undirected graph
Definition: undiGraph_inl.h:34
+ 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 294 of file staticTriangulation.h.

◆ _elim_cliques_

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

the cliques formed by the elimination of the nodes

Definition at line 252 of file staticTriangulation.h.

◆ _elim_order_

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

the order in which nodes are eliminated by the algorithm

Definition at line 246 of file staticTriangulation.h.

◆ _elim_tree_

CliqueGraph gum::StaticTriangulation::_elim_tree_
private

the elimination tree computed by the algorithm

Definition at line 255 of file staticTriangulation.h.

◆ _fill_ins_

EdgeSet gum::StaticTriangulation::_fill_ins_
private

the fill-ins added during the whole triangulation process

Definition at line 243 of file staticTriangulation.h.

◆ _has_elimination_tree_

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

a boolean indicating whether the elimination tree has been computed

Definition at line 277 of file staticTriangulation.h.

◆ _has_fill_ins_

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

indicates whether we actually computed fill-ins

Definition at line 287 of file staticTriangulation.h.

◆ _has_junction_tree_

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

a boolean indicating whether the junction tree has been constructed

Definition at line 280 of file staticTriangulation.h.

◆ _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 284 of file staticTriangulation.h.

◆ _has_triangulated_graph_

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

a boolean indicating whether we have constructed the triangulated graph

Definition at line 274 of file staticTriangulation.h.

◆ _has_triangulation_

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

a boolean indicating whether we have parformed a triangulation

Definition at line 271 of file staticTriangulation.h.

◆ _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 261 of file staticTriangulation.h.

◆ _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 264 of file staticTriangulation.h.

◆ _minimality_required_

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

indicates whether the triangulation must be minimal

Definition at line 290 of file staticTriangulation.h.

◆ _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 268 of file staticTriangulation.h.

◆ _original_graph_

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

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

Definition at line 237 of file staticTriangulation.h.

◆ _reverse_elim_order_

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

the elimination order (access by NodeId)

Definition at line 249 of file staticTriangulation.h.

◆ _triangulated_graph_

UndiGraph gum::StaticTriangulation::_triangulated_graph_
private

the triangulated graph

Definition at line 240 of file staticTriangulation.h.

◆ _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 298 of file staticTriangulation.h.

◆ domain_sizes_

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

the domain sizes of the variables/nodes of the graph

Definition at line 150 of file triangulation.h.

◆ elimination_sequence_strategy_

EliminationSequenceStrategy* gum::StaticTriangulation::elimination_sequence_strategy_ {nullptr}
protected

the elimination sequence strategy used by the triangulation

Definition at line 229 of file staticTriangulation.h.

◆ junction_tree_strategy_

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

the junction tree strategy used by the triangulation

Definition at line 232 of file staticTriangulation.h.


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