aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
gum::DefaultJunctionTreeStrategy Class Reference

An algorithm producing a junction given the elimination tree produced by a triangulation algorithm. More...

#include <defaultJunctionTreeStrategy.h>

+ Inheritance diagram for gum::DefaultJunctionTreeStrategy:
+ Collaboration diagram for gum::DefaultJunctionTreeStrategy:

Public Member Functions

Constructors / Destructors
 DefaultJunctionTreeStrategy ()
 default constructor More...
 
 DefaultJunctionTreeStrategy (const DefaultJunctionTreeStrategy &from)
 copy constructor More...
 
 DefaultJunctionTreeStrategy (DefaultJunctionTreeStrategy &&from)
 move constructor More...
 
virtual ~DefaultJunctionTreeStrategy ()
 destructor More...
 
virtual DefaultJunctionTreeStrategynewFactory () const final
 create a clone not assigned to any triangulation algorithm More...
 
virtual DefaultJunctionTreeStrategycopyFactory (StaticTriangulation *triangulation=nullptr) const final
 virtual copy constructor More...
 
Accessors / Modifiers
virtual bool requiresFillIns () const final
 indicates whether the junction tree strategy needs fill-ins to work properly More...
 
virtual const CliqueGraphjunctionTree () final
 returns the junction tree computed More...
 
virtual void setTriangulation (StaticTriangulation *triangulation) final
 assigns the triangulation to the junction tree strategy More...
 
virtual const NodeProperty< NodeId > & createdCliques () final
 returns, for each node, the clique of the junction tree which was created by its deletion More...
 
virtual NodeId createdClique (const NodeId id) final
 returns the Id of the clique of the junction tree created by the elimination of a given node during the triangulation process More...
 
virtual void clear () final
 resets the current junction tree strategy data structures More...
 
Accessors / Modifiers
virtual void moveTriangulation (StaticTriangulation *triangulation)
 assigns a new triangulation to the junction tree strategy during a move construction More...
 

Protected Attributes

StaticTriangulationtriangulation_ {nullptr}
 the triangulation to which the junction tree is associated More...
 

Detailed Description

An algorithm producing a junction given the elimination tree produced by a triangulation algorithm.

Definition at line 43 of file defaultJunctionTreeStrategy.h.

Constructor & Destructor Documentation

◆ DefaultJunctionTreeStrategy() [1/3]

gum::DefaultJunctionTreeStrategy::DefaultJunctionTreeStrategy ( )

default constructor

Definition at line 38 of file defaultJunctionTreeStrategy.cpp.

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

38  {
39  GUM_CONSTRUCTOR(DefaultJunctionTreeStrategy);
40  }
+ Here is the call graph for this function:

◆ DefaultJunctionTreeStrategy() [2/3]

gum::DefaultJunctionTreeStrategy::DefaultJunctionTreeStrategy ( const DefaultJunctionTreeStrategy from)

copy constructor

Definition at line 43 of file defaultJunctionTreeStrategy.cpp.

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

44  :
46  _has_junction_tree_(from._has_junction_tree_), _junction_tree_(from._junction_tree_),
47  _node_2_junction_clique_(from._node_2_junction_clique_) {
48  GUM_CONS_CPY(DefaultJunctionTreeStrategy);
49  }
bool _has_junction_tree_
a boolean indicating whether the junction tree has been constructed
NodeProperty< NodeId > _node_2_junction_clique_
indicates which clique of the junction tree was created by the elimination of a given node (the key o...
JunctionTreeStrategy()
default constructor
CliqueGraph _junction_tree_
the junction tree computed by the algorithm
+ Here is the call graph for this function:

◆ DefaultJunctionTreeStrategy() [3/3]

gum::DefaultJunctionTreeStrategy::DefaultJunctionTreeStrategy ( DefaultJunctionTreeStrategy &&  from)

move constructor

Definition at line 52 of file defaultJunctionTreeStrategy.cpp.

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

52  :
53  JunctionTreeStrategy(std::move(from)), _has_junction_tree_(from._has_junction_tree_),
54  _junction_tree_(std::move(from._junction_tree_)),
55  _node_2_junction_clique_(std::move(from._node_2_junction_clique_)) {
56  GUM_CONS_MOV(DefaultJunctionTreeStrategy);
57  }
bool _has_junction_tree_
a boolean indicating whether the junction tree has been constructed
NodeProperty< NodeId > _node_2_junction_clique_
indicates which clique of the junction tree was created by the elimination of a given node (the key o...
JunctionTreeStrategy()
default constructor
CliqueGraph _junction_tree_
the junction tree computed by the algorithm
+ Here is the call graph for this function:

◆ ~DefaultJunctionTreeStrategy()

gum::DefaultJunctionTreeStrategy::~DefaultJunctionTreeStrategy ( )
virtual

destructor

Definition at line 60 of file defaultJunctionTreeStrategy.cpp.

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

60  {
61  GUM_DESTRUCTOR(DefaultJunctionTreeStrategy);
62  ;
63  }
+ Here is the call graph for this function:

Member Function Documentation

◆ _computeJunctionTree_()

void gum::DefaultJunctionTreeStrategy::_computeJunctionTree_ ( )
private

computes a junction tree from an elimination tree

Definition at line 139 of file defaultJunctionTreeStrategy.cpp.

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

139  {
140  // if no triangulation is assigned to the strategy, we cannot compute
141  // the junction tree, so raise an exception
142  if (triangulation_ == nullptr)
143  GUM_ERROR(UndefinedElement,
144  "No triangulation has been assigned to "
145  "the DefaultJunctionTreeStrategy")
146 
147  // copy the elimination tree into the junction tree
148  _junction_tree_ = triangulation_->eliminationTree();
149 
150  // mark all the edges of the junction tree to false
151  EdgeProperty< bool > mark = _junction_tree_.edgesProperty(false);
152 
153  // create a vector indicating by which clique a given clique has been
154  // substituted during the transformation from the elimination tree to the
155  // junction tree. Assume that clique J of the elimination tree has been
156  // substituted by clique K of the elimination tree, and that clique J
157  // (resp. K) was the jth (resp. kth) one created during the triangulation
158  // process. Then, in the vector below, substitution[j] = k.
159  const std::vector< NodeId >& elim_order = triangulation_->eliminationOrder();
160 
161  auto size = elim_order.size();
162  std::vector< NodeId > substitution(size);
163  std::iota(substitution.begin(), substitution.end(), 0);
164 
165  // for all cliques C_i, from the last one created to the first one, check
166  // if there exists a parent C_j (a neighbor created before C_i) such that
167  // |C_j| = |C_i| + 1 and such that the edge is not marked. In this case,
168  // this means that C_j contains C_i. Hence, we should remove C_i, and link
169  // all of its neighbors to C_j. These links will be marked to true as no
170  // such neighbor can be included in C_j (and conversely).
171  if (size > 0) {
172  for (auto i = size; i >= 1; --i) {
173  const NodeId C_i = NodeId(i - 1);
174  const auto card_C_i_plus_1 = _junction_tree_.clique(C_i).size() + 1;
175 
176  // search for C_j such that |C_j| = [C_i| + 1
177  NodeId C_j = C_i;
178 
179  for (const auto C_jj: _junction_tree_.neighbours(C_i))
180  if ((C_i > C_jj) && !mark[Edge(C_jj, C_i)]
181  && (_junction_tree_.clique(C_jj).size() == card_C_i_plus_1)) {
182  // ok, here we found a parent such that |C_jj| = [C_i| + 1
183  C_j = C_jj;
184  _junction_tree_.eraseEdge(Edge(C_j, C_i));
185  break;
186  }
187 
188  // if we found a C_j, link the neighbors of C_i to C_j
189  if (C_j != C_i) {
190  for (const auto nei: _junction_tree_.neighbours(C_i)) {
191  _junction_tree_.addEdge(C_j, nei);
192  mark.insert(Edge(C_j, nei), true);
193  }
194 
195  // remove C_i
196  substitution[C_i] = C_j;
198  }
199  }
200  }
201 
202  // compute the transitive closure of vector substitution
203  for (std::size_t i = 0; i < size; ++i)
204  substitution[i] = substitution[substitution[i]];
205 
206  // using the transitive closure of vector substitution, compute for each
207  // node the clique of the junction tree that was created by its
208  // elimination during the triangulation
209  for (NodeId i = NodeId(0); i < size; ++i) {
210  _node_2_junction_clique_.insert(elim_order[i], substitution[i]);
211  }
212 
213  _has_junction_tree_ = true;
214  }
virtual void eraseNode(const NodeId node)
removes a given clique from the clique graph
STL namespace.
StaticTriangulation * triangulation_
the triangulation to which the junction tree is associated
const NodeSet & neighbours(const NodeId id) const
returns the set of node neighbours to a given node
bool _has_junction_tree_
a boolean indicating whether the junction tree has been constructed
virtual void eraseEdge(const Edge &edge)
removes an edge (and its separator) from the clique graph
NodeProperty< NodeId > _node_2_junction_clique_
indicates which clique of the junction tree was created by the elimination of a given node (the key o...
virtual void addEdge(const NodeId first, const NodeId second)
inserts a new edge between two cliques
HashTable< Edge, VAL > EdgeProperty
Property on graph elements.
const NodeSet & clique(const NodeId idClique) const
returns the set of nodes included into a given clique
CliqueGraph _junction_tree_
the junction tree computed by the algorithm
Size size() const noexcept
Returns the number of elements in the set.
Definition: set_tpl.h:694
Size NodeId
Type for node ids.
Definition: graphElements.h:97
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
+ Here is the call graph for this function:

◆ clear()

void gum::DefaultJunctionTreeStrategy::clear ( )
finalvirtual

resets the current junction tree strategy data structures

Implements gum::JunctionTreeStrategy.

Definition at line 132 of file defaultJunctionTreeStrategy.cpp.

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

132  {
133  _has_junction_tree_ = false;
135  _node_2_junction_clique_.clear();
136  }
virtual void clear()
removes all the cliques and separators from the graph (as well as their adjacent edges) ...
bool _has_junction_tree_
a boolean indicating whether the junction tree has been constructed
NodeProperty< NodeId > _node_2_junction_clique_
indicates which clique of the junction tree was created by the elimination of a given node (the key o...
CliqueGraph _junction_tree_
the junction tree computed by the algorithm
+ Here is the call graph for this function:

◆ copyFactory()

DefaultJunctionTreeStrategy * gum::DefaultJunctionTreeStrategy::copyFactory ( StaticTriangulation triangulation = nullptr) const
finalvirtual

virtual copy constructor

Parameters
triangulationif triangulation is different from nullptr, this becomes the new triangulation algorithm associated with the junction tree strategy

Implements gum::JunctionTreeStrategy.

Definition at line 72 of file defaultJunctionTreeStrategy.cpp.

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

72  {
73  if (tr == nullptr) {
74  return new DefaultJunctionTreeStrategy(*this);
75  } else {
76  // here, we need to assign new triangulation "tr" to the new strategy
77 
78  // if there was already a triangulation associated with the current
79  // strategy, 2 cases can obtain:
80  // 1/ both _triangulation_ and tr point toward the same graph to be
81  // triangulated. In this case, no need to recompute anything
82  // 2/ they point toward different graphs. Then, we must indicate that
83  // the new strategy has not computed anything yet
84  if ((triangulation_ != nullptr) && (tr->originalGraph() == triangulation_->originalGraph())) {
85  auto new_strategy = new DefaultJunctionTreeStrategy(*this); // case 1/
86  new_strategy->triangulation_ = tr;
87  return new_strategy;
88  } else { // case 2/
89  auto new_strategy = new DefaultJunctionTreeStrategy;
90  new_strategy->setTriangulation(tr);
91  return new_strategy;
92  }
93  }
94  }
const UndiGraph * originalGraph() const
returns the graph to be triangulated
StaticTriangulation * triangulation_
the triangulation to which the junction tree is associated
+ Here is the call graph for this function:

◆ createdClique()

NodeId gum::DefaultJunctionTreeStrategy::createdClique ( const NodeId  id)
finalvirtual

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

Parameters
idthe id of the node in the original undirected graph whose created clique's id is looked for
Exceptions
UndefinedElementis raised if no triangulation has been assigned to the DefaultJunctionTreeStrategy

Implements gum::JunctionTreeStrategy.

Definition at line 116 of file defaultJunctionTreeStrategy.cpp.

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

116  {
117  // compute the junction tree only if it does not already exist
119 
120  return _node_2_junction_clique_[id];
121  }
void _computeJunctionTree_()
computes a junction tree from an elimination tree
bool _has_junction_tree_
a boolean indicating whether the junction tree has been constructed
NodeProperty< NodeId > _node_2_junction_clique_
indicates which clique of the junction tree was created by the elimination of a given node (the key o...
+ Here is the call graph for this function:

◆ createdCliques()

const NodeProperty< NodeId > & gum::DefaultJunctionTreeStrategy::createdCliques ( )
finalvirtual

returns, for each node, the clique of the junction tree which was created by its deletion

Exceptions
UndefinedElementis raised if no triangulation has been assigned to the DefaultJunctionTreeStrategy

Implements gum::JunctionTreeStrategy.

Definition at line 107 of file defaultJunctionTreeStrategy.cpp.

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

107  {
108  // compute the junction tree only if it does not already exist
110 
112  }
void _computeJunctionTree_()
computes a junction tree from an elimination tree
bool _has_junction_tree_
a boolean indicating whether the junction tree has been constructed
NodeProperty< NodeId > _node_2_junction_clique_
indicates which clique of the junction tree was created by the elimination of a given node (the key o...
+ Here is the call graph for this function:

◆ junctionTree()

const CliqueGraph & gum::DefaultJunctionTreeStrategy::junctionTree ( )
finalvirtual

returns the junction tree computed

The idea behind this method is that the JunctionTreeStrategy asks its assigned triangulation (see method setTriangulation) all the data it needs to compute correctly the junction tree. For instance, it may asks for a triangulated graph or an elimination tree, or even the order of elimination of the nodes, etc. All these data are available from the triangulation class. Knowing these data, the junctionTreeStrategy computes and returns a junction tree corresponding to the triangulated graph.

Exceptions
UndefinedElementis raised if no triangulation has been assigned to the DefaultJunctionTreeStrategy

Implements gum::JunctionTreeStrategy.

Definition at line 124 of file defaultJunctionTreeStrategy.cpp.

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

124  {
125  // compute the junction tree only if it does not already exist
127 
128  return _junction_tree_;
129  }
void _computeJunctionTree_()
computes a junction tree from an elimination tree
bool _has_junction_tree_
a boolean indicating whether the junction tree has been constructed
CliqueGraph _junction_tree_
the junction tree computed by the algorithm
+ Here is the call graph for this function:

◆ moveTriangulation()

void gum::JunctionTreeStrategy::moveTriangulation ( StaticTriangulation triangulation)
virtualinherited

assigns a new triangulation to the junction tree strategy during a move construction

Definition at line 60 of file junctionTreeStrategy.cpp.

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

60  {
61  triangulation_ = triangulation;
62  }
StaticTriangulation * triangulation_
the triangulation to which the junction tree is associated
+ Here is the call graph for this function:

◆ newFactory()

DefaultJunctionTreeStrategy * gum::DefaultJunctionTreeStrategy::newFactory ( ) const
finalvirtual

create a clone not assigned to any triangulation algorithm

Implements gum::JunctionTreeStrategy.

Definition at line 66 of file defaultJunctionTreeStrategy.cpp.

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

66  {
67  return new DefaultJunctionTreeStrategy;
68  }
+ Here is the call graph for this function:

◆ requiresFillIns()

bool gum::DefaultJunctionTreeStrategy::requiresFillIns ( ) const
finalvirtual

indicates whether the junction tree strategy needs fill-ins to work properly

If the junctionTreeStrategy needs fill-ins to work properly, its assigned triangulation instance (see method setTriangulation) will be commited to compute them.

Implements gum::JunctionTreeStrategy.

Definition at line 98 of file defaultJunctionTreeStrategy.cpp.

98 { return false; }

◆ setTriangulation()

void gum::DefaultJunctionTreeStrategy::setTriangulation ( StaticTriangulation triangulation)
finalvirtual

assigns the triangulation to the junction tree strategy

Parameters
thetriangulation whose resulting cliques will be used to construct the junction tree
Warning
note that, by aGrUM's rule, the graph and the domain sizes are not copied but only referenced by the junction tree strategy.

Implements gum::JunctionTreeStrategy.

Definition at line 101 of file defaultJunctionTreeStrategy.cpp.

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

101  {
102  clear();
103  triangulation_ = tr;
104  }
StaticTriangulation * triangulation_
the triangulation to which the junction tree is associated
virtual void clear() final
resets the current junction tree strategy data structures
+ Here is the call graph for this function:

Member Data Documentation

◆ _has_junction_tree_

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

a boolean indicating whether the junction tree has been constructed

Definition at line 129 of file defaultJunctionTreeStrategy.h.

◆ _junction_tree_

CliqueGraph gum::DefaultJunctionTreeStrategy::_junction_tree_
private

the junction tree computed by the algorithm

Definition at line 132 of file defaultJunctionTreeStrategy.h.

◆ _node_2_junction_clique_

NodeProperty< NodeId > gum::DefaultJunctionTreeStrategy::_node_2_junction_clique_
private

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

Definition at line 136 of file defaultJunctionTreeStrategy.h.

◆ triangulation_

StaticTriangulation* gum::JunctionTreeStrategy::triangulation_ {nullptr}
protectedinherited

the triangulation to which the junction tree is associated

Definition at line 117 of file junctionTreeStrategy.h.


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