aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
edgeGraphPart.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
42#ifndef GUM_EDGE_GRAPH_PART_H
43#define GUM_EDGE_GRAPH_PART_H
44
45
46#include <algorithm>
47#include <utility>
48
49#include <agrum/agrum.h>
50
53
54namespace gum {
55
93
95 public:
97
98 Signaler2< NodeId, NodeId > onEdgeAdded;
99 Signaler2< NodeId, NodeId > onEdgeDeleted;
100
101 // ############################################################################
103 // ############################################################################
105
107
109 explicit EdgeGraphPart(Size edges_size = HashTableConst::default_size,
110 bool edges_resize_policy = true);
111
113
115
117 virtual ~EdgeGraphPart();
118
120
121 // ############################################################################
123 // ############################################################################
125
127
129
131
132 bool operator==(const EdgeGraphPart& p) const;
134
135 // ############################################################################
137 // ############################################################################
139
141
145 virtual void addEdge(NodeId n1, NodeId n2);
146
148
152 virtual void eraseEdge(const Edge& edge);
153
155
157 bool existsEdge(const Edge& edge) const;
158
160
164 bool existsEdge(NodeId n1, NodeId n2) const;
165
167 bool emptyEdges() const;
168
170 virtual void clearEdges();
171
173 Size sizeEdges() const;
174
176 const EdgeSet& edges() const;
177
179
182 const NodeSet& neighbours(NodeId id) const;
183
185
190 void eraseNeighbours(NodeId id);
191
194
196
198 virtual std::string toString() const;
199
208 template < typename VAL >
209 EdgeProperty< VAL > edgesProperty(VAL (*f)(const Edge&), Size size = 0) const;
210
219 template < typename VAL >
220 EdgeProperty< VAL > edgesProperty(const VAL& val, Size size = 0) const;
221
225 template < typename VAL >
226 List< VAL > listMapEdges(VAL (*f)(const Edge&)) const;
227
229
233 std::vector< NodeId > undirectedPath(NodeId node1, NodeId node2) const;
240 bool hasUndirectedPath(NodeId n1, NodeId n2) const;
241
252 bool hasUndirectedPath(NodeId n1, NodeId n2, const NodeSet& except) const;
261 bool hasUndirectedPath(const NodeSet& n1, const NodeSet& n2, const NodeSet& except) const;
263
264 private:
267
270
274 void _checkNeighbours_(NodeId id);
275
276 void _clearEdges_();
277 };
278
280 std::ostream& operator<<(std::ostream&, const EdgeGraphPart&);
281
282} /* namespace gum */
283
284#ifndef GUM_NO_INLINE
286#endif // GUM_NO_INLINE
287
289
290#endif // GUM_EDGE_GRAPH_PART_H
Classes for undirected edge sets.
EdgeProperty< VAL > edgesProperty(VAL(*f)(const Edge &), Size size=0) const
a method to create a hashMap of VAL from a set of edges (using for every edge, say x,...
std::vector< NodeId > undirectedPath(NodeId node1, NodeId node2) const
returns a possible path from node1 to node2 in the edge set
void unvirtualizedEraseNeighbours(NodeId id)
same function as eraseNeighbours but without any virtual call to an erase
Size sizeEdges() const
indicates the number of edges stored within the EdgeGraphPart
EdgeGraphPart & operator=(const EdgeGraphPart &s)
copy operator
bool hasUndirectedPath(NodeId n1, NodeId n2) const
return true if n1 and n2 are connected (by an undirected path) in the graph.
virtual ~EdgeGraphPart()
destructor
void _checkNeighbours_(NodeId id)
when the EdgeGraphPart contains no edge adjacent to a given node, this function adds an empty set ent...
bool operator==(const EdgeGraphPart &p) const
tests whether two EdgeGraphParts contain the same edges
EdgeGraphPart(Size edges_size=HashTableConst::default_size, bool edges_resize_policy=true)
default constructor
virtual void addEdge(NodeId n1, NodeId n2)
insert a new edge into the EdgeGraphPart
EdgeSet _edges_
the set of all the edges contained within the EdgeGraphPart
EdgeSetIterator EdgeIterator
virtual void eraseEdge(const Edge &edge)
removes an edge from the EdgeGraphPart
void eraseNeighbours(NodeId id)
erase all the edges adjacent to a given node
Signaler2< NodeId, NodeId > onEdgeDeleted
NodeProperty< NodeSet * > _neighbours_
for each node, the set of its adjacent edges
Signaler2< NodeId, NodeId > onEdgeAdded
const EdgeSet & edges() const
returns the set of edges stored within the EdgeGraphPart
virtual std::string toString() const
to friendly display the content of the EdgeGraphPart
virtual void clearEdges()
removes all the edges from the EdgeGraphPart
bool existsEdge(const Edge &edge) const
indicates whether a given edge exists
bool emptyEdges() const
indicates wether the EdgeGraphPart contains any edge
List< VAL > listMapEdges(VAL(*f)(const Edge &)) const
a method to create a list of VAL from a set of edges (using for every edge, say x,...
const NodeSet & neighbours(NodeId id) const
returns the set of node neighbours to a given node
EdgeProperty< VAL > edgesProperty(const VAL &val, Size size=0) const
a method to create a hashMap of VAL from a set of edges (using for every edge, say x,...
The base class for all undirected edges.
Generic doubly linked lists.
Definition list.h:379
Inline implementation of classes for undirected edge sets.
Implementation of the EdgeGraphPart.
some utils for topology : NodeId, Edge, Arc and consorts ...
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition types.h:74
Set< Edge > EdgeSet
Some typdefs and define for shortcuts ...
Size NodeId
Type for node ids.
HashTable< Edge, VAL > EdgeProperty
Property on graph elements.
EdgeSet::const_iterator EdgeSetIterator
Some typdefs and define for shortcuts ...
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
Declare all signalers.
static constexpr Size default_size
The default number of slots in hashtables.
Definition hashTable.h:101