aGrUM 3.1.1
a C++ library for (probabilistic) graphical models
diGraph_inl.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#pragma once
42
43
50
51// to ease parser in IDEs
56
57namespace gum {
58
59 INLINE void DiGraph::addArc(const NodeId tail, const NodeId head) {
60 if (!exists(head)) { GUM_ERROR(InvalidNode, "no head node : " << head) }
61
62 if (!exists(tail)) { GUM_ERROR(InvalidNode, "no tail node : " << tail) }
63
64 ArcGraphPart::addArc(tail, head);
65 }
66
71
73 // avoid self assigment
74 if (this != &g) {
78 GUM_OP_CPY(DiGraph);
79 }
80
81 return *this;
82 }
83
85 if (this != &g) {
86 NodeGraphPart::operator=(std::move(g));
87 ArcGraphPart::operator=(std::move(g));
88 GUM_OP_MOV(DiGraph);
89 }
90 return *this;
91 }
92
93 INLINE void DiGraph::eraseNode(const NodeId id) {
94 // warning: to remove the arcs adjacent to id, use the unvirtualized
95 // versions
96 // of arc removals
99
101 }
102
103 INLINE bool DiGraph::operator==(const DiGraph& p) const {
105 }
106
107 // INLINE bool DiGraph::operator!=(const DiGraph& p) const { return !operator==(p); }
108
109 INLINE std::optional< std::vector< NodeId > > DiGraph::directedPath(NodeId node1,
110 NodeId node2) const {
111 return graph::directedPath(*this, node1, node2);
112 }
113
114 INLINE std::optional< std::vector< NodeId > >
116 return graph::directedUnorientedPath(*this, node1, node2);
117 }
118
119 INLINE NodeSet DiGraph::ancestors(NodeId id) const { return graph::ancestors(*this, id); }
120
121 INLINE NodeSet DiGraph::descendants(NodeId id) const { return graph::descendants(*this, id); }
122
123 INLINE NodeSet DiGraph::family(NodeId id) const { return graph::family(*this, id); }
124
125 INLINE NodeSet DiGraph::family(const NodeSet& ids) const { return graph::family(*this, ids); }
126
130
134
135} /* namespace gum */
virtual void addArc(NodeId tail, NodeId head)
insert a new arc into the ArcGraphPart
bool operator==(const ArcGraphPart &p) const
tests whether two ArcGraphParts contain the same arcs
ArcGraphPart & operator=(const ArcGraphPart &s)
copy operator
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
void unvirtualizedEraseParents(NodeId id)
same function as eraseParents but without any virtual call to an erase
NodeSet ancestors(NodeId id) const
returns the set of all ancestors of id (nodes from which id is reachable)
NodeSet family(NodeId id) const
returns { id } ∪ parents(id)
std::optional< std::vector< NodeId > > directedPath(NodeId node1, NodeId node2) const
returns a directed path from node1 to node2, or std::nullopt if none
DiGraph & operator=(const DiGraph &g)
copy operator
Definition diGraph_inl.h:72
void clear() override
removes all the nodes and arcs from the graph
Definition diGraph_inl.h:67
void addArc(const NodeId tail, const NodeId head) override
insert a new arc into the directed graph
Definition diGraph_inl.h:59
NodeProperty< NodeId > connectedComponents() const
returns a property {node:id of weakly connected component}
DiGraph(Size nodes_size=HashTableConst::default_size, bool nodes_resize_policy=true, Size arcs_size=HashTableConst::default_size, bool arcs_resize_policy=true)
default constructor
Definition diGraph.cpp:70
void eraseNode(const NodeId id) override
remove a node and its adjacent arcs from the graph
Definition diGraph_inl.h:93
Sequence< NodeId > topologicalOrder() const
Build and return a topological order.
bool operator==(const DiGraph &g) const
tests whether two DiGraphs are identical (same nodes, same arcs)
NodeSet descendants(NodeId id) const
returns the set of all descendants of id (nodes reachable from id)
std::optional< std::vector< NodeId > > directedUnorientedPath(NodeId node1, NodeId node2) const
returns a shortest path from node1 to node2 ignoring arc orientation, or std::nullopt if none
Exception : node does not exist.
virtual void eraseNode(const NodeId id)
erase the node with the given id
NodeGraphPart & operator=(const NodeGraphPart &p)
copy operator
bool exists(const NodeId id) const
alias for existsNode
virtual void clearNodes()
remove all the nodes from the NodeGraphPart
bool operator==(const NodeGraphPart &p) const
check whether two NodeGraphParts contain the same nodes
Generic cycle-detection algorithms for aGrUM graphs.
Base classes for oriented graphs.
#define GUM_ERROR(type, msg)
Definition exceptions.h:76
Size NodeId
Type for node ids.
HashTable< NodeId, VAL > NodeProperty
Property on graph elements.
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
NodeSet descendants(const G &g, NodeId id)
Returns the set of all descendants of id (nodes reachable from id following arc direction).
NodeSet ancestors(const G &g, NodeId id)
Returns the set of all ancestors of id (nodes from which id is reachable following arc direction).
std::optional< std::vector< NodeId > > directedUnorientedPath(const G &g, NodeId n1, NodeId n2)
Shortest path from n1 to n2 ignoring arc orientation (BFS).
std::optional< std::vector< NodeId > > directedPath(const G &g, NodeId n1, NodeId n2)
Shortest directed path from n1 to n2 (BFS, arc direction).
NodeSet family(const G &g, NodeId id)
Returns the family of id : { id } ∪ parents(id).
NodeProperty< NodeId > connectedComponents(const G &g)
Returns a node-to-component-id mapping for the (weakly) connected components of g.
Sequence< NodeId > topologicalOrder(const G &g)
Returns a topological ordering of the nodes of g (Kahn's algorithm).
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
Generic BFS-based path-finding algorithms for aGrUM graphs.
Generic node-reachability algorithms for aGrUM graphs.