aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
graphChange_inl.h
Go to the documentation of this file.
1/****************************************************************************
2 * This file is part of the aGrUM/pyAgrum library. *
3 * *
4 * Copyright (c) 2005-2025 by *
5 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
6 * - Christophe GONZALES(_at_AMU) *
7 * *
8 * The aGrUM/pyAgrum library is free software; you can redistribute it *
9 * and/or modify it under the terms of either : *
10 * *
11 * - the GNU Lesser General Public License as published by *
12 * the Free Software Foundation, either version 3 of the License, *
13 * or (at your option) any later version, *
14 * - the MIT license (MIT), *
15 * - or both in dual license, as here. *
16 * *
17 * (see https://agrum.gitlab.io/articles/dual-licenses-lgplv3mit.html) *
18 * *
19 * This aGrUM/pyAgrum library is distributed in the hope that it will be *
20 * useful, but WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
21 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES MERCHANTABILITY or FITNESS *
22 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
25 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
26 * OTHER DEALINGS IN THE SOFTWARE. *
27 * *
28 * See LICENCES for more details. *
29 * *
30 * SPDX-FileCopyrightText: Copyright 2005-2025 *
31 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
32 * - Christophe GONZALES(_at_AMU) *
33 * SPDX-License-Identifier: LGPL-3.0-or-later OR MIT *
34 * *
35 * Contact : info_at_agrum_dot_org *
36 * homepage : http://agrum.gitlab.io *
37 * gitlab : https://gitlab.com/agrumery/agrum *
38 * *
39 ****************************************************************************/
40#pragma once
41
42
51#ifndef DOXYGEN_SHOULD_SKIP_THIS
52
53namespace gum {
54
55 namespace learning {
56
58 INLINE GraphChange::GraphChange(GraphChangeType type, NodeId node1, NodeId node2) noexcept :
59 _type_{type}, _node1_{node1}, _node2_{node2} {
60 GUM_CONSTRUCTOR(GraphChange);
61 }
62
64 INLINE GraphChange::GraphChange(const GraphChange& from) noexcept :
65 _type_{from._type_}, _node1_{from._node1_}, _node2_{from._node2_} {
66 GUM_CONS_CPY(GraphChange);
67 }
68
70 INLINE GraphChange::GraphChange(GraphChange&& from) noexcept :
71 _type_{from._type_}, _node1_{from._node1_}, _node2_{from._node2_} {
72 GUM_CONS_MOV(GraphChange);
73 }
74
76 INLINE GraphChange::~GraphChange() noexcept {
77 GUM_DESTRUCTOR(GraphChange);
78 ;
79 }
80
82 INLINE GraphChange& GraphChange::operator=(const GraphChange& from) noexcept {
83 _type_ = from._type_;
84 _node1_ = from._node1_;
85 _node2_ = from._node2_;
86 return *this;
87 }
88
90 INLINE GraphChange& GraphChange::operator=(GraphChange&& from) noexcept {
91 _type_ = from._type_;
92 _node1_ = from._node1_;
93 _node2_ = from._node2_;
94 return *this;
95 }
96
98 INLINE GraphChangeType GraphChange::type() const noexcept { return _type_; }
99
101 INLINE NodeId GraphChange::node1() const noexcept { return _node1_; }
102
104 INLINE NodeId GraphChange::node2() const noexcept { return _node2_; }
105
107 INLINE bool GraphChange::operator==(const GraphChange& from) const noexcept {
108 return ((_node1_ == from._node1_) && (_node2_ == from._node2_) && (_type_ == from._type_));
109 }
110
112 INLINE bool GraphChange::operator!=(const GraphChange& from) const noexcept {
113 return !operator==(from);
114 }
115
116 // ===========================================================================
117
119 INLINE ArcAddition::ArcAddition(NodeId node1, NodeId node2) noexcept :
121 // do not use GUM_CONSTRUCTOR here because, to speed up GraphChange's
122 // destructor, we did not make the latter's destructor virtual.
123 }
124
126 INLINE ArcAddition::ArcAddition(const ArcAddition& from) noexcept : GraphChange(from) {
127 // do not use GUM_CONS_CPY here because, to speed up GraphChange's
128 // destructor, we did not make the latter's destructor virtual.
129 }
130
132 INLINE ArcAddition::ArcAddition(ArcAddition&& from) noexcept : GraphChange(std::move(from)) {
133 // do not use GUM_CONS_MOV here because, to speed up GraphChange's
134 // destructor, we did not make the latter's destructor virtual.
135 }
136
138 INLINE ArcAddition::~ArcAddition() noexcept {
139 // do not use GUM_DESTRUCTOR here because, to speed up GraphChange's
140 // destructor, we did not make the latter's destructor virtual.
141 }
142
144 INLINE ArcAddition& ArcAddition::operator=(const ArcAddition& from) noexcept {
146 return *this;
147 }
148
150 INLINE ArcAddition& ArcAddition::operator=(ArcAddition&& from) noexcept {
151 GraphChange::operator=(std::move(from));
152 return *this;
153 }
154
156 INLINE bool ArcAddition::operator==(const ArcAddition& from) const noexcept {
157 return ((node1() == from.node1()) && (node2() == from.node2()));
158 }
159
161 INLINE bool ArcAddition::operator!=(const ArcAddition& from) const noexcept {
162 return !operator==(from);
163 }
164
165 // ===========================================================================
166
168 INLINE ArcDeletion::ArcDeletion(NodeId node1, NodeId node2) noexcept :
170 // do not use GUM_CONSTRUCTOR here because, to speed up GraphChange's
171 // destructor, we did not make the latter's destructor virtual.
172 }
173
175 INLINE ArcDeletion::ArcDeletion(const ArcDeletion& from) noexcept : GraphChange(from) {
176 // do not use GUM_CONS_CPY here because, to speed up GraphChange's
177 // destructor, we did not make the latter's destructor virtual.
178 }
179
181 INLINE ArcDeletion::ArcDeletion(ArcDeletion&& from) noexcept : GraphChange(std::move(from)) {
182 // do not use GUM_CONS_MOV here because, to speed up GraphChange's
183 // destructor, we did not make the latter's destructor virtual.
184 }
185
187 INLINE ArcDeletion::~ArcDeletion() noexcept {
188 // do not use GUM_DESTRUCTOR here because, to speed up GraphChange's
189 // destructor, we did not make the latter's destructor virtual.
190 }
191
193 INLINE ArcDeletion& ArcDeletion::operator=(const ArcDeletion& from) noexcept {
195 return *this;
196 }
197
199 INLINE ArcDeletion& ArcDeletion::operator=(ArcDeletion&& from) noexcept {
200 GraphChange::operator=(std::move(from));
201 return *this;
202 }
203
205 INLINE bool ArcDeletion::operator==(const ArcDeletion& from) const noexcept {
206 return ((node1() == from.node1()) && (node2() == from.node2()));
207 }
208
210 INLINE bool ArcDeletion::operator!=(const ArcDeletion& from) const noexcept {
211 return !operator==(from);
212 }
213
214 // ===========================================================================
215
217 INLINE ArcReversal::ArcReversal(NodeId node1, NodeId node2) noexcept :
219 // do not use GUM_CONSTRUCTOR here because, to speed up GraphChange's
220 // destructor, we did not make the latter's destructor virtual.
221 }
222
224 INLINE ArcReversal::ArcReversal(const ArcReversal& from) noexcept : GraphChange(from) {
225 // do not use GUM_CONS_CPY here because, to speed up GraphChange's
226 // destructor, we did not make the latter's destructor virtual.
227 }
228
230 INLINE ArcReversal::ArcReversal(ArcReversal&& from) noexcept : GraphChange(std::move(from)) {
231 // do not use GUM_CONS_MOV here because, to speed up GraphChange's
232 // destructor, we did not make the latter's destructor virtual.
233 }
234
236 INLINE ArcReversal::~ArcReversal() noexcept {
237 // do not use GUM_DESTRUCTOR here because, to speed up GraphChange's
238 // destructor, we did not make the latter's destructor virtual.
239 }
240
242 INLINE ArcReversal& ArcReversal::operator=(const ArcReversal& from) noexcept {
244 return *this;
245 }
246
248 INLINE ArcReversal& ArcReversal::operator=(ArcReversal&& from) noexcept {
249 GraphChange::operator=(std::move(from));
250 return *this;
251 }
252
254 INLINE bool ArcReversal::operator==(const ArcReversal& from) const noexcept {
255 return ((node1() == from.node1()) && (node2() == from.node2()));
256 }
257
259 INLINE bool ArcReversal::operator!=(const ArcReversal& from) const noexcept {
260 return !operator==(from);
261 }
262
263 // ===========================================================================
264
266 INLINE EdgeAddition::EdgeAddition(NodeId node1, NodeId node2) noexcept :
268 // do not use GUM_CONSTRUCTOR here because, to speed up GraphChange's
269 // destructor, we did not make the latter's destructor virtual.
270 }
271
273 INLINE EdgeAddition::EdgeAddition(const EdgeAddition& from) noexcept : GraphChange(from) {
274 // do not use GUM_CONS_CPY here because, to speed up GraphChange's
275 // destructor, we did not make the latter's destructor virtual.
276 }
277
279 INLINE EdgeAddition::EdgeAddition(EdgeAddition&& from) noexcept : GraphChange(std::move(from)) {
280 // do not use GUM_CONS_MOV here because, to speed up GraphChange's
281 // destructor, we did not make the latter's destructor virtual.
282 }
283
285 INLINE EdgeAddition::~EdgeAddition() noexcept {
286 // do not use GUM_DESTRUCTOR here because, to speed up GraphChange's
287 // destructor, we did not make the latter's destructor virtual.
288 }
289
291 INLINE EdgeAddition& EdgeAddition::operator=(const EdgeAddition& from) noexcept {
293 return *this;
294 }
295
297 INLINE EdgeAddition& EdgeAddition::operator=(EdgeAddition&& from) noexcept {
298 GraphChange::operator=(std::move(from));
299 return *this;
300 }
301
303 INLINE bool EdgeAddition::operator==(const EdgeAddition& from) const noexcept {
304 return (((node1() == from.node1()) && (node2() == from.node2()))
305 || ((node1() == from.node2()) && (node2() == from.node1())));
306 }
307
309 INLINE bool EdgeAddition::operator!=(const EdgeAddition& from) const noexcept {
310 return !operator==(from);
311 }
312
313 // ===========================================================================
314
316 INLINE EdgeDeletion::EdgeDeletion(NodeId node1, NodeId node2) noexcept :
318 // do not use GUM_CONSTRUCTOR here because, to speed up GraphChange's
319 // destructor, we did not make the latter's destructor virtual.
320 }
321
323 INLINE EdgeDeletion::EdgeDeletion(const EdgeDeletion& from) noexcept : GraphChange(from) {
324 // do not use GUM_CONS_CPY here because, to speed up GraphChange's
325 // destructor, we did not make the latter's destructor virtual.
326 }
327
329 INLINE EdgeDeletion::EdgeDeletion(EdgeDeletion&& from) noexcept : GraphChange(std::move(from)) {
330 // do not use GUM_CONS_MOV here because, to speed up GraphChange's
331 // destructor, we did not make the latter's destructor virtual.
332 }
333
335 INLINE EdgeDeletion::~EdgeDeletion() noexcept {
336 // do not use GUM_DESTRUCTOR here because, to speed up GraphChange's
337 // destructor, we did not make the latter's destructor virtual.
338 }
339
341 INLINE EdgeDeletion& EdgeDeletion::operator=(const EdgeDeletion& from) noexcept {
343 return *this;
344 }
345
347 INLINE EdgeDeletion& EdgeDeletion::operator=(EdgeDeletion&& from) noexcept {
348 GraphChange::operator=(std::move(from));
349 return *this;
350 }
351
353 INLINE bool EdgeDeletion::operator==(const EdgeDeletion& from) const noexcept {
354 return (((node1() == from.node1()) && (node2() == from.node2()))
355 || ((node1() == from.node2()) && (node2() == from.node1())));
356 }
357
359 INLINE bool EdgeDeletion::operator!=(const EdgeDeletion& from) const noexcept {
360 return !operator==(from);
361 }
362
363
364 } /* namespace learning */
365
366 // ===========================================================================
367
368 // Returns the value of a key as a Size.
370 return Size(key.node1()) * HashFuncConst::gold + Size(key.node2()) * HashFuncConst::pi;
371 }
372
374 INLINE Size
376 return castToSize(key) >> this->right_shift_;
377 }
378
379 // Returns the value of a key as a Size.
381 return Size(key.node1()) * HashFuncConst::gold + Size(key.node2()) * HashFuncConst::pi;
382 }
383
385 INLINE Size
387 return castToSize(key) >> this->right_shift_;
388 }
389
390 // Returns the value of a key as a Size.
392 return Size(key.node1()) * HashFuncConst::gold + Size(key.node2()) * HashFuncConst::pi;
393 }
394
396 INLINE Size
398 return castToSize(key) >> this->right_shift_;
399 }
400
401 // Returns the value of a key as a Size.
403 return Size(key.node1()) * HashFuncConst::gold + Size(key.node2()) * HashFuncConst::pi;
404 }
405
407 INLINE Size
409 return castToSize(key) >> this->right_shift_;
410 }
411
412 // Returns the value of a key as a Size.
414 return Size(key.node1()) * HashFuncConst::gold + Size(key.node2()) * HashFuncConst::pi;
415 }
416
418 INLINE Size
420 return castToSize(key) >> this->right_shift_;
421 }
422
423 // Returns the value of a key as a Size.
425 return Size(key.node1()) * HashFuncConst::gold + Size(key.node2()) * HashFuncConst::pi;
426 }
427
429 INLINE Size
431 return castToSize(key) >> this->right_shift_;
432 }
433
434} /* namespace gum */
435
436#endif /* DOXYGEN_SHOULD_SKIP_THIS */
static Size castToSize(const learning::ArcAddition &key)
Returns the value of a key as a Size.
virtual Size operator()(const learning::ArcAddition &key) const override final
computes the hashed value of a key
static Size castToSize(const learning::ArcDeletion &key)
Returns the value of a key as a Size.
virtual Size operator()(const learning::ArcDeletion &key) const override final
computes the hashed value of a key
virtual Size operator()(const learning::ArcReversal &key) const override final
computes the hashed value of a key
static Size castToSize(const learning::ArcReversal &key)
Returns the value of a key as a Size.
static Size castToSize(const learning::EdgeAddition &key)
Returns the value of a key as a Size.
virtual Size operator()(const learning::EdgeAddition &key) const override final
computes the hashed value of a key
static Size castToSize(const learning::EdgeDeletion &key)
Returns the value of a key as a Size.
virtual Size operator()(const learning::EdgeDeletion &key) const override final
computes the hashed value of a key
static Size castToSize(const learning::GraphChange &key)
Returns the value of a key as a Size.
virtual Size operator()(const learning::GraphChange &key) const override final
computes the hashed value of a key
The class for notifying learning algorithms of new arc additions.
bool operator!=(const ArcAddition &from) const noexcept
returns whether two arc additions are different or not
ArcAddition & operator=(const ArcAddition &from) noexcept
copy constructor
ArcAddition(NodeId node1, NodeId node2) noexcept
default constructor
bool operator==(const ArcAddition &from) const noexcept
returns whether two arc additions are identical or not
~ArcAddition() noexcept
destructor
The class for notifying learning algorithms of arc removals.
bool operator!=(const ArcDeletion &from) const noexcept
returns whether two arc deletions are different or not
bool operator==(const ArcDeletion &from) const noexcept
returns whether two arc deletions are identical or not
ArcDeletion(NodeId node1, NodeId node2) noexcept
default constructor
ArcDeletion & operator=(const ArcDeletion &from) noexcept
copy constructor
~ArcDeletion() noexcept
destructor
The class for notifying learning algorithms of arc reversals.
ArcReversal & operator=(const ArcReversal &from) noexcept
copy constructor
bool operator!=(const ArcReversal &from) const noexcept
returns whether two arc reversals are different or not
ArcReversal(NodeId node1, NodeId node2) noexcept
default constructor
~ArcReversal() noexcept
destructor
bool operator==(const ArcReversal &from) const noexcept
returns whether two arc reversals are identical or not
The class for notifying learning algorithms of new edge additions.
bool operator!=(const EdgeAddition &from) const noexcept
returns whether two edge additions are different or not
bool operator==(const EdgeAddition &from) const noexcept
returns whether two edge additions are identical or not
EdgeAddition & operator=(const EdgeAddition &from) noexcept
copy constructor
EdgeAddition(NodeId node1, NodeId node2) noexcept
default constructor
~EdgeAddition() noexcept
destructor
The class for notifying learning algorithms of edge removals.
EdgeDeletion & operator=(const EdgeDeletion &from) noexcept
copy constructor
EdgeDeletion(NodeId node1, NodeId node2) noexcept
default constructor
~EdgeDeletion() noexcept
destructor
bool operator!=(const EdgeDeletion &from) const noexcept
returns whether two edge deletions are different or not
bool operator==(const EdgeDeletion &from) const noexcept
returns whether two edge deletions are identical or not
GraphChangeType _type_
the type of modification
bool operator==(const GraphChange &from) const noexcept
returns whether two graph changes are identical or not
GraphChange(GraphChangeType type, NodeId node1, NodeId node2) noexcept
default constructor
NodeId node1() const noexcept
returns the first node involved in the modification
NodeId _node1_
the first node in the edge or arc to be modified
NodeId _node2_
the second node in the edge or arc to be modified
GraphChangeType type() const noexcept
returns the type of the operation
GraphChange & operator=(const GraphChange &from) noexcept
copy constructor
NodeId node2() const noexcept
returns the second node involved in the modification
~GraphChange() noexcept
destructor
bool operator!=(const GraphChange &from) const noexcept
returns whether two graph changes are different or not
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition types.h:74
Size NodeId
Type for node ids.
include the inlined functions if necessary
Definition CSVParser.h:54
GraphChangeType
the type of modification that can be applied to the graph
Definition graphChange.h:66
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
bool operator==(const HashTableIteratorSafe< Key, Val > &from) const noexcept
Checks whether two iterators are pointing toward equal elements.
static constexpr Size pi
Definition hashFunc.h:100
static constexpr Size gold
Definition hashFunc.h:98