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