aGrUM  0.16.0
orderedEliminationSequenceStrategy.cpp
Go to the documentation of this file.
1 
31 #include <agrum/agrum.h>
32 
34 
35 #ifdef GUM_NO_INLINE
37 #endif // GUM_NOINLINE
38 
39 namespace gum {
40 
43  // for debugging purposes
44  GUM_CONSTRUCTOR(OrderedEliminationSequenceStrategy);
45  }
46 
50  const NodeProperty< Size >* dom_sizes,
51  const std::vector< NodeId >* order) :
52  EliminationSequenceStrategy(graph, dom_sizes) {
53  // check that the user passed appropriate graphs and orders
54  if (((graph == nullptr) && (order != nullptr))
55  || ((graph != nullptr) && (order == nullptr))) {
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  }
66 
73  // for debugging purposes
75  }
76 
80  EliminationSequenceStrategy(std::move(from)),
83  // for debugging purposes
85  }
86 
89  // for debugging purposes
90  GUM_DESTRUCTOR(OrderedEliminationSequenceStrategy);
91  }
92 
98  }
99 
103  return new OrderedEliminationSequenceStrategy(*this);
104  }
105 
108  UndiGraph* graph, const NodeProperty< Size >* domain_sizes) {
109  if (EliminationSequenceStrategy::setGraph(graph, domain_sizes)) {
110  setOrder(__order);
111  return true;
112  }
113 
114  return false;
115  }
116 
119  const std::vector< NodeId >* order) const {
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  }
131 
134  const std::vector< NodeId >* order) {
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  }
154 
158  __order_needed = true;
159  __order_index = std::size_t(0);
160  }
161 
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  }
171 
175  // do nothing: we are not able to compute fill-ins
176  }
177 
182  return false;
183  }
184 
188  return false;
189  }
190 
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)) {
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  }
212 
217  }
218 
219 } /* namespace gum */
virtual void clear()
clears the sequence (to prepare, for instance, a new elimination sequence)
virtual const EdgeSet & fillIns()
in case fill-ins are provided, this function returns the fill-ins due to all the nodes eliminated so ...
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
An Elimination sequence algorithm that imposes a given complete ordering on the nodes elimination seq...
Size size() const
alias for sizeNodes
OrderedEliminationSequenceStrategy()
default constructor (uses an empty graph)
bool __order_needed
indicate whether a new complete ordering is necessary for the elimination
STL namespace.
virtual void clear() final
clears the order (to prepare, for instance, a new elimination sequence)
virtual bool setGraph(UndiGraph *graph, const NodeProperty< Size > *dom_sizes) final
sets a new graph to be triangulated
std::size_t __order_index
the index in the order indicating the new node to eliminate
virtual bool setOrder(const std::vector< NodeId > *order) final
sets the sequence of elimination
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
The class for generic Hash Tables.
Definition: hashTable.h:679
UndiGraph * graph() const noexcept
returns the current graph
const std::vector< NodeId > * order() const noexcept
returns the current complete ordering
virtual NodeId nextNodeToEliminate() final
returns the new node to be eliminated within the triangulation algorithm
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
virtual void eliminationUpdate(const NodeId node) final
performs all the graph/fill-ins updates provided (if any)
bool existsNode(const NodeId id) const
returns true iff the NodeGraphPart contains the given nodeId
virtual bool setGraph(UndiGraph *graph, const NodeProperty< Size > *dom_sizes)
sets a new graph to be triangulated
The base class for all elimination sequence algorithms used by triangulation algorithms.
virtual OrderedEliminationSequenceStrategy * copyFactory() const final
virtual copy constructor
Base class for undirected graphs.
Definition: undiGraph.h:109
virtual bool providesGraphUpdate() const final
indicates whether the elimination sequence updates by itself the graph after a node has been eliminat...
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
const std::vector< NodeId > * __order
the vector indicating in which order we should eliminate the nodes
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 ...
Size NodeId
Type for node ids.
Definition: graphElements.h:98
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:613
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
virtual OrderedEliminationSequenceStrategy * newFactory() const final
creates a new elimination sequence of the same type as the current object, but this sequence contains...
virtual const EdgeSet & fillIns() final
in case fill-ins are provided, this function returns the fill-ins due to all the nodes eliminated so ...
virtual bool providesFillIns() const final
indicates whether the fill-ins generated by the eliminated nodes, if needed, will be computed by the ...