aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
partialOrderedTriangulation.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 class for graph triangulations for which we enforce a given partial
24  * ordering on the nodes eliminations, that is, the set of all the nodes is
25  * divided into several subsets. Within each subset, any ordering can be chosen.
26  * But all the nodes of the first subset must be eliminated before the nodes
27  * of the second, which must be eliminated before those of the third subset,
28  * and so on.
29  *
30  * @author Christophe GONZALES(@AMU) and Pierre-Henri WUILLEMIN(@LIP6)
31  */
32 #ifndef GUM_PARTIAL_ORDERED_TRIANGULATION_H
33 #define GUM_PARTIAL_ORDERED_TRIANGULATION_H
34 
35 #include <agrum/tools/graphs/algorithms/triangulations/eliminationStrategies/defaultPartialOrderedEliminationSequenceStrategy.h>
36 #include <agrum/tools/graphs/algorithms/triangulations/junctionTreeStrategies/defaultJunctionTreeStrategy.h>
37 #include <agrum/tools/graphs/algorithms/triangulations/staticTriangulation.h>
38 
39 
40 namespace gum {
41 
42 
43  /** @class PartialOrderedTriangulation
44  * @brief class for graph triangulations for which we enforce a given partial
45  * ordering on the nodes eliminations, that is, the set of all the nodes is
46  * divided into several subsets. Within each subset, any ordering can be
47  * chosen. But all the nodes of the first subset must be eliminated before
48  * the nodes of the second, which must be eliminated before those of the third
49  * subset, and so on.
50  *
51  * \ingroup graph_group
52  */
54  public:
55  // ############################################################################
56  /// @name Constructors / Destructors
57  // ############################################################################
58  /// @{
59 
60  /// default constructor
61  /** @param elimSeq the elimination sequence used to triangulate the graph
62  * @param JTStrategy the junction tree strategy used to create junction
63  * trees
64  * @param minimality a Boolean indicating whether we should enforce that
65  * the triangulation is minimal w.r.t. inclusion */
66  PartialOrderedTriangulation(const PartialOrderedEliminationSequenceStrategy& elimSeq
68  const JunctionTreeStrategy& JTStrategy
70  bool minimality = false);
71 
72  /// constructor with a given graph
73  /** @param graph the graph to be triangulated, i.e., the nodes of which will
74  * be eliminated
75  * @param domsizes the domain sizes of the nodes to be eliminated
76  * @param partial_order the list of the subsets constituting the partial
77  * ordering
78  * @param elimSeq the elimination sequence used to triangulate the graph
79  * @param JTStrategy the junction tree strategy used to create junction
80  * trees
81  * @param minimality a Boolean indicating whether we should enforce that
82  * the triangulation is minimal w.r.t. inclusion
83  * @warning Note that we allow dom_sizes to be defined over nodes/variables
84  * that do not belong to graph. These sizes will simply be ignored. However,
85  * it is compulsory that all the nodes of graph belong to dom_sizes
86  * @warning note that, by aGrUM's rule, the graph, the domain sizes and the
87  * partial ordering are not copied but only referenced by the
88  * triangulation algorithm. */
89  PartialOrderedTriangulation(const UndiGraph* graph,
90  const NodeProperty< Size >* domsizes,
91  const List< NodeSet >* partial_order,
92  const PartialOrderedEliminationSequenceStrategy& elimSeq
94  const JunctionTreeStrategy& JTStrategy
96  bool minimality = false);
97 
98  /// copy constructor
100 
101  /// move constructor
103 
104  /** @brief returns a fresh triangulation (over an empty graph) of the same
105  * type as the current object
106  *
107  * note that we return a pointer as it enables subclasses to return
108  * pointers to their types, not Triangulation pointers. See item 25 of the
109  * more effective C++.*/
110  virtual PartialOrderedTriangulation* newFactory() const;
111 
112  /// virtual copy constructor
113  virtual PartialOrderedTriangulation* copyFactory() const final;
114 
115  /// destructor
116  virtual ~PartialOrderedTriangulation();
117 
118  /// @}
119 
120 
121  // ############################################################################
122  /// @name Accessors / Modifiers
123  // ############################################################################
124  /// @{
125 
126  /// initialize the triangulation data structures for a new graph
127  /** @param graph the graph to be triangulated, i.e., the nodes of which will
128  * be eliminated
129  * @param domsizes the domain sizes of the nodes to be eliminated
130  * @param sequence the order in which the nodes should be eliminated
131  * @warning note that, by aGrUM's rule, the graph and the domain sizes are
132  * not
133  * notcopied but only referenced by the triangulation algorithm. */
134  virtual void setGraph(const UndiGraph* graph, const NodeProperty< Size >* domsizes) final;
135 
136  /// sets the elimination sequence's partial order (only a reference is
137  /// stored)
138  /** The elimination sequence is kept outside this class for efficiency
139  * reasons. */
140  virtual void setPartialOrder(const List< NodeSet >* partial_order) final;
141 
142  /// @}
143 
144 
145  protected:
146  /// the function called to initialize the triangulation process
147  /** This function is called when the triangulation process starts and is
148  * used to initialize the elimination sequence strategy. Actually, the
149  * graph that is modified by the triangulation algorithm is a copy of
150  * the original graph, and this copy need be known by the elimination
151  * sequence strategy. initTriangulation_ is used to transmit this
152  * knowledge to the elimination sequence (through method setGraph of the
153  * elimination sequence class).
154  * @param graph the very graph that is triangulated (this is a copy of
155  * original_graph_) */
156  virtual void initTriangulation_(UndiGraph& graph) final;
157 
158  /// the partial ordering to apply to eliminate nodes
159  const List< NodeSet >* _partial_order_{nullptr};
160 
161  /// @}
162 
163  private:
164  /// forbid copy operator
166  };
167 
168 } /* namespace gum */
169 
170 #endif /* GUM_PARTIAL_ORDERED_TRIANGULATION_H */
PartialOrderedTriangulation(PartialOrderedTriangulation &&from)
move constructor
PartialOrderedTriangulation(const PartialOrderedTriangulation &from)
copy constructor
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:643
virtual PartialOrderedTriangulation * newFactory() const
returns a fresh triangulation (over an empty graph) of the same type as the current object ...
PartialOrderedTriangulation & operator=(const PartialOrderedTriangulation &)
forbid copy operator
PartialOrderedTriangulation(const PartialOrderedEliminationSequenceStrategy &elimSeq=DefaultPartialOrderedEliminationSequenceStrategy(), const JunctionTreeStrategy &JTStrategy=DefaultJunctionTreeStrategy(), bool minimality=false)
default constructor
class for graph triangulations for which we enforce a given partial ordering on the nodes elimination...
virtual void setPartialOrder(const List< NodeSet > *partial_order) final
sets the elimination sequence&#39;s partial order (only a reference is stored)
virtual PartialOrderedTriangulation * copyFactory() const final
virtual copy constructor
virtual void initTriangulation_(UndiGraph &graph) final
the function called to initialize the triangulation process
const List< NodeSet > * _partial_order_
the partial ordering to apply to eliminate nodes
virtual void setGraph(const UndiGraph *graph, const NodeProperty< Size > *domsizes) final
initialize the triangulation data structures for a new graph
PartialOrderedTriangulation(const UndiGraph *graph, const NodeProperty< Size > *domsizes, const List< NodeSet > *partial_order, const PartialOrderedEliminationSequenceStrategy &elimSeq=DefaultPartialOrderedEliminationSequenceStrategy(), const JunctionTreeStrategy &JTStrategy=DefaultJunctionTreeStrategy(), bool minimality=false)
constructor with a given graph