aGrUM  0.14.2
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...
 
UndiGraph_graph {nullptr}
 the graph to be triangulated More...
 
const NodeProperty< Size > * _domain_sizes {nullptr}
 the domain sizes of the variables/nodes More...
 
NodeProperty< double_log_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 79 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 36 of file defaultPartialOrderedEliminationSequenceStrategy.cpp.

Referenced by copyFactory(), DefaultPartialOrderedEliminationSequenceStrategy(), and newFactory().

37  :
38  __simplicial_ratio(theRatio),
39  __simplicial_threshold(theThreshold) {
40  // for debugging purposes
42  }
double __simplicial_ratio
the ratio used by __simplicial_set for its quasi-simplicial nodes
double __simplicial_threshold
the threshold used by __simplicial_set to determine small cliques
DefaultPartialOrderedEliminationSequenceStrategy(double theRatio=GUM_QUASI_RATIO, double theThreshold=GUM_WEIGHT_THRESHOLD)
default constructor (uses an empty graph)
+ Here is the caller 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 46 of file defaultPartialOrderedEliminationSequenceStrategy.cpp.

References DefaultPartialOrderedEliminationSequenceStrategy(), setGraph(), and gum::PartialOrderedEliminationSequenceStrategy::setPartialOrder().

51  :
52  __simplicial_ratio(ratio),
53  __simplicial_threshold(threshold) {
54  setGraph(graph, dom_sizes);
55  setPartialOrder(subsets);
56 
57  // for debugging purposes
59  }
virtual bool setPartialOrder(const List< NodeSet > *subsets)
sets a new partial ordering constraint on the elimination sequence
double __simplicial_ratio
the ratio used by __simplicial_set for its quasi-simplicial nodes
double __simplicial_threshold
the threshold used by __simplicial_set to determine small cliques
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 DefaultPartialOrderedEliminationSequenceStrategy().

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  }
UndiGraph * _graph
the graph to be triangulated
NodeProperty< double > _log_domain_sizes
the log of the domain sizes of the variables/nodes
NodeProperty< double > __log_weights
for each node, the weight of the clique created by the node&#39;s elimination
double __simplicial_ratio
the ratio used by __simplicial_set for its quasi-simplicial nodes
double __simplicial_threshold
the threshold used by __simplicial_set to determine small cliques
SimplicialSet * __simplicial_set
the simplicial set used for determining the best nodes to eliminate
PartialOrderedEliminationSequenceStrategy()
default constructor (uses an empty graph)
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() [4/4]

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

move constructor

Definition at line 82 of file defaultPartialOrderedEliminationSequenceStrategy.cpp.

References __log_weights, __simplicial_set, gum::SimplicialSet::replaceLogWeights(), and ~DefaultPartialOrderedEliminationSequenceStrategy().

83  :
85  __log_weights(std::move(from.__log_weights)),
86  __simplicial_set(from.__simplicial_set),
87  __simplicial_ratio(from.__simplicial_ratio),
88  __simplicial_threshold(from.__simplicial_threshold),
89  __provide_fill_ins(from.__provide_fill_ins) {
90  __simplicial_set->replaceLogWeights(&from.__log_weights, &__log_weights);
91  from.__simplicial_set = nullptr;
92 
93  // for debugging purposes
95  }
void replaceLogWeights(NodeProperty< double > *old_weigths, NodeProperty< double > *new_weights)
reassigns a new set of cliques&#39; log weights (with the same content)
NodeProperty< double > __log_weights
for each node, the weight of the clique created by the node&#39;s elimination
double __simplicial_ratio
the ratio used by __simplicial_set for its quasi-simplicial nodes
double __simplicial_threshold
the threshold used by __simplicial_set to determine small cliques
SimplicialSet * __simplicial_set
the simplicial set used for determining the best nodes to eliminate
PartialOrderedEliminationSequenceStrategy()
default constructor (uses an empty graph)
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 99 of file defaultPartialOrderedEliminationSequenceStrategy.cpp.

References __simplicial_set.

Referenced by DefaultPartialOrderedEliminationSequenceStrategy().

99  {
100  // for debugging purposes
102 
104  }
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 caller 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 107 of file defaultPartialOrderedEliminationSequenceStrategy.cpp.

References __log_weights, __provide_fill_ins, __simplicial_ratio, __simplicial_set, __simplicial_threshold, gum::EliminationSequenceStrategy::_graph, gum::EliminationSequenceStrategy::_log_domain_sizes, and gum::SimplicialSet::setFillIns().

Referenced by setGraph().

107  {
108  // remove the old simplicial set, if any
109  if (__simplicial_set != nullptr) {
110  delete __simplicial_set;
111  __simplicial_set = nullptr;
112  }
113 
114  if (_graph != nullptr) {
115  // create a simplicial set suited for the graph
116  __simplicial_set = new SimplicialSet(_graph,
118  &__log_weights,
121 
123  }
124  }
UndiGraph * _graph
the graph to be triangulated
NodeProperty< double > _log_domain_sizes
the log of the domain sizes of the variables/nodes
NodeProperty< double > __log_weights
for each node, the weight of the clique created by the node&#39;s elimination
double __simplicial_ratio
the ratio used by __simplicial_set for its quasi-simplicial nodes
double __simplicial_threshold
the threshold used by __simplicial_set to determine small cliques
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:
+ Here is the caller 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::PartialOrderedEliminationSequenceStrategy::_nodeset, GUM_ERROR, and gum::PriorityQueueImplementation< Val, Priority, Cmp, Alloc, Gen >::priority().

Referenced by nextNodeToEliminate().

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.
NodeSet _nodeset
the nodes which can be currently eliminated
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:

◆ _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 102 of file partialOrderedEliminationSequenceStrategy.cpp.

References gum::EliminationSequenceStrategy::_graph, gum::NodeGraphPart::existsNode(), gum::Set< Key, Alloc >::insert(), and gum::NodeGraphPart::size().

Referenced by gum::PartialOrderedEliminationSequenceStrategy::setPartialOrder().

103  {
104  if ((_graph == nullptr) || (subsets == nullptr)) return true;
105 
106  // determine the set of nodes in the subsets that belong to the graph
107  NodeSet nodes_found(_graph->size() / 2);
108  for (const auto& nodes : *subsets) {
109  for (const auto node : nodes) {
110  if (_graph->existsNode(node)) { nodes_found.insert(node); }
111  }
112  }
113 
114  // check that the size of nodes_found is equal to that of the graph
115  return nodes_found.size() != _graph->size();
116  }
UndiGraph * _graph
the graph to be triangulated
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
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:610
+ Here is the call graph for this function:
+ Here is the caller 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 __provide_fill_ins, __simplicial_set, and gum::SimplicialSet::setFillIns().

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 __log_weights, __simplicial_set, and gum::PartialOrderedEliminationSequenceStrategy::clear().

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)
NodeProperty< double > __log_weights
for each node, the weight of the clique created by the node&#39;s elimination
SimplicialSet * __simplicial_set
the simplicial set used for determining the best nodes to eliminate
+ 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 282 of file defaultPartialOrderedEliminationSequenceStrategy.cpp.

References DefaultPartialOrderedEliminationSequenceStrategy().

282  {
284  }
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 41 of file eliminationSequenceStrategy_inl.h.

References gum::EliminationSequenceStrategy::_domain_sizes.

41  {
42  return _domain_sizes;
43  }
const NodeProperty< Size > * _domain_sizes
the domain sizes of the variables/nodes

◆ 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 239 of file defaultPartialOrderedEliminationSequenceStrategy.cpp.

References __simplicial_set, gum::EliminationSequenceStrategy::_graph, gum::PartialOrderedEliminationSequenceStrategy::_nodeset, gum::PartialOrderedEliminationSequenceStrategy::_partial_order_needed, gum::PartialOrderedEliminationSequenceStrategy::_subset_iter, gum::PartialOrderedEliminationSequenceStrategy::_subsets, gum::Set< Key, Alloc >::empty(), gum::Set< Key, Alloc >::erase(), gum::SimplicialSet::eraseClique(), gum::NodeGraphPart::existsNode(), gum::Set< Key, Alloc >::insert(), and gum::SimplicialSet::makeClique().

240  {
241  // check whether we can do something
242  if (__simplicial_set != nullptr) {
245 
246  if (!_partial_order_needed) {
247  // remove the node from _nodeset
248  _nodeset.erase(id);
249 
250  if (_nodeset.empty()) {
251  // go to the next non-empty subset
252  for (++_subset_iter; _subset_iter != _subsets->cend(); ++_subset_iter) {
253  for (const auto node : *_subset_iter) {
254  if (_graph->existsNode(node)) { _nodeset.insert(node); }
255  }
256  if (!_nodeset.empty()) break;
257  }
258  }
259  }
260  }
261  }
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:704
UndiGraph * _graph
the graph to be triangulated
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:653
SimplicialSet * __simplicial_set
the simplicial set used for determining the best nodes to eliminate
NodeSet _nodeset
the nodes which can be currently eliminated
const List< NodeSet > * _subsets
the subsets constituting the partial ordering
bool existsNode(const NodeId id) const
returns true iff the NodeGraphPart contains the given nodeId
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
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:610
+ 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 265 of file defaultPartialOrderedEliminationSequenceStrategy.cpp.

References __provide_fill_ins, __simplicial_set, gum::EliminationSequenceStrategy::fillIns(), and gum::SimplicialSet::fillIns().

265  {
266  if (!__provide_fill_ins || (__simplicial_set == nullptr))
268  else
269  return __simplicial_set->fillIns();
270  }
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 34 of file eliminationSequenceStrategy_inl.h.

References gum::EliminationSequenceStrategy::_graph.

Referenced by gum::EliminationSequenceStrategy::setGraph().

34  {
35  return _graph;
36  }
UndiGraph * _graph
the graph to be triangulated
+ Here is the caller 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 43 of file partialOrderedEliminationSequenceStrategy_inl.h.

References gum::PartialOrderedEliminationSequenceStrategy::_partial_order_needed.

44  {
45  return _partial_order_needed;
46  }
bool _partial_order_needed
indicate whether a new partial ordering is necessary for the elimination

◆ 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 275 of file defaultPartialOrderedEliminationSequenceStrategy.cpp.

References __simplicial_ratio, __simplicial_threshold, and DefaultPartialOrderedEliminationSequenceStrategy().

275  {
278  }
double __simplicial_ratio
the ratio used by __simplicial_set for its quasi-simplicial nodes
double __simplicial_threshold
the threshold used by __simplicial_set to determine small cliques
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 __log_weights, __nodeToEliminate(), __simplicial_set, gum::EliminationSequenceStrategy::_graph, gum::PartialOrderedEliminationSequenceStrategy::_nodeset, gum::PartialOrderedEliminationSequenceStrategy::_partial_order_needed, gum::SimplicialSet::allAlmostSimplicialNodes(), gum::SimplicialSet::allQuasiSimplicialNodes(), gum::SimplicialSet::allSimplicialNodes(), gum::Set< Key, Alloc >::cbegin(), gum::Set< Key, Alloc >::cend(), gum::Set< Key, Alloc >::empty(), and GUM_ERROR.

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  }
bool empty() const noexcept
Indicates whether the set is the empty set.
Definition: set_tpl.h:704
UndiGraph * _graph
the graph to be triangulated
NodeProperty< double > __log_weights
for each node, the weight of the clique created by the node&#39;s elimination
const_iterator cbegin() const
The usual unsafe begin iterator to parse the set.
Definition: set_tpl.h:521
NodeId __nodeToEliminate(const PriorityQueue< NodeId, double > &possibleNodes)
returns the best possible node to be eliminated
SimplicialSet * __simplicial_set
the simplicial set used for determining the best nodes to eliminate
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:536
NodeSet _nodeset
the nodes which can be currently eliminated
const PriorityQueue< NodeId, double > & allAlmostSimplicialNodes()
returns all the almost simplicial nodes
bool _partial_order_needed
indicate whether a new partial ordering is necessary for the elimination
const PriorityQueue< NodeId, double > & allQuasiSimplicialNodes()
returns all the quasi simplicial nodes
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:

◆ partialOrder()

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

returns the current partial ordering

Definition at line 36 of file partialOrderedEliminationSequenceStrategy_inl.h.

References gum::PartialOrderedEliminationSequenceStrategy::_subsets.

36  {
37  return _subsets;
38  }
const List< NodeSet > * _subsets
the subsets constituting the partial ordering

◆ 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 __provide_fill_ins.

227  {
228  return __provide_fill_ins;
229  }

◆ 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.

234  {
235  return true;
236  }

◆ 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 127 of file defaultPartialOrderedEliminationSequenceStrategy.cpp.

References __createSimplicialSet(), and gum::PartialOrderedEliminationSequenceStrategy::setGraph().

Referenced by DefaultPartialOrderedEliminationSequenceStrategy().

128  {
131  return true;
132  }
133 
134  return false;
135  }
void __createSimplicialSet()
create a new simplicial set suited for the current graph
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
+ Here is the call graph for this function:
+ Here is the caller 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 119 of file partialOrderedEliminationSequenceStrategy.cpp.

References gum::EliminationSequenceStrategy::_graph, gum::PartialOrderedEliminationSequenceStrategy::_isPartialOrderNeeded(), gum::PartialOrderedEliminationSequenceStrategy::_nodeset, gum::PartialOrderedEliminationSequenceStrategy::_partial_order_needed, gum::PartialOrderedEliminationSequenceStrategy::_subset_iter, gum::PartialOrderedEliminationSequenceStrategy::_subsets, gum::Set< Key, Alloc >::clear(), gum::Set< Key, Alloc >::empty(), gum::NodeGraphPart::existsNode(), and gum::Set< Key, Alloc >::insert().

Referenced by gum::PartialOrderedTriangulation::_initTriangulation(), DefaultPartialOrderedEliminationSequenceStrategy(), gum::PartialOrderedEliminationSequenceStrategy::PartialOrderedEliminationSequenceStrategy(), and gum::PartialOrderedEliminationSequenceStrategy::setGraph().

120  {
121  // check that the partial order contains all the nodes of the graph
123 
124  if (!_partial_order_needed) {
125  _subsets = subsets;
126 
127  // initialize properly the set of nodes that can be currently eliminated:
128  // find the first subset that contains some node(s) of the graph
129  _nodeset.clear();
130  for (_subset_iter = _subsets->cbegin(); _subset_iter != _subsets->cend();
131  ++_subset_iter) {
132  for (const auto node : *_subset_iter) {
133  if (_graph->existsNode(node)) { _nodeset.insert(node); }
134  }
135  if (!_nodeset.empty()) return true;
136  }
137  }
138 
139  return false;
140  }
bool empty() const noexcept
Indicates whether the set is the empty set.
Definition: set_tpl.h:704
UndiGraph * _graph
the graph to be triangulated
bool _isPartialOrderNeeded(const List< NodeSet > *subsets) const
indicate whether a partial ordering is compatible with the current graph
NodeSet _nodeset
the nodes which can be currently eliminated
const List< NodeSet > * _subsets
the subsets constituting the partial ordering
bool existsNode(const NodeId id) const
returns true iff the NodeGraphPart contains the given nodeId
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
void clear()
Removes all the elements, if any, from the set.
Definition: set_tpl.h:372
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:610
+ Here is the call graph for this function:
+ Here is the caller 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 226 of file defaultPartialOrderedEliminationSequenceStrategy.h.

Referenced by __createSimplicialSet(), clear(), DefaultPartialOrderedEliminationSequenceStrategy(), and nextNodeToEliminate().

◆ __provide_fill_ins

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

indicates whether we compute new fill-ins

Definition at line 238 of file defaultPartialOrderedEliminationSequenceStrategy.h.

Referenced by __createSimplicialSet(), askFillIns(), fillIns(), and providesFillIns().

◆ __simplicial_ratio

double gum::DefaultPartialOrderedEliminationSequenceStrategy::__simplicial_ratio
private

the ratio used by __simplicial_set for its quasi-simplicial nodes

Definition at line 232 of file defaultPartialOrderedEliminationSequenceStrategy.h.

Referenced by __createSimplicialSet(), and newFactory().

◆ __simplicial_set

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

◆ __simplicial_threshold

double gum::DefaultPartialOrderedEliminationSequenceStrategy::__simplicial_threshold
private

the threshold used by __simplicial_set to determine small cliques

Definition at line 235 of file defaultPartialOrderedEliminationSequenceStrategy.h.

Referenced by __createSimplicialSet(), and newFactory().

◆ _domain_sizes

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

◆ _graph

◆ _log_domain_sizes

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

◆ _nodeset

NodeSet gum::PartialOrderedEliminationSequenceStrategy::_nodeset
protectedinherited

◆ _partial_order_needed

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

◆ _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 129 of file partialOrderedEliminationSequenceStrategy.h.

Referenced by eliminationUpdate(), and gum::PartialOrderedEliminationSequenceStrategy::setPartialOrder().

◆ _subsets


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