aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
eliminationSequenceStrategy.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 Base Class for all elimination sequence algorithms used by
24  * triangulations
25  *
26  * This class is the interface that should be implemented by all elimination
27  * sequence algorithms used by triangulation algorithms.
28  *
29  * @author Christophe GONZALES(@AMU) and Pierre-Henri WUILLEMIN(@LIP6)
30  */
31 
32 #ifndef GUM_ELIMINATION_SEQUENCE_STRATEGY_H
33 #define GUM_ELIMINATION_SEQUENCE_STRATEGY_H
34 
35 #include <agrum/agrum.h>
36 #include <agrum/tools/graphs/graphElements.h>
37 #include <agrum/tools/graphs/undiGraph.h>
38 
39 
40 namespace gum {
41 
42  /** @class EliminationSequenceStrategy
43  * @brief The base class for all elimination sequence algorithms used by
44  * triangulation algorithms.
45  *
46  * \ingroup graph_group
47  *
48  */
50  public:
51  // ############################################################################
52  /// @name Constructors / Destructors
53  // ############################################################################
54  /// @{
55 
56  /// destructor
57  virtual ~EliminationSequenceStrategy();
58 
59  /** @brief creates a new elimination sequence of the same type as the
60  * current object, but this sequence contains only an empty graph
61  * @warning you must deallocate by yourself the object returned
62  * @return an empty clone of the current object with the same type */
63  virtual EliminationSequenceStrategy* newFactory() const = 0;
64 
65  /// virtual copy constructor
66  /** @return a full clone of the current object */
67  virtual EliminationSequenceStrategy* copyFactory() const = 0;
68 
69  /// @}
70 
71 
72  // ############################################################################
73  /// @name Accessors / Modifiers
74  // ############################################################################
75  /// @{
76 
77  /// sets a new graph to be triangulated
78  /** The elimination sequence algorithms reinitializes its data to start a
79  * new triangulation with graph Graph
80  * @param graph the new graph to be triangulated
81  * @param dom_sizes the domain sizes of the variables/nodes
82  * @return true if the data structures were modified (if the graph or the
83  * domain sizes did not change, then there is no need to update the
84  * data structures).
85  * @warning Note that we allow dom_sizes to be defined over nodes/variables
86  * that do not belong to graph. These sizes will simply be ignored. However,
87  * it is compulsory that all the nodes of graph belong to dom_sizes
88  * @warning the graph can be altered during the triangulation.
89  * @warning note that, by aGrUM's rule, the graph and the domain sizes
90  * are not copied but only referenced by the elimination sequence algorithm.
91  */
92  virtual bool setGraph(UndiGraph* graph, const NodeProperty< Size >* dom_sizes);
93 
94  /// returns the new node to be eliminated within the triangulation algorithm
95  /** @throws NotFound exception is thrown if there is no more node to
96  * eliminate in the graph */
97  virtual NodeId nextNodeToEliminate() = 0;
98 
99  /** @brief if the elimination sequence is able to compute fill-ins, we
100  *indicate
101  * whether we want this feature to be activated
102  *
103  * @param do_it when true and the elimination sequence has the ability to
104  * compute fill-ins, the elimination sequence will actually compute them
105  *(for
106  * the triangulation to use them), else they will not be available. */
107  virtual void askFillIns(bool do_it) = 0;
108 
109  /** @brief indicates whether the fill-ins generated by the eliminated
110  * nodes, if needed, will be computed by the elimination sequence, or need
111  *be
112  * computed by the triangulation itself.
113  *
114  * An elimination sequence provides fill-ins to its triangulation if and
115  * only if it has the ability to compute them and it has been asked to do so
116  * (by method askFillIns) */
117  virtual bool providesFillIns() const = 0;
118 
119  /** @brief indicates whether the elimination sequence updates by itself the
120  * graph after a node has been eliminated
121  *
122  * Some algorithms have more informations than the triangulation algorithm
123  * to update the graph after a node has been eliminated. They can thus
124  * exploit these informations to update the graph faster than the
125  * triangulation itself. Hence the latter should delegate this operation
126  * to the elimination sequence. This is the case, for instance, for the
127  * defaultEliminationSequenceStrategy, which uses a SimplicialSet that knows
128  * that some eliminated nodes do not require any fill-in. */
129  virtual bool providesGraphUpdate() const = 0;
130 
131  /// performs all the graph/fill-ins updates provided (if any)
132  /** @param node the node the elimination of which requires the graph update
133  */
134  virtual void eliminationUpdate(const NodeId node);
135 
136  /** @brief in case fill-ins are provided, this function returns the fill-ins
137  * due to all the nodes eliminated so far */
138  virtual const EdgeSet& fillIns();
139 
140  /// clears the sequence (to prepare, for instance, a new elimination
141  /// sequence)
142  virtual void clear();
143 
144  /// returns the current graph
145  UndiGraph* graph() const noexcept;
146 
147  /// returns the current domain sizes
148  const NodeProperty< Size >* domainSizes() const noexcept;
149 
150  /// @}
151 
152 
153  protected:
154  /// the graph to be triangulated
155  UndiGraph* graph_{nullptr};
156 
157  /// the domain sizes of the variables/nodes
158  const NodeProperty< Size >* domain_sizes_{nullptr};
159 
160  /// the log of the domain sizes of the variables/nodes
162 
163 
164  // ############################################################################
165  /// @name Constructors / Destructors
166  // ############################################################################
167  /// @{
168 
169  /// default constructor
171 
172  /// constructor for an a priori non empty graph
173  EliminationSequenceStrategy(UndiGraph* graph, const NodeProperty< Size >* domain_sizes);
174 
175  /// copy constructor
177 
178  /// move constructor
180 
181  /// @}
182 
183  private:
184  /// an empty fill-ins set used by default
185  static const EdgeSet& _empty_fill_ins_();
186  };
187 
188 
189 } /* namespace gum */
190 
191 
192 #ifndef GUM_NO_INLINE
193 # include <agrum/tools/graphs/algorithms/triangulations/eliminationStrategies/eliminationSequenceStrategy_inl.h>
194 #endif // GUM_NOINLINE
195 
196 
197 #endif /* GUM_ELIMINATION_SEQUENCE_STRATEGY_H */
virtual void clear()
clears the sequence (to prepare, for instance, a new elimination sequence)
virtual void eliminationUpdate(const NodeId node)
performs all the graph/fill-ins updates provided (if any)
virtual const EdgeSet & fillIns()
in case fill-ins are provided, this function returns the fill-ins due to all the nodes eliminated so ...
virtual EliminationSequenceStrategy * copyFactory() const =0
virtual copy constructor
EliminationSequenceStrategy(UndiGraph *graph, const NodeProperty< Size > *domain_sizes)
constructor for an a priori non empty graph
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:643
UndiGraph * graph() const noexcept
returns the current graph
const NodeProperty< Size > * domainSizes() const noexcept
returns the current domain sizes
EliminationSequenceStrategy(EliminationSequenceStrategy &&from)
move constructor
virtual EliminationSequenceStrategy * newFactory() const =0
creates a new elimination sequence of the same type as the current object, but this sequence contains...
const NodeProperty< Size > * domain_sizes_
the domain sizes of the variables/nodes
NodeProperty< double > log_domain_sizes_
the log of the domain sizes of the variables/nodes
virtual bool providesGraphUpdate() const =0
indicates whether the elimination sequence updates by itself the graph after a node has been eliminat...
virtual NodeId nextNodeToEliminate()=0
returns the new node to be eliminated within the triangulation algorithm
virtual bool setGraph(UndiGraph *graph, const NodeProperty< Size > *dom_sizes)
sets a new graph to be triangulated
The base class for all elimination sequence algorithms used by triangulation algorithms.
static const EdgeSet & _empty_fill_ins_()
an empty fill-ins set used by default
EliminationSequenceStrategy(const EliminationSequenceStrategy &from)
copy constructor
UndiGraph * graph_
the graph to be triangulated
virtual bool providesFillIns() const =0
indicates whether the fill-ins generated by the eliminated nodes, if needed, will be computed by the ...
virtual void askFillIns(bool do_it)=0
if the elimination sequence is able to compute fill-ins, we indicate whether we want this feature to ...