aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
undiGraph.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_UNDIGRAPH_H
48#define GUM_UNDIGRAPH_H
49
50#include <iostream>
51#include <utility>
52
53#include <agrum/agrum.h>
54
57
58namespace gum {
59
60 /* ===========================================================================
61 */
62 /* === BASE CLASS FOR MANIPULATING ALL UNDIRECTED GRAPHS ===
63 */
64 /* ===========================================================================
65 */
125 /* ===========================================================================
126 */
127
128 class UndiGraph: public virtual NodeGraphPart, public EdgeGraphPart {
129 public:
130 // ############################################################################
132 // ############################################################################
134
136
140 explicit UndiGraph(Size nodes_size = HashTableConst::default_size,
141 bool nodes_resize_policy = true,
143 bool edges_resize_policy = true);
144
146
147 UndiGraph(const UndiGraph& g);
148
150 virtual ~UndiGraph();
151
157 static UndiGraph completeGraph(int n);
158
160
161 // ############################################################################
163 // ############################################################################
165
167
168 UndiGraph& operator=(const UndiGraph& g);
169
171
172 // not virtual : it is a feature !!! :)
173 bool operator==(const UndiGraph& g) const;
174
176
177 // not virtual : it is a feature !!! :)
178 bool operator!=(const UndiGraph& g) const;
179
181
182 // ############################################################################
184 // ############################################################################
186
188
195 void addEdge(NodeId first, NodeId second) override;
196
198
201 void eraseNode(NodeId id) override;
202
204 void clear() override;
205
207 std::string toString() const override;
208
210 virtual std::string toDot() const;
211
213 bool hasUndirectedCycle() const;
214
217
220
222 };
223
225 std::ostream& operator<<(std::ostream&, const UndiGraph&);
226
227} /* namespace gum */
228
229#ifndef GUM_NO_INLINE
231#endif // GU%_NO_INLINE
232
233#endif /* GUM_UNDIGRAPH_H */
EdgeGraphPart(Size edges_size=HashTableConst::default_size, bool edges_resize_policy=true)
default constructor
const NodeGraphPart & nodes() const
return *this as a NodeGraphPart
NodeGraphPart(Size holes_size=HashTableConst::default_size, bool holes_resize_policy=true)
default constructor
Base class for undirected graphs.
Definition undiGraph.h:128
bool operator==(const UndiGraph &g) const
tests whether two UndiGraphs are identical (same nodes, same edges)
UndiGraph & operator=(const UndiGraph &g)
copy operator
void clear() override
removes all the nodes and edges from the graph
virtual std::string toDot() const
to friendly display graph in DOT format
bool hasUndirectedCycle() const
checks whether the graph contains cycles
Definition undiGraph.cpp:90
static UndiGraph completeGraph(int n)
create a complete UndiGraph with n nodes
Definition undiGraph.cpp:60
void addEdge(NodeId first, NodeId second) override
insert a new edge into the undirected graph
virtual ~UndiGraph()
destructor
Definition undiGraph.cpp:85
NodeProperty< NodeId > nodes2ConnectedComponent() const
returns a property {node:id of connected component}
bool operator!=(const UndiGraph &g) const
tests whether two UndiGraphs are different
std::string toString() const override
to friendly display the content of the graph
virtual UndiGraph partialUndiGraph(NodeSet nodes)
returns the partial graph formed by the nodes given in parameter
void eraseNode(NodeId id) override
remove a node and its adjacent edges from the graph
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
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition types.h:74
Size NodeId
Type for node ids.
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
Base node set class for graphs.
static constexpr Size default_size
The default number of slots in hashtables.
Definition hashTable.h:101
Inline implementation of Base classes for undirected graphs.