aGrUM  0.20.2
a C++ library for (probabilistic) graphical models
triangulation.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 Abstract base class for computing triangulations of graphs
24  *
25  * @author Christophe GONZALES(@AMU) and Pierre-Henri WUILLEMIN(@LIP6)
26  */
27 #ifndef GUM_TRIANGULATION_H
28 #define GUM_TRIANGULATION_H
29 
30 #include <vector>
31 
32 #include <agrum/agrum.h>
33 #include <agrum/tools/core/sequence.h>
34 #include <agrum/tools/graphs/cliqueGraph.h>
35 #include <vector>
36 
37 namespace gum {
38 
39 
40  /** @class Triangulation
41  * @brief Interface for all the triangulation methods
42  *
43  * \ingroup graph_group
44  *
45  */
46  class Triangulation {
47  public:
48  // ############################################################################
49  /// @name Constructors / Destructors
50  // ############################################################################
51  /// @{
52 
53  /** @brief returns a fresh triangulation of the same type as the current
54  * object but with an empty graph
55  *
56  * note that we return a pointer as it enables subclasses to return
57  * pointers to their types, not Triangulation pointers. See item 25 of the
58  * more effective C++.*/
59  virtual Triangulation* newFactory() const = 0;
60 
61  /// virtual copy constructor
62  /** note that we return a pointer as it enables subclasses to return
63  * pointers to their types, not Triangulation pointers. See item 25 of the
64  * more effective C++.*/
65  virtual Triangulation* copyFactory() const = 0;
66 
67  /// destructor
68  virtual ~Triangulation();
69 
70  /// @}
71 
72 
73  // ############################################################################
74  /// @name Accessors / Modifiers
75  // ############################################################################
76  /// @{
77 
78  /// initialize the triangulation data structures for a new graph
79  /** @param graph the graph to be triangulated, i.e., the nodes of which
80  * will be eliminated
81  * @param domsizes the domain sizes of the nodes to be eliminated
82  * @warning Note that we allow domsizes to be defined over nodes/variables
83  * that do not belong to graph. These sizes will simply be ignored. However,
84  * it is compulsory that all the nodes of graph belong to dom_sizes
85  * @warning the graph is not copied but only referenced by the elimination
86  * sequence algorithm. */
87  virtual void setGraph(const UndiGraph* graph,
88  const NodeProperty< Size >* domsizes)
89  = 0;
90 
91  /// returns the fill-ins added by the triangulation algorithm
92  virtual const EdgeSet& fillIns() = 0;
93 
94  /// returns an elimination ordering compatible with the triangulated graph
95  virtual const std::vector< NodeId >& eliminationOrder() = 0;
96 
97  /** @brief returns the index of a given node in the elimination order
98  * (0 = first node eliminated) */
99  virtual Idx eliminationOrder(const NodeId) = 0;
100 
101  /// returns the triangulated graph
102  virtual const UndiGraph& triangulatedGraph() = 0;
103 
104  /// returns the elimination tree of a compatible ordering
105  virtual const CliqueGraph& eliminationTree() = 0;
106 
107  /// returns a compatible junction tree
108  virtual const CliqueGraph& junctionTree() = 0;
109 
110  /// returns the max of log10DomainSize of the cliques in the junction tree.
111  /** This is usefull for instance to estimate the complexity (both in space
112  * and in time) of the inference that will use the junction tree.
113  *
114  * This method is not 'const' since it can be called before building any
115  * junction tree and hence it needs to build it...
116  */
117  double maxLog10CliqueDomainSize();
118 
119  /** @brief returns the Id of the clique created by the
120  * elimination of a given node during the triangulation process */
121  virtual NodeId createdJunctionTreeClique(const NodeId id) = 0;
122 
123  /** @brief returns the Ids of the cliques of the junction tree created by
124  * the elimination of the nodes */
125  virtual const NodeProperty< NodeId >& createdJunctionTreeCliques() = 0;
126 
127  /// returns a junction tree of maximal prime subgraphs
128  /** @warning Actually, the cliques of the junction tree are guarranteed to
129  * be maximal prime subgraph of the original graph that was triangulated
130  * only if the triangulation performed is minimal (in the sense that
131  * removing any edge in the triangulated graph results in a nontriangulated
132  * graph). This can be ensured by requiring minimality of the
133  * triangulation. */
134  virtual const CliqueGraph& maxPrimeSubgraphTree() = 0;
135 
136  /** @brief returns the Id of the maximal prime subgraph created by the
137  * elimination of a given node during the triangulation process */
138  virtual NodeId createdMaxPrimeSubgraph(const NodeId id) = 0;
139 
140  /// reinitialize the graph to be triangulated to an empty graph
141  virtual void clear() = 0;
142 
143  /// returns the domain sizes of the variables of the graph to be
144  /// triangulated
145  const NodeProperty< Size >* domainSizes() const;
146 
147  /// @}
148 
149 
150  protected:
151  /// the domain sizes of the variables/nodes of the graph
152  const NodeProperty< Size >* domain_sizes_{nullptr};
153 
154 
155  /// default constructor
156  Triangulation();
157 
158  /// constructor with a domain size specified
159  /** @warning note that, by aGrUM's rule, domsizes is not copied but only
160  * referenced by the triangulation algorithm. */
161  Triangulation(const NodeProperty< Size >* domsizes);
162 
163  /// prevent copy constructor except when using newFactory
165 
166  /// prevent move constructor except when used by children
168 
169 
170  private:
171  /// prevent copy operator
173  };
174 
175 } /* namespace gum */
176 
177 
178 #ifndef GUM_NO_INLINE
179 # include <agrum/tools/graphs/algorithms/triangulations/triangulation_inl.h>
180 #endif // GUM_NO_INLINE
181 
182 
183 #endif /* GUM_TRIANGULATION_H */
virtual void clear()=0
reinitialize the graph to be triangulated to an empty graph
Triangulation(const NodeProperty< Size > *domsizes)
constructor with a domain size specified
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:669
const NodeProperty< Size > * domain_sizes_
the domain sizes of the variables/nodes of the graph
Triangulation(const Triangulation &)
prevent copy constructor except when using newFactory
double maxLog10CliqueDomainSize()
returns the max of log10DomainSize of the cliques in the junction tree.
virtual const CliqueGraph & eliminationTree()=0
returns the elimination tree of a compatible ordering
virtual Idx eliminationOrder(const NodeId)=0
returns the index of a given node in the elimination order (0 = first node eliminated) ...
virtual const NodeProperty< NodeId > & createdJunctionTreeCliques()=0
returns the Ids of the cliques of the junction tree created by the elimination of the nodes ...
Triangulation(Triangulation &&)
prevent move constructor except when used by children
virtual NodeId createdJunctionTreeClique(const NodeId id)=0
returns the Id of the clique created by the elimination of a given node during the triangulation proc...
virtual const EdgeSet & fillIns()=0
returns the fill-ins added by the triangulation algorithm
virtual NodeId createdMaxPrimeSubgraph(const NodeId id)=0
returns the Id of the maximal prime subgraph created by the elimination of a given node during the tr...
virtual const CliqueGraph & maxPrimeSubgraphTree()=0
returns a junction tree of maximal prime subgraphs
Triangulation()
default constructor
virtual ~Triangulation()
destructor
const NodeProperty< Size > * domainSizes() const
returns the domain sizes of the variables of the graph to be triangulated
Triangulation & operator=(const Triangulation &)
prevent copy operator
virtual Triangulation * newFactory() const =0
returns a fresh triangulation of the same type as the current object but with an empty graph ...
virtual const UndiGraph & triangulatedGraph()=0
returns the triangulated graph
virtual Triangulation * copyFactory() const =0
virtual copy constructor
Interface for all the triangulation methods.
Definition: triangulation.h:46
virtual const CliqueGraph & junctionTree()=0
returns a compatible junction tree
virtual const std::vector< NodeId > & eliminationOrder()=0
returns an elimination ordering compatible with the triangulated graph
virtual void setGraph(const UndiGraph *graph, const NodeProperty< Size > *domsizes)=0
initialize the triangulation data structures for a new graph