aGrUM
0.20.3
a C++ library for (probabilistic) graphical models
edgeGraphPart_inl.h
Go to the documentation of this file.
1
/**
2
*
3
* Copyright (c) 2005-2021 by 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
{
return
_edges_
.
contains
(
edge
); }
41
42
INLINE
bool
EdgeGraphPart
::
existsEdge
(
const
NodeId
first
,
const
NodeId
second
)
const
{
43
return
_neighbours_
.
exists
(
first
) &&
_neighbours_
[
first
]->
exists
(
second
);
44
}
45
46
INLINE
void
EdgeGraphPart
::
_checkNeighbours_
(
const
NodeId
id
)
const
{
47
if
(!
_neighbours_
.
exists
(
id
)) {
_neighbours_
.
insert
(
id
,
new
NodeSet
); }
48
}
49
50
INLINE
void
EdgeGraphPart
::
addEdge
(
const
NodeId
first
,
const
NodeId
second
) {
51
Edge
edge
(
first
,
second
);
52
_edges_
.
insert
(
edge
);
53
_checkNeighbours_
(
first
);
54
_checkNeighbours_
(
second
);
55
_neighbours_
[
first
]->
insert
(
second
);
56
_neighbours_
[
second
]->
insert
(
first
);
57
58
GUM_EMIT2
(
onEdgeAdded
,
first
,
second
);
59
}
60
61
INLINE
void
EdgeGraphPart
::
eraseEdge
(
const
Edge
&
edge
) {
62
if
(
existsEdge
(
edge
)) {
63
// ASSUMING first and second exists in _neighbours_ (if not, it is an
64
// error)
65
NodeId
id1
=
edge
.
first
(),
id2
=
edge
.
second
();
66
67
_neighbours_
[
id1
]->
erase
(
id2
);
68
_neighbours_
[
id2
]->
erase
(
id1
);
69
_edges_
.
erase
(
edge
);
70
GUM_EMIT2
(
onEdgeDeleted
,
id1
,
id2
);
71
}
72
}
73
74
INLINE
const
NodeSet
&
EdgeGraphPart
::
neighbours
(
const
NodeId
id
)
const
{
75
_checkNeighbours_
(
id
);
76
return
*(
_neighbours_
[
id
]);
77
}
78
79
INLINE
void
EdgeGraphPart
::
eraseNeighbours
(
const
NodeId
id
) {
80
if
(
_neighbours_
.
exists
(
id
)) {
81
const
NodeSet
&
set
=
neighbours
(
id
);
82
83
for
(
auto
iter
=
set
.
beginSafe
();
iter
!=
set
.
endSafe
();
84
++
iter
) {
// safe iterator needed here
85
// warning: use this erase so that you actually use the virtualized
86
// edge removal function
87
eraseEdge
(
Edge
(*
iter
,
id
));
88
}
89
}
90
}
91
92
INLINE
void
EdgeGraphPart
::
unvirtualizedEraseNeighbours
(
const
NodeId
id
) {
93
if
(
_neighbours_
.
exists
(
id
)) {
94
const
NodeSet
&
set
=
neighbours
(
id
);
95
96
for
(
auto
iter
=
set
.
beginSafe
();
iter
!=
set
.
endSafe
();
97
++
iter
) {
// safe iterator needed here
98
EdgeGraphPart
::
eraseEdge
(
Edge
(*
iter
,
id
));
99
}
100
}
101
}
102
103
INLINE
bool
EdgeGraphPart
::
operator
==(
const
EdgeGraphPart
&
p
)
const
{
104
return
_edges_
==
p
.
_edges_
;
105
}
106
107
INLINE
bool
EdgeGraphPart
::
operator
!=(
const
EdgeGraphPart
&
p
)
const
{
108
return
_edges_
!=
p
.
_edges_
;
109
}
110
111
}
/* namespace gum */
gum::Set::emplace
INLINE void emplace(Args &&... args)
Definition:
set_tpl.h:643