aGrUM  0.14.2
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) More...
 
 OrderedEliminationSequenceStrategy (UndiGraph *graph, const NodeProperty< Size > *dom_sizes, const std::vector< NodeId > *order)
 constructor for an a priori non empty graph More...
 
 OrderedEliminationSequenceStrategy (const OrderedEliminationSequenceStrategy &from)
 copy constructor More...
 
 OrderedEliminationSequenceStrategy (OrderedEliminationSequenceStrategy &&from)
 move constructor More...
 
virtual ~OrderedEliminationSequenceStrategy ()
 destructor More...
 
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 More...
 
virtual OrderedEliminationSequenceStrategycopyFactory () 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 bool setOrder (const std::vector< NodeId > *order) final
 sets the sequence of elimination More...
 
virtual void clear () final
 clears the order (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...
 
const std::vector< NodeId > * order () const noexcept
 returns the current complete ordering More...
 
bool isOrderNeeded () const noexcept
 indicates whether a new complete 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

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

Detailed Description

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

Definition at line 42 of file orderedEliminationSequenceStrategy.h.

Constructor & Destructor Documentation

◆ OrderedEliminationSequenceStrategy() [1/4]

gum::OrderedEliminationSequenceStrategy::OrderedEliminationSequenceStrategy ( )

default constructor (uses an empty graph)

Definition at line 39 of file orderedEliminationSequenceStrategy.cpp.

Referenced by copyFactory(), and newFactory().

39  {
40  // for debugging purposes
41  GUM_CONSTRUCTOR(OrderedEliminationSequenceStrategy);
42  }
OrderedEliminationSequenceStrategy()
default constructor (uses an empty graph)
+ 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 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
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 45 of file orderedEliminationSequenceStrategy.cpp.

References GUM_ERROR, and setOrder().

48  :
50  // check that the user passed appropriate graphs and orders
51  if (((graph == nullptr) && (order != nullptr))
52  || ((graph != nullptr) && (order == nullptr))) {
53  GUM_ERROR(GraphError,
54  "OrderedEliminationSequenceStrategy needs either both nullptrs "
55  "or both non-nullptrs on graph and elimination ordering");
56  }
57 
58  setOrder(order);
59 
60  // for debugging purposes
61  GUM_CONSTRUCTOR(OrderedEliminationSequenceStrategy);
62  }
OrderedEliminationSequenceStrategy()
default constructor (uses an empty graph)
virtual bool setOrder(const std::vector< NodeId > *order) final
sets the sequence of elimination
UndiGraph * graph() const noexcept
returns the current graph
#define GUM_ERROR(type, msg)
Definition: exceptions.h:52
+ Here is the call graph for this function:

◆ OrderedEliminationSequenceStrategy() [3/4]

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

copy constructor

Definition at line 65 of file orderedEliminationSequenceStrategy.cpp.

66  :
68  __order(from.__order), __order_index(from.__order_index),
69  __order_needed(from.__order_needed) {
70  // for debugging purposes
72  }
OrderedEliminationSequenceStrategy()
default constructor (uses an empty graph)
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
const std::vector< NodeId > * __order
the vector indicating in which order we should eliminate the nodes

◆ OrderedEliminationSequenceStrategy() [4/4]

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

move constructor

Definition at line 75 of file orderedEliminationSequenceStrategy.cpp.

76  :
77  EliminationSequenceStrategy(std::move(from)),
78  __order(from.__order), __order_index(from.__order_index),
79  __order_needed(from.__order_needed) {
80  // for debugging purposes
82  }
OrderedEliminationSequenceStrategy()
default constructor (uses an empty graph)
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
const std::vector< NodeId > * __order
the vector indicating in which order we should eliminate the nodes

◆ ~OrderedEliminationSequenceStrategy()

gum::OrderedEliminationSequenceStrategy::~OrderedEliminationSequenceStrategy ( )
virtual

destructor

Definition at line 85 of file orderedEliminationSequenceStrategy.cpp.

85  {
86  // for debugging purposes
87  GUM_DESTRUCTOR(OrderedEliminationSequenceStrategy);
88  }
OrderedEliminationSequenceStrategy()
default constructor (uses an empty graph)

Member Function Documentation

◆ __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 115 of file orderedEliminationSequenceStrategy.cpp.

References gum::EliminationSequenceStrategy::_graph, gum::NodeGraphPart::existsNode(), gum::Set< Key, Alloc >::insert(), and gum::NodeGraphPart::size().

Referenced by setOrder().

116  {
117  if ((_graph == nullptr) || (order == nullptr)) return true;
118 
119  // determine the set of nodes in the order that belong to the graph
120  NodeSet nodes_found(_graph->size() / 2);
121  for (const auto node : *order) {
122  if (_graph->existsNode(node)) { nodes_found.insert(node); }
123  }
124 
125  // check that the size of nodes_found is equal to that of the graph
126  return nodes_found.size() != _graph->size();
127  }
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:610
+ 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 171 of file orderedEliminationSequenceStrategy.cpp.

171  {
172  // do nothing: we are not able to compute fill-ins
173  }

◆ clear()

void gum::OrderedEliminationSequenceStrategy::clear ( )
finalvirtual

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

Reimplemented from gum::EliminationSequenceStrategy.

Definition at line 153 of file orderedEliminationSequenceStrategy.cpp.

References __order_index, __order_needed, and gum::EliminationSequenceStrategy::clear().

153  {
155  __order_needed = true;
156  __order_index = std::size_t(0);
157  }
virtual void clear()
clears the sequence (to prepare, for instance, a new elimination sequence)
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
+ Here is the call graph for this function:

◆ copyFactory()

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

virtual copy constructor

Implements gum::EliminationSequenceStrategy.

Definition at line 99 of file orderedEliminationSequenceStrategy.cpp.

References OrderedEliminationSequenceStrategy().

99  {
100  return new OrderedEliminationSequenceStrategy(*this);
101  }
OrderedEliminationSequenceStrategy()
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 41 of file eliminationSequenceStrategy_inl.h.

References gum::EliminationSequenceStrategy::_domain_sizes.

41  {
42  return _domain_sizes;
43  }
const NodeProperty< Size > * _domain_sizes
the domain sizes of the variables/nodes

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

References __order, __order_index, __order_needed, gum::EliminationSequenceStrategy::_graph, gum::NodeGraphPart::existsNode(), and GUM_ERROR.

189  {
190  // check whether there is something to update
191  if (!__order_needed) {
192  // check that node corresponds to the current index
193  if ((__order_index >= __order->size())
194  || ((*__order)[__order_index] != node)) {
195  GUM_ERROR(OutOfBounds,
196  "update impossible because node "
197  << node
198  << " does not correspond to the current elimination index");
199  }
200 
201  // now perform the update: goto the next node that belongs to _graph
202  ++__order_index;
203  std::size_t size = __order->size();
204  while ((__order_index < size)
206  ++__order_index;
207  }
208  }
UndiGraph * _graph
the graph to be triangulated
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
bool existsNode(const NodeId id) const
returns true iff the NodeGraphPart contains the given nodeId
const std::vector< NodeId > * __order
the vector indicating in which order we should eliminate the nodes
#define GUM_ERROR(type, msg)
Definition: exceptions.h:52
+ Here is the call graph for this function:

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

References gum::EliminationSequenceStrategy::fillIns().

212  {
214  }
virtual const EdgeSet & fillIns()
in case fill-ins are provided, this function returns the fill-ins due to all the nodes eliminated so ...
+ Here is the call graph for this function:

◆ graph()

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

returns the current graph

Definition at line 34 of file eliminationSequenceStrategy_inl.h.

References gum::EliminationSequenceStrategy::_graph.

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

34  {
35  return _graph;
36  }
UndiGraph * _graph
the graph to be triangulated
+ Here is the caller graph for this function:

◆ 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 38 of file orderedEliminationSequenceStrategy_inl.h.

References __order_needed.

38  {
39  return __order_needed;
40  }
bool __order_needed
indicate whether a new complete ordering is necessary for the elimination

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

References OrderedEliminationSequenceStrategy().

93  {
95  }
OrderedEliminationSequenceStrategy()
default constructor (uses an empty graph)
+ 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 160 of file orderedEliminationSequenceStrategy.cpp.

References __order, __order_index, __order_needed, and GUM_ERROR.

160  {
161  // check that we can return a nodeId
162  if (__order_needed || (__order->size() <= __order_index)) {
163  GUM_ERROR(NotFound, "no node id can be returned");
164  }
165 
166  return (*__order)[__order_index];
167  }
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
const std::vector< NodeId > * __order
the vector indicating in which order we should eliminate the nodes
#define GUM_ERROR(type, msg)
Definition: exceptions.h:52

◆ order()

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

returns the current complete ordering

Definition at line 32 of file orderedEliminationSequenceStrategy_inl.h.

References __order.

Referenced by setOrder().

32  {
33  return __order;
34  }
const std::vector< NodeId > * __order
the vector indicating in which order we should eliminate the nodes
+ 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 178 of file orderedEliminationSequenceStrategy.cpp.

178  {
179  return false;
180  }

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

184  {
185  return false;
186  }

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

References __order, gum::EliminationSequenceStrategy::setGraph(), and setOrder().

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

105  {
106  if (EliminationSequenceStrategy::setGraph(graph, domain_sizes)) {
107  setOrder(__order);
108  return true;
109  }
110 
111  return false;
112  }
virtual bool setOrder(const std::vector< NodeId > *order) final
sets the sequence of elimination
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
const std::vector< NodeId > * __order
the vector indicating in which order we should eliminate the nodes
+ 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 130 of file orderedEliminationSequenceStrategy.cpp.

References __isOrderNeeded(), __order, __order_index, __order_needed, gum::EliminationSequenceStrategy::_graph, gum::NodeGraphPart::existsNode(), and order().

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

131  {
132  // check that the order contains all the nodes of the graph
134 
135  if (!__order_needed) {
136  __order = order;
137 
138  // determine the first element in order that belong to the graph
139  // here, note that we have the guarantee that __order_index will be
140  // lower than the size of __order since all the nodes in the graph
141  // belong to vector __order
142  __order_index = 0;
143  while (!_graph->existsNode((*__order)[__order_index]))
144  ++__order_index;
145 
146  return true;
147  }
148 
149  return false;
150  }
bool __isOrderNeeded(const std::vector< NodeId > *order) const
indicates whether an order is compatible with the current graph
UndiGraph * _graph
the graph to be triangulated
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
const std::vector< NodeId > * order() const noexcept
returns the current complete ordering
bool existsNode(const NodeId id) const
returns true iff the NodeGraphPart contains the given nodeId
const std::vector< NodeId > * __order
the vector indicating in which order we should eliminate the nodes
+ 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 175 of file orderedEliminationSequenceStrategy.h.

Referenced by 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 178 of file orderedEliminationSequenceStrategy.h.

Referenced by 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 182 of file orderedEliminationSequenceStrategy.h.

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

◆ _domain_sizes

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

◆ _graph

◆ _log_domain_sizes


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