aGrUM  0.14.2
orderedEliminationSequenceStrategy.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Christophe GONZALES and Pierre-Henri WUILLEMIN *
3  * {prenom.nom}_at_lip6.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
28 #include <agrum/agrum.h>
29 
31 
32 #ifdef GUM_NO_INLINE
34 #endif // GUM_NOINLINE
35 
36 namespace gum {
37 
40  // for debugging purposes
41  GUM_CONSTRUCTOR(OrderedEliminationSequenceStrategy);
42  }
43 
47  const NodeProperty< Size >* dom_sizes,
48  const std::vector< NodeId >* order) :
49  EliminationSequenceStrategy(graph, dom_sizes) {
50  // check that the user passed appropriate graphs and orders
51  if (((graph == nullptr) && (order != nullptr))
52  || ((graph != nullptr) && (order == nullptr))) {
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  }
63 
70  // for debugging purposes
72  }
73 
77  EliminationSequenceStrategy(std::move(from)),
80  // for debugging purposes
82  }
83 
86  // for debugging purposes
87  GUM_DESTRUCTOR(OrderedEliminationSequenceStrategy);
88  }
89 
95  }
96 
100  return new OrderedEliminationSequenceStrategy(*this);
101  }
102 
105  UndiGraph* graph, const NodeProperty< Size >* domain_sizes) {
106  if (EliminationSequenceStrategy::setGraph(graph, domain_sizes)) {
107  setOrder(__order);
108  return true;
109  }
110 
111  return false;
112  }
113 
116  const std::vector< NodeId >* order) const {
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  }
128 
131  const std::vector< NodeId >* order) {
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  }
151 
155  __order_needed = true;
156  __order_index = std::size_t(0);
157  }
158 
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  }
168 
172  // do nothing: we are not able to compute fill-ins
173  }
174 
179  return false;
180  }
181 
185  return false;
186  }
187 
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)) {
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  }
209 
214  }
215 
216 } /* 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
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
The class for generic Hash Tables.
Definition: hashTable.h:676
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
An Elimination sequence algorithm that imposes a given complete ordering on the nodes elimination seq...
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:106
virtual bool providesGraphUpdate() const final
indicates whether the elimination sequence updates by itself the graph after a node has been eliminat...
An Elimination sequence algorithm that imposes a given complete ordering on the nodes elimination seq...
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:97
void insert(const Key &k)
Inserts a new element into the set.
Definition: set_tpl.h:610
#define GUM_ERROR(type, msg)
Definition: exceptions.h:52
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 ...