aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
gum::EliminationSequenceStrategy Class Referenceabstract

The base class for all elimination sequence algorithms used by triangulation algorithms. More...

#include <eliminationSequenceStrategy.h>

+ Inheritance diagram for gum::EliminationSequenceStrategy:
+ Collaboration diagram for gum::EliminationSequenceStrategy:

Public Member Functions

Accessors / Modifiers
virtual bool setGraph (UndiGraph *graph, const NodeProperty< Size > *dom_sizes)
 sets a new graph to be triangulated More...
 
virtual NodeId nextNodeToEliminate ()=0
 returns the new node to be eliminated within the triangulation algorithm More...
 
virtual void askFillIns (bool do_it)=0
 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 =0
 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 =0
 indicates whether the elimination sequence updates by itself the graph after a node has been eliminated More...
 
virtual void eliminationUpdate (const NodeId node)
 performs all the graph/fill-ins updates provided (if any) More...
 
virtual const EdgeSetfillIns ()
 in case fill-ins are provided, this function returns the fill-ins due to all the nodes eliminated so far More...
 
virtual void clear ()
 clears the sequence (to prepare, for instance, a new elimination sequence) More...
 
UndiGraphgraph () const noexcept
 returns the current graph More...
 
const NodeProperty< Size > * domainSizes () const noexcept
 returns the current domain sizes More...
 

Protected Attributes

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

Constructors / Destructors

virtual ~EliminationSequenceStrategy ()
 destructor More...
 
virtual EliminationSequenceStrategynewFactory () const =0
 creates a new elimination sequence of the same type as the current object, but this sequence contains only an empty graph More...
 
virtual EliminationSequenceStrategycopyFactory () const =0
 virtual copy constructor More...
 
 EliminationSequenceStrategy ()
 default constructor More...
 
 EliminationSequenceStrategy (UndiGraph *graph, const NodeProperty< Size > *domain_sizes)
 constructor for an a priori non empty graph More...
 
 EliminationSequenceStrategy (const EliminationSequenceStrategy &from)
 copy constructor More...
 
 EliminationSequenceStrategy (EliminationSequenceStrategy &&from)
 move constructor More...
 

Detailed Description

The base class for all elimination sequence algorithms used by triangulation algorithms.

Definition at line 49 of file eliminationSequenceStrategy.h.

Constructor & Destructor Documentation

◆ ~EliminationSequenceStrategy()

gum::EliminationSequenceStrategy::~EliminationSequenceStrategy ( )
virtual

destructor

Definition at line 86 of file eliminationSequenceStrategy.cpp.

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

86  {
87  GUM_DESTRUCTOR(EliminationSequenceStrategy);
88  }
+ Here is the call graph for this function:

◆ EliminationSequenceStrategy() [1/4]

gum::EliminationSequenceStrategy::EliminationSequenceStrategy ( )
protected

default constructor

Definition at line 57 of file eliminationSequenceStrategy.cpp.

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

57  {
58  GUM_CONSTRUCTOR(EliminationSequenceStrategy);
59  }
+ Here is the call graph for this function:

◆ EliminationSequenceStrategy() [2/4]

gum::EliminationSequenceStrategy::EliminationSequenceStrategy ( UndiGraph graph,
const NodeProperty< Size > *  domain_sizes 
)
protected

constructor for an a priori non empty graph

Definition at line 62 of file eliminationSequenceStrategy.cpp.

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

64  {
66 
67  GUM_CONSTRUCTOR(EliminationSequenceStrategy);
68  }
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:

◆ EliminationSequenceStrategy() [3/4]

gum::EliminationSequenceStrategy::EliminationSequenceStrategy ( const EliminationSequenceStrategy from)
protected

copy constructor

Definition at line 71 of file eliminationSequenceStrategy.cpp.

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

72  :
73  graph_(from.graph_),
74  domain_sizes_(from.domain_sizes_), log_domain_sizes_(from.log_domain_sizes_) {
75  GUM_CONS_CPY(EliminationSequenceStrategy);
76  }
const NodeProperty< Size > * domain_sizes_
the domain sizes of the variables/nodes
NodeProperty< double > log_domain_sizes_
the log of the domain sizes of the variables/nodes
UndiGraph * graph_
the graph to be triangulated
+ Here is the call graph for this function:

◆ EliminationSequenceStrategy() [4/4]

gum::EliminationSequenceStrategy::EliminationSequenceStrategy ( EliminationSequenceStrategy &&  from)
protected

move constructor

Definition at line 79 of file eliminationSequenceStrategy.cpp.

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

79  :
80  graph_(from.graph_), domain_sizes_(from.domain_sizes_),
81  log_domain_sizes_(std::move(from.log_domain_sizes_)) {
82  GUM_CONS_MOV(EliminationSequenceStrategy);
83  }
const NodeProperty< Size > * domain_sizes_
the domain sizes of the variables/nodes
NodeProperty< double > log_domain_sizes_
the log of the domain sizes of the variables/nodes
UndiGraph * graph_
the graph to be triangulated
+ Here is the call graph for this function:

Member Function Documentation

◆ _empty_fill_ins_()

const EdgeSet & gum::EliminationSequenceStrategy::_empty_fill_ins_ ( )
staticprivate

an empty fill-ins set used by default

Definition at line 39 of file eliminationSequenceStrategy.cpp.

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

39  {
40 #ifdef GUM_DEBUG_MODE
41  static bool first_use = true;
42  if (first_use) {
43  first_use = false;
44  __debug__::_dec_creation_("Set", " __empty_edge_set", 0, "static variable correction", 0);
45  __debug__::_dec_creation_("HashTable",
46  " __empty_edge_set",
47  0,
48  "static variable correction",
49  0);
50  }
51 #endif
52  static EdgeSet empty_fill_ins;
53  return empty_fill_ins;
54  }
Set< Edge > EdgeSet
Some typdefs and define for shortcuts ...
+ Here is the call graph for this function:

◆ askFillIns()

virtual void gum::EliminationSequenceStrategy::askFillIns ( bool  do_it)
pure virtual

if the elimination sequence is able to compute fill-ins, we indicate whether 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.

Implemented in gum::DefaultPartialOrderedEliminationSequenceStrategy, gum::DefaultEliminationSequenceStrategy, and gum::OrderedEliminationSequenceStrategy.

◆ clear()

void gum::EliminationSequenceStrategy::clear ( )
virtual

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

Reimplemented in gum::DefaultPartialOrderedEliminationSequenceStrategy, gum::DefaultEliminationSequenceStrategy, gum::OrderedEliminationSequenceStrategy, and gum::PartialOrderedEliminationSequenceStrategy.

Definition at line 98 of file eliminationSequenceStrategy.cpp.

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

98  {
99  graph_ = nullptr;
100  domain_sizes_ = nullptr;
101  log_domain_sizes_.clear();
102  }
const NodeProperty< Size > * domain_sizes_
the domain sizes of the variables/nodes
NodeProperty< double > log_domain_sizes_
the log of the domain sizes of the variables/nodes
UndiGraph * graph_
the graph to be triangulated
+ Here is the call graph for this function:

◆ copyFactory()

virtual EliminationSequenceStrategy* gum::EliminationSequenceStrategy::copyFactory ( ) const
pure virtual

◆ domainSizes()

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

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::EliminationSequenceStrategy::eliminationUpdate ( const NodeId  node)
virtual

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

Parameters
nodethe node the elimination of which requires the graph update

Reimplemented in gum::DefaultPartialOrderedEliminationSequenceStrategy, gum::DefaultEliminationSequenceStrategy, and gum::OrderedEliminationSequenceStrategy.

Definition at line 91 of file eliminationSequenceStrategy.cpp.

91 {}

◆ fillIns()

const EdgeSet & gum::EliminationSequenceStrategy::fillIns ( )
virtual

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

Reimplemented in gum::DefaultPartialOrderedEliminationSequenceStrategy, gum::DefaultEliminationSequenceStrategy, and gum::OrderedEliminationSequenceStrategy.

Definition at line 95 of file eliminationSequenceStrategy.cpp.

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

95 { return _empty_fill_ins_(); }
static const EdgeSet & _empty_fill_ins_()
an empty fill-ins set used by default
+ Here is the call graph for this function:

◆ graph()

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

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:

◆ newFactory()

virtual EliminationSequenceStrategy* gum::EliminationSequenceStrategy::newFactory ( ) const
pure virtual

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

Implemented in gum::DefaultPartialOrderedEliminationSequenceStrategy, gum::DefaultEliminationSequenceStrategy, gum::OrderedEliminationSequenceStrategy, gum::UnconstrainedEliminationSequenceStrategy, and gum::PartialOrderedEliminationSequenceStrategy.

◆ nextNodeToEliminate()

virtual NodeId gum::EliminationSequenceStrategy::nextNodeToEliminate ( )
pure virtual

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

Implemented in gum::DefaultPartialOrderedEliminationSequenceStrategy, gum::DefaultEliminationSequenceStrategy, and gum::OrderedEliminationSequenceStrategy.

◆ providesFillIns()

virtual bool gum::EliminationSequenceStrategy::providesFillIns ( ) const
pure virtual

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.

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)

Implemented in gum::DefaultPartialOrderedEliminationSequenceStrategy, gum::DefaultEliminationSequenceStrategy, and gum::OrderedEliminationSequenceStrategy.

◆ providesGraphUpdate()

virtual bool gum::EliminationSequenceStrategy::providesGraphUpdate ( ) const
pure virtual

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

Some algorithms have more informations than the triangulation algorithm to update the graph after a node has been eliminated. They can thus exploit these informations to update the graph faster than the triangulation itself. Hence the latter should delegate this operation to the elimination sequence. This is the case, for instance, for the defaultEliminationSequenceStrategy, which uses a SimplicialSet that knows that some eliminated nodes do not require any fill-in.

Implemented in gum::DefaultPartialOrderedEliminationSequenceStrategy, gum::DefaultEliminationSequenceStrategy, and gum::OrderedEliminationSequenceStrategy.

◆ setGraph()

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

sets a new graph to be triangulated

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

Parameters
graphthe new graph to be triangulated
dom_sizesthe domain sizes of the variables/nodes
Returns
true if the data structures were modified (if the graph or the domain sizes did not change, then there is no need to update the data structures).
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 can be 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 in gum::DefaultPartialOrderedEliminationSequenceStrategy, gum::DefaultEliminationSequenceStrategy, gum::OrderedEliminationSequenceStrategy, and gum::PartialOrderedEliminationSequenceStrategy.

Definition at line 105 of file eliminationSequenceStrategy.cpp.

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

106  {
107  // check that both the graph and the domain sizes are different from nullptr
108  // or else that both are equal to nullptr
109  if (((graph != nullptr) && (dom_sizes == nullptr))
110  || ((graph == nullptr) && (dom_sizes != nullptr))) {
111  GUM_ERROR(GraphError,
112  "EliminationSequenceStrategy: one of the graph or the set of "
113  "domain sizes is a null pointer.");
114  }
115 
116  // check that each node has a domain size
117  if (graph != nullptr) {
118  for (const auto node: *graph)
119  if (!dom_sizes->exists(node))
120  GUM_ERROR(GraphError,
121  "EliminationSequenceStrategy needs a domain size "
122  "for every node in the graph.");
123  }
124 
125  // avoid empty modifications
126  if ((graph != graph_) || (dom_sizes != domain_sizes_)) {
127  // remove, if any, the current graph
128  clear();
129 
130  // assign a new graph
131  graph_ = graph;
132  domain_sizes_ = dom_sizes;
133 
134  if (graph_ != nullptr) {
135  // compute the log of the modalities
136  log_domain_sizes_.resize(graph_->sizeNodes() / 2);
137 
138  for (const auto node: *graph_)
139  log_domain_sizes_.insert(node, std::log((*domain_sizes_)[node]));
140  }
141 
142  return true;
143  }
144 
145  return false;
146  }
virtual void clear()
clears the sequence (to prepare, for instance, a new elimination sequence)
UndiGraph * graph() const noexcept
returns the current graph
const NodeProperty< Size > * domain_sizes_
the domain sizes of the variables/nodes
NodeProperty< double > log_domain_sizes_
the log of the domain sizes of the variables/nodes
Size sizeNodes() const
returns the number of nodes in the NodeGraphPart
UndiGraph * graph_
the graph to be triangulated
#define GUM_ERROR(type, msg)
Definition: exceptions.h:51
+ Here is the call graph for this function:

Member Data Documentation

◆ domain_sizes_

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

the domain sizes of the variables/nodes

Definition at line 158 of file eliminationSequenceStrategy.h.

◆ graph_

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

the graph to be triangulated

Definition at line 155 of file eliminationSequenceStrategy.h.

◆ log_domain_sizes_

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

the log of the domain sizes of the variables/nodes

Definition at line 161 of file eliminationSequenceStrategy.h.


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