aGrUM  0.16.0
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

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

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 50 of file eliminationSequenceStrategy.h.

Constructor & Destructor Documentation

◆ ~EliminationSequenceStrategy()

gum::EliminationSequenceStrategy::~EliminationSequenceStrategy ( )
virtual

destructor

Definition at line 91 of file eliminationSequenceStrategy.cpp.

91  {
92  // for debugging purposes
93  GUM_DESTRUCTOR(EliminationSequenceStrategy);
94  }

◆ EliminationSequenceStrategy() [1/4]

gum::EliminationSequenceStrategy::EliminationSequenceStrategy ( )
protected

default constructor

Definition at line 56 of file eliminationSequenceStrategy.cpp.

56  {
57  // for debugging purposes
58  GUM_CONSTRUCTOR(EliminationSequenceStrategy);
59  }

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

63  {
65 
66  // for debugging purposes
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.

72  :
73  _graph(from._graph),
74  _domain_sizes(from._domain_sizes),
75  _log_domain_sizes(from._log_domain_sizes) {
76  // for debugging purposes
77  GUM_CONS_CPY(EliminationSequenceStrategy);
78  }
UndiGraph * _graph
the graph to be triangulated
NodeProperty< double > _log_domain_sizes
the log of the domain sizes of the variables/nodes
const NodeProperty< Size > * _domain_sizes
the domain sizes of the variables/nodes

◆ EliminationSequenceStrategy() [4/4]

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

move constructor

Definition at line 81 of file eliminationSequenceStrategy.cpp.

82  :
83  _graph(from._graph),
84  _domain_sizes(from._domain_sizes),
85  _log_domain_sizes(std::move(from._log_domain_sizes)) {
86  // for debugging purposes
87  GUM_CONS_MOV(EliminationSequenceStrategy);
88  }
UndiGraph * _graph
the graph to be triangulated
NodeProperty< double > _log_domain_sizes
the log of the domain sizes of the variables/nodes
const NodeProperty< Size > * _domain_sizes
the domain sizes of the variables/nodes

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 40 of file eliminationSequenceStrategy.cpp.

Referenced by fillIns().

40  {
41 #ifdef GUM_DEBUG_MODE
42  static bool first_use = true;
43  if (first_use) {
44  first_use = false;
45  __debug__::__dec_creation(
46  "Set", "__empty_edge_set", 0, "static variable correction", 0);
47  __debug__::__dec_creation(
48  "HashTable", "__empty_edge_set", 0, "static variable correction", 0);
49  }
50 #endif
51  static EdgeSet empty_fill_ins;
52  return empty_fill_ins;
53  }
Set< Edge > EdgeSet
Some typdefs and define for shortcuts ...
+ Here is the caller 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.

Referenced by gum::StaticTriangulation::__triangulate().

+ Here is the caller graph for this function:

◆ 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 106 of file eliminationSequenceStrategy.cpp.

References _domain_sizes, _graph, and _log_domain_sizes.

Referenced by gum::PartialOrderedEliminationSequenceStrategy::clear(), gum::OrderedEliminationSequenceStrategy::clear(), gum::StaticTriangulation::clear(), gum::DefaultEliminationSequenceStrategy::clear(), and setGraph().

106  {
107  _graph = nullptr;
108  _domain_sizes = nullptr;
109  _log_domain_sizes.clear();
110  }
UndiGraph * _graph
the graph to be triangulated
NodeProperty< double > _log_domain_sizes
the log of the domain sizes of the variables/nodes
const NodeProperty< Size > * _domain_sizes
the domain sizes of the variables/nodes
+ Here is the caller graph for this function:

◆ copyFactory()

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

virtual copy constructor

Returns
a full clone of the current object

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

Referenced by gum::StaticTriangulation::StaticTriangulation().

+ Here is the caller graph for this function:

◆ domainSizes()

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

returns the current domain sizes

Definition at line 44 of file eliminationSequenceStrategy_inl.h.

References _domain_sizes.

44  {
45  return _domain_sizes;
46  }
const NodeProperty< Size > * _domain_sizes
the domain sizes of the variables/nodes

◆ 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 97 of file eliminationSequenceStrategy.cpp.

Referenced by gum::StaticTriangulation::__triangulate().

97 {}
+ Here is the caller graph for this function:

◆ 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 101 of file eliminationSequenceStrategy.cpp.

References __empty_fill_ins().

Referenced by gum::StaticTriangulation::fillIns(), gum::OrderedEliminationSequenceStrategy::fillIns(), gum::DefaultEliminationSequenceStrategy::fillIns(), and gum::DefaultPartialOrderedEliminationSequenceStrategy::fillIns().

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

◆ graph()

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

returns the current graph

Definition at line 37 of file eliminationSequenceStrategy_inl.h.

References _graph.

Referenced by setGraph().

37  {
38  return _graph;
39  }
UndiGraph * _graph
the graph to be triangulated
+ Here is the caller 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.

Referenced by gum::StaticTriangulation::__triangulate().

+ Here is the caller graph for this function:

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

Referenced by gum::StaticTriangulation::__triangulate(), and gum::StaticTriangulation::fillIns().

+ Here is the caller graph for this function:

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

Referenced by gum::StaticTriangulation::__triangulate().

+ Here is the caller graph for this function:

◆ 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 114 of file eliminationSequenceStrategy.cpp.

References _domain_sizes, _graph, _log_domain_sizes, clear(), gum::HashTable< Key, Val, Alloc >::exists(), graph(), GUM_ERROR, and gum::NodeGraphPart::sizeNodes().

Referenced by gum::StaticTriangulation::_initTriangulation(), EliminationSequenceStrategy(), gum::PartialOrderedEliminationSequenceStrategy::setGraph(), gum::OrderedEliminationSequenceStrategy::setGraph(), and gum::DefaultEliminationSequenceStrategy::setGraph().

115  {
116  // check that both the graph and the domain sizes are different from nullptr
117  // or else that both are equal to nullptr
118  if (((graph != nullptr) && (dom_sizes == nullptr))
119  || ((graph == nullptr) && (dom_sizes != nullptr))) {
120  GUM_ERROR(GraphError,
121  "EliminationSequenceStrategy: one of the graph or the set of "
122  "domain sizes is a null pointer.");
123  }
124 
125  // check that each node has a domain size
126  if (graph != nullptr) {
127  for (const auto node : *graph)
128  if (!dom_sizes->exists(node))
129  GUM_ERROR(GraphError,
130  "EliminationSequenceStrategy needs a domain size "
131  "for every node in the graph.");
132  }
133 
134  // avoid empty modifications
135  if ((graph != _graph) || (dom_sizes != _domain_sizes)) {
136  // remove, if any, the current graph
137  clear();
138 
139  // assign a new graph
140  _graph = graph;
141  _domain_sizes = dom_sizes;
142 
143  if (_graph != nullptr) {
144  // compute the log of the modalities
145  _log_domain_sizes.resize(_graph->sizeNodes() / 2);
146 
147  for (const auto node : *_graph)
148  _log_domain_sizes.insert(node, std::log((*_domain_sizes)[node]));
149  }
150 
151  return true;
152  }
153 
154  return false;
155  }
virtual void clear()
clears the sequence (to prepare, for instance, a new elimination sequence)
UndiGraph * _graph
the graph to be triangulated
NodeProperty< double > _log_domain_sizes
the log of the domain sizes of the variables/nodes
UndiGraph * graph() const noexcept
returns the current graph
Size sizeNodes() const
returns the number of nodes in the NodeGraphPart
const NodeProperty< Size > * _domain_sizes
the domain sizes of the variables/nodes
#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:

Member Data Documentation

◆ _domain_sizes

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

the domain sizes of the variables/nodes

Definition at line 159 of file eliminationSequenceStrategy.h.

Referenced by clear(), domainSizes(), and setGraph().

◆ _graph

◆ _log_domain_sizes

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

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