aGrUM  0.14.2
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

StaticTriangulation_triangulation {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 41 of file defaultJunctionTreeStrategy.h.

Constructor & Destructor Documentation

◆ DefaultJunctionTreeStrategy() [1/3]

gum::DefaultJunctionTreeStrategy::DefaultJunctionTreeStrategy ( )

default constructor

Definition at line 36 of file defaultJunctionTreeStrategy.cpp.

Referenced by copyFactory(), and newFactory().

36  {
37  // for debugging purposes
38  GUM_CONSTRUCTOR(DefaultJunctionTreeStrategy);
39  }
+ Here is the caller graph for this function:

◆ DefaultJunctionTreeStrategy() [2/3]

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

copy constructor

Definition at line 42 of file defaultJunctionTreeStrategy.cpp.

43  :
45  __has_junction_tree(from.__has_junction_tree),
46  __junction_tree(from.__junction_tree),
47  __node_2_junction_clique(from.__node_2_junction_clique) {
48  // for debugging purposes
49  GUM_CONS_CPY(DefaultJunctionTreeStrategy);
50  }
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
bool __has_junction_tree
a boolean indicating whether the junction tree has been constructed

◆ DefaultJunctionTreeStrategy() [3/3]

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

move constructor

Definition at line 53 of file defaultJunctionTreeStrategy.cpp.

54  :
55  JunctionTreeStrategy(std::move(from)),
56  __has_junction_tree(from.__has_junction_tree),
57  __junction_tree(std::move(from.__junction_tree)),
58  __node_2_junction_clique(std::move(from.__node_2_junction_clique)) {
59  // for debugging purposes
60  GUM_CONS_MOV(DefaultJunctionTreeStrategy);
61  }
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
bool __has_junction_tree
a boolean indicating whether the junction tree has been constructed

◆ ~DefaultJunctionTreeStrategy()

gum::DefaultJunctionTreeStrategy::~DefaultJunctionTreeStrategy ( )
virtual

destructor

Definition at line 64 of file defaultJunctionTreeStrategy.cpp.

64  {
65  // for debugging purposes
66  GUM_DESTRUCTOR(DefaultJunctionTreeStrategy);
67  }

Member Function Documentation

◆ __computeJunctionTree()

void gum::DefaultJunctionTreeStrategy::__computeJunctionTree ( )
private

computes a junction tree from an elimination tree

Definition at line 144 of file defaultJunctionTreeStrategy.cpp.

References __has_junction_tree, __junction_tree, __node_2_junction_clique, gum::JunctionTreeStrategy::_triangulation, gum::CliqueGraph::addEdge(), gum::CliqueGraph::clique(), gum::EdgeGraphPart::edgesProperty(), gum::StaticTriangulation::eliminationOrder(), gum::StaticTriangulation::eliminationTree(), gum::CliqueGraph::eraseEdge(), gum::CliqueGraph::eraseNode(), GUM_ERROR, gum::HashTable< Key, Val, Alloc >::insert(), gum::EdgeGraphPart::neighbours(), and gum::Set< Key, Alloc >::size().

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

144  {
145  // if no triangulation is assigned to the strategy, we cannot compute
146  // the junction tree, so raise an exception
147  if (_triangulation == nullptr)
148  GUM_ERROR(UndefinedElement,
149  "No triangulation has been assigned to "
150  "the DefaultJunctionTreeStrategy");
151 
152  // copy the elimination tree into the junction tree
154 
155  // mark all the edges of the junction tree to false
156  EdgeProperty< bool > mark = __junction_tree.edgesProperty(false);
157 
158  // create a vector indicating by which clique a given clique has been
159  // substituted during the transformation from the elimination tree to the
160  // junction tree. Assume that clique J of the elmination tree has been
161  // substituted by clique K of the elimination tree, and that clique J
162  // (resp. K) was the jth (resp. kth) one created during the triangulation
163  // process. Then, in the vector below, substitution[j] = k.
164  const std::vector< NodeId >& elim_order = _triangulation->eliminationOrder();
165 
166  auto size = elim_order.size();
167  std::vector< NodeId > substitution(size);
168  std::iota(substitution.begin(), substitution.end(), 0);
169 
170  // for all cliques C_i, from the last one created to the first one, check
171  // if there exists a parent C_j (a neighbor created before C_i) such that
172  // |C_j| = |C_i| + 1 and such that the edge is not marked. In this case,
173  // this means that C_j contains C_i. Hence, we should remove C_i, and link
174  // all of its neighbors to C_j. These links will be marked to true as no
175  // such neighbor can be included in C_j (and conversely).
176  if (size > 0) {
177  for (auto i = size; i >= 1; --i) {
178  const NodeId C_i = NodeId(i - 1);
179  const auto card_C_i_plus_1 = __junction_tree.clique(C_i).size() + 1;
180 
181  // search for C_j such that |C_j| = [C_i| + 1
182  NodeId C_j = C_i;
183 
184  for (const auto C_jj : __junction_tree.neighbours(C_i))
185  if ((C_i > C_jj) && !mark[Edge(C_jj, C_i)]
186  && (__junction_tree.clique(C_jj).size() == card_C_i_plus_1)) {
187  // ok, here we found a parent such that |C_jj| = [C_i| + 1
188  C_j = C_jj;
189  __junction_tree.eraseEdge(Edge(C_j, C_i));
190  break;
191  }
192 
193  // if we found a C_j, link the neighbors of C_i to C_j
194  if (C_j != C_i) {
195  for (const auto nei : __junction_tree.neighbours(C_i)) {
196  __junction_tree.addEdge(C_j, nei);
197  mark.insert(Edge(C_j, nei), true);
198  }
199 
200  // remove C_i
201  substitution[C_i] = C_j;
203  }
204  }
205  }
206 
207  // compute the transitive closure of vector substitution
208  for (std::size_t i = 0; i < size; ++i)
209  substitution[i] = substitution[substitution[i]];
210 
211  // using the transitive closure of vector substitution, compute for each
212  // node the clique of the junction tree that was created by its
213  // elimination during the triangulation
214  for (NodeId i = NodeId(0); i < size; ++i) {
215  __node_2_junction_clique.insert(elim_order[i], substitution[i]);
216  }
217 
218  __has_junction_tree = true;
219  }
virtual void eraseNode(const NodeId node)
removes a given clique from the clique graph
StaticTriangulation * _triangulation
the triangulation to which the junction tree is associated
const NodeSet & neighbours(const NodeId id) const
returns the set of edges adjacent to a given node
EdgeProperty< VAL > edgesProperty(VAL(*f)(const Edge &), Size size=0) const
a method to create a hashMap of VAL from a set of edges (using for every edge, say x...
const CliqueGraph & eliminationTree()
returns the elimination tree of a compatible ordering
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...
const std::vector< NodeId > & eliminationOrder()
returns an elimination ordering compatible with the triangulated graph
virtual void eraseEdge(const Edge &edge)
removes an edge (and its separator) from the clique graph
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
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:698
bool __has_junction_tree
a boolean indicating whether the junction tree has been constructed
Size NodeId
Type for node ids.
Definition: graphElements.h:97
#define GUM_ERROR(type, msg)
Definition: exceptions.h:52
+ 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 137 of file defaultJunctionTreeStrategy.cpp.

References __has_junction_tree, __junction_tree, __node_2_junction_clique, and gum::CliqueGraph::clear().

Referenced by setTriangulation().

137  {
138  __has_junction_tree = false;
140  __node_2_junction_clique.clear();
141  }
virtual void clear()
removes all the cliques and separators from the graph (as well as their adjacent edges) ...
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
bool __has_junction_tree
a boolean indicating whether the junction tree has been constructed
+ Here is the call graph for this function:
+ 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 76 of file defaultJunctionTreeStrategy.cpp.

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

76  {
77  if (tr == nullptr) {
78  return new DefaultJunctionTreeStrategy(*this);
79  } else {
80  // here, we need to assign new triangulation "tr" to the new strategy
81 
82  // if there was already a triangulation associated with the current
83  // strategy, 2 cases can obtain:
84  // 1/ both __triangulation and tr point toward the same graph to be
85  // triangulated. In this case, no need to recompute anything
86  // 2/ they point toward different graphs. Then, we must indicate that
87  // the new strategy has not computed anything yet
88  if ((_triangulation != nullptr)
89  && (tr->originalGraph() == _triangulation->originalGraph())) {
90  auto new_strategy = new DefaultJunctionTreeStrategy(*this); // case 1/
91  new_strategy->_triangulation = tr;
92  return new_strategy;
93  } else { // case 2/
94  auto new_strategy = new DefaultJunctionTreeStrategy;
95  new_strategy->setTriangulation(tr);
96  return new_strategy;
97  }
98  }
99  }
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 121 of file defaultJunctionTreeStrategy.cpp.

References __computeJunctionTree(), __has_junction_tree, and __node_2_junction_clique.

121  {
122  // compute the junction tree only if it does not already exist
124 
125  return __node_2_junction_clique[id];
126  }
void __computeJunctionTree()
computes a junction tree from an elimination tree
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...
bool __has_junction_tree
a boolean indicating whether the junction tree has been constructed
+ 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 112 of file defaultJunctionTreeStrategy.cpp.

References __computeJunctionTree(), __has_junction_tree, and __node_2_junction_clique.

112  {
113  // compute the junction tree only if it does not already exist
115 
117  }
void __computeJunctionTree()
computes a junction tree from an elimination tree
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...
bool __has_junction_tree
a boolean indicating whether the junction tree has been constructed
+ 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 129 of file defaultJunctionTreeStrategy.cpp.

References __computeJunctionTree(), __has_junction_tree, and __junction_tree.

129  {
130  // compute the junction tree only if it does not already exist
132 
133  return __junction_tree;
134  }
void __computeJunctionTree()
computes a junction tree from an elimination tree
CliqueGraph __junction_tree
the junction tree computed by the algorithm
bool __has_junction_tree
a boolean indicating whether the junction tree has been constructed
+ 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::JunctionTreeStrategy::_triangulation.

Referenced by gum::StaticTriangulation::StaticTriangulation().

60  {
61  _triangulation = triangulation;
62  }
StaticTriangulation * _triangulation
the triangulation to which the junction tree is associated
+ Here is the caller 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 70 of file defaultJunctionTreeStrategy.cpp.

References DefaultJunctionTreeStrategy().

70  {
71  return new DefaultJunctionTreeStrategy;
72  }
+ 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 103 of file defaultJunctionTreeStrategy.cpp.

103 { 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 106 of file defaultJunctionTreeStrategy.cpp.

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

106  {
107  clear();
108  _triangulation = tr;
109  }
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 127 of file defaultJunctionTreeStrategy.h.

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

◆ __junction_tree

CliqueGraph gum::DefaultJunctionTreeStrategy::__junction_tree
private

the junction tree computed by the algorithm

Definition at line 130 of file defaultJunctionTreeStrategy.h.

Referenced by __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 134 of file defaultJunctionTreeStrategy.h.

Referenced by __computeJunctionTree(), clear(), createdClique(), and createdCliques().

◆ _triangulation

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

the triangulation to which the junction tree is associated

Definition at line 115 of file junctionTreeStrategy.h.

Referenced by __computeJunctionTree(), copyFactory(), gum::JunctionTreeStrategy::moveTriangulation(), and setTriangulation().


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