aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
cliqueGraph.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_CLIQUE_GRAPH_H
48#define GUM_CLIQUE_GRAPH_H
49
50#include <iostream>
51
52#include <agrum/agrum.h>
53
55
56namespace gum {
57 /* ===========================================================================
58 */
59 /* === GRAPHS OF CLIQUES ===
60 */
61 /* ===========================================================================
62 */
74 /* ===========================================================================
75 */
76
77 class CliqueGraph: public UndiGraph {
78 public:
79 // ############################################################################
81 // ############################################################################
83
85
89
91 bool nodes_resize_policy = true,
93 bool edges_resize_policy = true);
94
96
97
99
101
102 virtual ~CliqueGraph();
103
105
106 // ############################################################################
108 // ############################################################################
110
112
120 virtual void addEdge(NodeId first, NodeId second);
121
123
126
127 virtual void eraseEdge(const Edge& edge);
128
130
131 virtual void clearEdges();
132
134
136
137
139
140 virtual NodeId addNode();
141
143
145 virtual void addNodeWithId(const NodeId id, const NodeSet& clique);
146
148
150 virtual void addNodeWithId(const NodeId id);
151
153
155
156 virtual void eraseNode(const NodeId node);
157
160
161 virtual void clear();
162
164
166
167 const NodeSet& clique(const NodeId idClique) const;
168
177
178 NodeId container(const NodeId idNode) const;
179
184
185 virtual void setClique(const NodeId idClique, const NodeSet& new_clique);
186
193
194 virtual void addToClique(const NodeId clique_id, const NodeId node_id);
195
197
200
201 virtual void eraseFromClique(const NodeId clique_id, const NodeId node_id);
202
204
206
207 const NodeSet& separator(const Edge& edge) const;
208
210
212
213 const NodeSet& separator(const NodeId clique1, const NodeId clique) const;
214
217
218
219 std::vector< NodeId > containerPath(const NodeId node1, const NodeId node2) const;
220
222
223
225
227
228 bool isJoinTree() const;
229
231
232 virtual std::string toString() const;
233
235
236 virtual std::string toDot() const;
237
239
240 virtual std::string mapToDot(double scaleClique,
241 double scaleSep,
242 double lenEdge,
243 const std::string& colorClique = "burlywood",
244 const std::string& colorSep = "palegreen") const;
245
247
248 // ############################################################################
250 // ############################################################################
252
254
256
257
259
260 bool operator==(const CliqueGraph& from) const;
261
263
264 private:
267
270
272
273 void _updateSeparators_(const NodeId clique1);
274
276
315
317
319 const NodeId from,
320 _RunningIntersect_& infos_DFS) const;
321 };
322
327
331
333
334 std::ostream& operator<<(std::ostream&, const CliqueGraph&);
335
336} /* namespace gum */
337
338#ifndef GUM_NO_INLINE
340#endif // GU%_NO_INLINE
341
342#endif /* GUM_CLIQUE_GRAPH_H */
Basic graph of cliques.
Definition cliqueGraph.h:77
const NodeSet & separator(const Edge &edge) const
returns the separator included in a given edge
CliqueGraph(const CliqueGraph &from)
copy constructor
const NodeSet & separator(const NodeId clique1, const NodeId clique) const
returns the separator included in an edge specified by its extremities
virtual ~CliqueGraph()
destructor
bool hasRunningIntersection() const
indicates whether the running intersection property holds
void _updateSeparators_(const NodeId clique1)
function used to update the separators when a clique is modified
virtual std::string mapToDot(double scaleClique, double scaleSep, double lenEdge, const std::string &colorClique="burlywood", const std::string &colorSep="palegreen") const
friendly displays the content of the map of the CliqueGraph in DOT format
virtual void addEdge(NodeId first, NodeId second)
inserts a new edge between two cliques
virtual void eraseFromClique(const NodeId clique_id, const NodeId node_id)
remove a node from a clique
virtual void addNodeWithId(const NodeId id, const NodeSet &clique)
try to add a new clique to the graph
virtual void addNodeWithId(const NodeId id)
try to add a new clique to the graph
NodeId addNode(const NodeSet &clique)
adds a new clique to the graph
virtual void setClique(const NodeId idClique, const NodeSet &new_clique)
changes the set of nodes included into a given clique and returns the new set
virtual void clear()
removes all the cliques and separators from the graph (as well as their adjacent edges)
virtual NodeId addNode()
adds a new clique to the graph
virtual std::string toDot() const
friendly displays the content of the CliqueGraph in DOT format
virtual void addToClique(const NodeId clique_id, const NodeId node_id)
changes the set of nodes included into a given clique and returns the new set
virtual std::string toString() const
friendly displays the content of the CliqueGraph
virtual void eraseEdge(const Edge &edge)
removes an edge (and its separator) from the clique graph
bool _runningIntersectionDFS_(const NodeId clique, const NodeId from, _RunningIntersect_ &infos_DFS) const
function used for the computation of the running intersection property
virtual void eraseNode(const NodeId node)
removes a given clique from the clique graph
NodeId container(const NodeId idNode) const
returns the id of a clique containing the node the id of which is in argument
EdgeProperty< NodeSet > _separators_
the set of nodes contained into the separators
bool operator==(const CliqueGraph &from) const
checks whether two clique graphs are equal
CliqueGraph(Size nodes_size=HashTableConst::default_size, bool nodes_resize_policy=true, Size edges_size=HashTableConst::default_size, bool edges_resize_policy=true)
basic constructor: creates an empty clique graph
NodeProperty< NodeSet > _cliques_
the set of nodes contained into the cliques
const NodeSet & clique(const NodeId idClique) const
returns the set of nodes included into a given clique
virtual void clearEdges()
removes all edges and their separators
std::vector< NodeId > containerPath(const NodeId node1, const NodeId node2) const
returns a path from a clique containing node1 to a clique containing node2
CliqueGraph & operator=(const CliqueGraph &from)
copy operator
bool isJoinTree() const
indicates whether the graph is a join tree
The base class for all undirected edges.
UndiGraph(Size nodes_size=HashTableConst::default_size, bool nodes_resize_policy=true, Size edges_size=HashTableConst::default_size, bool edges_resize_policy=true)
default constructor
Definition undiGraph.cpp:72
inline source of basic clique graphs
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition types.h:74
Size NodeId
Type for node ids.
HashTable< Edge, VAL > EdgeProperty
Property on graph elements.
HashTable< NodeId, VAL > NodeProperty
Property on graph elements.
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
std::ostream & operator<<(std::ostream &stream, const AVLTree< Val, Cmp > &tree)
display the content of a tree
Definition AVLTree.h:913
CliqueGraph JoinTree
a join tree is a clique graph satisfying the running intersection property (but some cliques may be i...
CliqueGraph JunctionTree
a junction tree is a clique graph satisfying the running intersection property and such that no cliqu...
structure used for the computation of the running intersection property
NodeSet nodes_DFS_seen
set of the nodes examined during the current DFS
NodeSet nodes_other_components
structure indicating the nodes that belong to other connected components
NodeSet nodes_DFS_forbidden
the nodes that are currently forbidden by separators in the DFS
NodeSet visited_cliques
structure indicating for each clique whether it has been examined by a DFS (Depth First Search)
NodeProperty< NodeSet > cliques_DFS_chain
for each clique, the list of its nodes that require accessing the clique through a chain
static constexpr Size default_size
The default number of slots in hashtables.
Definition hashTable.h:101
Base classes for undirected graphs.