aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
gum::OrderedEliminationSequenceStrategy Class Reference

An Elimination sequence algorithm that imposes a given complete ordering on the nodes elimination sequence. More...

#include <orderedEliminationSequenceStrategy.h>

Inheritance diagram for gum::OrderedEliminationSequenceStrategy:
Collaboration diagram for gum::OrderedEliminationSequenceStrategy:

Public Member Functions

Constructors / Destructors
 OrderedEliminationSequenceStrategy ()
 default constructor (uses an empty graph)
 OrderedEliminationSequenceStrategy (UndiGraph *graph, const NodeProperty< Size > *dom_sizes, const std::vector< NodeId > *order)
 constructor for a (tensorly) non empty graph
 OrderedEliminationSequenceStrategy (const OrderedEliminationSequenceStrategy &from)
 copy constructor
 OrderedEliminationSequenceStrategy (OrderedEliminationSequenceStrategy &&from)
 move constructor
virtual ~OrderedEliminationSequenceStrategy ()
 destructor
virtual OrderedEliminationSequenceStrategynewFactory () const final
 creates a new elimination sequence of the same type as the current object, but this sequence contains only an empty graph
virtual OrderedEliminationSequenceStrategycopyFactory () const final
 virtual copy constructor
Accessors / Modifiers
virtual bool setGraph (UndiGraph *graph, const NodeProperty< Size > *dom_sizes) final
 sets a new graph to be triangulated
virtual bool setOrder (const std::vector< NodeId > *order) final
 sets the sequence of elimination
virtual void clear () final
 clears the order (to prepare, for instance, a new elimination sequence)
virtual NodeId nextNodeToEliminate () final
 returns the new node to be eliminated within the triangulation algorithm
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
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.
virtual bool providesGraphUpdate () const final
 indicates whether the elimination sequence updates by itself the graph after a node has been eliminated
virtual void eliminationUpdate (const NodeId node) final
 performs all the graph/fill-ins updates provided (if any)
virtual const EdgeSetfillIns () final
 in case fill-ins are provided, this function returns the fill-ins due to all the nodes eliminated so far
const std::vector< NodeId > * order () const noexcept
 returns the current complete ordering
bool isOrderNeeded () const noexcept
 indicates whether a new complete ordering is needed
Accessors / Modifiers
UndiGraphgraph () const noexcept
 returns the current graph
const NodeProperty< Size > * domainSizes () const noexcept
 returns the current domain sizes

Protected Attributes

UndiGraphgraph_ {nullptr}
 the graph to be triangulated
const NodeProperty< Size > * domain_sizes_ {nullptr}
 the domain sizes of the variables/nodes
NodeProperty< doublelog_domain_sizes_
 the log of the domain sizes of the variables/nodes

Private Member Functions

bool _isOrderNeeded_ (const std::vector< NodeId > *order) const
 indicates whether an order is compatible with the current graph

Static Private Member Functions

static const EdgeSet_empty_fill_ins_ ()
 an empty fill-ins set used by default

Private Attributes

const std::vector< NodeId > * _order_ {nullptr}
 the vector indicating in which order we should eliminate the nodes
std::size_t _order_index_ {std::size_t(0)}
 the index in the order indicating the new node to eliminate
bool _order_needed_ {true}
 indicate whether a new complete ordering is necessary for the elimination

Detailed Description

An Elimination sequence algorithm that imposes a given complete ordering on the nodes elimination sequence.

Definition at line 65 of file orderedEliminationSequenceStrategy.h.

Constructor & Destructor Documentation

◆ OrderedEliminationSequenceStrategy() [1/4]

gum::OrderedEliminationSequenceStrategy::OrderedEliminationSequenceStrategy ( )

default constructor (uses an empty graph)

Definition at line 61 of file orderedEliminationSequenceStrategy.cpp.

61 {
63 }
OrderedEliminationSequenceStrategy()
default constructor (uses an empty graph)

References OrderedEliminationSequenceStrategy().

Referenced by OrderedEliminationSequenceStrategy(), OrderedEliminationSequenceStrategy(), OrderedEliminationSequenceStrategy(), OrderedEliminationSequenceStrategy(), ~OrderedEliminationSequenceStrategy(), copyFactory(), and newFactory().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OrderedEliminationSequenceStrategy() [2/4]

gum::OrderedEliminationSequenceStrategy::OrderedEliminationSequenceStrategy ( UndiGraph * graph,
const NodeProperty< Size > * dom_sizes,
const std::vector< NodeId > * order )

constructor for a (tensorly) 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
orderthe order in which the nodes should be eliminated
Warning
Note that we allow dom_sizes and order to be defined over nodes/variables that do not belong to graph. These sizes/nodes will simply be ignored. However, it is compulsory that all the nodes of graph belong to both dom_sizes and order
the graph is altered during the triangulation.
note that, by aGrUM's rule, the graph and the order are not copied but only referenced by the elimination sequence algorithm.

Definition at line 66 of file orderedEliminationSequenceStrategy.cpp.

70 // check that the user passed appropriate graphs and orders
71 if (((graph == nullptr) && (order != nullptr)) || ((graph != nullptr) && (order == nullptr))) {
72 GUM_ERROR(GraphError,
73 "OrderedEliminationSequenceStrategy needs either both nullptrs "
74 "or both non-nullptrs on graph and elimination ordering");
75 }
76
78
80 }
UndiGraph * graph() const noexcept
returns the current graph
const std::vector< NodeId > * order() const noexcept
returns the current complete ordering
virtual bool setOrder(const std::vector< NodeId > *order) final
sets the sequence of elimination
#define GUM_ERROR(type, msg)
Definition exceptions.h:72

References gum::EliminationSequenceStrategy::EliminationSequenceStrategy(), OrderedEliminationSequenceStrategy(), gum::EliminationSequenceStrategy::graph(), GUM_ERROR, order(), and setOrder().

Here is the call graph for this function:

◆ OrderedEliminationSequenceStrategy() [3/4]

gum::OrderedEliminationSequenceStrategy::OrderedEliminationSequenceStrategy ( const OrderedEliminationSequenceStrategy & from)

copy constructor

Definition at line 83 of file orderedEliminationSequenceStrategy.cpp.

84 :
85 EliminationSequenceStrategy(from), _order_(from._order_), _order_index_(from._order_index_),
86 _order_needed_(from._order_needed_) {
88 }
const std::vector< NodeId > * _order_
the vector indicating in which order we should eliminate the nodes
bool _order_needed_
indicate whether a new complete ordering is necessary for the elimination
std::size_t _order_index_
the index in the order indicating the new node to eliminate

References gum::EliminationSequenceStrategy::EliminationSequenceStrategy(), OrderedEliminationSequenceStrategy(), _order_, _order_index_, and _order_needed_.

Here is the call graph for this function:

◆ OrderedEliminationSequenceStrategy() [4/4]

gum::OrderedEliminationSequenceStrategy::OrderedEliminationSequenceStrategy ( OrderedEliminationSequenceStrategy && from)

move constructor

Definition at line 91 of file orderedEliminationSequenceStrategy.cpp.

92 :
93 EliminationSequenceStrategy(std::move(from)), _order_(from._order_),
94 _order_index_(from._order_index_), _order_needed_(from._order_needed_) {
96 }

References gum::EliminationSequenceStrategy::EliminationSequenceStrategy(), OrderedEliminationSequenceStrategy(), _order_, _order_index_, and _order_needed_.

Here is the call graph for this function:

◆ ~OrderedEliminationSequenceStrategy()

gum::OrderedEliminationSequenceStrategy::~OrderedEliminationSequenceStrategy ( )
virtual

destructor

Definition at line 99 of file orderedEliminationSequenceStrategy.cpp.

99 {
101 }

References OrderedEliminationSequenceStrategy().

Here is the call graph for this function:

Member Function Documentation

◆ _empty_fill_ins_()

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

an empty fill-ins set used by default

Definition at line 60 of file eliminationSequenceStrategy.cpp.

60 {
61#ifdef GUM_DEBUG_MODE
62 static bool first_use = true;
63 if (first_use) {
64 first_use = false;
65 __debug__::_dec_creation_("Set", " __empty_edge_set", 0, "static variable correction", 0);
66 __debug__::_dec_creation_("HashTable",
67 " __empty_edge_set",
68 0,
69 "static variable correction",
70 0);
71 }
72#endif
73 static EdgeSet empty_fill_ins;
74 return empty_fill_ins;
75 }
Set< Edge > EdgeSet
Some typdefs and define for shortcuts ...

Referenced by fillIns().

Here is the caller graph for this function:

◆ _isOrderNeeded_()

bool gum::OrderedEliminationSequenceStrategy::_isOrderNeeded_ ( const std::vector< NodeId > * order) const
private

indicates whether an order is compatible with the current graph

Definition at line 126 of file orderedEliminationSequenceStrategy.cpp.

127 {
128 if ((graph_ == nullptr) || (order == nullptr)) return true;
129
130 // determine the set of nodes in the order that belong to the graph
131 NodeSet nodes_found(graph_->size() / 2);
132 for (const auto node: *order) {
133 if (graph_->existsNode(node)) { nodes_found.insert(node); }
134 }
135
136 // check that the size of nodes_found is equal to that of the graph
137 return nodes_found.size() != graph_->size();
138 }
UndiGraph * graph_
the graph to be triangulated
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...

References gum::EliminationSequenceStrategy::graph_, gum::Set< Key >::insert(), order(), and gum::Set< Key >::size().

Referenced by setOrder().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ askFillIns()

void gum::OrderedEliminationSequenceStrategy::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

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 181 of file orderedEliminationSequenceStrategy.cpp.

181 {
182 // do nothing: we are not able to compute fill-ins
183 }

◆ clear()

void gum::OrderedEliminationSequenceStrategy::clear ( )
finalvirtual

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

Reimplemented from gum::EliminationSequenceStrategy.

Definition at line 163 of file orderedEliminationSequenceStrategy.cpp.

163 {
165 _order_needed_ = true;
166 _order_index_ = std::size_t(0);
167 }
virtual void clear()
clears the sequence (to prepare, for instance, a new elimination sequence)

References _order_index_, _order_needed_, and gum::EliminationSequenceStrategy::clear().

Here is the call graph for this function:

◆ copyFactory()

OrderedEliminationSequenceStrategy * gum::OrderedEliminationSequenceStrategy::copyFactory ( ) const
finalvirtual

virtual copy constructor

Implements gum::EliminationSequenceStrategy.

Definition at line 110 of file orderedEliminationSequenceStrategy.cpp.

110 {
111 return new OrderedEliminationSequenceStrategy(*this);
112 }

References OrderedEliminationSequenceStrategy().

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 59 of file eliminationSequenceStrategy_inl.h.

59 {
60 return domain_sizes_;
61 }
const NodeProperty< Size > * domain_sizes_
the domain sizes of the variables/nodes

References domain_sizes_.

Referenced by providesGraphUpdate().

Here is the caller graph for this function:

◆ eliminationUpdate()

void gum::OrderedEliminationSequenceStrategy::eliminationUpdate ( const NodeId node)
finalvirtual

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

Parameters
nodethe node the elimination of which requires the graph update

Reimplemented from gum::EliminationSequenceStrategy.

Definition at line 195 of file orderedEliminationSequenceStrategy.cpp.

195 {
196 // check whether there is something to update
197 if (!_order_needed_) {
198 // check that node corresponds to the current index
199 if ((_order_index_ >= _order_->size()) || ((*_order_)[_order_index_] != node)) {
200 GUM_ERROR(OutOfBounds,
201 "update impossible because node "
202 << node << " does not correspond to the current elimination index");
203 }
204
205 // now perform the update: goto the next node that belongs to graph_
207 std::size_t size = _order_->size();
208 while ((_order_index_ < size) && !graph_->existsNode((*_order_)[_order_index_]))
210 }
211 }

References _order_, _order_index_, _order_needed_, gum::EliminationSequenceStrategy::graph_, and GUM_ERROR.

◆ fillIns()

const EdgeSet & gum::OrderedEliminationSequenceStrategy::fillIns ( )
finalvirtual

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

Reimplemented from gum::EliminationSequenceStrategy.

Definition at line 215 of file orderedEliminationSequenceStrategy.cpp.

215 {
217 }
virtual const EdgeSet & fillIns()
in case fill-ins are provided, this function returns the fill-ins due to all the nodes eliminated so ...

References gum::EliminationSequenceStrategy::fillIns().

Here is the call graph for this function:

◆ graph()

◆ isOrderNeeded()

INLINE bool gum::OrderedEliminationSequenceStrategy::isOrderNeeded ( ) const
noexcept

indicates whether a new complete ordering is needed

if the current complete ordering does not contain all the nodes of the graph or if the graph itself is not defined (nullptr) a new complete ordering will be needed for the next triangulation

Definition at line 58 of file orderedEliminationSequenceStrategy_inl.h.

58 {
59 return _order_needed_;
60 }

References _order_needed_.

◆ newFactory()

OrderedEliminationSequenceStrategy * gum::OrderedEliminationSequenceStrategy::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::EliminationSequenceStrategy.

Definition at line 105 of file orderedEliminationSequenceStrategy.cpp.

105 {
107 }

References OrderedEliminationSequenceStrategy().

Here is the call graph for this function:

◆ nextNodeToEliminate()

NodeId gum::OrderedEliminationSequenceStrategy::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 170 of file orderedEliminationSequenceStrategy.cpp.

170 {
171 // check that we can return a nodeId
172 if (_order_needed_ || (_order_->size() <= _order_index_)) {
173 GUM_ERROR(NotFound, "no node id can be returned")
174 }
175
176 return (*_order_)[_order_index_];
177 }

References _order_, _order_index_, _order_needed_, and GUM_ERROR.

◆ order()

INLINE const std::vector< NodeId > * gum::OrderedEliminationSequenceStrategy::order ( ) const
noexcept

returns the current complete ordering

Definition at line 53 of file orderedEliminationSequenceStrategy_inl.h.

53 {
54 return _order_;
55 }

References _order_.

Referenced by OrderedEliminationSequenceStrategy(), _isOrderNeeded_(), and setOrder().

Here is the caller graph for this function:

◆ providesFillIns()

bool gum::OrderedEliminationSequenceStrategy::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.

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 188 of file orderedEliminationSequenceStrategy.cpp.

188{ return false; }

◆ providesGraphUpdate()

bool gum::OrderedEliminationSequenceStrategy::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 192 of file orderedEliminationSequenceStrategy.cpp.

192{ return false; }

◆ setGraph()

bool gum::OrderedEliminationSequenceStrategy::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

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

Definition at line 115 of file orderedEliminationSequenceStrategy.cpp.

116 {
117 if (EliminationSequenceStrategy::setGraph(graph, domain_sizes)) {
119 return true;
120 }
121
122 return false;
123 }
virtual bool setGraph(UndiGraph *graph, const NodeProperty< Size > *dom_sizes)
sets a new graph to be triangulated

References _order_, gum::EliminationSequenceStrategy::graph(), gum::EliminationSequenceStrategy::setGraph(), and setOrder().

Referenced by gum::OrderedTriangulation::initTriangulation_().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setOrder()

bool gum::OrderedEliminationSequenceStrategy::setOrder ( const std::vector< NodeId > * order)
finalvirtual

sets the sequence of elimination

sets a new complete order

Parameters
orderthe order in which the nodes should be eliminated
Returns
true if the new complete order has been successfully assigned (i.e., if all the nodes of the graph belong to one of the subsets)
Warning
note that we allow order to contain nodes that do not belong to the current graph to be triangulated: those will simply be ignored. However, all the nodes of the graph need be contained in order.
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 141 of file orderedEliminationSequenceStrategy.cpp.

141 {
142 // check that the order contains all the nodes of the graph
144
145 if (!_order_needed_) {
146 _order_ = order;
147
148 // determine the first element in order that belong to the graph
149 // here, note that we have the guarantee that _order_index_ will be
150 // lower than the size of _order_ since all the nodes in the graph
151 // belong to vector _order_
152 _order_index_ = 0;
153 while (!graph_->existsNode((*_order_)[_order_index_]))
155
156 return true;
157 }
158
159 return false;
160 }
bool _isOrderNeeded_(const std::vector< NodeId > *order) const
indicates whether an order is compatible with the current graph

References _isOrderNeeded_(), _order_, _order_index_, _order_needed_, gum::EliminationSequenceStrategy::graph_, and order().

Referenced by OrderedEliminationSequenceStrategy(), gum::OrderedTriangulation::OrderedTriangulation(), gum::OrderedTriangulation::initTriangulation_(), and setGraph().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ _order_

const std::vector< NodeId >* gum::OrderedEliminationSequenceStrategy::_order_ {nullptr}
private

the vector indicating in which order we should eliminate the nodes

Definition at line 196 of file orderedEliminationSequenceStrategy.h.

196{nullptr};

Referenced by OrderedEliminationSequenceStrategy(), OrderedEliminationSequenceStrategy(), eliminationUpdate(), nextNodeToEliminate(), order(), setGraph(), and setOrder().

◆ _order_index_

std::size_t gum::OrderedEliminationSequenceStrategy::_order_index_ {std::size_t(0)}
private

the index in the order indicating the new node to eliminate

Definition at line 199 of file orderedEliminationSequenceStrategy.h.

199{std::size_t(0)};

Referenced by OrderedEliminationSequenceStrategy(), OrderedEliminationSequenceStrategy(), clear(), eliminationUpdate(), nextNodeToEliminate(), and setOrder().

◆ _order_needed_

bool gum::OrderedEliminationSequenceStrategy::_order_needed_ {true}
private

indicate whether a new complete ordering is necessary for the elimination

Definition at line 203 of file orderedEliminationSequenceStrategy.h.

203{true};

Referenced by OrderedEliminationSequenceStrategy(), OrderedEliminationSequenceStrategy(), clear(), eliminationUpdate(), isOrderNeeded(), nextNodeToEliminate(), and setOrder().

◆ domain_sizes_

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

the domain sizes of the variables/nodes

Definition at line 177 of file eliminationSequenceStrategy.h.

177{nullptr};

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

◆ graph_

◆ log_domain_sizes_


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