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

Protected Attributes

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

Private Member Functions

void _computeJunctionTree_ ()
 computes a junction tree from an elimination tree

Private Attributes

bool _has_junction_tree_ {false}
 a boolean indicating whether the junction tree has been constructed
CliqueGraph _junction_tree_
 the junction tree computed by the algorithm
NodeProperty< NodeId_node_2_junction_clique_
 indicates which clique of the junction tree was created by the elimination of a given node (the key of the table)

Detailed Description

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

Definition at line 63 of file defaultJunctionTreeStrategy.h.

Constructor & Destructor Documentation

◆ DefaultJunctionTreeStrategy() [1/3]

gum::DefaultJunctionTreeStrategy::DefaultJunctionTreeStrategy ( )

default constructor

Definition at line 59 of file defaultJunctionTreeStrategy.cpp.

59 {
60 GUM_CONSTRUCTOR(DefaultJunctionTreeStrategy);
61 }

References DefaultJunctionTreeStrategy().

Referenced by DefaultJunctionTreeStrategy(), DefaultJunctionTreeStrategy(), DefaultJunctionTreeStrategy(), ~DefaultJunctionTreeStrategy(), copyFactory(), and newFactory().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DefaultJunctionTreeStrategy() [2/3]

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

copy constructor

Definition at line 64 of file defaultJunctionTreeStrategy.cpp.

65 :
66 JunctionTreeStrategy(from), _has_junction_tree_(from._has_junction_tree_),
67 _junction_tree_(from._junction_tree_),
68 _node_2_junction_clique_(from._node_2_junction_clique_) {
69 GUM_CONS_CPY(DefaultJunctionTreeStrategy);
70 }
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
JunctionTreeStrategy()
default constructor

References DefaultJunctionTreeStrategy(), gum::JunctionTreeStrategy::JunctionTreeStrategy(), _has_junction_tree_, _junction_tree_, and _node_2_junction_clique_.

Here is the call graph for this function:

◆ DefaultJunctionTreeStrategy() [3/3]

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

move constructor

Definition at line 73 of file defaultJunctionTreeStrategy.cpp.

73 :
74 JunctionTreeStrategy(std::move(from)), _has_junction_tree_(from._has_junction_tree_),
75 _junction_tree_(std::move(from._junction_tree_)),
76 _node_2_junction_clique_(std::move(from._node_2_junction_clique_)) {
77 GUM_CONS_MOV(DefaultJunctionTreeStrategy);
78 }

References DefaultJunctionTreeStrategy(), gum::JunctionTreeStrategy::JunctionTreeStrategy(), _has_junction_tree_, _junction_tree_, and _node_2_junction_clique_.

Here is the call graph for this function:

◆ ~DefaultJunctionTreeStrategy()

gum::DefaultJunctionTreeStrategy::~DefaultJunctionTreeStrategy ( )
virtual

destructor

Definition at line 81 of file defaultJunctionTreeStrategy.cpp.

81 {
82 GUM_DESTRUCTOR(DefaultJunctionTreeStrategy);
83 ;
84 }

References DefaultJunctionTreeStrategy().

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 160 of file defaultJunctionTreeStrategy.cpp.

160 {
161 // if no triangulation is assigned to the strategy, we cannot compute
162 // the junction tree, so raise an exception
163 if (triangulation_ == nullptr)
164 GUM_ERROR(UndefinedElement,
165 "No triangulation has been assigned to "
166 "the DefaultJunctionTreeStrategy")
167
168 // copy the elimination tree into the junction tree
169 _junction_tree_ = triangulation_->eliminationTree();
170
171 // mark all the edges of the junction tree to false
172 EdgeProperty< bool > mark = _junction_tree_.edgesProperty(false);
173
174 // create a vector indicating by which clique a given clique has been
175 // substituted during the transformation from the elimination tree to the
176 // junction tree. Assume that clique J of the elimination tree has been
177 // substituted by clique K of the elimination tree, and that clique J
178 // (resp. K) was the jth (resp. kth) one created during the triangulation
179 // process. Then, in the vector below, substitution[j] = k.
180 const std::vector< NodeId >& elim_order = triangulation_->eliminationOrder();
181
182 auto size = elim_order.size();
183 std::vector< NodeId > substitution(size);
184 std::iota(substitution.begin(), substitution.end(), 0);
185
186 // for all cliques C_i, from the last one created to the first one, check
187 // if there exists a parent C_j (a neighbor created before C_i) such that
188 // |C_j| = |C_i| + 1 and such that the edge is not marked. In this case,
189 // this means that C_j contains C_i. Hence, we should remove C_i, and link
190 // all of its neighbors to C_j. These links will be marked to true as no
191 // such neighbor can be included in C_j (and conversely).
192 if (size > 0) {
193 for (auto i = size; i >= 1; --i) {
194 const NodeId C_i = NodeId(i - 1);
195 const auto card_C_i_plus_1 = _junction_tree_.clique(C_i).size() + 1;
196
197 // search for C_j such that |C_j| = [C_i| + 1
198 NodeId C_j = C_i;
199
200 for (const auto C_jj: _junction_tree_.neighbours(C_i))
201 if ((C_i > C_jj) && !mark[Edge(C_jj, C_i)]
202 && (_junction_tree_.clique(C_jj).size() == card_C_i_plus_1)) {
203 // ok, here we found a parent such that |C_jj| = [C_i| + 1
204 C_j = C_jj;
205 _junction_tree_.eraseEdge(Edge(C_j, C_i));
206 break;
207 }
208
209 // if we found a C_j, link the neighbors of C_i to C_j
210 if (C_j != C_i) {
211 for (const auto nei: _junction_tree_.neighbours(C_i)) {
212 _junction_tree_.addEdge(C_j, nei);
213 mark.insert(Edge(C_j, nei), true);
214 }
215
216 // remove C_i
217 substitution[C_i] = C_j;
218 _junction_tree_.eraseNode(C_i);
219 }
220 }
221 }
222
223 // compute the transitive closure of vector substitution
224 for (std::size_t i = 0; i < size; ++i)
225 substitution[i] = substitution[substitution[i]];
226
227 // using the transitive closure of vector substitution, compute for each
228 // node the clique of the junction tree that was created by its
229 // elimination during the triangulation
230 for (NodeId i = NodeId(0); i < size; ++i) {
231 _node_2_junction_clique_.insert(elim_order[i], substitution[i]);
232 }
233
234 _has_junction_tree_ = true;
235 }
StaticTriangulation * triangulation_
the triangulation to which the junction tree is associated
#define GUM_ERROR(type, msg)
Definition exceptions.h:72
Size NodeId
Type for node ids.
HashTable< Edge, VAL > EdgeProperty
Property on graph elements.

References _has_junction_tree_, _junction_tree_, _node_2_junction_clique_, GUM_ERROR, gum::HashTable< Key, Val >::insert(), and gum::JunctionTreeStrategy::triangulation_.

Referenced by createdClique(), createdCliques(), and junctionTree().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ clear()

void gum::DefaultJunctionTreeStrategy::clear ( )
finalvirtual

resets the current junction tree strategy data structures

Implements gum::JunctionTreeStrategy.

Definition at line 153 of file defaultJunctionTreeStrategy.cpp.

153 {
154 _has_junction_tree_ = false;
155 _junction_tree_.clear();
157 }

References _has_junction_tree_, _junction_tree_, and _node_2_junction_clique_.

Referenced by setTriangulation().

Here is the caller 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 93 of file defaultJunctionTreeStrategy.cpp.

93 {
94 if (tr == nullptr) {
95 return new DefaultJunctionTreeStrategy(*this);
96 } else {
97 // here, we need to assign new triangulation "tr" to the new strategy
98
99 // if there was already a triangulation associated with the current
100 // strategy, 2 cases can obtain:
101 // 1/ both _triangulation_ and tr point toward the same graph to be
102 // triangulated. In this case, no need to recompute anything
103 // 2/ they point toward different graphs. Then, we must indicate that
104 // the new strategy has not computed anything yet
105 if ((triangulation_ != nullptr) && (tr->originalGraph() == triangulation_->originalGraph())) {
106 auto new_strategy = new DefaultJunctionTreeStrategy(*this); // case 1/
107 new_strategy->triangulation_ = tr;
108 return new_strategy;
109 } else { // case 2/
110 auto new_strategy = new DefaultJunctionTreeStrategy;
111 new_strategy->setTriangulation(tr);
112 return new_strategy;
113 }
114 }
115 }

References DefaultJunctionTreeStrategy(), gum::StaticTriangulation::originalGraph(), and gum::JunctionTreeStrategy::triangulation_.

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 137 of file defaultJunctionTreeStrategy.cpp.

137 {
138 // compute the junction tree only if it does not already exist
140
141 return _node_2_junction_clique_[id];
142 }
void _computeJunctionTree_()
computes a junction tree from an elimination tree

References _computeJunctionTree_(), _has_junction_tree_, and _node_2_junction_clique_.

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 128 of file defaultJunctionTreeStrategy.cpp.

128 {
129 // compute the junction tree only if it does not already exist
131
133 }

References _computeJunctionTree_(), _has_junction_tree_, and _node_2_junction_clique_.

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 145 of file defaultJunctionTreeStrategy.cpp.

145 {
146 // compute the junction tree only if it does not already exist
148
149 return _junction_tree_;
150 }

References _computeJunctionTree_(), _has_junction_tree_, and _junction_tree_.

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 80 of file junctionTreeStrategy.cpp.

80 {
81 triangulation_ = triangulation;
82 }

References triangulation_.

◆ newFactory()

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

create a clone not assigned to any triangulation algorithm

Implements gum::JunctionTreeStrategy.

Definition at line 87 of file defaultJunctionTreeStrategy.cpp.

87 {
89 }

References DefaultJunctionTreeStrategy().

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 119 of file defaultJunctionTreeStrategy.cpp.

119{ 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 122 of file defaultJunctionTreeStrategy.cpp.

122 {
123 clear();
124 triangulation_ = tr;
125 }
virtual void clear() final
resets the current junction tree strategy data structures

References clear(), and gum::JunctionTreeStrategy::triangulation_.

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 149 of file defaultJunctionTreeStrategy.h.

149{false};

Referenced by DefaultJunctionTreeStrategy(), DefaultJunctionTreeStrategy(), _computeJunctionTree_(), clear(), createdClique(), createdCliques(), and junctionTree().

◆ _junction_tree_

CliqueGraph gum::DefaultJunctionTreeStrategy::_junction_tree_
private

the junction tree computed by the algorithm

Definition at line 152 of file defaultJunctionTreeStrategy.h.

Referenced by DefaultJunctionTreeStrategy(), DefaultJunctionTreeStrategy(), _computeJunctionTree_(), clear(), and junctionTree().

◆ _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 156 of file defaultJunctionTreeStrategy.h.

Referenced by DefaultJunctionTreeStrategy(), DefaultJunctionTreeStrategy(), _computeJunctionTree_(), clear(), createdClique(), and createdCliques().

◆ triangulation_

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

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