aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
triangulation.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 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, const NodeProperty< Size >* domsizes) = 0;
88 
89  /// returns the fill-ins added by the triangulation algorithm
90  virtual const EdgeSet& fillIns() = 0;
91 
92  /// returns an elimination ordering compatible with the triangulated graph
93  virtual const std::vector< NodeId >& eliminationOrder() = 0;
94 
95  /** @brief returns the index of a given node in the elimination order
96  * (0 = first node eliminated) */
97  virtual Idx eliminationOrder(const NodeId) = 0;
98 
99  /// returns the triangulated graph
100  virtual const UndiGraph& triangulatedGraph() = 0;
101 
102  /// returns the elimination tree of a compatible ordering
103  virtual const CliqueGraph& eliminationTree() = 0;
104 
105  /// returns a compatible junction tree
106  virtual const CliqueGraph& junctionTree() = 0;
107 
108  /// returns the max of log10DomainSize of the cliques in the junction tree.
109  /** This is usefull for instance to estimate the complexity (both in space
110  * and in time) of the inference that will use the junction tree.
111  *
112  * This method is not 'const' since it can be called before building any
113  * junction tree and hence it needs to build it...
114  */
115  double maxLog10CliqueDomainSize();
116 
117  /** @brief returns the Id of the clique created by the
118  * elimination of a given node during the triangulation process */
119  virtual NodeId createdJunctionTreeClique(const NodeId id) = 0;
120 
121  /** @brief returns the Ids of the cliques of the junction tree created by
122  * the elimination of the nodes */
123  virtual const NodeProperty< NodeId >& createdJunctionTreeCliques() = 0;
124 
125  /// returns a junction tree of maximal prime subgraphs
126  /** @warning Actually, the cliques of the junction tree are guarranteed to
127  * be maximal prime subgraph of the original graph that was triangulated
128  * only if the triangulation performed is minimal (in the sense that
129  * removing any edge in the triangulated graph results in a nontriangulated
130  * graph). This can be ensured by requiring minimality of the
131  * triangulation. */
132  virtual const CliqueGraph& maxPrimeSubgraphTree() = 0;
133 
134  /** @brief returns the Id of the maximal prime subgraph created by the
135  * elimination of a given node during the triangulation process */
136  virtual NodeId createdMaxPrimeSubgraph(const NodeId id) = 0;
137 
138  /// reinitialize the graph to be triangulated to an empty graph
139  virtual void clear() = 0;
140 
141  /// returns the domain sizes of the variables of the graph to be
142  /// triangulated
143  const NodeProperty< Size >* domainSizes() const;
144 
145  /// @}
146 
147 
148  protected:
149  /// the domain sizes of the variables/nodes of the graph
150  const NodeProperty< Size >* domain_sizes_{nullptr};
151 
152 
153  /// default constructor
154  Triangulation();
155 
156  /// constructor with a domain size specified
157  /** @warning note that, by aGrUM's rule, domsizes is not copied but only
158  * referenced by the triangulation algorithm. */
159  Triangulation(const NodeProperty< Size >* domsizes);
160 
161  /// prevent copy constructor except when using newFactory
163 
164  /// prevent move constructor except when used by children
166 
167 
168  private:
169  /// prevent copy operator
171  };
172 
173 } /* namespace gum */
174 
175 
176 #ifndef GUM_NO_INLINE
177 # include <agrum/tools/graphs/algorithms/triangulations/triangulation_inl.h>
178 #endif // GUM_NO_INLINE
179 
180 
181 #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:643
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