aGrUM
0.20.2
a C++ library for (probabilistic) graphical models
edgeGraphPart_inl.h
Go to the documentation of this file.
1
/**
2
*
3
* Copyright 2005-2020 Pierre-Henri WUILLEMIN(@LIP6) & Christophe GONZALES(@AMU)
4
* info_at_agrum_dot_org
5
*
6
* This library is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU Lesser General Public License as published by
8
* the Free Software Foundation, either version 3 of the License, or
9
* (at your option) any later version.
10
*
11
* This library is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU Lesser General Public License for more details.
15
*
16
* You should have received a copy of the GNU Lesser General Public License
17
* along with this library. If not, see <http://www.gnu.org/licenses/>.
18
*
19
*/
20
21
22
/** @file
23
* @brief Inline implementation of classes for undirected edge sets
24
*
25
* @author Pierre-Henri WUILLEMIN(@LIP6) & Christophe GONZALES(@AMU)
26
*
27
*/
28
29
// to ease parsing by IDE
30
#
include
<
agrum
/
tools
/
graphs
/
parts
/
edgeGraphPart
.
h
>
31
32
namespace
gum
{
33
34
INLINE
bool
EdgeGraphPart
::
emptyEdges
()
const
{
return
edges__
.
empty
(); }
35
36
INLINE Size
EdgeGraphPart
::
sizeEdges
()
const
{
return
edges__
.
size
(); }
37
38
INLINE
const
EdgeSet
&
EdgeGraphPart
::
edges
()
const
{
return
edges__
; }
39
40
INLINE
bool
EdgeGraphPart
::
existsEdge
(
const
Edge
&
edge
)
const
{
41
return
edges__
.
contains
(
edge
);
42
}
43
44
INLINE
bool
EdgeGraphPart
::
existsEdge
(
const
NodeId
first
,
45
const
NodeId
second
)
const
{
46
return
neighbours__
.
exists
(
first
) &&
neighbours__
[
first
]->
exists
(
second
);
47
}
48
49
INLINE
void
EdgeGraphPart
::
checkNeighbours__
(
const
NodeId
id
)
const
{
50
if
(!
neighbours__
.
exists
(
id
)) {
neighbours__
.
insert
(
id
,
new
NodeSet
); }
51
}
52
53
INLINE
void
EdgeGraphPart
::
addEdge
(
const
NodeId
first
,
const
NodeId
second
) {
54
Edge
edge
(
first
,
second
);
55
edges__
.
insert
(
edge
);
56
checkNeighbours__
(
first
);
57
checkNeighbours__
(
second
);
58
neighbours__
[
first
]->
insert
(
second
);
59
neighbours__
[
second
]->
insert
(
first
);
60
61
GUM_EMIT2
(
onEdgeAdded
,
first
,
second
);
62
}
63
64
INLINE
void
EdgeGraphPart
::
eraseEdge
(
const
Edge
&
edge
) {
65
if
(
existsEdge
(
edge
)) {
66
// ASSUMING first and second exists in neighbours__ (if not, it is an
67
// error)
68
NodeId
id1
=
edge
.
first
(),
id2
=
edge
.
second
();
69
70
neighbours__
[
id1
]->
erase
(
id2
);
71
neighbours__
[
id2
]->
erase
(
id1
);
72
edges__
.
erase
(
edge
);
73
GUM_EMIT2
(
onEdgeDeleted
,
id1
,
id2
);
74
}
75
}
76
77
INLINE
const
NodeSet
&
EdgeGraphPart
::
neighbours
(
const
NodeId
id
)
const
{
78
checkNeighbours__
(
id
);
79
return
*(
neighbours__
[
id
]);
80
}
81
82
INLINE
void
EdgeGraphPart
::
eraseNeighbours
(
const
NodeId
id
) {
83
if
(
neighbours__
.
exists
(
id
)) {
84
const
NodeSet
&
set
=
neighbours
(
id
);
85
86
for
(
auto
iter
=
set
.
beginSafe
();
iter
!=
set
.
endSafe
();
87
++
iter
) {
// safe iterator needed here
88
// warning: use this erase so that you actually use the virtualized
89
// edge removal function
90
eraseEdge
(
Edge
(*
iter
,
id
));
91
}
92
}
93
}
94
95
INLINE
void
EdgeGraphPart
::
unvirtualizedEraseNeighbours
(
const
NodeId
id
) {
96
if
(
neighbours__
.
exists
(
id
)) {
97
const
NodeSet
&
set
=
neighbours
(
id
);
98
99
for
(
auto
iter
=
set
.
beginSafe
();
iter
!=
set
.
endSafe
();
100
++
iter
) {
// safe iterator needed here
101
EdgeGraphPart
::
eraseEdge
(
Edge
(*
iter
,
id
));
102
}
103
}
104
}
105
106
INLINE
bool
EdgeGraphPart
::
operator
==(
const
EdgeGraphPart
&
p
)
const
{
107
return
edges__
==
p
.
edges__
;
108
}
109
110
INLINE
bool
EdgeGraphPart
::
operator
!=(
const
EdgeGraphPart
&
p
)
const
{
111
return
edges__
!=
p
.
edges__
;
112
}
113
114
}
/* namespace gum */
gum::Set::emplace
INLINE void emplace(Args &&... args)
Definition:
set_tpl.h:669