aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
partialOrderedEliminationSequenceStrategy.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 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  */
55  public:
56  // ############################################################################
57  /// @name Constructors / Destructors
58  // ############################################################################
59  /// @{
60 
61  /// destructor
63 
64  /** @brief creates a new elimination sequence of the same type as the
65  * current object, but this sequence contains only an empty graph
66  * @warning you must deallocate by yourself the object returned
67  * @return an empty clone of the current object with the same type */
69 
70  /// virtual copy constructor
72 
73  /// @}
74 
75 
76  // ############################################################################
77  /// @name Accessors / Modifiers
78  // ############################################################################
79  /// @{
80 
81  /// sets a new graph to be triangulated
82  /** The elimination sequence algorithms reinitializes its data to start a
83  * new triangulation with graph Graph
84  * @param graph the new graph to be triangulated
85  * @param dom_sizes the domain sizes of the nodes/variables
86  * @return true if the data structures were modified (if the graph or the
87  * domain sizes did not change, then there is no need to update the
88  * data structures).
89  * @warning Note that we allow dom_sizes to be defined over nodes/variables
90  * that do not belong to graph. These sizes will simply be ignored. However,
91  * it is compulsory that all the nodes of graph belong to dom_sizes
92  * @warning the graph is altered during the triangulation.
93  * @warning note that, by aGrUM's rule, the graph and the sequence are not
94  * copied but only referenced by the elimination sequence algorithm. */
95  virtual bool setGraph(UndiGraph* graph, const NodeProperty< Size >* dom_sizes);
96 
97  /// sets a new partial ordering constraint on the elimination sequence
98  /** @param subsets the list of the subsets constituting the partial ordering
99  * @return true if the new partial order has been successfully assigned
100  * (i.e.,
101  * if all the nodes of the graph belong to one of the subsets)
102  * @warning if the subsets contain some nodes that do not belong to the
103  * graph,
104  * then these nodes are simply ignored.
105  * @warning note that, by aGrUM's rule, the partial ordering is not copied
106  * but only referenced by the elimination sequence algorithm. */
107  virtual bool setPartialOrder(const List< NodeSet >* subsets);
108 
109  /// clears the sequence (to prepare, for instance, a new elimination
110  /// sequence)
111  virtual void clear();
112 
113  /// returns the current partial ordering
114  const List< NodeSet >* partialOrder() const noexcept;
115 
116  /// indicates if a new partial ordering is needed
117  /** if the current partial ordering does not contain all the nodes of the
118  * graph or if the graph itself is not defined (nullptr) a new partial
119  * ordering will be needed for the next triangulation */
120  bool isPartialOrderNeeded() const noexcept;
121 
122  /// @}
123 
124 
125  protected:
126  /// the subsets constituting the partial ordering
127  const List< NodeSet >* subsets_{nullptr};
128 
129  /// the iterator indicating which is the current subset on which we work
130  List< NodeSet >::const_iterator subset_iter_;
131 
132  /// the nodes which can be currently eliminated
134 
135  /// indicate whether a new partial ordering is necessary for the elimination
137 
138 
139  /// indicate whether a partial ordering is compatible with the current graph
140  /** The method checks whether all the nodes of the graph belong to the
141  * partial ordering.
142  * @return true if some nodes in graph_ do not belong to subsets or if
143  * graph_ is not defnined (nullptr) */
144  bool isPartialOrderNeeded_(const List< NodeSet >* subsets) const;
145 
146 
147  // ############################################################################
148  /// @name Constructors / Destructors
149  // ############################################################################
150  /// @{
151 
152  /// default constructor (uses an empty graph)
154 
155  /// constructor for an a priori non empty graph
156  /** @param graph the graph to be triangulated, i.e., the nodes of which will
157  * be eliminated
158  * @param dom_sizes thedomain sizes of the nodes/variables
159  * @param subsets the list of the subsets constituting the partial ordering
160  * @warning Note that we allow dom_sizes to be defined over nodes/variables
161  * that do not belong to graph. These sizes will simply be ignored. However,
162  * it is compulsory that all the nodes of graph belong to dom_sizes
163  * @warning the graph is altered during the triangulation.
164  * @warning note that, by aGrUM's rule, the graph, the domain sizes and
165  * the sequence are not copied but only referenced by the elimination
166  * sequence algorithm. */
168  const NodeProperty< Size >* dom_sizes,
169  const List< NodeSet >* subsets);
170 
171  /// copy constructor
173 
174  /// move constructor
176 
177  /// @}
178  };
179 
180 } /* namespace gum */
181 
182 
183 #ifndef GUM_NO_INLINE
184 # include <agrum/tools/graphs/algorithms/triangulations/eliminationStrategies/partialOrderedEliminationSequenceStrategy_inl.h>
185 #endif // GUM_NOINLINE
186 
187 
188 #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:643
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