aGrUM 3.1.1
a C++ library for (probabilistic) graphical models
edgeGraphPart.cpp
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
49
50#ifdef GUM_NO_INLINE
52#endif // GUM_NO_INLINE
54
55namespace gum {
56
58 EdgeGraphPart::EdgeGraphPart(Size edges_size, bool edges_resize_policy) :
59 _edges_(edges_size, edges_resize_policy) {
60 GUM_CONSTRUCTOR(EdgeGraphPart);
61 }
62
67
69 GUM_CONS_CPY(EdgeGraphPart)
70
71 // copy the set of neighbours
72 _neighbours_.resize(s._neighbours_.capacity());
73
74 for (const auto& [key, nodeset]: s._neighbours_) {
75 NodeSet* newneigh = new NodeSet(*nodeset);
76 _neighbours_.insert(key, newneigh);
77 }
78
79 // send signals to indicate that there are new edges
80 if (onEdgeAdded.hasListener())
81 for (const auto& edge: _edges_)
82 GUM_EMIT2(onEdgeAdded, edge.first(), edge.second());
83 }
84
86 GUM_DESTRUCTOR(EdgeGraphPart)
87 // be sure to deallocate all the neighbours sets
89 }
90
92
94 for (const auto& elt: _neighbours_)
95 delete elt.second;
96
97 _neighbours_.clear();
98
99 if (onEdgeDeleted.hasListener()) {
100 EdgeSet tmp = _edges_;
101 _edges_.clear();
102
103 for (const auto& edge: tmp)
104 GUM_EMIT2(onEdgeDeleted, edge.first(), edge.second());
105 } else {
106 _edges_.clear();
107 }
108 }
109
111 // avoid self assignment
112 if (this != &s) {
113 clearEdges();
114
115 _edges_ = s._edges_;
116
117 // copy the set of neighbours
118 _neighbours_.resize(s._neighbours_.capacity());
119
120 for (const auto& [key, nodeset]: s._neighbours_) {
121 NodeSet* newneigh = new NodeSet(*nodeset);
122 _neighbours_.insert(key, newneigh);
123 }
124
125 if (onEdgeAdded.hasListener())
126 for (const auto& edge: _edges_)
127 GUM_EMIT2(onEdgeAdded, edge.first(), edge.second());
128
129 GUM_OP_CPY(EdgeGraphPart);
130 }
131
132 return *this;
133 }
134
136 if (this != &s) {
137 clearEdges();
138 _edges_ = std::move(s._edges_);
139 _neighbours_ = std::move(s._neighbours_);
140 if (onEdgeAdded.hasListener()) {
141 for (const auto& edge: _edges_) {
142 GUM_EMIT2(onEdgeAdded, edge.first(), edge.second());
143 }
144 }
145 GUM_OP_MOV(EdgeGraphPart);
146 }
147 return *this;
148 }
149
150 std::string EdgeGraphPart::toString() const {
151 std::stringstream s;
152 bool first = true;
153 s << "{";
154
155 for (const auto& edge: _edges_) {
156 if (first) first = false;
157 else s << ",";
158
159 s << edge;
160 }
161
162 s << "}";
163
164 return s.str();
165 }
166
167 std::ostream& operator<<(std::ostream& stream, const EdgeGraphPart& set) {
168 stream << set.toString();
169 return stream;
170 }
171
172} /* namespace gum */
Classes for undirected edge sets.
Signaler< NodeId, NodeId > onEdgeAdded
EdgeGraphPart & operator=(const EdgeGraphPart &s)
copy operator
virtual ~EdgeGraphPart()
destructor
EdgeGraphPart(Size edges_size=HashTableConst::default_size, bool edges_resize_policy=true)
default constructor
EdgeSet _edges_
the set of all the edges contained within the EdgeGraphPart
NodeProperty< NodeSet * > _neighbours_
for each node, the set of its adjacent edges
virtual std::string toString() const
to friendly display the content of the EdgeGraphPart
virtual void clearEdges()
removes all the edges from the EdgeGraphPart
Signaler< NodeId, NodeId > onEdgeDeleted
Inline implementation of classes for undirected edge sets.
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 ...
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
STL namespace.
#define GUM_EMIT2(signal, arg1, arg2)
Definition signaler.h:290