aGrUM 2.3.2
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-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_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 Signaler2< NodeId, NodeId > onArcAdded; // onArcAdded(tail,head)
103 Signaler2< 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
121 virtual ~ArcGraphPart();
122
124
125 // ############################################################################
127 // ############################################################################
129
131
133
135
136 bool operator==(const ArcGraphPart& p) const;
138
139 // ############################################################################
141 // ############################################################################
143
145
149 virtual void addArc(NodeId tail, NodeId head);
150
152
156 virtual void eraseArc(const Arc& arc);
157
159
161 bool existsArc(const Arc& arc) const;
162
164
168 bool existsArc(NodeId tail, NodeId head) const;
169
171 bool emptyArcs() const;
172
174 void clearArcs();
175
177 Size sizeArcs() const;
178
180 const ArcSet& arcs() const;
181
183
186 const NodeSet& parents(NodeId id) const;
187
189
194 NodeSet family(NodeId id) const;
195
197
202 NodeSet descendants(NodeId id) const;
203
204
206
211 NodeSet ancestors(NodeId id) const;
212
214 NodeSet children(const NodeSet& ids) const;
215
217 NodeSet parents(const NodeSet& ids) const;
218
220 NodeSet family(const NodeSet& ids) const;
221
222
224
227 const NodeSet& children(NodeId id) const;
228
230
237 void eraseParents(NodeId id);
238
240
242
244
251 void eraseChildren(NodeId id);
252
254
256
258 std::string toString() const;
259
267 template < typename VAL >
268 ArcProperty< VAL > arcsProperty(VAL (*f)(const Arc&), Size size = 0) const;
269
277 template < typename VAL >
278 ArcProperty< VAL > arcsProperty(const VAL& a, Size size = 0) const;
279
283 template < typename VAL >
284 List< VAL > listMapArcs(VAL (*f)(const Arc&)) const;
285
287
291 std::vector< NodeId > directedPath(NodeId node1, NodeId node2) const;
292
294
298 std::vector< NodeId > directedUnorientedPath(NodeId node1, NodeId node2) const;
299
301
302 protected:
304
306 void eraseSetOfArcs_(const ArcSet& set);
307
309
312 void unvirtualizedEraseSetOfArcs_(const ArcSet& set);
313
314 private:
317
320
323
327 void _checkParents_(NodeId id);
328
332 void _checkChildren_(NodeId id);
333 };
334
336
338 std::ostream& operator<<(std::ostream& s, const ArcGraphPart& a);
339
340} /* namespace gum */
341
342#ifndef GUM_NO_INLINE
344#endif // GU%_NO_INLINE
345
347
348#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
NodeSet family(NodeId id) const
returns the set of nodes which consists in the node and its parents
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
Signaler2< NodeId, NodeId > onArcAdded
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
std::vector< NodeId > directedUnorientedPath(NodeId node1, NodeId node2) const
returns an unoriented (directed) path from node1 to node2 in the arc set
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
NodeSet descendants(NodeId id) const
returns the set of nodes with directed path outgoing from a given node
void eraseParents(NodeId id)
erase all the parents of a given node
void eraseChildren(NodeId id)
removes all the children of a given node
void unvirtualizedEraseSetOfArcs_(const ArcSet &set)
similar to eraseSetOfArcs_ except that it is unvirtualized
NodeProperty< NodeSet * > _parents_
for each arc, the sets of its parents
NodeSet children(const NodeSet &ids) const
returns the set of children of a set of nodes
NodeSet ancestors(NodeId id) const
returns the set of nodes with directed path ingoing to a given node
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
std::vector< NodeId > directedPath(NodeId node1, NodeId node2) const
returns a directed path from node1 to node2 belonging to the set of arcs
const ArcSet & arcs() const
returns the set of arcs stored within the ArcGraphPart
Signaler2< NodeId, NodeId > onArcDeleted
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:379
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
Definition AVLTree.h:913
Declare all signalers.
static constexpr Size default_size
The default number of slots in hashtables.
Definition hashTable.h:101