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

An Elimination sequence algorithm that imposes a given partial ordering on the nodes elimination sequence. More...

#include <defaultPartialOrderedEliminationSequenceStrategy.h>

+ Inheritance diagram for gum::DefaultPartialOrderedEliminationSequenceStrategy:
+ Collaboration diagram for gum::DefaultPartialOrderedEliminationSequenceStrategy:

Public Member Functions

Constructors / Destructors
 DefaultPartialOrderedEliminationSequenceStrategy (double theRatio=GUM_QUASI_RATIO, double theThreshold=GUM_WEIGHT_THRESHOLD)
 default constructor (uses an empty graph) More...
 
 DefaultPartialOrderedEliminationSequenceStrategy (UndiGraph *graph, const NodeProperty< Size > *dom_sizes, const List< NodeSet > *subsets, double ratio=GUM_QUASI_RATIO, double threshold=GUM_WEIGHT_THRESHOLD)
 constructor for an a priori non empty graph More...
 
 DefaultPartialOrderedEliminationSequenceStrategy (const DefaultPartialOrderedEliminationSequenceStrategy &from)
 copy constructor More...
 
 DefaultPartialOrderedEliminationSequenceStrategy (DefaultPartialOrderedEliminationSequenceStrategy &&from)
 move constructor More...
 
virtual ~DefaultPartialOrderedEliminationSequenceStrategy ()
 destructor More...
 
virtual DefaultPartialOrderedEliminationSequenceStrategynewFactory () const final
 creates a new elimination sequence of the same type as the current object, but this sequence contains only an empty graph More...
 
virtual DefaultPartialOrderedEliminationSequenceStrategycopyFactory () const final
 virtual copy constructor More...
 
Accessors / Modifiers
virtual bool setGraph (UndiGraph *graph, const NodeProperty< Size > *dom_sizes) final
 sets a new graph to be triangulated More...
 
virtual void clear () final
 clears the sequence (to prepare, for instance, a new elimination sequence) More...
 
virtual NodeId nextNodeToEliminate () final
 returns the new node to be eliminated within the triangulation algorithm More...
 
virtual void askFillIns (bool do_it) final
 if the elimination sequence is able to compute fill-ins, we indicate whether we want this feature to be activated More...
 
virtual bool providesFillIns () const final
 indicates whether the fill-ins generated by the eliminated nodes, if needed, will be computed by the elimination sequence, or need be computed by the triangulation itself. More...
 
virtual bool providesGraphUpdate () const final
 indicates whether the elimination sequence updates by itself the graph after a node has been eliminated More...
 
virtual void eliminationUpdate (const NodeId node) final
 performs all the graph/fill-ins updates provided (if any) More...
 
virtual const EdgeSetfillIns () final
 in case fill-ins are provided, this function returns the fill-ins due to all the nodes eliminated so far More...
 
Accessors / Modifiers
virtual bool setPartialOrder (const List< NodeSet > *subsets)
 sets a new partial ordering constraint on the elimination sequence More...
 
const List< NodeSet > * partialOrder () const noexcept
 returns the current partial ordering More...
 
bool isPartialOrderNeeded () const noexcept
 indicates if a new partial ordering is needed More...
 
Accessors / Modifiers
UndiGraphgraph () const noexcept
 returns the current graph More...
 
const NodeProperty< Size > * domainSizes () const noexcept
 returns the current domain sizes More...
 

Protected Attributes

const List< NodeSet > * subsets_ {nullptr}
 the subsets constituting the partial ordering More...
 
List< NodeSet >::const_iterator subset_iter_
 the iterator indicating which is the current subset on which we work More...
 
NodeSet nodeset_
 the nodes which can be currently eliminated More...
 
bool partial_order_needed_ {true}
 indicate whether a new partial ordering is necessary for the elimination More...
 
UndiGraphgraph_ {nullptr}
 the graph to be triangulated More...
 
const NodeProperty< Size > * domain_sizes_ {nullptr}
 the domain sizes of the variables/nodes More...
 
NodeProperty< doublelog_domain_sizes_
 the log of the domain sizes of the variables/nodes More...
 

Protected Member Functions

bool isPartialOrderNeeded_ (const List< NodeSet > *subsets) const
 indicate whether a partial ordering is compatible with the current graph More...
 

Detailed Description

An Elimination sequence algorithm that imposes a given partial ordering on the nodes elimination sequence.

Class DefaultPartialOrderedEliminationSequenceStrategy implements an elimination sequence algorithm that satisfies a partial ordering, that is, the set of all the nodes is divided into several subsets. All the nodes of the first subset must be eliminated before the nodes of the second, which must be eliminated before those of the third subset, and so on. Within a subset, the ordering is determined as follows:

the nodes that are simplicial (i.e., those that already form a clique

with their neighbors) are eliminated first

then the nodes that are almost simplicial (i.e. if we remove one of their

neighbors, they become simplicial) and that create small cliques, are eliminated (see Bodlaender's safe reductions)

the quasi simplicial nodes (i.e., the nodes that do not require many

fill-ins to create cliques) that would create small cliques, are eliminated

finally, the heuristic proposed by Kjaerulff(90) is used to compute the

last nodes to be eliminated.

Definition at line 81 of file defaultPartialOrderedEliminationSequenceStrategy.h.

Constructor & Destructor Documentation

◆ DefaultPartialOrderedEliminationSequenceStrategy() [1/4]

gum::DefaultPartialOrderedEliminationSequenceStrategy::DefaultPartialOrderedEliminationSequenceStrategy ( double  theRatio = GUM_QUASI_RATIO,
double  theThreshold = GUM_WEIGHT_THRESHOLD 
)

default constructor (uses an empty graph)

Parameters
theRatiothe ratio used by the SimplicialSet included in the DefaultEliminationSequenceStrategy
theThresholdthe weight threshhold of the SimplicialSet included in the DefaultEliminationSequenceStrategy

Definition at line 38 of file defaultPartialOrderedEliminationSequenceStrategy.cpp.

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

38  :
39  _simplicial_ratio_(theRatio),
40  _simplicial_threshold_(theThreshold) {
41  // for debugging purposes
43  }
double _simplicial_threshold_
the threshold used by simplicial_set to determine small cliques
double _simplicial_ratio_
the ratio used by simplicial_set for its quasi-simplicial nodes
DefaultPartialOrderedEliminationSequenceStrategy(double theRatio=GUM_QUASI_RATIO, double theThreshold=GUM_WEIGHT_THRESHOLD)
default constructor (uses an empty graph)
+ Here is the call graph for this function:

◆ DefaultPartialOrderedEliminationSequenceStrategy() [2/4]

gum::DefaultPartialOrderedEliminationSequenceStrategy::DefaultPartialOrderedEliminationSequenceStrategy ( UndiGraph graph,
const NodeProperty< Size > *  dom_sizes,
const List< NodeSet > *  subsets,
double  ratio = GUM_QUASI_RATIO,
double  threshold = GUM_WEIGHT_THRESHOLD 
)

constructor for an a priori non empty graph

Parameters
graphthe graph to be triangulated, i.e., the nodes of which will be eliminated
dom_sizesthedomain sizes of the nodes/variables
subsetsthe list of the subsets constituting the partial ordering
ratiothe ratio used by the SimplicialSet included in the DefaultEliminationSequenceStrategy
thresholdthe weight threshhold of the SimplicialSet included in the DefaultEliminationSequenceStrategy
Warning
Note that we allow dom_sizes to be defined over nodes/variables that do not belong to graph. These sizes will simply be ignored. However, it is compulsory that all the nodes of graph belong to dom_sizes
the graph is altered during the triangulation.
note that, by aGrUM's rule, the graph, the domain sizes and the sequence are not copied but only referenced by the elimination sequence algorithm.

Definition at line 47 of file defaultPartialOrderedEliminationSequenceStrategy.cpp.

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

51  :
52  _simplicial_ratio_(ratio),
53  _simplicial_threshold_(threshold) {
54  setGraph(graph, dom_sizes);
55  setPartialOrder(subsets);
56 
57  // for debugging purposes
59  }
double _simplicial_threshold_
the threshold used by simplicial_set to determine small cliques
double _simplicial_ratio_
the ratio used by simplicial_set for its quasi-simplicial nodes
virtual bool setPartialOrder(const List< NodeSet > *subsets)
sets a new partial ordering constraint on the elimination sequence
UndiGraph * graph() const noexcept
returns the current graph
virtual bool setGraph(UndiGraph *graph, const NodeProperty< Size > *dom_sizes) final
sets a new graph to be triangulated
DefaultPartialOrderedEliminationSequenceStrategy(double theRatio=GUM_QUASI_RATIO, double theThreshold=GUM_WEIGHT_THRESHOLD)
default constructor (uses an empty graph)
+ Here is the call graph for this function:

◆ DefaultPartialOrderedEliminationSequenceStrategy() [3/4]

gum::DefaultPartialOrderedEliminationSequenceStrategy::DefaultPartialOrderedEliminationSequenceStrategy ( const DefaultPartialOrderedEliminationSequenceStrategy from)

copy constructor

Warning
The newly created elimination sequence strategy points toward the same undirected graph as the one contained in from but each strategy possesses its own simplicial set. As a result, if both elimination strategies are used at the same time, they will probably result in a mess because their simplicial sets won't be synchronized correctly with the changing undirected graph. So, whenever using this copy constructor, be sure that either from or the newly created strategy is used for a triangulation but not both. This will necessarily be OK in DefaultTriangulations.

Definition at line 63 of file defaultPartialOrderedEliminationSequenceStrategy.cpp.

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

64  :
66  // no need to set _log_weights_ because the copy of the simplicial set
67  // will set it properly
68  _simplicial_set_(new SimplicialSet(*from._simplicial_set_,
69  graph_,
72  false)),
73  _simplicial_ratio_(from._simplicial_ratio_),
74  _simplicial_threshold_(from._simplicial_threshold_),
75  _provide_fill_ins_(from._provide_fill_ins_) {
76  // for debugging purposes
78  }
double _simplicial_threshold_
the threshold used by simplicial_set to determine small cliques
double _simplicial_ratio_
the ratio used by simplicial_set for its quasi-simplicial nodes
SimplicialSet * _simplicial_set_
the simplicial set used for determining the best nodes to eliminate
PartialOrderedEliminationSequenceStrategy()
default constructor (uses an empty graph)
NodeProperty< double > _log_weights_
for each node, the weight of the clique created by the node&#39;s elimination
NodeProperty< double > log_domain_sizes_
the log of the domain sizes of the variables/nodes
DefaultPartialOrderedEliminationSequenceStrategy(double theRatio=GUM_QUASI_RATIO, double theThreshold=GUM_WEIGHT_THRESHOLD)
default constructor (uses an empty graph)
UndiGraph * graph_
the graph to be triangulated
+ Here is the call graph for this function:

◆ DefaultPartialOrderedEliminationSequenceStrategy() [4/4]

gum::DefaultPartialOrderedEliminationSequenceStrategy::DefaultPartialOrderedEliminationSequenceStrategy ( DefaultPartialOrderedEliminationSequenceStrategy &&  from)

move constructor

Definition at line 82 of file defaultPartialOrderedEliminationSequenceStrategy.cpp.

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

83  :
85  _log_weights_(std::move(from._log_weights_)), _simplicial_set_(from._simplicial_set_),
86  _simplicial_ratio_(from._simplicial_ratio_),
87  _simplicial_threshold_(from._simplicial_threshold_),
88  _provide_fill_ins_(from._provide_fill_ins_) {
89  _simplicial_set_->replaceLogWeights(&from._log_weights_, &_log_weights_);
90  from._simplicial_set_ = nullptr;
91 
92  // for debugging purposes
94  }
double _simplicial_threshold_
the threshold used by simplicial_set to determine small cliques
double _simplicial_ratio_
the ratio used by simplicial_set for its quasi-simplicial nodes
void replaceLogWeights(NodeProperty< double > *old_weigths, NodeProperty< double > *new_weights)
reassigns a new set of cliques&#39; log weights (with the same content)
SimplicialSet * _simplicial_set_
the simplicial set used for determining the best nodes to eliminate
PartialOrderedEliminationSequenceStrategy()
default constructor (uses an empty graph)
NodeProperty< double > _log_weights_
for each node, the weight of the clique created by the node&#39;s elimination
DefaultPartialOrderedEliminationSequenceStrategy(double theRatio=GUM_QUASI_RATIO, double theThreshold=GUM_WEIGHT_THRESHOLD)
default constructor (uses an empty graph)
+ Here is the call graph for this function:

◆ ~DefaultPartialOrderedEliminationSequenceStrategy()

gum::DefaultPartialOrderedEliminationSequenceStrategy::~DefaultPartialOrderedEliminationSequenceStrategy ( )
virtual

destructor

Definition at line 98 of file defaultPartialOrderedEliminationSequenceStrategy.cpp.

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

98  {
99  // for debugging purposes
101 
103  }
SimplicialSet * _simplicial_set_
the simplicial set used for determining the best nodes to eliminate
DefaultPartialOrderedEliminationSequenceStrategy(double theRatio=GUM_QUASI_RATIO, double theThreshold=GUM_WEIGHT_THRESHOLD)
default constructor (uses an empty graph)
+ Here is the call graph for this function:

Member Function Documentation

◆ _createSimplicialSet_()

void gum::DefaultPartialOrderedEliminationSequenceStrategy::_createSimplicialSet_ ( )
private

create a new simplicial set suited for the current graph

Definition at line 106 of file defaultPartialOrderedEliminationSequenceStrategy.cpp.

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

106  {
107  // remove the old simplicial set, if any
108  if (_simplicial_set_ != nullptr) {
109  delete _simplicial_set_;
110  _simplicial_set_ = nullptr;
111  }
112 
113  if (graph_ != nullptr) {
114  // create a simplicial set suited for the graph
115  _simplicial_set_ = new SimplicialSet(graph_,
117  &_log_weights_,
120 
122  }
123  }
double _simplicial_threshold_
the threshold used by simplicial_set to determine small cliques
double _simplicial_ratio_
the ratio used by simplicial_set for its quasi-simplicial nodes
SimplicialSet * _simplicial_set_
the simplicial set used for determining the best nodes to eliminate
NodeProperty< double > _log_weights_
for each node, the weight of the clique created by the node&#39;s elimination
NodeProperty< double > log_domain_sizes_
the log of the domain sizes of the variables/nodes
UndiGraph * graph_
the graph to be triangulated
void setFillIns(bool on_off)
sets/unset the fill-ins storage in the standard triangulation procedure
+ Here is the call graph for this function:

◆ _nodeToEliminate_()

NodeId gum::DefaultPartialOrderedEliminationSequenceStrategy::_nodeToEliminate_ ( const PriorityQueue< NodeId, double > &  possibleNodes)
private

returns the best possible node to be eliminated

this function is used by method nextNodeToEliminate

Definition at line 149 of file defaultPartialOrderedEliminationSequenceStrategy.cpp.

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

150  {
151  bool found = false;
152  double min_score = 0;
153  NodeId best_node = 0;
154 
155  for (const auto node: nodeset_) {
156  try {
157  double score = possibleNodes.priority(node);
158 
159  if (!found || (score < min_score)) {
160  found = true;
161  min_score = score;
162  best_node = node;
163  }
164  } catch (NotFound&) {}
165  }
166 
167  if (!found) { GUM_ERROR(NotFound, "no possible node to eliminate") }
168 
169  return best_node;
170  }
const Priority & priority(const Val &elt) const
Returns the priority of an instance of the value passed in argument.
Size NodeId
Type for node ids.
Definition: graphElements.h:97
NodeSet nodeset_
the nodes which can be currently eliminated
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
+ Here is the call graph for this function:

◆ askFillIns()

void gum::DefaultPartialOrderedEliminationSequenceStrategy::askFillIns ( bool  do_it)
finalvirtual

if the elimination sequence is able to compute fill-ins, we indicate whether we want this feature to be activated

if the elimination sequence is able to compute fill-ins, we indicatewhether we want this feature to be activated

Parameters
do_itwhen true and the elimination sequence has the ability to compute fill-ins, the elimination sequence will actually compute them (for the triangulation to use them), else they will not be available.

Implements gum::EliminationSequenceStrategy.

Definition at line 218 of file defaultPartialOrderedEliminationSequenceStrategy.cpp.

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

218  {
219  _provide_fill_ins_ = do_it;
220 
222  }
SimplicialSet * _simplicial_set_
the simplicial set used for determining the best nodes to eliminate
void setFillIns(bool on_off)
sets/unset the fill-ins storage in the standard triangulation procedure
+ Here is the call graph for this function:

◆ clear()

void gum::DefaultPartialOrderedEliminationSequenceStrategy::clear ( )
finalvirtual

clears the sequence (to prepare, for instance, a new elimination sequence)

Reimplemented from gum::PartialOrderedEliminationSequenceStrategy.

Definition at line 138 of file defaultPartialOrderedEliminationSequenceStrategy.cpp.

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

138  {
140  _log_weights_.clear();
141 
142  if (_simplicial_set_ != nullptr) {
143  delete _simplicial_set_;
144  _simplicial_set_ = nullptr;
145  }
146  }
virtual void clear()
clears the sequence (to prepare, for instance, a new elimination sequence)
SimplicialSet * _simplicial_set_
the simplicial set used for determining the best nodes to eliminate
NodeProperty< double > _log_weights_
for each node, the weight of the clique created by the node&#39;s elimination
+ Here is the call graph for this function:

◆ copyFactory()

DefaultPartialOrderedEliminationSequenceStrategy * gum::DefaultPartialOrderedEliminationSequenceStrategy::copyFactory ( ) const
finalvirtual

virtual copy constructor

Warning
The newly created elimination sequence strategy points toward the same undirected graph as the one contained in the current strategy but each strategy possesses its own simplicial set. As a result, if both elimination strategies are used at the same time, they will probably result in a mess because their simplicial sets won't be synchronized correctly with the changing undirected graph. So, whenever using this virtual copy constructor, be sure that either the current or the newly created strategy is used for a triangulation but not both. This will necessarily be OK in DefaultTriangulations.

Implements gum::PartialOrderedEliminationSequenceStrategy.

Definition at line 280 of file defaultPartialOrderedEliminationSequenceStrategy.cpp.

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

280  {
282  }
DefaultPartialOrderedEliminationSequenceStrategy(double theRatio=GUM_QUASI_RATIO, double theThreshold=GUM_WEIGHT_THRESHOLD)
default constructor (uses an empty graph)
+ Here is the call graph for this function:

◆ domainSizes()

INLINE const NodeProperty< Size > * gum::EliminationSequenceStrategy::domainSizes ( ) const
noexceptinherited

returns the current domain sizes

Definition at line 40 of file eliminationSequenceStrategy_inl.h.

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

40  {
41  return domain_sizes_;
42  }
const NodeProperty< Size > * domain_sizes_
the domain sizes of the variables/nodes
+ Here is the call graph for this function:

◆ eliminationUpdate()

void gum::DefaultPartialOrderedEliminationSequenceStrategy::eliminationUpdate ( const NodeId  node)
finalvirtual

performs all the graph/fill-ins updates provided (if any)

performs all the graph/fill-ins updates provided

Parameters
nodethe node the elimination of which requires the graph update

Reimplemented from gum::EliminationSequenceStrategy.

Definition at line 238 of file defaultPartialOrderedEliminationSequenceStrategy.cpp.

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

238  {
239  // check whether we can do something
240  if (_simplicial_set_ != nullptr) {
243 
244  if (!partial_order_needed_) {
245  // remove the node from nodeset_
246  nodeset_.erase(id);
247 
248  if (nodeset_.empty()) {
249  // go to the next non-empty subset
250  for (++subset_iter_; subset_iter_ != subsets_->cend(); ++subset_iter_) {
251  for (const auto node: *subset_iter_) {
252  if (graph_->existsNode(node)) { nodeset_.insert(node); }
253  }
254  if (!nodeset_.empty()) break;
255  }
256  }
257  }
258  }
259  }
void makeClique(const NodeId id)
adds the necessary edges so that node &#39;id&#39; and its neighbors form a clique
bool empty() const noexcept
Indicates whether the set is the empty set.
Definition: set_tpl.h:700
void eraseClique(const NodeId id)
removes a node and its adjacent edges from the underlying graph
void erase(const Key &k)
Erases an element from the set.
Definition: set_tpl.h:649
SimplicialSet * _simplicial_set_
the simplicial set used for determining the best nodes to eliminate
List< NodeSet >::const_iterator subset_iter_
the iterator indicating which is the current subset on which we work
bool partial_order_needed_
indicate whether a new partial ordering is necessary for the elimination
bool existsNode(const NodeId id) const
returns true iff the NodeGraphPart contains the given nodeId
const List< NodeSet > * subsets_
the subsets constituting the partial ordering
UndiGraph * graph_
the graph to be triangulated
NodeSet nodeset_
the nodes which can be currently eliminated
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:606
+ Here is the call graph for this function:

◆ fillIns()

const EdgeSet & gum::DefaultPartialOrderedEliminationSequenceStrategy::fillIns ( )
finalvirtual

in case fill-ins are provided, this function returns the fill-ins due to all the nodes eliminated so far

in case fill-ins are provided, this function returns the fill-ins generated after the last node elimination

Reimplemented from gum::EliminationSequenceStrategy.

Definition at line 263 of file defaultPartialOrderedEliminationSequenceStrategy.cpp.

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

263  {
264  if (!_provide_fill_ins_ || (_simplicial_set_ == nullptr))
266  else
267  return _simplicial_set_->fillIns();
268  }
virtual const EdgeSet & fillIns()
in case fill-ins are provided, this function returns the fill-ins due to all the nodes eliminated so ...
SimplicialSet * _simplicial_set_
the simplicial set used for determining the best nodes to eliminate
const EdgeSet & fillIns() const
returns the set of all the fill-ins added to the graph so far
+ Here is the call graph for this function:

◆ graph()

INLINE UndiGraph * gum::EliminationSequenceStrategy::graph ( ) const
noexceptinherited

returns the current graph

Definition at line 36 of file eliminationSequenceStrategy_inl.h.

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

36 { return graph_; }
UndiGraph * graph_
the graph to be triangulated
+ Here is the call graph for this function:

◆ isPartialOrderNeeded()

INLINE bool gum::PartialOrderedEliminationSequenceStrategy::isPartialOrderNeeded ( ) const
noexceptinherited

indicates if a new partial ordering is needed

if the current partial ordering does not contain all the nodes of the graph or if the graph itself is not defined (nullptr) a new partial ordering will be needed for the next triangulation

Definition at line 44 of file partialOrderedEliminationSequenceStrategy_inl.h.

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

44  {
45  return partial_order_needed_;
46  }
bool partial_order_needed_
indicate whether a new partial ordering is necessary for the elimination
+ Here is the call graph for this function:

◆ isPartialOrderNeeded_()

bool gum::PartialOrderedEliminationSequenceStrategy::isPartialOrderNeeded_ ( const List< NodeSet > *  subsets) const
protectedinherited

indicate whether a partial ordering is compatible with the current graph

The method checks whether all the nodes of the graph belong to the partial ordering.

Returns
true if some nodes in graph_ do not belong to subsets or if graph_ is not defnined (nullptr)

Definition at line 99 of file partialOrderedEliminationSequenceStrategy.cpp.

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

100  {
101  if ((graph_ == nullptr) || (subsets == nullptr)) return true;
102 
103  // determine the set of nodes in the subsets that belong to the graph
104  NodeSet nodes_found(graph_->size() / 2);
105  for (const auto& nodes: *subsets) {
106  for (const auto node: nodes) {
107  if (graph_->existsNode(node)) { nodes_found.insert(node); }
108  }
109  }
110 
111  // check that the size of nodes_found is equal to that of the graph
112  return nodes_found.size() != graph_->size();
113  }
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
Size size() const
alias for sizeNodes
bool existsNode(const NodeId id) const
returns true iff the NodeGraphPart contains the given nodeId
UndiGraph * graph_
the graph to be triangulated
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:606
+ Here is the call graph for this function:

◆ newFactory()

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

creates a new elimination sequence of the same type as the current object, but this sequence contains only an empty graph

Warning
you must deallocate by yourself the object returned
Returns
an empty clone of the current object with the same type

Implements gum::PartialOrderedEliminationSequenceStrategy.

Definition at line 273 of file defaultPartialOrderedEliminationSequenceStrategy.cpp.

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

273  {
276  }
double _simplicial_threshold_
the threshold used by simplicial_set to determine small cliques
double _simplicial_ratio_
the ratio used by simplicial_set for its quasi-simplicial nodes
DefaultPartialOrderedEliminationSequenceStrategy(double theRatio=GUM_QUASI_RATIO, double theThreshold=GUM_WEIGHT_THRESHOLD)
default constructor (uses an empty graph)
+ Here is the call graph for this function:

◆ nextNodeToEliminate()

NodeId gum::DefaultPartialOrderedEliminationSequenceStrategy::nextNodeToEliminate ( )
finalvirtual

returns the new node to be eliminated within the triangulation algorithm

Exceptions
NotFoundexception is thrown if there is no more node to eliminate in the graph

Implements gum::EliminationSequenceStrategy.

Definition at line 173 of file defaultPartialOrderedEliminationSequenceStrategy.cpp.

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

173  {
174  // if there is no simplicial set, send an exception
175  if (graph_ == nullptr) GUM_ERROR(NotFound, "the graph is empty")
176 
178  GUM_ERROR(NotFound,
179  "the partial order does not cover all the nodes "
180  "of the graph");
181 
182  if (nodeset_.empty()) { GUM_ERROR(NotFound, "no node is admissible") }
183 
184  // select a node to be eliminated: try simplicial nodes, then almost
185  // simplicial nodes, then quasi-simplicial nodes
186  // note that if graph_ != nullptr, _simplicial_set_ has been allocated
187  try {
189  } catch (NotFound&) {}
190 
191  try {
193  } catch (NotFound&) {}
194 
195  try {
197  } catch (NotFound&) {}
198 
199  // here: select the node through Kjaerulff's heuristic
200  auto iter = nodeset_.cbegin();
201  double min_score = _log_weights_[*iter];
202  NodeId best_node = *iter;
203 
204  for (++iter; iter != nodeset_.cend(); ++iter) {
205  double score = _log_weights_[*iter];
206 
207  if (score < min_score) {
208  min_score = score;
209  best_node = *iter;
210  }
211  }
212 
213  return best_node;
214  }
NodeId _nodeToEliminate_(const PriorityQueue< NodeId, double > &possibleNodes)
returns the best possible node to be eliminated
const_iterator cbegin() const
The usual unsafe begin iterator to parse the set.
Definition: set_tpl.h:504
SimplicialSet * _simplicial_set_
the simplicial set used for determining the best nodes to eliminate
UndiGraph * graph() const noexcept
returns the current graph
const PriorityQueue< NodeId, double > & allSimplicialNodes()
returns all the simplicial nodes
const const_iterator & cend() const noexcept
The usual unsafe end iterator to parse the set.
Definition: set_tpl.h:517
NodeProperty< double > _log_weights_
for each node, the weight of the clique created by the node&#39;s elimination
bool partial_order_needed_
indicate whether a new partial ordering is necessary for the elimination
const PriorityQueue< NodeId, double > & allAlmostSimplicialNodes()
returns all the almost simplicial nodes
UndiGraph * graph_
the graph to be triangulated
const PriorityQueue< NodeId, double > & allQuasiSimplicialNodes()
returns all the quasi simplicial nodes
Size NodeId
Type for node ids.
Definition: graphElements.h:97
NodeSet nodeset_
the nodes which can be currently eliminated
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
+ Here is the call graph for this function:

◆ partialOrder()

INLINE const List< NodeSet > * gum::PartialOrderedEliminationSequenceStrategy::partialOrder ( ) const
noexceptinherited

returns the current partial ordering

Definition at line 38 of file partialOrderedEliminationSequenceStrategy_inl.h.

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

38  {
39  return subsets_;
40  }
const List< NodeSet > * subsets_
the subsets constituting the partial ordering
+ Here is the call graph for this function:

◆ providesFillIns()

bool gum::DefaultPartialOrderedEliminationSequenceStrategy::providesFillIns ( ) const
finalvirtual

indicates whether the fill-ins generated by the eliminated nodes, if needed, will be computed by the elimination sequence, or need be computed by the triangulation itself.

indicates whether the new fill-ins generated by a new eliminated node, if needed, will be computed by the elimination sequence, or need be computed by the triangulation itself.

An elimination sequence provides fill-ins to its triangulation if and only if it has the ability to compute them and it has been asked to do so (by method askFillIns)

Implements gum::EliminationSequenceStrategy.

Definition at line 227 of file defaultPartialOrderedEliminationSequenceStrategy.cpp.

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

227  {
228  return _provide_fill_ins_;
229  }
+ Here is the call graph for this function:

◆ providesGraphUpdate()

bool gum::DefaultPartialOrderedEliminationSequenceStrategy::providesGraphUpdate ( ) const
finalvirtual

indicates whether the elimination sequence updates by itself the graph after a node has been eliminated

Implements gum::EliminationSequenceStrategy.

Definition at line 233 of file defaultPartialOrderedEliminationSequenceStrategy.cpp.

233  {
234  return true;
235  }

◆ setGraph()

bool gum::DefaultPartialOrderedEliminationSequenceStrategy::setGraph ( UndiGraph graph,
const NodeProperty< Size > *  dom_sizes 
)
finalvirtual

sets a new graph to be triangulated

The elimination sequence algorithms reinitializes its data to start a new triangulation with graph Graph and a new partial ordrering

Parameters
graphthe new graph to be triangulated
dom_sizesthe domain sizes of the nodes/variables
Warning
Note that we allow dom_sizes to be defined over nodes/variables that do not belong to graph. These sizes will simply be ignored. However, it is compulsory that all the nodes of graph belong to dom_sizes
the graph is altered during the triangulation.
note that, by aGrUM's rule, the graph and the domain sizes are not copied but only referenced by the elimination sequence algorithm.

Reimplemented from gum::PartialOrderedEliminationSequenceStrategy.

Definition at line 126 of file defaultPartialOrderedEliminationSequenceStrategy.cpp.

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

128  {
131  return true;
132  }
133 
134  return false;
135  }
UndiGraph * graph() const noexcept
returns the current graph
virtual bool setGraph(UndiGraph *graph, const NodeProperty< Size > *dom_sizes)
sets a new graph to be triangulated
void _createSimplicialSet_()
create a new simplicial set suited for the current graph
+ Here is the call graph for this function:

◆ setPartialOrder()

bool gum::PartialOrderedEliminationSequenceStrategy::setPartialOrder ( const List< NodeSet > *  subsets)
virtualinherited

sets a new partial ordering constraint on the elimination sequence

sets a new partial order

Parameters
subsetsthe list of the subsets constituting the partial ordering
Returns
true if the new partial order has been successfully assigned (i.e., if all the nodes of the graph belong to one of the subsets)
Warning
if the subsets contain some nodes that do not belong to the graph, then these nodes are simply ignored.
note that, by aGrUM's rule, the partial ordering is not copied but only referenced by the elimination sequence algorithm.

Definition at line 116 of file partialOrderedEliminationSequenceStrategy.cpp.

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

116  {
117  // check that the partial order contains all the nodes of the graph
119 
120  if (!partial_order_needed_) {
121  subsets_ = subsets;
122 
123  // initialize properly the set of nodes that can be currently eliminated:
124  // find the first subset that contains some node(s) of the graph
125  nodeset_.clear();
126  for (subset_iter_ = subsets_->cbegin(); subset_iter_ != subsets_->cend(); ++subset_iter_) {
127  for (const auto node: *subset_iter_) {
128  if (graph_->existsNode(node)) { nodeset_.insert(node); }
129  }
130  if (!nodeset_.empty()) return true;
131  }
132  }
133 
134  return false;
135  }
bool empty() const noexcept
Indicates whether the set is the empty set.
Definition: set_tpl.h:700
List< NodeSet >::const_iterator subset_iter_
the iterator indicating which is the current subset on which we work
bool partial_order_needed_
indicate whether a new partial ordering is necessary for the elimination
bool isPartialOrderNeeded_(const List< NodeSet > *subsets) const
indicate whether a partial ordering is compatible with the current graph
bool existsNode(const NodeId id) const
returns true iff the NodeGraphPart contains the given nodeId
const List< NodeSet > * subsets_
the subsets constituting the partial ordering
void clear()
Removes all the elements, if any, from the set.
Definition: set_tpl.h:361
UndiGraph * graph_
the graph to be triangulated
NodeSet nodeset_
the nodes which can be currently eliminated
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:606
+ Here is the call graph for this function:

Member Data Documentation

◆ _log_weights_

NodeProperty< double > gum::DefaultPartialOrderedEliminationSequenceStrategy::_log_weights_
private

for each node, the weight of the clique created by the node's elimination

Definition at line 223 of file defaultPartialOrderedEliminationSequenceStrategy.h.

◆ _provide_fill_ins_

bool gum::DefaultPartialOrderedEliminationSequenceStrategy::_provide_fill_ins_ {false}
private

indicates whether we compute new fill-ins

Definition at line 235 of file defaultPartialOrderedEliminationSequenceStrategy.h.

◆ _simplicial_ratio_

double gum::DefaultPartialOrderedEliminationSequenceStrategy::_simplicial_ratio_
private

the ratio used by simplicial_set for its quasi-simplicial nodes

Definition at line 229 of file defaultPartialOrderedEliminationSequenceStrategy.h.

◆ _simplicial_set_

SimplicialSet* gum::DefaultPartialOrderedEliminationSequenceStrategy::_simplicial_set_ {nullptr}
private

the simplicial set used for determining the best nodes to eliminate

Definition at line 226 of file defaultPartialOrderedEliminationSequenceStrategy.h.

◆ _simplicial_threshold_

double gum::DefaultPartialOrderedEliminationSequenceStrategy::_simplicial_threshold_
private

the threshold used by simplicial_set to determine small cliques

Definition at line 232 of file defaultPartialOrderedEliminationSequenceStrategy.h.

◆ domain_sizes_

const NodeProperty< Size >* gum::EliminationSequenceStrategy::domain_sizes_ {nullptr}
protectedinherited

the domain sizes of the variables/nodes

Definition at line 158 of file eliminationSequenceStrategy.h.

◆ graph_

UndiGraph* gum::EliminationSequenceStrategy::graph_ {nullptr}
protectedinherited

the graph to be triangulated

Definition at line 155 of file eliminationSequenceStrategy.h.

◆ log_domain_sizes_

NodeProperty< double > gum::EliminationSequenceStrategy::log_domain_sizes_
protectedinherited

the log of the domain sizes of the variables/nodes

Definition at line 161 of file eliminationSequenceStrategy.h.

◆ nodeset_

NodeSet gum::PartialOrderedEliminationSequenceStrategy::nodeset_
protectedinherited

the nodes which can be currently eliminated

Definition at line 133 of file partialOrderedEliminationSequenceStrategy.h.

◆ partial_order_needed_

bool gum::PartialOrderedEliminationSequenceStrategy::partial_order_needed_ {true}
protectedinherited

indicate whether a new partial ordering is necessary for the elimination

Definition at line 136 of file partialOrderedEliminationSequenceStrategy.h.

◆ subset_iter_

List< NodeSet >::const_iterator gum::PartialOrderedEliminationSequenceStrategy::subset_iter_
protectedinherited

the iterator indicating which is the current subset on which we work

Definition at line 130 of file partialOrderedEliminationSequenceStrategy.h.

◆ subsets_

const List< NodeSet >* gum::PartialOrderedEliminationSequenceStrategy::subsets_ {nullptr}
protectedinherited

the subsets constituting the partial ordering

Definition at line 127 of file partialOrderedEliminationSequenceStrategy.h.


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