aGrUM
3.2.0
a C++ library for (probabilistic) graphical models
Toggle main menu visibility
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
48
#include <
agrum/base/graphs/parts/edgeGraphPart.h
>
49
50
#ifdef GUM_NO_INLINE
51
# include <
agrum/base/graphs/parts/edgeGraphPart_inl.h
>
52
#endif
// GUM_NO_INLINE
53
#include "
agrum/base/graphs/graphElements.h
"
54
55
namespace
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
63
EdgeGraphPart::EdgeGraphPart
(
EdgeGraphPart
&& s) :
64
_edges_
(
std
::move(s.
_edges_
)),
_neighbours_
(
std
::move(s.
_neighbours_
)) {
65
GUM_CONS_MOV(
EdgeGraphPart
);
66
}
67
68
EdgeGraphPart::EdgeGraphPart
(
const
EdgeGraphPart
& s) :
_edges_
(s.
_edges_
) {
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
85
EdgeGraphPart::~EdgeGraphPart
() {
86
GUM_DESTRUCTOR(
EdgeGraphPart
)
87
// be sure to deallocate all the neighbours sets
88
_clearEdges_
();
89
}
90
91
void
EdgeGraphPart::clearEdges
() {
_clearEdges_
(); }
92
93
void
EdgeGraphPart::_clearEdges_
() {
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
110
EdgeGraphPart
&
EdgeGraphPart::operator=
(
const
EdgeGraphPart
& s) {
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
135
EdgeGraphPart
&
EdgeGraphPart::operator=
(
EdgeGraphPart
&& s) {
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 */
gum::EdgeGraphPart
Classes for undirected edge sets.
Definition
edgeGraphPart.h:94
gum::EdgeGraphPart::onEdgeAdded
Signaler< NodeId, NodeId > onEdgeAdded
Definition
edgeGraphPart.h:98
gum::EdgeGraphPart::operator=
EdgeGraphPart & operator=(const EdgeGraphPart &s)
copy operator
Definition
edgeGraphPart.cpp:110
gum::EdgeGraphPart::~EdgeGraphPart
virtual ~EdgeGraphPart()
destructor
Definition
edgeGraphPart.cpp:85
gum::EdgeGraphPart::EdgeGraphPart
EdgeGraphPart(Size edges_size=HashTableConst::default_size, bool edges_resize_policy=true)
default constructor
Definition
edgeGraphPart.cpp:58
gum::EdgeGraphPart::_clearEdges_
void _clearEdges_()
Definition
edgeGraphPart.cpp:93
gum::EdgeGraphPart::_edges_
EdgeSet _edges_
the set of all the edges contained within the EdgeGraphPart
Definition
edgeGraphPart.h:238
gum::EdgeGraphPart::_neighbours_
NodeProperty< NodeSet * > _neighbours_
for each node, the set of its adjacent edges
Definition
edgeGraphPart.h:241
gum::EdgeGraphPart::toString
virtual std::string toString() const
to friendly display the content of the EdgeGraphPart
Definition
edgeGraphPart.cpp:150
gum::EdgeGraphPart::clearEdges
virtual void clearEdges()
removes all the edges from the EdgeGraphPart
Definition
edgeGraphPart.cpp:91
gum::EdgeGraphPart::onEdgeDeleted
Signaler< NodeId, NodeId > onEdgeDeleted
Definition
edgeGraphPart.h:99
gum::Set::clear
void clear()
Removes all the elements, if any, from the set.
Definition
set_tpl.h:315
gum::__sig__::BasicSignaler< Args... >::hasListener
bool hasListener() override
Definition
signaler_tpl.h:109
edgeGraphPart.h
edgeGraphPart_inl.h
Inline implementation of classes for undirected edge sets.
graphElements.h
some utils for topology : NodeId, Edge, Arc and consorts ...
gum::Size
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition
types.h:74
gum::EdgeSet
Set< Edge > EdgeSet
Some typdefs and define for shortcuts ...
Definition
graphElements.h:391
gum::NodeSet
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
Definition
graphElements.h:392
gum
gum is the global namespace for all aGrUM entities
Definition
agrum.h:46
gum::operator<<
std::ostream & operator<<(std::ostream &stream, const AVLTree< Val, Cmp > &tree)
display the content of a tree
std
STL namespace.
GUM_EMIT2
#define GUM_EMIT2(signal, arg1, arg2)
Definition
signaler.h:290
aGrUM
3.2.0
© PHW&CG&others - 2022
DoXyGeN 1.18.0