aGrUM  0.16.0
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 82 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 39 of file defaultPartialOrderedEliminationSequenceStrategy.cpp.

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

40  :
41  __simplicial_ratio(theRatio),
42  __simplicial_threshold(theThreshold) {
43  // for debugging purposes
45  }
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 49 of file defaultPartialOrderedEliminationSequenceStrategy.cpp.

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

54  :
55  __simplicial_ratio(ratio),
56  __simplicial_threshold(threshold) {
57  setGraph(graph, dom_sizes);
58  setPartialOrder(subsets);
59 
60  // for debugging purposes
62  }
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 66 of file defaultPartialOrderedEliminationSequenceStrategy.cpp.

References DefaultPartialOrderedEliminationSequenceStrategy().

67  :
69  // no need to set __log_weights because the copy of the simplicial set
70  // will set it properly
71  __simplicial_set(new SimplicialSet(*from.__simplicial_set,
72  _graph,
75  false)),
76  __simplicial_ratio(from.__simplicial_ratio),
77  __simplicial_threshold(from.__simplicial_threshold),
78  __provide_fill_ins(from.__provide_fill_ins) {
79  // for debugging purposes
81  }
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 85 of file defaultPartialOrderedEliminationSequenceStrategy.cpp.

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

86  :
88  __log_weights(std::move(from.__log_weights)),
89  __simplicial_set(from.__simplicial_set),
90  __simplicial_ratio(from.__simplicial_ratio),
91  __simplicial_threshold(from.__simplicial_threshold),
92  __provide_fill_ins(from.__provide_fill_ins) {
93  __simplicial_set->replaceLogWeights(&from.__log_weights, &__log_weights);
94  from.__simplicial_set = nullptr;
95 
96  // for debugging purposes
98  }
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 102 of file defaultPartialOrderedEliminationSequenceStrategy.cpp.

References __simplicial_set.

Referenced by DefaultPartialOrderedEliminationSequenceStrategy().

102  {
103  // for debugging purposes
105 
107  }
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 110 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().

110  {
111  // remove the old simplicial set, if any
112  if (__simplicial_set != nullptr) {
113  delete __simplicial_set;
114  __simplicial_set = nullptr;
115  }
116 
117  if (_graph != nullptr) {
118  // create a simplicial set suited for the graph
119  __simplicial_set = new SimplicialSet(_graph,
121  &__log_weights,
124 
126  }
127  }
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 152 of file defaultPartialOrderedEliminationSequenceStrategy.cpp.

References gum::PartialOrderedEliminationSequenceStrategy::_nodeset, GUM_ERROR, and gum::PriorityQueueImplementation< Val, Priority, Cmp, Alloc, Gen >::priority().

Referenced by nextNodeToEliminate().

153  {
154  bool found = false;
155  double min_score = 0;
156  NodeId best_node = 0;
157 
158  for (const auto node : _nodeset) {
159  try {
160  double score = possibleNodes.priority(node);
161 
162  if (!found || (score < min_score)) {
163  found = true;
164  min_score = score;
165  best_node = node;
166  }
167  } catch (NotFound&) {}
168  }
169 
170  if (!found) { GUM_ERROR(NotFound, "no possible node to eliminate"); }
171 
172  return best_node;
173  }
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:98
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _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 105 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().

106  {
107  if ((_graph == nullptr) || (subsets == nullptr)) return true;
108 
109  // determine the set of nodes in the subsets that belong to the graph
110  NodeSet nodes_found(_graph->size() / 2);
111  for (const auto& nodes : *subsets) {
112  for (const auto node : nodes) {
113  if (_graph->existsNode(node)) { nodes_found.insert(node); }
114  }
115  }
116 
117  // check that the size of nodes_found is equal to that of the graph
118  return nodes_found.size() != _graph->size();
119  }
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:613
+ 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 221 of file defaultPartialOrderedEliminationSequenceStrategy.cpp.

References __provide_fill_ins, __simplicial_set, and gum::SimplicialSet::setFillIns().

221  {
222  __provide_fill_ins = do_it;
223 
225  }
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 141 of file defaultPartialOrderedEliminationSequenceStrategy.cpp.

References __log_weights, __simplicial_set, and gum::PartialOrderedEliminationSequenceStrategy::clear().

141  {
143  __log_weights.clear();
144 
145  if (__simplicial_set != nullptr) {
146  delete __simplicial_set;
147  __simplicial_set = nullptr;
148  }
149  }
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 285 of file defaultPartialOrderedEliminationSequenceStrategy.cpp.

References DefaultPartialOrderedEliminationSequenceStrategy().

285  {
287  }
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 44 of file eliminationSequenceStrategy_inl.h.

References gum::EliminationSequenceStrategy::_domain_sizes.

44  {
45  return _domain_sizes;
46  }
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 242 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().

243  {
244  // check whether we can do something
245  if (__simplicial_set != nullptr) {
248 
249  if (!_partial_order_needed) {
250  // remove the node from _nodeset
251  _nodeset.erase(id);
252 
253  if (_nodeset.empty()) {
254  // go to the next non-empty subset
255  for (++_subset_iter; _subset_iter != _subsets->cend(); ++_subset_iter) {
256  for (const auto node : *_subset_iter) {
257  if (_graph->existsNode(node)) { _nodeset.insert(node); }
258  }
259  if (!_nodeset.empty()) break;
260  }
261  }
262  }
263  }
264  }
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:707
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:656
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:613
+ 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 268 of file defaultPartialOrderedEliminationSequenceStrategy.cpp.

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

268  {
269  if (!__provide_fill_ins || (__simplicial_set == nullptr))
271  else
272  return __simplicial_set->fillIns();
273  }
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 37 of file eliminationSequenceStrategy_inl.h.

References gum::EliminationSequenceStrategy::_graph.

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

37  {
38  return _graph;
39  }
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 46 of file partialOrderedEliminationSequenceStrategy_inl.h.

References gum::PartialOrderedEliminationSequenceStrategy::_partial_order_needed.

47  {
48  return _partial_order_needed;
49  }
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 278 of file defaultPartialOrderedEliminationSequenceStrategy.cpp.

References __simplicial_ratio, __simplicial_threshold, and DefaultPartialOrderedEliminationSequenceStrategy().

278  {
281  }
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 176 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.

176  {
177  // if there is no simplicial set, send an exception
178  if (_graph == nullptr) GUM_ERROR(NotFound, "the graph is empty");
179 
181  GUM_ERROR(NotFound,
182  "the partial order does not cover all the nodes "
183  "of the graph");
184 
185  if (_nodeset.empty()) { GUM_ERROR(NotFound, "no node is admissible"); }
186 
187  // select a node to be eliminated: try simplicial nodes, then almost
188  // simplicial nodes, then quasi-simplicial nodes
189  // note that if _graph != nullptr, __simplicial_set has been allocated
190  try {
192  } catch (NotFound&) {}
193 
194  try {
196  } catch (NotFound&) {}
197 
198  try {
200  } catch (NotFound&) {}
201 
202  // here: select the node through Kjaerulff's heuristic
203  auto iter = _nodeset.cbegin();
204  double min_score = __log_weights[*iter];
205  NodeId best_node = *iter;
206 
207  for (++iter; iter != _nodeset.cend(); ++iter) {
208  double score = __log_weights[*iter];
209 
210  if (score < min_score) {
211  min_score = score;
212  best_node = *iter;
213  }
214  }
215 
216  return best_node;
217  }
bool empty() const noexcept
Indicates whether the set is the empty set.
Definition: set_tpl.h:707
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:524
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:539
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:98
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
+ 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 39 of file partialOrderedEliminationSequenceStrategy_inl.h.

References gum::PartialOrderedEliminationSequenceStrategy::_subsets.

39  {
40  return _subsets;
41  }
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 230 of file defaultPartialOrderedEliminationSequenceStrategy.cpp.

References __provide_fill_ins.

230  {
231  return __provide_fill_ins;
232  }

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

237  {
238  return true;
239  }

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

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

Referenced by DefaultPartialOrderedEliminationSequenceStrategy().

131  {
134  return true;
135  }
136 
137  return false;
138  }
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 122 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().

123  {
124  // check that the partial order contains all the nodes of the graph
126 
127  if (!_partial_order_needed) {
128  _subsets = subsets;
129 
130  // initialize properly the set of nodes that can be currently eliminated:
131  // find the first subset that contains some node(s) of the graph
132  _nodeset.clear();
133  for (_subset_iter = _subsets->cbegin(); _subset_iter != _subsets->cend();
134  ++_subset_iter) {
135  for (const auto node : *_subset_iter) {
136  if (_graph->existsNode(node)) { _nodeset.insert(node); }
137  }
138  if (!_nodeset.empty()) return true;
139  }
140  }
141 
142  return false;
143  }
bool empty() const noexcept
Indicates whether the set is the empty set.
Definition: set_tpl.h:707
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:375
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:613
+ 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 229 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 241 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 235 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 238 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 132 of file partialOrderedEliminationSequenceStrategy.h.

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

◆ _subsets


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