aGrUM  0.20.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 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  // for debugging purposes
40  GUM_CONSTRUCTOR(DefaultJunctionTreeStrategy);
41  }
+ Here is the call graph for this function:

◆ DefaultJunctionTreeStrategy() [2/3]

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

copy constructor

Definition at line 44 of file defaultJunctionTreeStrategy.cpp.

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

45  :
47  has_junction_tree__(from.has_junction_tree__),
48  junction_tree__(from.junction_tree__),
49  node_2_junction_clique__(from.node_2_junction_clique__) {
50  // for debugging purposes
51  GUM_CONS_CPY(DefaultJunctionTreeStrategy);
52  }
bool has_junction_tree__
a boolean indicating whether the junction tree has been constructed
CliqueGraph junction_tree__
the junction tree computed by the algorithm
JunctionTreeStrategy()
default constructor
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:

◆ DefaultJunctionTreeStrategy() [3/3]

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

move constructor

Definition at line 55 of file defaultJunctionTreeStrategy.cpp.

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

56  :
57  JunctionTreeStrategy(std::move(from)),
58  has_junction_tree__(from.has_junction_tree__),
59  junction_tree__(std::move(from.junction_tree__)),
60  node_2_junction_clique__(std::move(from.node_2_junction_clique__)) {
61  // for debugging purposes
62  GUM_CONS_MOV(DefaultJunctionTreeStrategy);
63  }
bool has_junction_tree__
a boolean indicating whether the junction tree has been constructed
CliqueGraph junction_tree__
the junction tree computed by the algorithm
JunctionTreeStrategy()
default constructor
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:

◆ ~DefaultJunctionTreeStrategy()

gum::DefaultJunctionTreeStrategy::~DefaultJunctionTreeStrategy ( )
virtual

destructor

Definition at line 66 of file defaultJunctionTreeStrategy.cpp.

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

66  {
67  // for debugging purposes
68  GUM_DESTRUCTOR(DefaultJunctionTreeStrategy);
69  }
+ Here is the call graph for this function:

Member Function Documentation

◆ clear()

void gum::DefaultJunctionTreeStrategy::clear ( )
finalvirtual

resets the current junction tree strategy data structures

Implements gum::JunctionTreeStrategy.

Definition at line 139 of file defaultJunctionTreeStrategy.cpp.

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

139  {
140  has_junction_tree__ = false;
142  node_2_junction_clique__.clear();
143  }
bool has_junction_tree__
a boolean indicating whether the junction tree has been constructed
virtual void clear()
removes all the cliques and separators from the graph (as well as their adjacent edges) ...
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 o...
+ Here is the call graph for this function:

◆ computeJunctionTree__()

void gum::DefaultJunctionTreeStrategy::computeJunctionTree__ ( )
private

computes a junction tree from an elimination tree

Definition at line 146 of file defaultJunctionTreeStrategy.cpp.

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

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

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

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

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

123  {
124  // compute the junction tree only if it does not already exist
126 
127  return node_2_junction_clique__[id];
128  }
bool has_junction_tree__
a boolean indicating whether the junction tree has been constructed
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...
+ 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 114 of file defaultJunctionTreeStrategy.cpp.

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

114  {
115  // compute the junction tree only if it does not already exist
117 
119  }
bool has_junction_tree__
a boolean indicating whether the junction tree has been constructed
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...
+ 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 131 of file defaultJunctionTreeStrategy.cpp.

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

131  {
132  // compute the junction tree only if it does not already exist
134 
135  return junction_tree__;
136  }
bool has_junction_tree__
a boolean indicating whether the junction tree has been constructed
void computeJunctionTree__()
computes a junction tree from an elimination tree
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 62 of file junctionTreeStrategy.cpp.

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

62  {
63  triangulation_ = triangulation;
64  }
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 72 of file defaultJunctionTreeStrategy.cpp.

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

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

105 { 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 108 of file defaultJunctionTreeStrategy.cpp.

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

108  {
109  clear();
110  triangulation_ = tr;
111  }
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: