aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
staticTriangulation.h
Go to the documentation of this file.
1/****************************************************************************
2 * This file is part of the aGrUM/pyAgrum library. *
3 * *
4 * Copyright (c) 2005-2025 by *
5 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
6 * - Christophe GONZALES(_at_AMU) *
7 * *
8 * The aGrUM/pyAgrum library is free software; you can redistribute it *
9 * and/or modify it under the terms of either : *
10 * *
11 * - the GNU Lesser General Public License as published by *
12 * the Free Software Foundation, either version 3 of the License, *
13 * or (at your option) any later version, *
14 * - the MIT license (MIT), *
15 * - or both in dual license, as here. *
16 * *
17 * (see https://agrum.gitlab.io/articles/dual-licenses-lgplv3mit.html) *
18 * *
19 * This aGrUM/pyAgrum library is distributed in the hope that it will be *
20 * useful, but WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
21 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES MERCHANTABILITY or FITNESS *
22 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
25 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
26 * OTHER DEALINGS IN THE SOFTWARE. *
27 * *
28 * See LICENCES for more details. *
29 * *
30 * SPDX-FileCopyrightText: Copyright 2005-2025 *
31 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
32 * - Christophe GONZALES(_at_AMU) *
33 * SPDX-License-Identifier: LGPL-3.0-or-later OR MIT *
34 * *
35 * Contact : info_at_agrum_dot_org *
36 * homepage : http://agrum.gitlab.io *
37 * gitlab : https://gitlab.com/agrumery/agrum *
38 * *
39 ****************************************************************************/
40
41
47#ifndef GUM_STATIC_TRIANGULATION_H
48#define GUM_STATIC_TRIANGULATION_H
49
50#include <vector>
51
52#include <agrum/agrum.h>
53
57
58namespace gum {
59
60
68 public:
69 // ############################################################################
71 // ############################################################################
73
80 virtual StaticTriangulation* newFactory() const = 0;
81
83
86 virtual StaticTriangulation* copyFactory() const = 0;
87
89 virtual ~StaticTriangulation();
90
92
93
94 // ############################################################################
96 // ############################################################################
98
100
108 virtual void setGraph(const UndiGraph* graph, const NodeProperty< Size >* domsizes);
109
111 const EdgeSet& fillIns();
112
114 const std::vector< NodeId >& eliminationOrder();
115
119
123
126
129
132
136
140
142
149
153
155 void clear();
156
159
161 virtual bool isMinimalityRequired() const final;
162
165 void setFillIns(bool);
166
168
170 const UndiGraph* originalGraph() const;
171
174
177
179
180
181 protected:
182 // ############################################################################
184 // ############################################################################
186
188
194 const JunctionTreeStrategy& JTStrategy,
195 bool minimality = false);
196
198
211 StaticTriangulation(const UndiGraph* graph,
212 const NodeProperty< Size >* dom_sizes,
213 const EliminationSequenceStrategy& elimSeq,
214 const JunctionTreeStrategy& JTStrategy,
215 bool minimality = false);
216
219
222
224
225
226 // ############################################################################
228 // ############################################################################
230
232
241 virtual void initTriangulation_(UndiGraph& graph);
242
244
245
248
251
252
253 private:
256
259
262
264 std::vector< NodeId > _elim_order_;
265
268
271
274
276
280
283
287
290
293
296
299
303
305 bool _has_fill_ins_{false};
306
309
312 std::vector< EdgeSet > _added_fill_ins_;
313
317
318 // ===========================================================================
319
321 void _triangulate_();
322
325
328
332
334 void _computeMaxPrimeMergings_(const NodeId node,
335 const NodeId from,
336 std::vector< Arc >& merged_cliques,
337 NodeSet& mark) const;
338
341 };
342
343} /* namespace gum */
344
345#ifndef GUM_NO_INLINE
347#endif // GUM_NO_INLINE
348
349#endif /* GUM_STATIC_TRIANGULATION_H */
Basic graph of cliques.
Definition cliqueGraph.h:77
The base class for all elimination sequence algorithms used by triangulation algorithms.
Base Class for all the algorithms producing a junction given a set of cliques/subcliques resulting fr...
bool _has_junction_tree_
a boolean indicating whether the junction tree has been constructed
NodeProperty< NodeId > _reverse_elim_order_
the elimination order (access by NodeId)
void setFillIns(bool)
sets/unsets the record of the fill-ins in the standard triangulation procedure
virtual StaticTriangulation * copyFactory() const =0
virtual copy constructor
const NodeProperty< NodeId > & reverseEliminationOrder()
returns a table indicating, for each node, at which step it was deleted by the triangulation process
JunctionTreeStrategy * junction_tree_strategy_
the junction tree strategy used by the triangulation
bool _has_fill_ins_
indicates whether we actually computed fill-ins
void _computeMaxPrimeMergings_(const NodeId node, const NodeId from, std::vector< Arc > &merged_cliques, NodeSet &mark) const
used for computing the junction tree of the maximal prime subgraphs
void _computeMaxPrimeJunctionTree_()
computes the junction tree of the maximal prime subgraphs
NodeId createdJunctionTreeClique(const NodeId id)
returns the Id of the clique of the junction tree created by the elimination of a given node during t...
const EdgeSet & fillIns()
returns the fill-ins added by the triangulation algorithm
const CliqueGraph & eliminationTree()
returns the elimination tree of a compatible ordering
void _computeEliminationTree_()
returns an elimination tree from a triangulated graph
JunctionTreeStrategy & junctionTreeStrategy() const
returns the junction tree strategy used by the triangulation
const std::vector< NodeId > & eliminationOrder()
returns an elimination ordering compatible with the triangulated graph
StaticTriangulation(const EliminationSequenceStrategy &elimSeq, const JunctionTreeStrategy &JTStrategy, bool minimality=false)
default constructor: without any graph
const UndiGraph * originalGraph() const
returns the graph to be triangulated
const CliqueGraph & junctionTree()
returns a compatible junction tree
StaticTriangulation & operator=(const StaticTriangulation &)
forbid copy operator
bool _has_triangulation_
a boolean indicating whether we have parformed a triangulation
virtual void initTriangulation_(UndiGraph &graph)
the function called to initialize the triangulation process
NodeProperty< NodeSet > _elim_cliques_
the cliques formed by the elimination of the nodes
bool _we_want_fill_ins_
a boolean indicating if we want fill-ins list with the standard triangulation method
EliminationSequenceStrategy * elimination_sequence_strategy_
the elimination sequence strategy used by the triangulation
NodeProperty< NodeId > _node_2_max_prime_clique_
indicates which clique of the max prime junction tree was created by the elmination of a given node (...
CliqueGraph _max_prime_junction_tree_
the maximal prime subgraph junction tree computed from the junction tree
void setMinimalRequirement(bool)
sets/unset the minimality requirement
const UndiGraph * _original_graph_
a pointer to the (external) original graph (which will be triangulated)
void clear()
reinitialize the graph to be triangulated to an empty graph
UndiGraph _triangulated_graph_
the triangulated graph
void _computeRecursiveThinning_()
removes redondant fill-ins and compute proper elimination cliques and order
std::vector< EdgeSet > _added_fill_ins_
a vector containing the set of fill-ins added after each node elimination (used by recursive thinning...
bool _has_elimination_tree_
a boolean indicating whether the elimination tree has been computed
NodeId createdMaxPrimeSubgraph(const NodeId id)
returns the Id of the maximal prime subgraph created by the elimination of a given node during the tr...
bool _minimality_required_
indicates whether the triangulation must be minimal
virtual StaticTriangulation * newFactory() const =0
returns a fresh triangulation of the same type as the current object but over an empty graph
const NodeProperty< NodeId > & createdJunctionTreeCliques()
returns the Ids of the cliques of the junction tree created by the elimination of the nodes
virtual bool isMinimalityRequired() const final
indicates wether minimality is required
virtual void setGraph(const UndiGraph *graph, const NodeProperty< Size > *domsizes)
initialize the triangulation data structures for a new graph
EliminationSequenceStrategy & eliminationSequenceStrategy() const
returns the elimination sequence strategy used by the triangulation
EdgeSet _fill_ins_
the fill-ins added during the whole triangulation process
virtual ~StaticTriangulation()
destructor
Idx eliminationOrder(const NodeId)
returns the index of a given node in the elimination order (0 = first node eliminated)
void _triangulate_()
the function that performs the triangulation
const UndiGraph & triangulatedGraph()
returns the triangulated graph
std::vector< NodeId > _elim_order_
the order in which nodes are eliminated by the algorithm
CliqueGraph _elim_tree_
the elimination tree computed by the algorithm
bool _has_max_prime_junction_tree_
indicates whether a maximal prime subgraph junction tree has been constructed
const CliqueGraph * _junction_tree_
the junction tree computed by the algorithm
bool _has_triangulated_graph_
a boolean indicating whether we have constructed the triangulated graph
const CliqueGraph & maxPrimeSubgraphTree()
returns a junction tree of maximal prime subgraphs
Triangulation()
default constructor
Base class for undirected graphs.
Definition undiGraph.h:128
Base Class for all elimination sequence algorithms used by triangulations.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition types.h:74
Size Idx
Type for indexes.
Definition types.h:79
Set< Edge > EdgeSet
Some typdefs and define for shortcuts ...
Size NodeId
Type for node ids.
HashTable< NodeId, VAL > NodeProperty
Property on graph elements.
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
Base Class for all the algorithms producing a junction given a set of cliques/subcliques resulting fr...
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
Inline implementations for computing default triangulations of graphs.
Abstract base class for computing triangulations of graphs.