aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
defaultPartialOrderedEliminationSequenceStrategy.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 partial
24  * ordering on the nodes elimination sequence
25  *
26  * Class DefaultPartialOrderedEliminationSequenceStrategy implements
27  * an elimination sequence algorithm that satisfies a partial ordering, that
28  * is, the set of all the nodes is divided into several subsets. All the nodes
29  * of the first subset must be eliminated before the nodes of the second,
30  * which must be eliminated before those of the third subset, and so on. Within
31  * a subset, the ordering is determined as follows:
32  * # the nodes that are simplicial (i.e., those that already form a clique with
33  * their neighbors) are eliminated first
34  * # then the nodes that are almost simplicial (i.e. if we remove one of their
35  * neighbors, they become simplicial) and that create small cliques, are
36  * eliminated (see Bodlaender's safe reductions)
37  * # the quasi simplicial nodes (i.e., the nodes that do not require many
38  * fill-ins to create cliques) that would create small cliques, are eliminated
39  * # finally, the heuristic proposed by Kjaerulff(90) is used to compute the
40  * last nodes to be eliminated.
41  *
42  * @author Christophe GONZALES(@AMU) and Pierre-Henri WUILLEMIN(@LIP6)
43  */
44 
45 #ifndef GUM_DEFAULT_PARTIAL_ORDERED_ELIMINATION_SEQUENCE_STRATEGY_H
46 #define GUM_DEFAULT_PARTIAL_ORDERED_ELIMINATION_SEQUENCE_STRATEGY_H
47 
48 #include <agrum/tools/core/priorityQueue.h>
49 #include <agrum/tools/graphs/algorithms/simplicialSet.h>
50 #include <agrum/tools/graphs/algorithms/triangulations/eliminationStrategies/partialOrderedEliminationSequenceStrategy.h>
51 #include <agrum/tools/graphs/graphElements.h>
52 
53 namespace gum {
54 
55  /** @class DefaultPartialOrderedEliminationSequenceStrategy
56  * @brief An Elimination sequence algorithm that imposes a given partial
57  * ordering on the nodes elimination sequence
58  *
59  * Class DefaultPartialOrderedEliminationSequenceStrategy implements
60  * an elimination sequence algorithm that satisfies a partial ordering, that
61  * is, the set of all the nodes is divided into several subsets. All the nodes
62  * of the first subset must be eliminated before the nodes of the second,
63  * which must be eliminated before those of the third subset, and so on.
64  * Within
65  * a subset, the ordering is determined as follows:
66  * # the nodes that are simplicial (i.e., those that already form a clique
67  * with
68  * their neighbors) are eliminated first
69  * # then the nodes that are almost simplicial (i.e. if we remove one of their
70  * neighbors, they become simplicial) and that create small cliques, are
71  * eliminated (see Bodlaender's safe reductions)
72  * # the quasi simplicial nodes (i.e., the nodes that do not require many
73  * fill-ins to create cliques) that would create small cliques, are
74  * eliminated
75  * # finally, the heuristic proposed by Kjaerulff(90) is used to compute the
76  * last nodes to be eliminated.
77  *
78  * \ingroup graph_group
79  *
80  */
83  public:
84  // ############################################################################
85  /// @name Constructors / Destructors
86  // ############################################################################
87  /// @{
88 
89  /// default constructor (uses an empty graph)
90  /** @param theRatio the ratio used by the SimplicialSet included in the
91  * DefaultEliminationSequenceStrategy
92  * @param theThreshold the weight threshhold of the SimplicialSet included
93  * in the DefaultEliminationSequenceStrategy */
95  double theThreshold = GUM_WEIGHT_THRESHOLD);
96 
97  /// constructor for an a priori non empty graph
98  /** @param graph the graph to be triangulated, i.e., the nodes of which will
99  * be eliminated
100  * @param dom_sizes thedomain sizes of the nodes/variables
101  * @param subsets the list of the subsets constituting the partial ordering
102  * @param ratio the ratio used by the SimplicialSet included in the
103  * DefaultEliminationSequenceStrategy
104  * @param threshold the weight threshhold of the SimplicialSet included in
105  * the DefaultEliminationSequenceStrategy
106  * @warning Note that we allow dom_sizes to be defined over nodes/variables
107  * that do not belong to graph. These sizes will simply be ignored. However,
108  * it is compulsory that all the nodes of graph belong to dom_sizes
109  * @warning the graph is altered during the triangulation.
110  * @warning note that, by aGrUM's rule, the graph, the domain sizes and
111  * the sequence are not copied but only referenced by the elimination
112  * sequence algorithm. */
114  const NodeProperty< Size >* dom_sizes,
115  const List< NodeSet >* subsets,
116  double ratio = GUM_QUASI_RATIO,
117  double threshold = GUM_WEIGHT_THRESHOLD);
118 
119  /// copy constructor
120  /** @warning The newly created elimination sequence strategy points toward
121  * the same undirected graph as the one contained in from but each strategy
122  * possesses its own simplicial set. As a result, if both elimination
123  * strategies are used at the same time, they will probably result in a mess
124  * because their simplicial sets won't be synchronized correctly with the
125  * changing undirected graph. So, whenever using this copy constructor, be
126  * sure that either from or the newly created strategy is used for a
127  * triangulation but not both. This will necessarily be OK in
128  * DefaultTriangulations. */
131 
132  /// move constructor
135 
136  /// destructor
138 
139  /** @brief creates a new elimination sequence of the same type as the
140  * current object, but this sequence contains only an empty graph
141  * @warning you must deallocate by yourself the object returned
142  * @return an empty clone of the current object with the same type */
144 
145  /// virtual copy constructor
146  /** @warning The newly created elimination sequence strategy points toward
147  * the same undirected graph as the one contained in the current strategy
148  * but each strategy possesses its own simplicial set. As a result, if both
149  * elimination strategies are used at the same time, they will probably
150  * result in a mess because their simplicial sets won't be synchronized
151  * correctly with the changing undirected graph. So, whenever using this
152  * virtual copy constructor, be sure that either the current or the newly
153  * created strategy is used for a triangulation but not both. This will
154  * necessarily be OK in DefaultTriangulations. */
156 
157  /// @}
158 
159 
160  // ############################################################################
161  /// @name Accessors / Modifiers
162  // ############################################################################
163  /// @{
164 
165  /// sets a new graph to be triangulated
166  /** The elimination sequence algorithms reinitializes its data to start a
167  * new triangulation with graph Graph and a new partial ordrering
168  * @param graph the new graph to be triangulated
169  * @param dom_sizes the domain sizes of the nodes/variables
170  * @warning Note that we allow dom_sizes to be defined over nodes/variables
171  * that do not belong to graph. These sizes will simply be ignored. However,
172  * it is compulsory that all the nodes of graph belong to dom_sizes
173  * @warning the graph is altered during the triangulation.
174  * @warning note that, by aGrUM's rule, the graph and the domain sizes
175  * are not copied but only referenced by the elimination sequence algorithm.
176  */
177  virtual bool setGraph(UndiGraph* graph, const NodeProperty< Size >* dom_sizes) final;
178 
179  /// clears the sequence (to prepare, for instance, a new elimination
180  /// sequence)
181  virtual void clear() final;
182 
183  /// returns the new node to be eliminated within the triangulation algorithm
184  /** @throws NotFound exception is thrown if there is no more node to
185  * eliminate in the graph */
186  virtual NodeId nextNodeToEliminate() final;
187 
188  /** @brief if the elimination sequence is able to compute fill-ins, we
189  * indicate whether we want this feature to be activated
190  *
191  * @param do_it when true and the elimination sequence has the ability to
192  * compute fill-ins, the elimination sequence will actually compute them
193  * (for the triangulation to use them), else they will not be available. */
194  virtual void askFillIns(bool do_it) final;
195 
196  /** @brief indicates whether the fill-ins generated by the eliminated
197  * nodes, if needed, will be computed by the elimination sequence, or need
198  * be computed by the triangulation itself.
199  *
200  * An elimination sequence provides fill-ins to its triangulation if and
201  * only if it has the ability to compute them and it has been asked to do so
202  * (by method askFillIns) */
203  virtual bool providesFillIns() const final;
204 
205  /** @brief indicates whether the elimination sequence updates by itself the
206  * graph after a node has been eliminated */
207  virtual bool providesGraphUpdate() const final;
208 
209  /// performs all the graph/fill-ins updates provided (if any)
210  /** @param node the node the elimination of which requires the graph update
211  */
212  virtual void eliminationUpdate(const NodeId node) final;
213 
214  /** @brief in case fill-ins are provided, this function returns the fill-ins
215  * due to all the nodes eliminated so far */
216  virtual const EdgeSet& fillIns() final;
217 
218  /// @}
219 
220  private:
221  /// for each node, the weight of the clique created by the node's
222  /// elimination
224 
225  /// the simplicial set used for determining the best nodes to eliminate
227 
228  /// the ratio used by _simplicial_set_ for its quasi-simplicial nodes
230 
231  /// the threshold used by _simplicial_set_ to determine small cliques
233 
234  /// indicates whether we compute new fill-ins
235  bool _provide_fill_ins_{false};
236 
237 
238  /// returns the best possible node to be eliminated
239  /** this function is used by method nextNodeToEliminate */
241 
242  /// create a new simplicial set suited for the current graph
243  void _createSimplicialSet_();
244  };
245 
246 } /* namespace gum */
247 
248 #endif /* GUM_DEFAULT_PARTIAL_ORDERED_ELIMINATION_SEQUENCE_STRATEGY_H */
double _simplicial_threshold_
the threshold used by simplicial_set to determine small cliques
NodeId _nodeToEliminate_(const PriorityQueue< NodeId, double > &possibleNodes)
returns the best possible node to be eliminated
DefaultPartialOrderedEliminationSequenceStrategy(DefaultPartialOrderedEliminationSequenceStrategy &&from)
move constructor
virtual void clear() final
clears the sequence (to prepare, for instance, a new elimination sequence)
virtual void eliminationUpdate(const NodeId node) final
performs all the graph/fill-ins updates provided (if any)
double _simplicial_ratio_
the ratio used by simplicial_set for its quasi-simplicial nodes
virtual DefaultPartialOrderedEliminationSequenceStrategy * newFactory() const final
creates a new elimination sequence of the same type as the current object, but this sequence contains...
virtual bool providesFillIns() const final
indicates whether the fill-ins generated by the eliminated nodes, if needed, will be computed by the ...
virtual const EdgeSet & fillIns() final
in case fill-ins are provided, this function returns the fill-ins due to all the nodes eliminated so ...
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:643
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 NodeId nextNodeToEliminate() final
returns the new node to be eliminated within the triangulation algorithm
SimplicialSet * _simplicial_set_
the simplicial set used for determining the best nodes to eliminate
An Elimination sequence algorithm that imposes a given partial ordering on the nodes elimination sequ...
NodeProperty< double > _log_weights_
for each node, the weight of the clique created by the node&#39;s elimination
DefaultPartialOrderedEliminationSequenceStrategy(const DefaultPartialOrderedEliminationSequenceStrategy &from)
copy constructor
virtual bool providesGraphUpdate() const final
indicates whether the elimination sequence updates by itself the graph after a node has been eliminat...
virtual DefaultPartialOrderedEliminationSequenceStrategy * copyFactory() const final
virtual copy constructor
DefaultPartialOrderedEliminationSequenceStrategy(UndiGraph *graph, const NodeProperty< Size > *dom_sizes, const List< NodeSet > *subsets, double ratio=GUM_QUASI_RATIO, double threshold=GUM_WEIGHT_THRESHOLD)
constructor for an a priori non empty graph
virtual bool setGraph(UndiGraph *graph, const NodeProperty< Size > *dom_sizes) final
sets a new graph to be triangulated
void _createSimplicialSet_()
create a new simplicial set suited for the current graph
DefaultPartialOrderedEliminationSequenceStrategy(double theRatio=GUM_QUASI_RATIO, double theThreshold=GUM_WEIGHT_THRESHOLD)
default constructor (uses an empty graph)