aGrUM  0.16.0
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 45 of file orderedEliminationSequenceStrategy.h.

Constructor & Destructor Documentation

◆ OrderedEliminationSequenceStrategy() [1/4]

gum::OrderedEliminationSequenceStrategy::OrderedEliminationSequenceStrategy ( )

default constructor (uses an empty graph)

Definition at line 42 of file orderedEliminationSequenceStrategy.cpp.

Referenced by copyFactory(), and newFactory().

42  {
43  // for debugging purposes
44  GUM_CONSTRUCTOR(OrderedEliminationSequenceStrategy);
45  }
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 48 of file orderedEliminationSequenceStrategy.cpp.

References GUM_ERROR, and setOrder().

51  :
53  // check that the user passed appropriate graphs and orders
54  if (((graph == nullptr) && (order != nullptr))
55  || ((graph != nullptr) && (order == nullptr))) {
56  GUM_ERROR(GraphError,
57  "OrderedEliminationSequenceStrategy needs either both nullptrs "
58  "or both non-nullptrs on graph and elimination ordering");
59  }
60 
61  setOrder(order);
62 
63  // for debugging purposes
64  GUM_CONSTRUCTOR(OrderedEliminationSequenceStrategy);
65  }
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:55
+ Here is the call graph for this function:

◆ OrderedEliminationSequenceStrategy() [3/4]

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

copy constructor

Definition at line 68 of file orderedEliminationSequenceStrategy.cpp.

69  :
71  __order(from.__order), __order_index(from.__order_index),
72  __order_needed(from.__order_needed) {
73  // for debugging purposes
75  }
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 78 of file orderedEliminationSequenceStrategy.cpp.

79  :
80  EliminationSequenceStrategy(std::move(from)),
81  __order(from.__order), __order_index(from.__order_index),
82  __order_needed(from.__order_needed) {
83  // for debugging purposes
85  }
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 88 of file orderedEliminationSequenceStrategy.cpp.

88  {
89  // for debugging purposes
90  GUM_DESTRUCTOR(OrderedEliminationSequenceStrategy);
91  }
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 118 of file orderedEliminationSequenceStrategy.cpp.

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

Referenced by setOrder().

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

174  {
175  // do nothing: we are not able to compute fill-ins
176  }

◆ clear()

void gum::OrderedEliminationSequenceStrategy::clear ( )
finalvirtual

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

Reimplemented from gum::EliminationSequenceStrategy.

Definition at line 156 of file orderedEliminationSequenceStrategy.cpp.

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

156  {
158  __order_needed = true;
159  __order_index = std::size_t(0);
160  }
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 102 of file orderedEliminationSequenceStrategy.cpp.

References OrderedEliminationSequenceStrategy().

102  {
103  return new OrderedEliminationSequenceStrategy(*this);
104  }
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 44 of file eliminationSequenceStrategy_inl.h.

References gum::EliminationSequenceStrategy::_domain_sizes.

44  {
45  return _domain_sizes;
46  }
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 192 of file orderedEliminationSequenceStrategy.cpp.

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

192  {
193  // check whether there is something to update
194  if (!__order_needed) {
195  // check that node corresponds to the current index
196  if ((__order_index >= __order->size())
197  || ((*__order)[__order_index] != node)) {
198  GUM_ERROR(OutOfBounds,
199  "update impossible because node "
200  << node
201  << " does not correspond to the current elimination index");
202  }
203 
204  // now perform the update: goto the next node that belongs to _graph
205  ++__order_index;
206  std::size_t size = __order->size();
207  while ((__order_index < size)
209  ++__order_index;
210  }
211  }
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:55
+ 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 215 of file orderedEliminationSequenceStrategy.cpp.

References gum::EliminationSequenceStrategy::fillIns().

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 ...
+ Here is the call graph for this function:

◆ graph()

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

returns the current graph

Definition at line 37 of file eliminationSequenceStrategy_inl.h.

References gum::EliminationSequenceStrategy::_graph.

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

37  {
38  return _graph;
39  }
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 41 of file orderedEliminationSequenceStrategy_inl.h.

References __order_needed.

41  {
42  return __order_needed;
43  }
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 96 of file orderedEliminationSequenceStrategy.cpp.

References OrderedEliminationSequenceStrategy().

96  {
98  }
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 163 of file orderedEliminationSequenceStrategy.cpp.

References __order, __order_index, __order_needed, and GUM_ERROR.

163  {
164  // check that we can return a nodeId
165  if (__order_needed || (__order->size() <= __order_index)) {
166  GUM_ERROR(NotFound, "no node id can be returned");
167  }
168 
169  return (*__order)[__order_index];
170  }
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:55

◆ order()

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

returns the current complete ordering

Definition at line 35 of file orderedEliminationSequenceStrategy_inl.h.

References __order.

Referenced by setOrder().

35  {
36  return __order;
37  }
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 181 of file orderedEliminationSequenceStrategy.cpp.

181  {
182  return false;
183  }

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

187  {
188  return false;
189  }

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

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

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

108  {
109  if (EliminationSequenceStrategy::setGraph(graph, domain_sizes)) {
110  setOrder(__order);
111  return true;
112  }
113 
114  return false;
115  }
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 133 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().

134  {
135  // check that the order contains all the nodes of the graph
137 
138  if (!__order_needed) {
139  __order = order;
140 
141  // determine the first element in order that belong to the graph
142  // here, note that we have the guarantee that __order_index will be
143  // lower than the size of __order since all the nodes in the graph
144  // belong to vector __order
145  __order_index = 0;
146  while (!_graph->existsNode((*__order)[__order_index]))
147  ++__order_index;
148 
149  return true;
150  }
151 
152  return false;
153  }
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 178 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 181 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 185 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: