aGrUM 3.1.1
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-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#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
102
104
105 ~CliqueGraph() override;
106
108
109 // ############################################################################
111 // ############################################################################
113
115
123 void addEdge(NodeId first, NodeId second) override;
124
126
129
130 void eraseEdge(const Edge& edge) override;
131
133
134 void clearEdges() override;
135
137
139
140
142
143 NodeId addNode() override;
144
146
148 void addNodeWithId(const NodeId id, const NodeSet& clique);
149
151
153 void addNodeWithId(const NodeId id) override;
154
156
158
159 void eraseNode(const NodeId node) override;
160
163
164 void clear() override;
165
167
169
170 const NodeSet& clique(const NodeId idClique) const;
171
180
181 NodeId container(const NodeId idNode) const;
182
187
188 virtual void setClique(const NodeId idClique, const NodeSet& new_clique);
189
196
197 virtual void addToClique(const NodeId clique_id, const NodeId node_id);
198
200
203
204 virtual void eraseFromClique(const NodeId clique_id, const NodeId node_id);
205
207
209
210 const NodeSet& separator(const Edge& edge) const;
211
213
215
216 const NodeSet& separator(const NodeId clique1, const NodeId clique) const;
217
220
221
222 std::vector< NodeId > containerPath(const NodeId node1, const NodeId node2) const;
223
225
226
228
230
231 bool isJoinTree() const;
232
234
235 std::string toString() const override;
236
238
239 std::string toDot() const override;
240
242
243 virtual std::string mapToDot(double scaleClique,
244 double scaleSep,
245 double lenEdge,
246 std::string_view colorClique = "burlywood",
247 std::string_view colorSep = "palegreen") const;
248
250
251 // ############################################################################
253 // ############################################################################
255
257
259
261
263
264
266
267 bool operator==(const CliqueGraph& from) const;
268
270
271 private:
274
277
279
280 void _updateSeparators_(const NodeId clique1);
281
283
322
324
326 const NodeId from,
327 _RunningIntersect_& infos_DFS) const;
328 };
329
334
338
340
341 std::ostream& operator<<(std::ostream&, const CliqueGraph&);
342
343} /* namespace gum */
344
345#ifndef GUM_NO_INLINE
347#endif // GU%_NO_INLINE
348
349#endif /* GUM_CLIQUE_GRAPH_H */
Basic graph of cliques.
Definition cliqueGraph.h:77
std::string toString() const override
friendly displays the content of the CliqueGraph
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
void eraseNode(const NodeId node) override
removes a given clique from the clique graph
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, std::string_view colorClique="burlywood", std::string_view colorSep="palegreen") const
friendly displays the content of the map of the CliqueGraph in DOT format
void addNodeWithId(const NodeId id, const NodeSet &clique)
try to add a new clique to the graph
void addEdge(NodeId first, NodeId second) override
inserts a new edge between two cliques
virtual void eraseFromClique(const NodeId clique_id, const NodeId node_id)
remove a node from a clique
void clearEdges() override
removes all edges and their separators
NodeId addNode(const NodeSet &clique)
adds a new clique to the graph
std::string toDot() const override
friendly displays the content of the CliqueGraph in DOT format
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
void addNodeWithId(const NodeId id) override
try to add a new clique to the graph
CliqueGraph & operator=(CliqueGraph &&from)
move operator
void eraseEdge(const Edge &edge) override
removes an edge (and its separator) from the clique graph
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
CliqueGraph(CliqueGraph &&from)
move constructor
bool _runningIntersectionDFS_(const NodeId clique, const NodeId from, _RunningIntersect_ &infos_DFS) const
function used for the computation of the running intersection property
void clear() override
removes all the cliques and separators from the graph (as well as their adjacent edges)
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() override
destructor
NodeId addNode() override
adds a new clique to the graph
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
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:73
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
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:102
Base classes for undirected graphs.