aGrUM
0.20.3
a C++ library for (probabilistic) graphical models
graphChange_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 A class to account for changes in a graph
24
*
25
* This class shall be used by learning algorithms to notify scores, structural
26
* constraints, etc, that the learnt graph has been modified.
27
*
28
* @author Christophe GONZALES(@AMU) and Pierre-Henri WUILLEMIN(@LIP6)
29
*/
30
#
ifndef
DOXYGEN_SHOULD_SKIP_THIS
31
32
namespace
gum
{
33
34
namespace
learning
{
35
36
/// default constructor
37
INLINE
GraphChange
::
GraphChange
(
GraphChangeType
type
,
NodeId
node1
,
NodeId
node2
)
noexcept
:
38
_type_
{
type
},
_node1_
{
node1
},
_node2_
{
node2
} {
39
GUM_CONSTRUCTOR
(
GraphChange
);
40
}
41
42
/// copy constructor
43
INLINE
GraphChange
::
GraphChange
(
const
GraphChange
&
from
)
noexcept
:
44
_type_
{
from
.
_type_
},
_node1_
{
from
.
_node1_
},
_node2_
{
from
.
_node2_
} {
45
GUM_CONS_CPY
(
GraphChange
);
46
}
47
48
/// move constructor
49
INLINE
GraphChange
::
GraphChange
(
GraphChange
&&
from
)
noexcept
:
50
_type_
{
from
.
_type_
},
_node1_
{
from
.
_node1_
},
_node2_
{
from
.
_node2_
} {
51
GUM_CONS_MOV
(
GraphChange
);
52
}
53
54
/// destructor
55
INLINE
GraphChange
::~
GraphChange
()
noexcept
{
56
GUM_DESTRUCTOR
(
GraphChange
);
57
;
58
}
59
60
/// copy constructor
61
INLINE GraphChange&
GraphChange
::
operator
=(
const
GraphChange
&
from
)
noexcept
{
62
_type_
=
from
.
_type_
;
63
_node1_
=
from
.
_node1_
;
64
_node2_
=
from
.
_node2_
;
65
return
*
this
;
66
}
67
68
/// move operator
69
INLINE
GraphChange
&
GraphChange
::
operator
=(
GraphChange
&&
from
)
noexcept
{
70
_type_
=
from
.
_type_
;
71
_node1_
=
from
.
_node1_
;
72
_node2_
=
from
.
_node2_
;
73
return
*
this
;
74
}
75
76
/// returns the type of the operation
77
INLINE
GraphChangeType
GraphChange
::
type
()
const
noexcept
{
return
_type_
; }
78
79
/// returns the first node involved in the modification
80
INLINE
NodeId
GraphChange
::
node1
()
const
noexcept
{
return
_node1_
; }
81
82
/// returns the second node involved in the modification
83
INLINE
NodeId
GraphChange
::
node2
()
const
noexcept
{
return
_node2_
; }
84
85
/// returns whether two graph changes are identical or not
86
INLINE
bool
GraphChange
::
operator
==(
const
GraphChange
&
from
)
const
noexcept
{
87
return
((
_node1_
==
from
.
_node1_
) && (
_node2_
==
from
.
_node2_
) && (
_type_
==
from
.
_type_
));
88
}
89
90
/// returns whether two graph changes are different or not
91
INLINE
bool
GraphChange
::
operator
!=(
const
GraphChange
&
from
)
const
noexcept
{
92
return
!
operator
==(
from
);
93
}
94
95
// ===========================================================================
96
97
/// default constructor
98
INLINE
ArcAddition
::
ArcAddition
(
NodeId
node1
,
NodeId
node2
)
noexcept
:
99
GraphChange
(
GraphChangeType
::
ARC_ADDITION
,
node1
,
node2
) {
100
// do not use GUM_CONSTRUCTOR here because, to speed up GraphChange's
101
// destructor, we did not make the latter's destructor virtual.
102
}
103
104
/// copy constructor
105
INLINE
ArcAddition
::
ArcAddition
(
const
ArcAddition
&
from
)
noexcept
:
GraphChange
(
from
) {
106
// do not use GUM_CONS_CPY here because, to speed up GraphChange's
107
// destructor, we did not make the latter's destructor virtual.
108
}
109
110
/// move constructor
111
INLINE
ArcAddition
::
ArcAddition
(
ArcAddition
&&
from
)
noexcept
:
GraphChange
(
std
::
move
(
from
)) {
112
// do not use GUM_CONS_MOV here because, to speed up GraphChange's
113
// destructor, we did not make the latter's destructor virtual.
114
}
115
116
/// destructor
117
INLINE
ArcAddition
::~
ArcAddition
()
noexcept
{
118
// do not use GUM_DESTRUCTOR here because, to speed up GraphChange's
119
// destructor, we did not make the latter's destructor virtual.
120
}
121
122
/// copy constructor
123
INLINE
ArcAddition
&
ArcAddition
::
operator
=(
const
ArcAddition
&
from
)
noexcept
{
124
GraphChange
::
operator
=(
from
);
125
return
*
this
;
126
}
127
128
/// move operator
129
INLINE
ArcAddition
&
ArcAddition
::
operator
=(
ArcAddition
&&
from
)
noexcept
{
130
GraphChange
::
operator
=(
std
::
move
(
from
));
131
return
*
this
;
132
}
133
134
/// returns whether two graph changes are identical or not
135
INLINE
bool
ArcAddition
::
operator
==(
const
ArcAddition
&
from
)
const
noexcept
{
136
return
((
node1
() ==
from
.
node1
()) && (
node2
() ==
from
.
node2
()));
137
}
138
139
/// returns whether two graph changes are different or not
140
INLINE
bool
ArcAddition
::
operator
!=(
const
ArcAddition
&
from
)
const
noexcept
{
141
return
!
operator
==(
from
);
142
}
143
144
// ===========================================================================
145
146
/// default constructor
147
INLINE
ArcDeletion
::
ArcDeletion
(
NodeId
node1
,
NodeId
node2
)
noexcept
:
148
GraphChange
(
GraphChangeType
::
ARC_DELETION
,
node1
,
node2
) {
149
// do not use GUM_CONSTRUCTOR here because, to speed up GraphChange's
150
// destructor, we did not make the latter's destructor virtual.
151
}
152
153
/// copy constructor
154
INLINE
ArcDeletion
::
ArcDeletion
(
const
ArcDeletion
&
from
)
noexcept
:
GraphChange
(
from
) {
155
// do not use GUM_CONS_CPY here because, to speed up GraphChange's
156
// destructor, we did not make the latter's destructor virtual.
157
}
158
159
/// move constructor
160
INLINE
ArcDeletion
::
ArcDeletion
(
ArcDeletion
&&
from
)
noexcept
:
GraphChange
(
std
::
move
(
from
)) {
161
// do not use GUM_CONS_MOV here because, to speed up GraphChange's
162
// destructor, we did not make the latter's destructor virtual.
163
}
164
165
/// destructor
166
INLINE
ArcDeletion
::~
ArcDeletion
()
noexcept
{
167
// do not use GUM_DESTRUCTOR here because, to speed up GraphChange's
168
// destructor, we did not make the latter's destructor virtual.
169
}
170
171
/// copy constructor
172
INLINE
ArcDeletion
&
ArcDeletion
::
operator
=(
const
ArcDeletion
&
from
)
noexcept
{
173
GraphChange
::
operator
=(
from
);
174
return
*
this
;
175
}
176
177
/// move operator
178
INLINE
ArcDeletion
&
ArcDeletion
::
operator
=(
ArcDeletion
&&
from
)
noexcept
{
179
GraphChange
::
operator
=(
std
::
move
(
from
));
180
return
*
this
;
181
}
182
183
/// returns whether two graph changes are identical or not
184
INLINE
bool
ArcDeletion
::
operator
==(
const
ArcDeletion
&
from
)
const
noexcept
{
185
return
((
node1
() ==
from
.
node1
()) && (
node2
() ==
from
.
node2
()));
186
}
187
188
/// returns whether two graph changes are different or not
189
INLINE
bool
ArcDeletion
::
operator
!=(
const
ArcDeletion
&
from
)
const
noexcept
{
190
return
!
operator
==(
from
);
191
}
192
193
// ===========================================================================
194
195
/// default constructor
196
INLINE
ArcReversal
::
ArcReversal
(
NodeId
node1
,
NodeId
node2
)
noexcept
:
197
GraphChange
(
GraphChangeType
::
ARC_REVERSAL
,
node1
,
node2
) {
198
// do not use GUM_CONSTRUCTOR here because, to speed up GraphChange's
199
// destructor, we did not make the latter's destructor virtual.
200
}
201
202
/// copy constructor
203
INLINE
ArcReversal
::
ArcReversal
(
const
ArcReversal
&
from
)
noexcept
:
GraphChange
(
from
) {
204
// do not use GUM_CONS_CPY here because, to speed up GraphChange's
205
// destructor, we did not make the latter's destructor virtual.
206
}
207
208
/// move constructor
209
INLINE
ArcReversal
::
ArcReversal
(
ArcReversal
&&
from
)
noexcept
:
GraphChange
(
std
::
move
(
from
)) {
210
// do not use GUM_CONS_MOV here because, to speed up GraphChange's
211
// destructor, we did not make the latter's destructor virtual.
212
}
213
214
/// destructor
215
INLINE
ArcReversal
::~
ArcReversal
()
noexcept
{
216
// do not use GUM_DESTRUCTOR here because, to speed up GraphChange's
217
// destructor, we did not make the latter's destructor virtual.
218
}
219
220
/// copy constructor
221
INLINE
ArcReversal
&
ArcReversal
::
operator
=(
const
ArcReversal
&
from
)
noexcept
{
222
GraphChange
::
operator
=(
from
);
223
return
*
this
;
224
}
225
226
/// move operator
227
INLINE
ArcReversal
&
ArcReversal
::
operator
=(
ArcReversal
&&
from
)
noexcept
{
228
GraphChange
::
operator
=(
std
::
move
(
from
));
229
return
*
this
;
230
}
231
232
/// returns whether two arc reversals are identical or not
233
INLINE
bool
ArcReversal
::
operator
==(
const
ArcReversal
&
from
)
const
noexcept
{
234
return
((
node1
() ==
from
.
node1
()) && (
node2
() ==
from
.
node2
()));
235
}
236
237
/// returns whether two arc reversals are different or not
238
INLINE
bool
ArcReversal
::
operator
!=(
const
ArcReversal
&
from
)
const
noexcept
{
239
return
!
operator
==(
from
);
240
}
241
242
// ===========================================================================
243
244
/// default constructor
245
INLINE
EdgeAddition
::
EdgeAddition
(
NodeId
node1
,
NodeId
node2
)
noexcept
:
246
GraphChange
(
GraphChangeType
::
EDGE_ADDITION
,
node1
,
node2
) {
247
// do not use GUM_CONSTRUCTOR here because, to speed up GraphChange's
248
// destructor, we did not make the latter's destructor virtual.
249
}
250
251
/// copy constructor
252
INLINE
EdgeAddition
::
EdgeAddition
(
const
EdgeAddition
&
from
)
noexcept
:
GraphChange
(
from
) {
253
// do not use GUM_CONS_CPY here because, to speed up GraphChange's
254
// destructor, we did not make the latter's destructor virtual.
255
}
256
257
/// move constructor
258
INLINE
EdgeAddition
::
EdgeAddition
(
EdgeAddition
&&
from
)
noexcept
:
GraphChange
(
std
::
move
(
from
)) {
259
// do not use GUM_CONS_MOV here because, to speed up GraphChange's
260
// destructor, we did not make the latter's destructor virtual.
261
}
262
263
/// destructor
264
INLINE
EdgeAddition
::~
EdgeAddition
()
noexcept
{
265
// do not use GUM_DESTRUCTOR here because, to speed up GraphChange's
266
// destructor, we did not make the latter's destructor virtual.
267
}
268
269
/// copy constructor
270
INLINE
EdgeAddition
&
EdgeAddition
::
operator
=(
const
EdgeAddition
&
from
)
noexcept
{
271
GraphChange
::
operator
=(
from
);
272
return
*
this
;
273
}
274
275
/// move operator
276
INLINE
EdgeAddition
&
EdgeAddition
::
operator
=(
EdgeAddition
&&
from
)
noexcept
{
277
GraphChange
::
operator
=(
std
::
move
(
from
));
278
return
*
this
;
279
}
280
281
/// returns whether two graph changes are identical or not
282
INLINE
bool
EdgeAddition
::
operator
==(
const
EdgeAddition
&
from
)
const
noexcept
{
283
return
(((
node1
() ==
from
.
node1
()) && (
node2
() ==
from
.
node2
()))
284
|| ((
node1
() ==
from
.
node2
()) && (
node2
() ==
from
.
node1
())));
285
}
286
287
/// returns whether two graph changes are different or not
288
INLINE
bool
EdgeAddition
::
operator
!=(
const
EdgeAddition
&
from
)
const
noexcept
{
289
return
!
operator
==(
from
);
290
}
291
292
// ===========================================================================
293
294
/// default constructor
295
INLINE
EdgeDeletion
::
EdgeDeletion
(
NodeId
node1
,
NodeId
node2
)
noexcept
:
296
GraphChange
(
GraphChangeType
::
EDGE_DELETION
,
node1
,
node2
) {
297
// do not use GUM_CONSTRUCTOR here because, to speed up GraphChange's
298
// destructor, we did not make the latter's destructor virtual.
299
}
300
301
/// copy constructor
302
INLINE
EdgeDeletion
::
EdgeDeletion
(
const
EdgeDeletion
&
from
)
noexcept
:
GraphChange
(
from
) {
303
// do not use GUM_CONS_CPY here because, to speed up GraphChange's
304
// destructor, we did not make the latter's destructor virtual.
305
}
306
307
/// move constructor
308
INLINE
EdgeDeletion
::
EdgeDeletion
(
EdgeDeletion
&&
from
)
noexcept
:
GraphChange
(
std
::
move
(
from
)) {
309
// do not use GUM_CONS_MOV here because, to speed up GraphChange's
310
// destructor, we did not make the latter's destructor virtual.
311
}
312
313
/// destructor
314
INLINE
EdgeDeletion
::~
EdgeDeletion
()
noexcept
{
315
// do not use GUM_DESTRUCTOR here because, to speed up GraphChange's
316
// destructor, we did not make the latter's destructor virtual.
317
}
318
319
/// copy constructor
320
INLINE
EdgeDeletion
&
EdgeDeletion
::
operator
=(
const
EdgeDeletion
&
from
)
noexcept
{
321
GraphChange
::
operator
=(
from
);
322
return
*
this
;
323
}
324
325
/// move operator
326
INLINE
EdgeDeletion
&
EdgeDeletion
::
operator
=(
EdgeDeletion
&&
from
)
noexcept
{
327
GraphChange
::
operator
=(
std
::
move
(
from
));
328
return
*
this
;
329
}
330
331
/// returns whether two graph changes are identical or not
332
INLINE
bool
EdgeDeletion
::
operator
==(
const
EdgeDeletion
&
from
)
const
noexcept
{
333
return
(((
node1
() ==
from
.
node1
()) && (
node2
() ==
from
.
node2
()))
334
|| ((
node1
() ==
from
.
node2
()) && (
node2
() ==
from
.
node1
())));
335
}
336
337
/// returns whether two graph changes are different or not
338
INLINE
bool
EdgeDeletion
::
operator
!=(
const
EdgeDeletion
&
from
)
const
noexcept
{
339
return
!
operator
==(
from
);
340
}
341
342
343
}
/* namespace learning */
344
345
346
// ===========================================================================
347
348
// Returns the value of a key as a Size.
349
INLINE Size
HashFunc
<
learning
::
GraphChange
>::
castToSize
(
const
learning
::
GraphChange
&
key
) {
350
return
Size
(
key
.
node1
()) *
HashFuncConst
::
gold
+
Size
(
key
.
node2
()) *
HashFuncConst
::
pi
;
351
}
352
353
/// computes the hashed value of a key
354
INLINE
Size
355
HashFunc
<
learning
::
GraphChange
>::
operator
()(
const
learning
::
GraphChange
&
key
)
const
{
356
return
castToSize
(
key
) >>
this
->
right_shift_
;
357
}
358
359
360
// Returns the value of a key as a Size.
361
INLINE
Size
HashFunc
<
learning
::
ArcAddition
>::
castToSize
(
const
learning
::
ArcAddition
&
key
) {
362
return
Size
(
key
.
node1
()) *
HashFuncConst
::
gold
+
Size
(
key
.
node2
()) *
HashFuncConst
::
pi
;
363
}
364
365
/// computes the hashed value of a key
366
INLINE
Size
367
HashFunc
<
learning
::
ArcAddition
>::
operator
()(
const
learning
::
ArcAddition
&
key
)
const
{
368
return
castToSize
(
key
) >>
this
->
right_shift_
;
369
}
370
371
372
// Returns the value of a key as a Size.
373
INLINE
Size
HashFunc
<
learning
::
ArcDeletion
>::
castToSize
(
const
learning
::
ArcDeletion
&
key
) {
374
return
Size
(
key
.
node1
()) *
HashFuncConst
::
gold
+
Size
(
key
.
node2
()) *
HashFuncConst
::
pi
;
375
}
376
377
/// computes the hashed value of a key
378
INLINE
Size
379
HashFunc
<
learning
::
ArcDeletion
>::
operator
()(
const
learning
::
ArcDeletion
&
key
)
const
{
380
return
castToSize
(
key
) >>
this
->
right_shift_
;
381
}
382
383
384
// Returns the value of a key as a Size.
385
INLINE
Size
HashFunc
<
learning
::
ArcReversal
>::
castToSize
(
const
learning
::
ArcReversal
&
key
) {
386
return
Size
(
key
.
node1
()) *
HashFuncConst
::
gold
+
Size
(
key
.
node2
()) *
HashFuncConst
::
pi
;
387
}
388
389
/// computes the hashed value of a key
390
INLINE
Size
391
HashFunc
<
learning
::
ArcReversal
>::
operator
()(
const
learning
::
ArcReversal
&
key
)
const
{
392
return
castToSize
(
key
) >>
this
->
right_shift_
;
393
}
394
395
396
// Returns the value of a key as a Size.
397
INLINE
Size
HashFunc
<
learning
::
EdgeAddition
>::
castToSize
(
const
learning
::
EdgeAddition
&
key
) {
398
return
Size
(
key
.
node1
()) *
HashFuncConst
::
gold
+
Size
(
key
.
node2
()) *
HashFuncConst
::
pi
;
399
}
400
401
/// computes the hashed value of a key
402
INLINE
Size
403
HashFunc
<
learning
::
EdgeAddition
>::
operator
()(
const
learning
::
EdgeAddition
&
key
)
const
{
404
return
castToSize
(
key
) >>
this
->
right_shift_
;
405
}
406
407
408
// Returns the value of a key as a Size.
409
INLINE
Size
HashFunc
<
learning
::
EdgeDeletion
>::
castToSize
(
const
learning
::
EdgeDeletion
&
key
) {
410
return
Size
(
key
.
node1
()) *
HashFuncConst
::
gold
+
Size
(
key
.
node2
()) *
HashFuncConst
::
pi
;
411
}
412
413
/// computes the hashed value of a key
414
INLINE
Size
415
HashFunc
<
learning
::
EdgeDeletion
>::
operator
()(
const
learning
::
EdgeDeletion
&
key
)
const
{
416
return
castToSize
(
key
) >>
this
->
right_shift_
;
417
}
418
419
}
/* namespace gum */
420
421
#
endif
/* DOXYGEN_SHOULD_SKIP_THIS */
gum::Set::emplace
INLINE void emplace(Args &&... args)
Definition:
set_tpl.h:643
gum::learning::genericBNLearner::Database::Database
Database(const std::string &filename, const BayesNet< GUM_SCALAR > &bn, const std::vector< std::string > &missing_symbols)
Definition:
genericBNLearner_tpl.h:31