aGrUM 3.1.1
a C++ library for (probabilistic) graphical models
arcGraphPart.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
42#ifndef GUM_ARC_GRAPH_PART_H
43#define GUM_ARC_GRAPH_PART_H
44
45#include <algorithm>
46#include <utility>
47
48#include <agrum/agrum.h>
49
52
53namespace gum {
54
97
99 public:
101
102 Signaler< NodeId, NodeId > onArcAdded; // onArcAdded(tail,head)
103 Signaler< NodeId, NodeId > onArcDeleted; // onArcDeleted(tail,head)
104
105 // ############################################################################
107 // ############################################################################
109
111
114 bool arcs_resize_policy = true);
115
117
118 ArcGraphPart(const ArcGraphPart& s);
119
122
124 virtual ~ArcGraphPart();
125
127
128 // ############################################################################
130 // ############################################################################
132
134
136
139
141
142 bool operator==(const ArcGraphPart& p) const;
144
145 // ############################################################################
147 // ############################################################################
149
151
155 virtual void addArc(NodeId tail, NodeId head);
156
158
162 virtual void eraseArc(const Arc& arc);
163
165
167 bool existsArc(const Arc& arc) const;
168
170
174 bool existsArc(NodeId tail, NodeId head) const;
175
177 bool emptyArcs() const;
178
180 void clearArcs();
181
183 Size sizeArcs() const;
184
186 const ArcSet& arcs() const;
187
189
192 const NodeSet& parents(NodeId id) const;
193
196 NodeSet children(const NodeSet& ids) const;
197
199 NodeSet parents(const NodeSet& ids) const;
200
201
203
206 const NodeSet& children(NodeId id) const;
207
209
216 void eraseParents(NodeId id);
217
219
221
223
230 void eraseChildren(NodeId id);
231
233
235
237 std::string toString() const;
238
246 template < typename VAL >
247 ArcProperty< VAL > arcsProperty(VAL (*f)(const Arc&), Size size = 0) const;
248
256 template < typename VAL >
257 ArcProperty< VAL > arcsProperty(const VAL& a, Size size = 0) const;
258
262 template < typename VAL >
263 List< VAL > listMapArcs(VAL (*f)(const Arc&)) const;
264
266
267 protected:
269
271 void eraseSetOfArcs_(const ArcSet& set);
272
274
277 void unvirtualizedEraseSetOfArcs_(const ArcSet& set);
278
279 private:
282
285
288
292 void _checkParents_(NodeId id);
293
297 void _checkChildren_(NodeId id);
298 };
299
301
303 std::ostream& operator<<(std::ostream& s, const ArcGraphPart& a);
304
305} /* namespace gum */
306
307#ifndef GUM_NO_INLINE
309#endif // GU%_NO_INLINE
310
312
313#endif // GUM_ARC_GRAPH_PART_H
Inline implementation of classes for directed edge sets.
Implementation of the gumArcGraphPart.
Classes for directed edge sets.
ArcProperty< VAL > arcsProperty(VAL(*f)(const Arc &), Size size=0) const
a method to create a hashMap of VAL from a set of arcs (using for every arc, say x,...
bool emptyArcs() const
indicates wether the ArcGraphPart contains any arc
virtual void addArc(NodeId tail, NodeId head)
insert a new arc into the ArcGraphPart
bool existsArc(const Arc &arc) const
indicates whether a given arc exists
bool operator==(const ArcGraphPart &p) const
tests whether two ArcGraphParts contain the same arcs
Size sizeArcs() const
indicates the number of arcs stored within the ArcGraphPart
void _checkParents_(NodeId id)
when the ArcGraphPart contains no arc ingoing into a given node, this function adds an empty set entr...
virtual ~ArcGraphPart()
destructor
ArcSetIterator ArcIterator
const NodeSet & parents(NodeId id) const
returns the set of nodes with arc ingoing to a given node
Set< Arc > _arcs_
the set of all the arcs contained within the ArcGraphPart
ArcGraphPart & operator=(const ArcGraphPart &s)
copy operator
void _checkChildren_(NodeId id)
when the ArcGraphPart contains no arc outgoing from a given node, this function adds an empty set ent...
void eraseSetOfArcs_(const ArcSet &set)
a (virtualized) function to remove a given set of arcs
ArcProperty< VAL > arcsProperty(const VAL &a, Size size=0) const
a method to create a hashMap of VAL from a set of arcs (using for every arc, say x,...
void clearArcs()
removes all the arcs from the ArcGraphPart
void unvirtualizedEraseChildren(NodeId id)
same function as eraseChildren but without any virtual call to an erase
NodeProperty< NodeSet * > _children_
for each arc, the set of its children
List< VAL > listMapArcs(VAL(*f)(const Arc &)) const
a method to create a list of VAL from a set of arcs (using for every arc, say x, the VAL f(x))
void unvirtualizedEraseParents(NodeId id)
same function as eraseParents but without any virtual call to an erase
void eraseParents(NodeId id)
erase all the parents of a given node
void eraseChildren(NodeId id)
removes all the children of a given node
Signaler< NodeId, NodeId > onArcDeleted
void unvirtualizedEraseSetOfArcs_(const ArcSet &set)
similar to eraseSetOfArcs_ except that it is unvirtualized
Signaler< NodeId, NodeId > onArcAdded
NodeProperty< NodeSet * > _parents_
for each arc, the sets of its parents
NodeSet children(const NodeSet &ids) const
returns the set of nodes which consists in the node and its parents returns the set of children of a ...
virtual void eraseArc(const Arc &arc)
removes an arc from the ArcGraphPart
ArcGraphPart(Size arcs_size=HashTableConst::default_size, bool arcs_resize_policy=true)
default constructor
const ArcSet & arcs() const
returns the set of arcs stored within the ArcGraphPart
std::string toString() const
to friendly display the content of the ArcGraphPart
The base class for all directed edges.
Generic doubly linked lists.
Definition list.h:378
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
Size NodeId
Type for node ids.
HashTable< Arc, VAL > ArcProperty
Property on graph elements.
ArcSet::const_iterator ArcSetIterator
Some typdefs and define for shortcuts ...
Set< Arc > ArcSet
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
Convenience header for the signal/listener pattern.
static constexpr Size default_size
The default number of slots in hashtables.
Definition hashTable.h:102