aGrUM  0.16.0
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 44 of file defaultJunctionTreeStrategy.h.

Constructor & Destructor Documentation

◆ DefaultJunctionTreeStrategy() [1/3]

gum::DefaultJunctionTreeStrategy::DefaultJunctionTreeStrategy ( )

default constructor

Definition at line 39 of file defaultJunctionTreeStrategy.cpp.

Referenced by copyFactory(), and newFactory().

39  {
40  // for debugging purposes
41  GUM_CONSTRUCTOR(DefaultJunctionTreeStrategy);
42  }
+ Here is the caller graph for this function:

◆ DefaultJunctionTreeStrategy() [2/3]

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

copy constructor

Definition at line 45 of file defaultJunctionTreeStrategy.cpp.

46  :
48  __has_junction_tree(from.__has_junction_tree),
49  __junction_tree(from.__junction_tree),
50  __node_2_junction_clique(from.__node_2_junction_clique) {
51  // for debugging purposes
52  GUM_CONS_CPY(DefaultJunctionTreeStrategy);
53  }
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 56 of file defaultJunctionTreeStrategy.cpp.

57  :
58  JunctionTreeStrategy(std::move(from)),
59  __has_junction_tree(from.__has_junction_tree),
60  __junction_tree(std::move(from.__junction_tree)),
61  __node_2_junction_clique(std::move(from.__node_2_junction_clique)) {
62  // for debugging purposes
63  GUM_CONS_MOV(DefaultJunctionTreeStrategy);
64  }
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 67 of file defaultJunctionTreeStrategy.cpp.

67  {
68  // for debugging purposes
69  GUM_DESTRUCTOR(DefaultJunctionTreeStrategy);
70  }

Member Function Documentation

◆ __computeJunctionTree()

void gum::DefaultJunctionTreeStrategy::__computeJunctionTree ( )
private

computes a junction tree from an elimination tree

Definition at line 147 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().

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

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

Referenced by setTriangulation().

140  {
141  __has_junction_tree = false;
143  __node_2_junction_clique.clear();
144  }
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 79 of file defaultJunctionTreeStrategy.cpp.

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

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

References __computeJunctionTree(), __has_junction_tree, and __node_2_junction_clique.

124  {
125  // compute the junction tree only if it does not already exist
127 
128  return __node_2_junction_clique[id];
129  }
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 115 of file defaultJunctionTreeStrategy.cpp.

References __computeJunctionTree(), __has_junction_tree, and __node_2_junction_clique.

115  {
116  // compute the junction tree only if it does not already exist
118 
120  }
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 132 of file defaultJunctionTreeStrategy.cpp.

References __computeJunctionTree(), __has_junction_tree, and __junction_tree.

132  {
133  // compute the junction tree only if it does not already exist
135 
136  return __junction_tree;
137  }
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 63 of file junctionTreeStrategy.cpp.

References gum::JunctionTreeStrategy::_triangulation.

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

63  {
64  _triangulation = triangulation;
65  }
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 73 of file defaultJunctionTreeStrategy.cpp.

References DefaultJunctionTreeStrategy().

73  {
74  return new DefaultJunctionTreeStrategy;
75  }
+ 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 106 of file defaultJunctionTreeStrategy.cpp.

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

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

109  {
110  clear();
111  _triangulation = tr;
112  }
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 130 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 133 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 137 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 118 of file junctionTreeStrategy.h.

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


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