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

The base class for all elimination sequence algorithms that require only the graph to be triangulated and the nodes' domain sizes to produce the node elimination ordering. More...

#include <unconstrainedEliminationSequenceStrategy.h>

+ Inheritance diagram for gum::UnconstrainedEliminationSequenceStrategy:
+ Collaboration diagram for gum::UnconstrainedEliminationSequenceStrategy:

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 ~UnconstrainedEliminationSequenceStrategy ()
 destructor More...
 
virtual UnconstrainedEliminationSequenceStrategynewFactory () 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 UnconstrainedEliminationSequenceStrategycopyFactory () const =0
 virtual copy constructor More...
 
 UnconstrainedEliminationSequenceStrategy ()
 default constructor More...
 
 UnconstrainedEliminationSequenceStrategy (UndiGraph *graph, const NodeProperty< Size > *dom_sizes)
 constructor for an a priori non empty graph More...
 
 UnconstrainedEliminationSequenceStrategy (const UnconstrainedEliminationSequenceStrategy &)
 copy constructor More...
 
 UnconstrainedEliminationSequenceStrategy (UnconstrainedEliminationSequenceStrategy &&)
 move constructor More...
 

Detailed Description

The base class for all elimination sequence algorithms that require only the graph to be triangulated and the nodes' domain sizes to produce the node elimination ordering.

Definition at line 59 of file unconstrainedEliminationSequenceStrategy.h.

Constructor & Destructor Documentation

◆ ~UnconstrainedEliminationSequenceStrategy()

gum::UnconstrainedEliminationSequenceStrategy::~UnconstrainedEliminationSequenceStrategy ( )
virtual

destructor

Definition at line 62 of file unconstrainedEliminationSequenceStrategy.cpp.

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

+ Here is the call graph for this function:

◆ UnconstrainedEliminationSequenceStrategy() [1/4]

gum::UnconstrainedEliminationSequenceStrategy::UnconstrainedEliminationSequenceStrategy ( )
protected

default constructor

Definition at line 36 of file unconstrainedEliminationSequenceStrategy.cpp.

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

+ Here is the call graph for this function:

◆ UnconstrainedEliminationSequenceStrategy() [2/4]

gum::UnconstrainedEliminationSequenceStrategy::UnconstrainedEliminationSequenceStrategy ( UndiGraph graph,
const NodeProperty< Size > *  dom_sizes 
)
protected

constructor for an a priori non empty graph

Parameters
graphthe graph to be triangulated, i.e., the nodes of which will be eliminated
dom_sizesthe domain sizes of the nodes to be eliminated
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.

Definition at line 41 of file unconstrainedEliminationSequenceStrategy.cpp.

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

43  :
46  }
UndiGraph * graph() const noexcept
returns the current graph
+ Here is the call graph for this function:

◆ UnconstrainedEliminationSequenceStrategy() [3/4]

gum::UnconstrainedEliminationSequenceStrategy::UnconstrainedEliminationSequenceStrategy ( const UnconstrainedEliminationSequenceStrategy from)
protected

copy constructor

Definition at line 49 of file unconstrainedEliminationSequenceStrategy.cpp.

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

+ Here is the call graph for this function:

◆ UnconstrainedEliminationSequenceStrategy() [4/4]

gum::UnconstrainedEliminationSequenceStrategy::UnconstrainedEliminationSequenceStrategy ( UnconstrainedEliminationSequenceStrategy &&  from)
protected

move constructor

Definition at line 56 of file unconstrainedEliminationSequenceStrategy.cpp.

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

+ Here is the call graph for this function:

Member Function Documentation

◆ askFillIns()

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

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 ( )
virtualinherited

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 UnconstrainedEliminationSequenceStrategy* gum::UnconstrainedEliminationSequenceStrategy::copyFactory ( ) const
pure virtual

virtual copy constructor

Implements gum::EliminationSequenceStrategy.

Implemented in gum::DefaultEliminationSequenceStrategy.

◆ domainSizes()

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

returns the current domain sizes

Definition at line 40 of file eliminationSequenceStrategy_inl.h.

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

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

◆ eliminationUpdate()

void gum::EliminationSequenceStrategy::eliminationUpdate ( const NodeId  node)
virtualinherited

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 ( )
virtualinherited

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
noexceptinherited

returns the current graph

Definition at line 36 of file eliminationSequenceStrategy_inl.h.

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

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

◆ newFactory()

virtual UnconstrainedEliminationSequenceStrategy* gum::UnconstrainedEliminationSequenceStrategy::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

Implements gum::EliminationSequenceStrategy.

Implemented in gum::DefaultEliminationSequenceStrategy.

◆ nextNodeToEliminate()

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

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 virtualinherited

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 virtualinherited

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 
)
virtualinherited

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}
protectedinherited

the domain sizes of the variables/nodes

Definition at line 158 of file eliminationSequenceStrategy.h.

◆ graph_

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

the graph to be triangulated

Definition at line 155 of file eliminationSequenceStrategy.h.

◆ log_domain_sizes_

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

the log of the domain sizes of the variables/nodes

Definition at line 161 of file eliminationSequenceStrategy.h.


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