aGrUM
0.20.2
a C++ library for (probabilistic) graphical models
graphChange_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 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
,
38
NodeId
node1
,
39
NodeId
node2
)
noexcept
:
40
type__
{
type
},
41
node1__
{
node1
},
node2__
{
node2
} {
42
GUM_CONSTRUCTOR
(
GraphChange
);
43
}
44
45
/// copy constructor
46
INLINE
GraphChange
::
GraphChange
(
const
GraphChange
&
from
)
noexcept
:
47
type__
{
from
.
type__
},
node1__
{
from
.
node1__
},
node2__
{
from
.
node2__
} {
48
GUM_CONS_CPY
(
GraphChange
);
49
}
50
51
/// move constructor
52
INLINE
GraphChange
::
GraphChange
(
GraphChange
&&
from
)
noexcept
:
53
type__
{
from
.
type__
},
node1__
{
from
.
node1__
},
node2__
{
from
.
node2__
} {
54
GUM_CONS_MOV
(
GraphChange
);
55
}
56
57
/// destructor
58
INLINE
GraphChange
::~
GraphChange
()
noexcept
{
GUM_DESTRUCTOR
(
GraphChange
); }
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__
)
88
&& (
type__
==
from
.
type__
));
89
}
90
91
/// returns whether two graph changes are different or not
92
INLINE
bool
GraphChange
::
operator
!=(
const
GraphChange
&
from
)
const
noexcept
{
93
return
!
operator
==(
from
);
94
}
95
96
// ===========================================================================
97
98
/// default constructor
99
INLINE
ArcAddition
::
ArcAddition
(
NodeId
node1
,
NodeId
node2
)
noexcept
:
100
GraphChange
(
GraphChangeType
::
ARC_ADDITION
,
node1
,
node2
) {
101
// do not use GUM_CONSTRUCTOR here because, to speed up GraphChange's
102
// destructor, we did not make the latter's destructor virtual.
103
}
104
105
/// copy constructor
106
INLINE
ArcAddition
::
ArcAddition
(
const
ArcAddition
&
from
)
noexcept
:
107
GraphChange
(
from
) {
108
// do not use GUM_CONS_CPY here because, to speed up GraphChange's
109
// destructor, we did not make the latter's destructor virtual.
110
}
111
112
/// move constructor
113
INLINE
ArcAddition
::
ArcAddition
(
ArcAddition
&&
from
)
noexcept
:
114
GraphChange
(
std
::
move
(
from
)) {
115
// do not use GUM_CONS_MOV here because, to speed up GraphChange's
116
// destructor, we did not make the latter's destructor virtual.
117
}
118
119
/// destructor
120
INLINE
ArcAddition
::~
ArcAddition
()
noexcept
{
121
// do not use GUM_DESTRUCTOR here because, to speed up GraphChange's
122
// destructor, we did not make the latter's destructor virtual.
123
}
124
125
/// copy constructor
126
INLINE
ArcAddition
&
ArcAddition
::
operator
=(
const
ArcAddition
&
from
)
noexcept
{
127
GraphChange
::
operator
=(
from
);
128
return
*
this
;
129
}
130
131
/// move operator
132
INLINE
ArcAddition
&
ArcAddition
::
operator
=(
ArcAddition
&&
from
)
noexcept
{
133
GraphChange
::
operator
=(
std
::
move
(
from
));
134
return
*
this
;
135
}
136
137
/// returns whether two graph changes are identical or not
138
INLINE
bool
ArcAddition
::
operator
==(
const
ArcAddition
&
from
)
const
noexcept
{
139
return
((
node1
() ==
from
.
node1
()) && (
node2
() ==
from
.
node2
()));
140
}
141
142
/// returns whether two graph changes are different or not
143
INLINE
bool
ArcAddition
::
operator
!=(
const
ArcAddition
&
from
)
const
noexcept
{
144
return
!
operator
==(
from
);
145
}
146
147
// ===========================================================================
148
149
/// default constructor
150
INLINE
ArcDeletion
::
ArcDeletion
(
NodeId
node1
,
NodeId
node2
)
noexcept
:
151
GraphChange
(
GraphChangeType
::
ARC_DELETION
,
node1
,
node2
) {
152
// do not use GUM_CONSTRUCTOR here because, to speed up GraphChange's
153
// destructor, we did not make the latter's destructor virtual.
154
}
155
156
/// copy constructor
157
INLINE
ArcDeletion
::
ArcDeletion
(
const
ArcDeletion
&
from
)
noexcept
:
158
GraphChange
(
from
) {
159
// do not use GUM_CONS_CPY here because, to speed up GraphChange's
160
// destructor, we did not make the latter's destructor virtual.
161
}
162
163
/// move constructor
164
INLINE
ArcDeletion
::
ArcDeletion
(
ArcDeletion
&&
from
)
noexcept
:
165
GraphChange
(
std
::
move
(
from
)) {
166
// do not use GUM_CONS_MOV here because, to speed up GraphChange's
167
// destructor, we did not make the latter's destructor virtual.
168
}
169
170
/// destructor
171
INLINE
ArcDeletion
::~
ArcDeletion
()
noexcept
{
172
// do not use GUM_DESTRUCTOR here because, to speed up GraphChange's
173
// destructor, we did not make the latter's destructor virtual.
174
}
175
176
/// copy constructor
177
INLINE
ArcDeletion
&
ArcDeletion
::
operator
=(
const
ArcDeletion
&
from
)
noexcept
{
178
GraphChange
::
operator
=(
from
);
179
return
*
this
;
180
}
181
182
/// move operator
183
INLINE
ArcDeletion
&
ArcDeletion
::
operator
=(
ArcDeletion
&&
from
)
noexcept
{
184
GraphChange
::
operator
=(
std
::
move
(
from
));
185
return
*
this
;
186
}
187
188
/// returns whether two graph changes are identical or not
189
INLINE
bool
ArcDeletion
::
operator
==(
const
ArcDeletion
&
from
)
const
noexcept
{
190
return
((
node1
() ==
from
.
node1
()) && (
node2
() ==
from
.
node2
()));
191
}
192
193
/// returns whether two graph changes are different or not
194
INLINE
bool
ArcDeletion
::
operator
!=(
const
ArcDeletion
&
from
)
const
noexcept
{
195
return
!
operator
==(
from
);
196
}
197
198
// ===========================================================================
199
200
/// default constructor
201
INLINE
ArcReversal
::
ArcReversal
(
NodeId
node1
,
NodeId
node2
)
noexcept
:
202
GraphChange
(
GraphChangeType
::
ARC_REVERSAL
,
node1
,
node2
) {
203
// do not use GUM_CONSTRUCTOR here because, to speed up GraphChange's
204
// destructor, we did not make the latter's destructor virtual.
205
}
206
207
/// copy constructor
208
INLINE
ArcReversal
::
ArcReversal
(
const
ArcReversal
&
from
)
noexcept
:
209
GraphChange
(
from
) {
210
// do not use GUM_CONS_CPY here because, to speed up GraphChange's
211
// destructor, we did not make the latter's destructor virtual.
212
}
213
214
/// move constructor
215
INLINE
ArcReversal
::
ArcReversal
(
ArcReversal
&&
from
)
noexcept
:
216
GraphChange
(
std
::
move
(
from
)) {
217
// do not use GUM_CONS_MOV here because, to speed up GraphChange's
218
// destructor, we did not make the latter's destructor virtual.
219
}
220
221
/// destructor
222
INLINE
ArcReversal
::~
ArcReversal
()
noexcept
{
223
// do not use GUM_DESTRUCTOR here because, to speed up GraphChange's
224
// destructor, we did not make the latter's destructor virtual.
225
}
226
227
/// copy constructor
228
INLINE
ArcReversal
&
ArcReversal
::
operator
=(
const
ArcReversal
&
from
)
noexcept
{
229
GraphChange
::
operator
=(
from
);
230
return
*
this
;
231
}
232
233
/// move operator
234
INLINE
ArcReversal
&
ArcReversal
::
operator
=(
ArcReversal
&&
from
)
noexcept
{
235
GraphChange
::
operator
=(
std
::
move
(
from
));
236
return
*
this
;
237
}
238
239
/// returns whether two arc reversals are identical or not
240
INLINE
bool
ArcReversal
::
operator
==(
const
ArcReversal
&
from
)
const
noexcept
{
241
return
((
node1
() ==
from
.
node1
()) && (
node2
() ==
from
.
node2
()));
242
}
243
244
/// returns whether two arc reversals are different or not
245
INLINE
bool
ArcReversal
::
operator
!=(
const
ArcReversal
&
from
)
const
noexcept
{
246
return
!
operator
==(
from
);
247
}
248
249
// ===========================================================================
250
251
/// default constructor
252
INLINE
EdgeAddition
::
EdgeAddition
(
NodeId
node1
,
NodeId
node2
)
noexcept
:
253
GraphChange
(
GraphChangeType
::
EDGE_ADDITION
,
node1
,
node2
) {
254
// do not use GUM_CONSTRUCTOR here because, to speed up GraphChange's
255
// destructor, we did not make the latter's destructor virtual.
256
}
257
258
/// copy constructor
259
INLINE
EdgeAddition
::
EdgeAddition
(
const
EdgeAddition
&
from
)
noexcept
:
260
GraphChange
(
from
) {
261
// do not use GUM_CONS_CPY here because, to speed up GraphChange's
262
// destructor, we did not make the latter's destructor virtual.
263
}
264
265
/// move constructor
266
INLINE
EdgeAddition
::
EdgeAddition
(
EdgeAddition
&&
from
)
noexcept
:
267
GraphChange
(
std
::
move
(
from
)) {
268
// do not use GUM_CONS_MOV here because, to speed up GraphChange's
269
// destructor, we did not make the latter's destructor virtual.
270
}
271
272
/// destructor
273
INLINE
EdgeAddition
::~
EdgeAddition
()
noexcept
{
274
// do not use GUM_DESTRUCTOR here because, to speed up GraphChange's
275
// destructor, we did not make the latter's destructor virtual.
276
}
277
278
/// copy constructor
279
INLINE
EdgeAddition
&
280
EdgeAddition
::
operator
=(
const
EdgeAddition
&
from
)
noexcept
{
281
GraphChange
::
operator
=(
from
);
282
return
*
this
;
283
}
284
285
/// move operator
286
INLINE
EdgeAddition
&
EdgeAddition
::
operator
=(
EdgeAddition
&&
from
)
noexcept
{
287
GraphChange
::
operator
=(
std
::
move
(
from
));
288
return
*
this
;
289
}
290
291
/// returns whether two graph changes are identical or not
292
INLINE
bool
EdgeAddition
::
operator
==(
const
EdgeAddition
&
from
)
const
noexcept
{
293
return
(((
node1
() ==
from
.
node1
()) && (
node2
() ==
from
.
node2
()))
294
|| ((
node1
() ==
from
.
node2
()) && (
node2
() ==
from
.
node1
())));
295
}
296
297
/// returns whether two graph changes are different or not
298
INLINE
bool
EdgeAddition
::
operator
!=(
const
EdgeAddition
&
from
)
const
noexcept
{
299
return
!
operator
==(
from
);
300
}
301
302
// ===========================================================================
303
304
/// default constructor
305
INLINE
EdgeDeletion
::
EdgeDeletion
(
NodeId
node1
,
NodeId
node2
)
noexcept
:
306
GraphChange
(
GraphChangeType
::
EDGE_DELETION
,
node1
,
node2
) {
307
// do not use GUM_CONSTRUCTOR here because, to speed up GraphChange's
308
// destructor, we did not make the latter's destructor virtual.
309
}
310
311
/// copy constructor
312
INLINE
EdgeDeletion
::
EdgeDeletion
(
const
EdgeDeletion
&
from
)
noexcept
:
313
GraphChange
(
from
) {
314
// do not use GUM_CONS_CPY here because, to speed up GraphChange's
315
// destructor, we did not make the latter's destructor virtual.
316
}
317
318
/// move constructor
319
INLINE
EdgeDeletion
::
EdgeDeletion
(
EdgeDeletion
&&
from
)
noexcept
:
320
GraphChange
(
std
::
move
(
from
)) {
321
// do not use GUM_CONS_MOV here because, to speed up GraphChange's
322
// destructor, we did not make the latter's destructor virtual.
323
}
324
325
/// destructor
326
INLINE
EdgeDeletion
::~
EdgeDeletion
()
noexcept
{
327
// do not use GUM_DESTRUCTOR here because, to speed up GraphChange's
328
// destructor, we did not make the latter's destructor virtual.
329
}
330
331
/// copy constructor
332
INLINE
EdgeDeletion
&
333
EdgeDeletion
::
operator
=(
const
EdgeDeletion
&
from
)
noexcept
{
334
GraphChange
::
operator
=(
from
);
335
return
*
this
;
336
}
337
338
/// move operator
339
INLINE
EdgeDeletion
&
EdgeDeletion
::
operator
=(
EdgeDeletion
&&
from
)
noexcept
{
340
GraphChange
::
operator
=(
std
::
move
(
from
));
341
return
*
this
;
342
}
343
344
/// returns whether two graph changes are identical or not
345
INLINE
bool
EdgeDeletion
::
operator
==(
const
EdgeDeletion
&
from
)
const
noexcept
{
346
return
(((
node1
() ==
from
.
node1
()) && (
node2
() ==
from
.
node2
()))
347
|| ((
node1
() ==
from
.
node2
()) && (
node2
() ==
from
.
node1
())));
348
}
349
350
/// returns whether two graph changes are different or not
351
INLINE
bool
EdgeDeletion
::
operator
!=(
const
EdgeDeletion
&
from
)
const
noexcept
{
352
return
!
operator
==(
from
);
353
}
354
355
356
}
/* namespace learning */
357
358
359
// ===========================================================================
360
361
// Returns the value of a key as a Size.
362
INLINE Size
HashFunc
<
learning
::
GraphChange
>::
castToSize
(
363
const
learning
::
GraphChange
&
key
) {
364
return
Size
(
key
.
node1
()) *
HashFuncConst
::
gold
365
+
Size
(
key
.
node2
()) *
HashFuncConst
::
pi
;
366
}
367
368
/// computes the hashed value of a key
369
INLINE
Size
HashFunc
<
learning
::
GraphChange
>::
operator
()(
370
const
learning
::
GraphChange
&
key
)
const
{
371
return
castToSize
(
key
) >>
this
->
right_shift_
;
372
}
373
374
375
// Returns the value of a key as a Size.
376
INLINE
Size
HashFunc
<
learning
::
ArcAddition
>::
castToSize
(
377
const
learning
::
ArcAddition
&
key
) {
378
return
Size
(
key
.
node1
()) *
HashFuncConst
::
gold
379
+
Size
(
key
.
node2
()) *
HashFuncConst
::
pi
;
380
}
381
382
/// computes the hashed value of a key
383
INLINE
Size
HashFunc
<
learning
::
ArcAddition
>::
operator
()(
384
const
learning
::
ArcAddition
&
key
)
const
{
385
return
castToSize
(
key
) >>
this
->
right_shift_
;
386
}
387
388
389
// Returns the value of a key as a Size.
390
INLINE
Size
HashFunc
<
learning
::
ArcDeletion
>::
castToSize
(
391
const
learning
::
ArcDeletion
&
key
) {
392
return
Size
(
key
.
node1
()) *
HashFuncConst
::
gold
393
+
Size
(
key
.
node2
()) *
HashFuncConst
::
pi
;
394
}
395
396
/// computes the hashed value of a key
397
INLINE
Size
HashFunc
<
learning
::
ArcDeletion
>::
operator
()(
398
const
learning
::
ArcDeletion
&
key
)
const
{
399
return
castToSize
(
key
) >>
this
->
right_shift_
;
400
}
401
402
403
// Returns the value of a key as a Size.
404
INLINE
Size
HashFunc
<
learning
::
ArcReversal
>::
castToSize
(
405
const
learning
::
ArcReversal
&
key
) {
406
return
Size
(
key
.
node1
()) *
HashFuncConst
::
gold
407
+
Size
(
key
.
node2
()) *
HashFuncConst
::
pi
;
408
}
409
410
/// computes the hashed value of a key
411
INLINE
Size
HashFunc
<
learning
::
ArcReversal
>::
operator
()(
412
const
learning
::
ArcReversal
&
key
)
const
{
413
return
castToSize
(
key
) >>
this
->
right_shift_
;
414
}
415
416
417
// Returns the value of a key as a Size.
418
INLINE
Size
HashFunc
<
learning
::
EdgeAddition
>::
castToSize
(
419
const
learning
::
EdgeAddition
&
key
) {
420
return
Size
(
key
.
node1
()) *
HashFuncConst
::
gold
421
+
Size
(
key
.
node2
()) *
HashFuncConst
::
pi
;
422
}
423
424
/// computes the hashed value of a key
425
INLINE
Size
HashFunc
<
learning
::
EdgeAddition
>::
operator
()(
426
const
learning
::
EdgeAddition
&
key
)
const
{
427
return
castToSize
(
key
) >>
this
->
right_shift_
;
428
}
429
430
431
// Returns the value of a key as a Size.
432
INLINE
Size
HashFunc
<
learning
::
EdgeDeletion
>::
castToSize
(
433
const
learning
::
EdgeDeletion
&
key
) {
434
return
Size
(
key
.
node1
()) *
HashFuncConst
::
gold
435
+
Size
(
key
.
node2
()) *
HashFuncConst
::
pi
;
436
}
437
438
/// computes the hashed value of a key
439
INLINE
Size
HashFunc
<
learning
::
EdgeDeletion
>::
operator
()(
440
const
learning
::
EdgeDeletion
&
key
)
const
{
441
return
castToSize
(
key
) >>
this
->
right_shift_
;
442
}
443
444
}
/* namespace gum */
445
446
#
endif
/* DOXYGEN_SHOULD_SKIP_THIS */
gum::Set::emplace
INLINE void emplace(Args &&... args)
Definition:
set_tpl.h:669
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