aGrUM 3.1.1
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-2026 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-2026 *
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
57namespace gum {
58
63 public:
64 // ############################################################################
66 // ############################################################################
68
70
75 const UndiGraph* theGraph,
76 const NodeProperty< Size >* modal);
77
80
83
86
89
91
92
93 // ############################################################################
95 // ############################################################################
97
100
102 void addNode(const NodeId node, Size modal);
103
106 void eraseNode(const NodeId node);
107
110 void addEdge(const NodeId X, const NodeId Y);
111
114 void eraseEdge(const Edge& edge);
115
117 const EdgeSet& fillIns() override;
118
120 const std::vector< NodeId >& eliminationOrder() override;
121
124 Idx eliminationOrder(const NodeId) override;
125
127 const UndiGraph& triangulatedGraph() override;
128
130 const UndiGraph& graph() const;
131
133 const CliqueGraph& eliminationTree() override;
134
136 const CliqueGraph& junctionTree() override;
137
141
145
148
152
154 void clear() override;
155
157 void setGraph(const UndiGraph* theGraph, const NodeProperty< Size >* domain_sizes) override;
158
161
163
164
165 // ############################################################################
167 // ############################################################################
169
172
175
177 [[nodiscard]] IncrementalTriangulation* newFactory() const final;
178
180 [[nodiscard]] IncrementalTriangulation* copyFactory() const final;
181
184
186
187
188 private:
191
194
197
200
203
206
209
212
215
217 bool _require_update_{false};
218
221
223 std::vector< NodeId > _elimination_order_;
224
227
230
233
235 void _markAffectedMPSsByRemoveLink_(const NodeId My, const NodeId Mz, const Edge& edge);
236
239 const NodeId Mz,
240 const NodeId X,
241 const NodeId Y);
242
244 void _performRemoveNode_(const NodeId node, const NodeId My, const NodeId Mz);
245
247 void _performAddNode_(const NodeId node);
248
251 NodeId Mfrom,
252 UndiGraph& theGraph,
253 std::vector< Edge >& notAffectedneighborClique,
254 HashTable< NodeId, bool >& cliques_affected);
255
258 const NodeId from,
259 std::vector< std::pair< NodeId, NodeId > >& merged_cliques,
261 const NodeSet& new_nodes_in_junction_tree) const;
262
264 void _updateJunctionTree_(NodeProperty< bool >& all_cliques_affected,
265 NodeSet& new_nodes_in_junction_tree);
266
269 const NodeSet& new_nodes_in_junction_tree);
270
273 const NodeId from,
274 NodeProperty< bool >& examined,
275 Idx& index);
276
278 void _collectJTCliques_(const NodeId clique, const NodeId from, NodeProperty< bool >& examined);
279 };
280
281} /* namespace gum */
282
283#ifndef GUM_NO_INLINE
285#endif // GUM_NO_INLINE
286
287#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 constructor
IncrementalTriangulation & operator=(const IncrementalTriangulation &from)
copy operator
const NodeProperty< NodeId > & createdJunctionTreeCliques() override
returns the Ids of the cliques of the junction tree created by the elimination of the nodes
IncrementalTriangulation(const UnconstrainedTriangulation &triang_algo, const UndiGraph *theGraph, const NodeProperty< Size > *modal)
constructor
UndiGraph _graph_
the graph that needs be triangulated
const UndiGraph & triangulatedGraph() override
returns the triangulated graph
IncrementalTriangulation * copyFactory() const final
virtual copy constructor
const std::vector< NodeId > & eliminationOrder() override
returns an elimination ordering compatible with the triangulated graph
const CliqueGraph & junctionTree() override
returns a junction tree corresponding to the current graph
std::vector< NodeId > _elimination_order_
the current elimination ordering
~IncrementalTriangulation() override
destructor
CliqueGraph _junction_tree_
the junction tree computed so far
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
IncrementalTriangulation(IncrementalTriangulation &&from)
move constructor
NodeId createdMaxPrimeSubgraph(const NodeId id) override
returns the Id of the maximal prime subgraph created by the elimination of a given node during the tr...
NodeProperty< Idx > _reverse_elimination_order_
the elimination order (access by NodeId)
NodeId createdJunctionTreeClique(const NodeId id) override
returns the Id of the clique created by the elimination of a given node during the triangulation proc...
bool checkConsistency()
checks that the incremental triangulation is consistent
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() override
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
Idx eliminationOrder(const NodeId) override
returns the number of a given node in the elimination order (0 = first node eliminated)
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
const CliqueGraph & eliminationTree() override
returns the elimination tree of a compatible ordering
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
const UndiGraph & graph() const
returns the current graph (that which is incrementally triangulated)
void setGraph(const UndiGraph *theGraph, const NodeProperty< Size > *domain_sizes) override
changes 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
const EdgeSet & fillIns() override
returns the fill-ins added by the triangulation algorithm
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
IncrementalTriangulation & operator=(IncrementalTriangulation &&from)
move operator
IncrementalTriangulation(const UnconstrainedTriangulation &triangAlgo)
default constructor: initialize the triangulation with en empty graph
UnconstrainedTriangulation * _triangulation_
the triangulation algorithm that will be used incremantally
void clear() override
sets the graph to the empty graph
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
IncrementalTriangulation * newFactory() const final
virtual clone constructor
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
Generic doubly linked lists.
Definition list.h:378
Triangulation()
default constructor
Interface for all triangulation methods without constraints on node elimination orderings.
Base class for undirected graphs.
Definition undiGraph.h:130
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.