aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
incrementalTriangulation.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
48#ifndef GUM_INCREMENTAL_TRIANGULATION_H
49#define GUM_INCREMENTAL_TRIANGULATION_H
50
51#include <iostream>
52#include <sstream>
53#include <vector>
54
56
57#ifndef DOXYGEN_SHOULD_SKIP_THIS
58namespace gum_tests {
59 class IncrementalTriangulationTestSuite;
60}
61#endif
62
63namespace gum {
64
69 public:
70 // ############################################################################
72 // ############################################################################
74
76
81 const UndiGraph* theGraph,
82 const NodeProperty< Size >* modal);
83
86
89
92
94
95
96 // ############################################################################
98 // ############################################################################
100
103
105 void addNode(const NodeId node, Size modal);
106
109 void eraseNode(const NodeId node);
110
113 void addEdge(const NodeId X, const NodeId Y);
114
117 void eraseEdge(const Edge& edge);
118
120 const EdgeSet& fillIns() { GUM_ERROR(OperationNotAllowed, "Not implemented yet") }
121
123 const std::vector< NodeId >& eliminationOrder();
124
128
130 const UndiGraph& triangulatedGraph() { GUM_ERROR(OperationNotAllowed, "Not implemented yet") }
131
133 const UndiGraph& graph() const;
134
136 const CliqueGraph& eliminationTree() { GUM_ERROR(OperationNotAllowed, "Not implemented yet") }
137
140
144
148
151
155
157 void clear();
158
160 void setGraph(const UndiGraph* theGraph, const NodeProperty< Size >* domain_sizes);
161
164
166
167
168 // ############################################################################
170 // ############################################################################
172
175
177 virtual IncrementalTriangulation* newFactory() const final;
178
180 virtual IncrementalTriangulation* copyFactory() const final;
181
183
184
185 private:
188
191
194
197
200
203
206
209
212
214 bool _require_update_{false};
215
218
220 std::vector< NodeId > _elimination_order_;
221
224
227
230
232 void _markAffectedMPSsByRemoveLink_(const NodeId My, const NodeId Mz, const Edge& edge);
233
236 const NodeId Mz,
237 const NodeId X,
238 const NodeId Y);
239
241 void _performRemoveNode_(const NodeId node, const NodeId My, const NodeId Mz);
242
244 void _performAddNode_(const NodeId node);
245
248 NodeId Mfrom,
249 UndiGraph& theGraph,
250 std::vector< Edge >& notAffectedneighborClique,
251 HashTable< NodeId, bool >& cliques_affected);
252
255 const NodeId from,
256 std::vector< std::pair< NodeId, NodeId > >& merged_cliques,
258 const NodeSet& new_nodes_in_junction_tree) const;
259
261 void _updateJunctionTree_(NodeProperty< bool >& all_cliques_affected,
262 NodeSet& new_nodes_in_junction_tree);
263
266 const NodeSet& new_nodes_in_junction_tree);
267
270 const NodeId from,
271 NodeProperty< bool >& examined,
272 Idx& index);
273
275 void _collectJTCliques_(const NodeId clique, const NodeId from, NodeProperty< bool >& examined);
276
278 bool _check_();
279
282 };
283
284} /* namespace gum */
285
286#ifndef GUM_NO_INLINE
288#endif // GUM_NO_INLINE
289
290#endif /* GUM_INCREMENTAL_TRIANGULATION_H */
Basic graph of cliques.
Definition cliqueGraph.h:77
The base class for all undirected edges.
bool _require_elimination_order_
a Boolean indicating wether we should update the elimination order
void _collectJTCliques_(const NodeId clique, const NodeId from, NodeProperty< bool > &examined)
a collect algorithm to compute, for each node, one container JT's clique
IncrementalTriangulation(const IncrementalTriangulation &from)
copy operator
friend class gum_tests::IncrementalTriangulationTestSuite
to enable testunits to use check
void setGraph(const UndiGraph *theGraph, const NodeProperty< Size > *domain_sizes)
changes the current graph
IncrementalTriangulation & operator=(const IncrementalTriangulation &from)
copy operator
IncrementalTriangulation(const UnconstrainedTriangulation &triang_algo, const UndiGraph *theGraph, const NodeProperty< Size > *modal)
constructor
UndiGraph _graph_
the graph that needs be triangulated
void clear()
sets the graph to the empty graph
const std::vector< NodeId > & eliminationOrder()
returns an elimination ordering compatible with the triangulated graph
std::vector< NodeId > _elimination_order_
the current elimination ordering
CliqueGraph _junction_tree_
the junction tree computed so far
Idx eliminationOrder(const NodeId)
returns the number of a given node in the elimination order (0 = first node eliminated)
void _updateJunctionTree_(NodeProperty< bool > &all_cliques_affected, NodeSet &new_nodes_in_junction_tree)
update the junction tree
void _setUpConnectedTriangulation_(NodeId Mx, NodeId Mfrom, UndiGraph &theGraph, std::vector< Edge > &notAffectedneighborClique, HashTable< NodeId, bool > &cliques_affected)
set-up the connected subgraph that needs be retriangulated
NodeProperty< Idx > _reverse_elimination_order_
the elimination order (access by NodeId)
const UndiGraph & triangulatedGraph()
returns the triangulated graph
bool _require_created_JT_cliques_
a Boolean indicating whether we should compute the createdJTCliques
void eraseNode(const NodeId node)
removes a node from the graph (the join tree may need a triangulation update)
const CliqueGraph & maxPrimeSubgraphTree()
returns the junction tree of the maximal prime subgraphs
NodeProperty< NodeId > _mps_of_clique_
indicate for each clique the MPS it belongs to
void _performAddNode_(const NodeId node)
adds a new node to T_mpd, the graph and the clique graph
NodeProperty< List< NodeId > > _mps_of_node_
for each node in graph, store the MPS containing the node
void _markAffectedMPSsByRemoveLink_(const NodeId My, const NodeId Mz, const Edge &edge)
mark the mps affected by the deletion of a given edge
virtual IncrementalTriangulation * copyFactory() const final
virtual copy constructor
NodeProperty< bool > _mps_affected_
the set of MPS affected by a new triangulation
NodeProperty< std::vector< NodeId > > _cliques_of_mps_
indicate for each MPS its set of cliques in the junction tree
virtual IncrementalTriangulation * newFactory() const final
virtual clone constructor
void _performRemoveNode_(const NodeId node, const NodeId My, const NodeId Mz)
remove a given node from the T_mpd structure
NodeProperty< NodeId > _created_JT_cliques_
For each node, a clique that contains it.
CliqueGraph _T_mpd_
the maximal prime subgraph tree
NodeId createdJunctionTreeClique(const NodeId id)
returns the Id of the clique created by the elimination of a given node during the triangulation proc...
const UndiGraph & graph() const
returns the current graph (that which is incrementally triangulated)
const CliqueGraph & junctionTree()
returns a junction tree corresponding to the current graph
void _computeMaxPrimeMergings_(const NodeId node, const NodeId from, std::vector< std::pair< NodeId, NodeId > > &merged_cliques, NodeProperty< bool > &mark, const NodeSet &new_nodes_in_junction_tree) const
used for computing the junction tree of the maximal prime subgraphs
bool _check_()
checks that the incremental triangulation works properly
void eraseEdge(const Edge &edge)
removes an edge from the graph (the join tree may need a retriangulation)
bool _require_update_
a Boolean indicating whether the triangulation need be updated
const NodeProperty< NodeId > & createdJunctionTreeCliques()
returns the Ids of the cliques of the junction tree created by the elimination of the nodes
IncrementalTriangulation(const UnconstrainedTriangulation &triangAlgo)
default constructor: initialize the triangulation with en empty graph
NodeId createdMaxPrimeSubgraph(const NodeId id)
returns the Id of the maximal prime subgraph created by the elimination of a given node during the tr...
UnconstrainedTriangulation * _triangulation_
the triangulation algorithm that will be used incremantally
void updateTriangulation()
updates the triangulated graph using the modif list
NodeProperty< Size > _domain_sizes_
the domain sizes of the nodes
void addNode(const NodeId node, Size modal)
adds a new node to the graph
const UnconstrainedTriangulation & triangulationAlgo() const
returns the triangulation algorithm (useful for fine tuning it)
int _markAffectedMPSsByAddLink_(const NodeId My, const NodeId Mz, const NodeId X, const NodeId Y)
mark the mps affected by the insertion of a new edge
const CliqueGraph & eliminationTree()
returns the elimination tree of a compatible ordering
void _updateMaxPrimeSubgraph_(NodeProperty< bool > &cliques_affected, const NodeSet &new_nodes_in_junction_tree)
update the max prime subgraph
void addEdge(const NodeId X, const NodeId Y)
adds a new edge to the graph (the join tree may need a triangulation update)
void _collectEliminationOrder_(const NodeId node, const NodeId from, NodeProperty< bool > &examined, Idx &index)
a collect algorithm to compute elimination orderings
const EdgeSet & fillIns()
returns the fill-ins added by the triangulation algorithm
Generic doubly linked lists.
Definition list.h:379
Exception : operation not allowed.
Triangulation()
default constructor
Interface for all triangulation methods without constraints on node elimination orderings.
Base class for undirected graphs.
Definition undiGraph.h:128
#define GUM_ERROR(type, msg)
Definition exceptions.h:72
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 ...
Inline implementations for computing default triangulations of graphs.
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
STL namespace.
base class for graph triangulations without constraints on nodes elimination ordering.