aGrUM  0.20.2
a C++ library for (probabilistic) graphical models
partialOrderedEliminationSequenceStrategy.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 Base class for all elimination sequence algorithm that impose a given
24  * partial ordering on the nodes elimination sequence, that is, the set of all
25  * the nodes is divided into several subsets. Within each subset, any ordering
26  * can be chosen. But all the nodes of the first subset must be eliminated
27  * before the nodes of the second, which must be eliminated before those of the
28  * third subset, and so on.
29  *
30  * @author Christophe GONZALES(@AMU) and Pierre-Henri WUILLEMIN(@LIP6)
31  */
32 
33 #ifndef GUM_PARTIAL_ORDERED_ELIMINATION_SEQUENCE_STRATEGY_H
34 #define GUM_PARTIAL_ORDERED_ELIMINATION_SEQUENCE_STRATEGY_H
35 
36 #include <agrum/tools/core/list.h>
37 #include <agrum/tools/graphs/algorithms/triangulations/eliminationStrategies/eliminationSequenceStrategy.h>
38 
39 namespace gum {
40 
41  /** @class PartialOrderedEliminationSequenceStrategy
42  * @brief Base class for all elimination sequence algorithm that impose a
43  * given
44  * partial ordering on the nodes elimination sequence, that is, the set of all
45  * the nodes is divided into several subsets. Within each subset, any ordering
46  * can be chosen. But all the nodes of the first subset must be eliminated
47  * before the nodes of the second, which must be eliminated before those of
48  * the
49  * third subset, and so on.
50  *
51  * \ingroup graph_group
52  *
53  */
56  public:
57  // ############################################################################
58  /// @name Constructors / Destructors
59  // ############################################################################
60  /// @{
61 
62  /// destructor
64 
65  /** @brief creates a new elimination sequence of the same type as the
66  * current object, but this sequence contains only an empty graph
67  * @warning you must deallocate by yourself the object returned
68  * @return an empty clone of the current object with the same type */
70 
71  /// virtual copy constructor
73 
74  /// @}
75 
76 
77  // ############################################################################
78  /// @name Accessors / Modifiers
79  // ############################################################################
80  /// @{
81 
82  /// sets a new graph to be triangulated
83  /** The elimination sequence algorithms reinitializes its data to start a
84  * new triangulation with graph Graph
85  * @param graph the new graph to be triangulated
86  * @param dom_sizes the domain sizes of the nodes/variables
87  * @return true if the data structures were modified (if the graph or the
88  * domain sizes did not change, then there is no need to update the
89  * data structures).
90  * @warning Note that we allow dom_sizes to be defined over nodes/variables
91  * that do not belong to graph. These sizes will simply be ignored. However,
92  * it is compulsory that all the nodes of graph belong to dom_sizes
93  * @warning the graph is altered during the triangulation.
94  * @warning note that, by aGrUM's rule, the graph and the sequence are not
95  * copied but only referenced by the elimination sequence algorithm. */
96  virtual bool setGraph(UndiGraph* graph, const NodeProperty< Size >* dom_sizes);
97 
98  /// sets a new partial ordering constraint on the elimination sequence
99  /** @param subsets the list of the subsets constituting the partial ordering
100  * @return true if the new partial order has been successfully assigned
101  * (i.e.,
102  * if all the nodes of the graph belong to one of the subsets)
103  * @warning if the subsets contain some nodes that do not belong to the
104  * graph,
105  * then these nodes are simply ignored.
106  * @warning note that, by aGrUM's rule, the partial ordering is not copied
107  * but only referenced by the elimination sequence algorithm. */
108  virtual bool setPartialOrder(const List< NodeSet >* subsets);
109 
110  /// clears the sequence (to prepare, for instance, a new elimination
111  /// sequence)
112  virtual void clear();
113 
114  /// returns the current partial ordering
115  const List< NodeSet >* partialOrder() const noexcept;
116 
117  /// indicates if a new partial ordering is needed
118  /** if the current partial ordering does not contain all the nodes of the
119  * graph or if the graph itself is not defined (nullptr) a new partial
120  * ordering will be needed for the next triangulation */
121  bool isPartialOrderNeeded() const noexcept;
122 
123  /// @}
124 
125 
126  protected:
127  /// the subsets constituting the partial ordering
128  const List< NodeSet >* subsets_{nullptr};
129 
130  /// the iterator indicating which is the current subset on which we work
131  List< NodeSet >::const_iterator subset_iter_;
132 
133  /// the nodes which can be currently eliminated
135 
136  /// indicate whether a new partial ordering is necessary for the elimination
138 
139 
140  /// indicate whether a partial ordering is compatible with the current graph
141  /** The method checks whether all the nodes of the graph belong to the
142  * partial ordering.
143  * @return true if some nodes in graph_ do not belong to subsets or if
144  * graph_ is not defnined (nullptr) */
145  bool isPartialOrderNeeded_(const List< NodeSet >* subsets) const;
146 
147 
148  // ############################################################################
149  /// @name Constructors / Destructors
150  // ############################################################################
151  /// @{
152 
153  /// default constructor (uses an empty graph)
155 
156  /// constructor for an a priori non empty graph
157  /** @param graph the graph to be triangulated, i.e., the nodes of which will
158  * be eliminated
159  * @param dom_sizes thedomain sizes of the nodes/variables
160  * @param subsets the list of the subsets constituting the partial ordering
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, the domain sizes and
166  * the sequence are not copied but only referenced by the elimination
167  * sequence algorithm. */
169  UndiGraph* graph,
170  const NodeProperty< Size >* dom_sizes,
171  const List< NodeSet >* subsets);
172 
173  /// copy constructor
176 
177  /// move constructor
180 
181  /// @}
182  };
183 
184 } /* namespace gum */
185 
186 
187 #ifndef GUM_NO_INLINE
188 # include <agrum/tools/graphs/algorithms/triangulations/eliminationStrategies/partialOrderedEliminationSequenceStrategy_inl.h>
189 #endif // GUM_NOINLINE
190 
191 
192 #endif /* GUM_PARTIAL_ORDERED_ELIMINATION_SEQUENCE_STRATEGY_H */
virtual void clear()
clears the sequence (to prepare, for instance, a new elimination sequence)
PartialOrderedEliminationSequenceStrategy(const PartialOrderedEliminationSequenceStrategy &)
copy constructor
virtual PartialOrderedEliminationSequenceStrategy * copyFactory() const =0
virtual copy constructor
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:669
virtual bool setPartialOrder(const List< NodeSet > *subsets)
sets a new partial ordering constraint on the elimination sequence
PartialOrderedEliminationSequenceStrategy(PartialOrderedEliminationSequenceStrategy &&)
move constructor
List< NodeSet >::const_iterator subset_iter_
the iterator indicating which is the current subset on which we work
PartialOrderedEliminationSequenceStrategy()
default constructor (uses an empty graph)
virtual bool setGraph(UndiGraph *graph, const NodeProperty< Size > *dom_sizes)
sets a new graph to be triangulated
PartialOrderedEliminationSequenceStrategy(UndiGraph *graph, const NodeProperty< Size > *dom_sizes, const List< NodeSet > *subsets)
constructor for an a priori non empty graph
bool partial_order_needed_
indicate whether a new partial ordering is necessary for the elimination
virtual PartialOrderedEliminationSequenceStrategy * newFactory() const =0
creates a new elimination sequence of the same type as the current object, but this sequence contains...
bool isPartialOrderNeeded_(const List< NodeSet > *subsets) const
indicate whether a partial ordering is compatible with the current graph
bool isPartialOrderNeeded() const noexcept
indicates if a new partial ordering is needed
const List< NodeSet > * partialOrder() const noexcept
returns the current partial ordering
const List< NodeSet > * subsets_
the subsets constituting the partial ordering
NodeSet nodeset_
the nodes which can be currently eliminated