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