aGrUM  0.20.2
a C++ library for (probabilistic) graphical models
defaultPartialOrderedEliminationSequenceStrategy.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 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 */
96  double theThreshold
98 
99  /// constructor for an a priori non empty graph
100  /** @param graph the graph to be triangulated, i.e., the nodes of which will
101  * be eliminated
102  * @param dom_sizes thedomain sizes of the nodes/variables
103  * @param subsets the list of the subsets constituting the partial ordering
104  * @param ratio the ratio used by the SimplicialSet included in the
105  * DefaultEliminationSequenceStrategy
106  * @param threshold the weight threshhold of the SimplicialSet included in
107  * the DefaultEliminationSequenceStrategy
108  * @warning Note that we allow dom_sizes to be defined over nodes/variables
109  * that do not belong to graph. These sizes will simply be ignored. However,
110  * it is compulsory that all the nodes of graph belong to dom_sizes
111  * @warning the graph is altered during the triangulation.
112  * @warning note that, by aGrUM's rule, the graph, the domain sizes and
113  * the sequence are not copied but only referenced by the elimination
114  * sequence algorithm. */
116  UndiGraph* graph,
117  const NodeProperty< Size >* dom_sizes,
118  const List< NodeSet >* subsets,
119  double ratio = GUM_QUASI_RATIO,
120  double threshold = GUM_WEIGHT_THRESHOLD);
121 
122  /// copy constructor
123  /** @warning The newly created elimination sequence strategy points toward
124  * the same undirected graph as the one contained in from but each strategy
125  * possesses its own simplicial set. As a result, if both elimination
126  * strategies are used at the same time, they will probably result in a mess
127  * because their simplicial sets won't be synchronized correctly with the
128  * changing undirected graph. So, whenever using this copy constructor, be
129  * sure that either from or the newly created strategy is used for a
130  * triangulation but not both. This will necessarily be OK in
131  * DefaultTriangulations. */
134 
135  /// move constructor
138 
139  /// destructor
141 
142  /** @brief creates a new elimination sequence of the same type as the
143  * current object, but this sequence contains only an empty graph
144  * @warning you must deallocate by yourself the object returned
145  * @return an empty clone of the current object with the same type */
147  newFactory() const final;
148 
149  /// virtual copy constructor
150  /** @warning The newly created elimination sequence strategy points toward
151  * the same undirected graph as the one contained in the current strategy
152  * but each strategy possesses its own simplicial set. As a result, if both
153  * elimination strategies are used at the same time, they will probably
154  * result in a mess because their simplicial sets won't be synchronized
155  * correctly with the changing undirected graph. So, whenever using this
156  * virtual copy constructor, be sure that either the current or the newly
157  * created strategy is used for a triangulation but not both. This will
158  * necessarily be OK in DefaultTriangulations. */
160  copyFactory() const final;
161 
162  /// @}
163 
164 
165  // ############################################################################
166  /// @name Accessors / Modifiers
167  // ############################################################################
168  /// @{
169 
170  /// sets a new graph to be triangulated
171  /** The elimination sequence algorithms reinitializes its data to start a
172  * new triangulation with graph Graph and a new partial ordrering
173  * @param graph the new graph to be triangulated
174  * @param dom_sizes the domain sizes of the nodes/variables
175  * @warning Note that we allow dom_sizes to be defined over nodes/variables
176  * that do not belong to graph. These sizes will simply be ignored. However,
177  * it is compulsory that all the nodes of graph belong to dom_sizes
178  * @warning the graph is altered during the triangulation.
179  * @warning note that, by aGrUM's rule, the graph and the domain sizes
180  * are not copied but only referenced by the elimination sequence algorithm.
181  */
182  virtual bool setGraph(UndiGraph* graph,
183  const NodeProperty< Size >* dom_sizes) final;
184 
185  /// clears the sequence (to prepare, for instance, a new elimination
186  /// sequence)
187  virtual void clear() final;
188 
189  /// returns the new node to be eliminated within the triangulation algorithm
190  /** @throws NotFound exception is thrown if there is no more node to
191  * eliminate in the graph */
192  virtual NodeId nextNodeToEliminate() final;
193 
194  /** @brief if the elimination sequence is able to compute fill-ins, we
195  * indicate whether we want this feature to be activated
196  *
197  * @param do_it when true and the elimination sequence has the ability to
198  * compute fill-ins, the elimination sequence will actually compute them
199  * (for the triangulation to use them), else they will not be available. */
200  virtual void askFillIns(bool do_it) final;
201 
202  /** @brief indicates whether the fill-ins generated by the eliminated
203  * nodes, if needed, will be computed by the elimination sequence, or need
204  * be computed by the triangulation itself.
205  *
206  * An elimination sequence provides fill-ins to its triangulation if and
207  * only if it has the ability to compute them and it has been asked to do so
208  * (by method askFillIns) */
209  virtual bool providesFillIns() const final;
210 
211  /** @brief indicates whether the elimination sequence updates by itself the
212  * graph after a node has been eliminated */
213  virtual bool providesGraphUpdate() const final;
214 
215  /// performs all the graph/fill-ins updates provided (if any)
216  /** @param node the node the elimination of which requires the graph update
217  */
218  virtual void eliminationUpdate(const NodeId node) final;
219 
220  /** @brief in case fill-ins are provided, this function returns the fill-ins
221  * due to all the nodes eliminated so far */
222  virtual const EdgeSet& fillIns() final;
223 
224  /// @}
225 
226  private:
227  /// for each node, the weight of the clique created by the node's
228  /// elimination
230 
231  /// the simplicial set used for determining the best nodes to eliminate
233 
234  /// the ratio used by simplicial_set__ for its quasi-simplicial nodes
236 
237  /// the threshold used by simplicial_set__ to determine small cliques
239 
240  /// indicates whether we compute new fill-ins
241  bool provide_fill_ins__{false};
242 
243 
244  /// returns the best possible node to be eliminated
245  /** this function is used by method nextNodeToEliminate */
247 
248  /// create a new simplicial set suited for the current graph
249  void createSimplicialSet__();
250  };
251 
252 } /* namespace gum */
253 
254 #endif /* GUM_DEFAULT_PARTIAL_ORDERED_ELIMINATION_SEQUENCE_STRATEGY_H */
DefaultPartialOrderedEliminationSequenceStrategy(DefaultPartialOrderedEliminationSequenceStrategy &&from)
move constructor
virtual void clear() final
clears the sequence (to prepare, for instance, a new elimination sequence)
void createSimplicialSet__()
create a new simplicial set suited for the current graph
virtual void eliminationUpdate(const NodeId node) final
performs all the graph/fill-ins updates provided (if any)
NodeId nodeToEliminate__(const PriorityQueue< NodeId, double > &possibleNodes)
returns the best possible node to be eliminated
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:669
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
An Elimination sequence algorithm that imposes a given partial ordering on the nodes elimination sequ...
SimplicialSet * simplicial_set__
the simplicial set used for determining the best nodes to eliminate
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...
NodeProperty< double > log_weights__
for each node, the weight of the clique created by the node&#39;s elimination
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
DefaultPartialOrderedEliminationSequenceStrategy(double theRatio=GUM_QUASI_RATIO, double theThreshold=GUM_WEIGHT_THRESHOLD)
default constructor (uses an empty graph)
double simplicial_ratio__
the ratio used by simplicial_set__ for its quasi-simplicial nodes
double simplicial_threshold__
the threshold used by simplicial_set__ to determine small cliques