aGrUM
0.20.2
a C++ library for (probabilistic) graphical models
DFSCode_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
/**
23
* @file
24
* @brief Inline implementation of the DFSCode class.
25
*
26
* @author Lionel TORTI and Pierre-Henri WUILLEMIN(@LIP6)
27
*/
28
29
namespace
gum
{
30
namespace
prm
{
31
namespace
gspan
{
32
33
INLINE
34
DFSCode
::
DFSCode
() {
GUM_CONSTRUCTOR
(
DFSCode
); }
35
36
INLINE
37
DFSCode
::
DFSCode
(
const
DFSCode
&
source
) {
38
GUM_CONS_CPY
(
DFSCode
);
39
40
for
(
const
auto
code
:
source
.
codes
)
41
codes
.
push_back
(
new
EdgeCode
(*
code
));
42
}
43
44
INLINE
45
DFSCode
::~
DFSCode
() {
46
GUM_DESTRUCTOR
(
DFSCode
);
47
48
for
(
const
auto
item
:
codes
)
49
delete
item
;
50
}
51
52
INLINE
53
DFSCode&
DFSCode
::
operator
=(
const
DFSCode
&
source
) {
54
for
(
const
auto
item
:
codes
)
55
delete
item
;
56
57
for
(
const
auto
srcitem
:
source
.
codes
)
58
codes
.
push_back
(
new
EdgeCode
(*
srcitem
));
59
60
return
*
this
;
61
}
62
63
INLINE
64
bool
DFSCode
::
operator
==(
const
DFSCode
&
from
)
const
{
65
if
(
codes
.
size
() ==
from
.
codes
.
size
()) {
66
for
(
size_t
idx
= 0;
idx
<
codes
.
size
(); ++
idx
) {
67
if
((*
codes
[
idx
]) != (*
codes
[
idx
])) {
return
false
; }
68
}
69
70
return
true
;
71
}
else
{
72
return
false
;
73
}
74
}
75
76
INLINE
77
bool
DFSCode
::
operator
!=(
const
DFSCode
&
from
)
const
{
78
if
(
codes
.
size
() ==
from
.
codes
.
size
()) {
79
for
(
size_t
idx
= 0;
idx
<
codes
.
size
(); ++
idx
) {
80
if
((*
codes
[
idx
]) != (*
codes
[
idx
])) {
return
true
; }
81
}
82
83
return
false
;
84
}
else
{
85
return
true
;
86
}
87
}
88
89
INLINE
90
bool
DFSCode
::
operator
<(
const
DFSCode
&
from
)
const
{
91
DFSCode
::
const_iterator
iter
=
codes
.
begin
();
92
DFSCode
::
const_iterator
jter
=
from
.
codes
.
begin
();
93
94
for
(; (
iter
!=
codes
.
end
()) && (
jter
!=
from
.
codes
.
end
());
95
++
iter
, ++
jter
) {
96
if
((**
iter
) != (**
jter
)) {
97
EdgeCode
&
alpha
= **
iter
;
98
EdgeCode
&
beta
= **
jter
;
99
100
if
(
alpha
.
isBackward
()) {
101
if
(
beta
.
isForward
()) {
102
return
true
;
103
}
else
if
(
alpha
.
j
<
beta
.
j
) {
104
// beta is a backward edge
105
return
true
;
106
}
else
if
((
alpha
.
j
==
beta
.
j
) && (
alpha
.
l_ij
<
beta
.
l_ij
)) {
107
return
true
;
108
}
109
110
return
false
;
111
}
else
{
112
// alpha is a forward edge
113
if
(
beta
.
isBackward
()) {
114
return
false
;
115
}
else
if
(
beta
.
i
<
alpha
.
i
) {
116
// Beta is a forward edge
117
return
true
;
118
}
else
if
(
beta
.
i
==
alpha
.
i
) {
119
if
(
alpha
.
l_i
<
beta
.
l_i
) {
120
return
true
;
121
}
else
if
(
alpha
.
l_i
==
beta
.
l_i
) {
122
if
(
alpha
.
l_ij
<
beta
.
l_ij
) {
123
return
true
;
124
}
else
if
(
alpha
.
l_ij
==
beta
.
l_ij
) {
125
return
alpha
.
l_j
<
beta
.
l_j
;
126
}
127
}
128
}
129
130
return
false
;
131
}
132
133
return
(**
iter
) < (**
jter
);
134
}
135
}
136
137
return
false
;
138
}
139
140
INLINE
141
bool
DFSCode
::
operator
<=(
const
DFSCode
&
from
)
const
{
142
DFSCode
::
const_iterator
iter
=
codes
.
begin
();
143
DFSCode
::
const_iterator
jter
=
from
.
codes
.
begin
();
144
145
for
(; (
iter
!=
codes
.
end
()) && (
jter
!=
from
.
codes
.
end
());
146
++
iter
, ++
jter
) {
147
if
((**
iter
) != (**
jter
)) {
return
(**
iter
) < (**
jter
); }
148
}
149
150
return
codes
.
size
() <=
from
.
codes
.
size
();
151
}
152
153
}
/* namespace gspan */
154
}
/* namespace prm */
155
}
/* namespace gum */
gum::Set::emplace
INLINE void emplace(Args &&... args)
Definition:
set_tpl.h:669
gum::prm::ParamScopeData::ParamScopeData
ParamScopeData(const std::string &s, const PRMReferenceSlot< GUM_SCALAR > &ref, Idx d)
Definition:
PRMClass_tpl.h:1101
gum::prm::gspan::operator<<
INLINE std::ostream & operator<<(std::ostream &out, const EdgeData< GUM_SCALAR > &data)
Print a EdgeData<GUM_SCALAR> in out.
Definition:
interfaceGraph_tpl.h:393