aGrUM  0.20.2
a C++ library for (probabilistic) graphical models
orderedEliminationSequenceStrategy.h
Go to the documentation of this file.
1 /**
2  *
3  * Copyright 2005-2020 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
73 
74  /// move constructor
76 
77  /// destructor
79 
80  /** @brief creates a new elimination sequence of the same type as the
81  * current object, but this sequence contains only an empty graph
82  * @warning you must deallocate by yourself the object returned
83  * @return an empty clone of the current object with the same type */
84  virtual OrderedEliminationSequenceStrategy* newFactory() const final;
85 
86  /// virtual copy constructor
87  virtual OrderedEliminationSequenceStrategy* copyFactory() const final;
88 
89  /// @}
90 
91 
92  // ############################################################################
93  /// @name Accessors / Modifiers
94  // ############################################################################
95  /// @{
96 
97  /// sets a new graph to be triangulated
98  /** The elimination sequence algorithms reinitializes its data to start a
99  * new triangulation with graph Graph
100  * @param graph the new graph to be triangulated
101  * @param dom_sizes the domain sizes of the nodes/variables
102  * @warning Note that we allow dom_sizes to be defined over nodes/variables
103  * that do not belong to graph. These sizes will simply be ignored. However,
104  * it is compulsory that all the nodes of graph belong to dom_sizes
105  * @warning the graph is altered during the triangulation.
106  * @warning note that, by aGrUM's rule, the graph and the domain sizes
107  * are not copied but only referenced by the elimination sequence algorithm.
108  */
109  virtual bool setGraph(UndiGraph* graph,
110  const NodeProperty< Size >* dom_sizes) final;
111 
112  /// sets the sequence of elimination
113  /** @param order the order in which the nodes should be eliminated
114  * @return true if the new complete order has been successfully assigned
115  * (i.e., if all the nodes of the graph belong to one of the subsets)
116  * @warning note that we allow order to contain nodes that do not
117  * belong to the current graph to be triangulated: those will simply be
118  * ignored. However, all the nodes of the graph need be contained in
119  * order.
120  * @warning note that, by aGrUM's rule, the graph and the domain sizes
121  * are not copied but only referenced by the elimination sequence
122  * algorithm. */
123  virtual bool setOrder(const std::vector< NodeId >* order) final;
124 
125  /// clears the order (to prepare, for instance, a new elimination sequence)
126  virtual void clear() final;
127 
128  /// returns the new node to be eliminated within the triangulation algorithm
129  /** @throws NotFound exception is thrown if there is no more node to
130  * eliminate in the graph */
131  virtual NodeId nextNodeToEliminate() final;
132 
133  /** @brief if the elimination sequence is able to compute fill-ins, we
134  * indicate whether we want this feature to be activated
135  *
136  * @param do_it when true and the elimination sequence has the ability to
137  * compute fill-ins, the elimination sequence will actually compute them
138  * (for the triangulation to use them), else they will not be available. */
139  virtual void askFillIns(bool do_it) final;
140 
141  /** @brief indicates whether the fill-ins generated by the eliminated
142  * nodes, if needed, will be computed by the elimination sequence, or need
143  * be computed by the triangulation itself.
144  *
145  * An elimination sequence provides fill-ins to its triangulation if and
146  * only if it has the ability to compute them and it has been asked to do so
147  * (by method askFillIns) */
148  virtual bool providesFillIns() const final;
149 
150  /** @brief indicates whether the elimination sequence updates by itself the
151  * graph after a node has been eliminated */
152  virtual bool providesGraphUpdate() const final;
153 
154  /// performs all the graph/fill-ins updates provided (if any)
155  /** @param node the node the elimination of which requires the graph update
156  */
157  virtual void eliminationUpdate(const NodeId node) final;
158 
159  /** @brief in case fill-ins are provided, this function returns the fill-ins
160  * due to all the nodes eliminated so far */
161  virtual const EdgeSet& fillIns() final;
162 
163  /// returns the current complete ordering
164  const std::vector< NodeId >* order() const noexcept;
165 
166  /// indicates whether a new complete ordering is needed
167  /** if the current complete ordering does not contain all the nodes of the
168  * graph or if the graph itself is not defined (nullptr) a new complete
169  * ordering will be needed for the next triangulation */
170  bool isOrderNeeded() const noexcept;
171 
172  /// @}
173 
174 
175  private:
176  /// the vector indicating in which order we should eliminate the nodes
177  const std::vector< NodeId >* order__{nullptr};
178 
179  /// the index in the order indicating the new node to eliminate
180  std::size_t order_index__{std::size_t(0)};
181 
182  /// indicate whether a new complete ordering is necessary for the
183  /// elimination
184  bool order_needed__{true};
185 
186 
187  /// indicates whether an order is compatible with the current graph
188  bool isOrderNeeded__(const std::vector< NodeId >* order) const;
189  };
190 
191 
192 } /* namespace gum */
193 
194 
195 #ifndef GUM_NO_INLINE
196 # include <agrum/tools/graphs/algorithms/triangulations/eliminationStrategies/orderedEliminationSequenceStrategy_inl.h>
197 #endif // GUM_NOINLINE
198 
199 
200 #endif /* GUM_ORDERED_ELIMINATION_SEQUENCE_STRATEGY_H */
bool isOrderNeeded() const noexcept
indicates whether a new complete ordering is needed
const std::vector< NodeId > * order__
the vector indicating in which order we should eliminate the nodes
An Elimination sequence algorithm that imposes a given complete ordering on the nodes elimination seq...
bool order_needed__
indicate whether a new complete ordering is necessary for the elimination
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:669
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
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
virtual NodeId nextNodeToEliminate() final
returns the new node to be eliminated within the triangulation algorithm
virtual void eliminationUpdate(const NodeId node) final
performs all the graph/fill-ins updates provided (if any)
OrderedEliminationSequenceStrategy(OrderedEliminationSequenceStrategy &&from)
move constructor
bool isOrderNeeded__(const std::vector< NodeId > *order) const
indicates whether an order is compatible with the current graph
virtual OrderedEliminationSequenceStrategy * copyFactory() const final
virtual copy constructor
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 ...