aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
orderedEliminationSequenceStrategy.h
Go to the documentation of this file.
1 /**
2  *
3  * Copyright (c) 2005-2021 by Pierre-Henri WUILLEMIN(@LIP6) & Christophe GONZALES(@AMU)
4  * info_at_agrum_dot_org
5  *
6  * This library is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library. If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 
22 /** @file
23  * @brief An Elimination sequence algorithm that imposes a given complete
24  * ordering on the nodes elimination sequence
25  *
26  * @author Christophe GONZALES(@AMU) and Pierre-Henri WUILLEMIN(@LIP6)
27  */
28 
29 #ifndef GUM_ORDERED_ELIMINATION_SEQUENCE_STRATEGY_H
30 #define GUM_ORDERED_ELIMINATION_SEQUENCE_STRATEGY_H
31 
32 #include <agrum/tools/graphs/algorithms/triangulations/eliminationStrategies/eliminationSequenceStrategy.h>
33 #include <vector>
34 
35 namespace gum {
36 
37  /** @class OrderedEliminationSequenceStrategy
38  * @brief An Elimination sequence algorithm that imposes a given complete
39  * ordering on the nodes elimination sequence.
40  *
41  * \ingroup graph_group
42  *
43  */
45  public:
46  // ############################################################################
47  /// @name Constructors / Destructors
48  // ############################################################################
49  /// @{
50 
51  /// default constructor (uses an empty graph)
53 
54  /// constructor for an a priori non empty graph
55  /** @param graph the graph to be triangulated, i.e., the nodes of which will
56  * be eliminated
57  * @param dom_sizes thedomain sizes of the nodes/variables
58  * @param order the order in which the nodes should be eliminated
59  * @warning Note that we allow dom_sizes and order to be defined over
60  * nodes/variables that do not belong to graph. These sizes/nodes will
61  * simply be ignored. However, it is compulsory that all the nodes of graph
62  * belong to both dom_sizes and order
63  * @warning the graph is altered during the triangulation.
64  * @warning note that, by aGrUM's rule, the graph and the order are not
65  * copied but only referenced by the elimination sequence algorithm. */
66  OrderedEliminationSequenceStrategy(UndiGraph* graph,
67  const NodeProperty< Size >* dom_sizes,
68  const std::vector< NodeId >* order);
69 
70  /// copy constructor
72 
73  /// move constructor
75 
76  /// destructor
78 
79  /** @brief creates a new elimination sequence of the same type as the
80  * current object, but this sequence contains only an empty graph
81  * @warning you must deallocate by yourself the object returned
82  * @return an empty clone of the current object with the same type */
83  virtual OrderedEliminationSequenceStrategy* newFactory() const final;
84 
85  /// virtual copy constructor
86  virtual OrderedEliminationSequenceStrategy* copyFactory() const final;
87 
88  /// @}
89 
90 
91  // ############################################################################
92  /// @name Accessors / Modifiers
93  // ############################################################################
94  /// @{
95 
96  /// sets a new graph to be triangulated
97  /** The elimination sequence algorithms reinitializes its data to start a
98  * new triangulation with graph Graph
99  * @param graph the new graph to be triangulated
100  * @param dom_sizes the domain sizes of the nodes/variables
101  * @warning Note that we allow dom_sizes to be defined over nodes/variables
102  * that do not belong to graph. These sizes will simply be ignored. However,
103  * it is compulsory that all the nodes of graph belong to dom_sizes
104  * @warning the graph is altered during the triangulation.
105  * @warning note that, by aGrUM's rule, the graph and the domain sizes
106  * are not copied but only referenced by the elimination sequence algorithm.
107  */
108  virtual bool setGraph(UndiGraph* graph, const NodeProperty< Size >* dom_sizes) final;
109 
110  /// sets the sequence of elimination
111  /** @param order the order in which the nodes should be eliminated
112  * @return true if the new complete order has been successfully assigned
113  * (i.e., if all the nodes of the graph belong to one of the subsets)
114  * @warning note that we allow order to contain nodes that do not
115  * belong to the current graph to be triangulated: those will simply be
116  * ignored. However, all the nodes of the graph need be contained in
117  * order.
118  * @warning note that, by aGrUM's rule, the graph and the domain sizes
119  * are not copied but only referenced by the elimination sequence
120  * algorithm. */
121  virtual bool setOrder(const std::vector< NodeId >* order) final;
122 
123  /// clears the order (to prepare, for instance, a new elimination sequence)
124  virtual void clear() final;
125 
126  /// returns the new node to be eliminated within the triangulation algorithm
127  /** @throws NotFound exception is thrown if there is no more node to
128  * eliminate in the graph */
129  virtual NodeId nextNodeToEliminate() final;
130 
131  /** @brief if the elimination sequence is able to compute fill-ins, we
132  * indicate whether we want this feature to be activated
133  *
134  * @param do_it when true and the elimination sequence has the ability to
135  * compute fill-ins, the elimination sequence will actually compute them
136  * (for the triangulation to use them), else they will not be available. */
137  virtual void askFillIns(bool do_it) final;
138 
139  /** @brief indicates whether the fill-ins generated by the eliminated
140  * nodes, if needed, will be computed by the elimination sequence, or need
141  * be computed by the triangulation itself.
142  *
143  * An elimination sequence provides fill-ins to its triangulation if and
144  * only if it has the ability to compute them and it has been asked to do so
145  * (by method askFillIns) */
146  virtual bool providesFillIns() const final;
147 
148  /** @brief indicates whether the elimination sequence updates by itself the
149  * graph after a node has been eliminated */
150  virtual bool providesGraphUpdate() const final;
151 
152  /// performs all the graph/fill-ins updates provided (if any)
153  /** @param node the node the elimination of which requires the graph update
154  */
155  virtual void eliminationUpdate(const NodeId node) final;
156 
157  /** @brief in case fill-ins are provided, this function returns the fill-ins
158  * due to all the nodes eliminated so far */
159  virtual const EdgeSet& fillIns() final;
160 
161  /// returns the current complete ordering
162  const std::vector< NodeId >* order() const noexcept;
163 
164  /// indicates whether a new complete ordering is needed
165  /** if the current complete ordering does not contain all the nodes of the
166  * graph or if the graph itself is not defined (nullptr) a new complete
167  * ordering will be needed for the next triangulation */
168  bool isOrderNeeded() const noexcept;
169 
170  /// @}
171 
172 
173  private:
174  /// the vector indicating in which order we should eliminate the nodes
175  const std::vector< NodeId >* _order_{nullptr};
176 
177  /// the index in the order indicating the new node to eliminate
178  std::size_t _order_index_{std::size_t(0)};
179 
180  /// indicate whether a new complete ordering is necessary for the
181  /// elimination
182  bool _order_needed_{true};
183 
184 
185  /// indicates whether an order is compatible with the current graph
186  bool _isOrderNeeded_(const std::vector< NodeId >* order) const;
187  };
188 
189 
190 } /* namespace gum */
191 
192 
193 #ifndef GUM_NO_INLINE
194 # include <agrum/tools/graphs/algorithms/triangulations/eliminationStrategies/orderedEliminationSequenceStrategy_inl.h>
195 #endif // GUM_NOINLINE
196 
197 
198 #endif /* GUM_ORDERED_ELIMINATION_SEQUENCE_STRATEGY_H */
bool isOrderNeeded() const noexcept
indicates whether a new complete ordering is needed
An Elimination sequence algorithm that imposes a given complete ordering on the nodes elimination seq...
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:643
OrderedEliminationSequenceStrategy()
default constructor (uses an empty graph)
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
virtual bool setOrder(const std::vector< NodeId > *order) final
sets the sequence of elimination
OrderedEliminationSequenceStrategy(const OrderedEliminationSequenceStrategy &from)
copy constructor
bool _isOrderNeeded_(const std::vector< NodeId > *order) const
indicates whether an order is compatible with 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
const std::vector< NodeId > * _order_
the vector indicating in which order we should eliminate the nodes
virtual void eliminationUpdate(const NodeId node) final
performs all the graph/fill-ins updates provided (if any)
OrderedEliminationSequenceStrategy(OrderedEliminationSequenceStrategy &&from)
move constructor
virtual OrderedEliminationSequenceStrategy * copyFactory() const final
virtual copy constructor
bool _order_needed_
indicate whether a new complete ordering is necessary for the elimination
OrderedEliminationSequenceStrategy(UndiGraph *graph, const NodeProperty< Size > *dom_sizes, const std::vector< NodeId > *order)
constructor for an a priori non empty graph
virtual bool providesGraphUpdate() const final
indicates whether the elimination sequence updates by itself the graph after a node has been eliminat...
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 ...
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 ...
std::size_t _order_index_
the index in the order indicating the new node to eliminate