aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
graphChange.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
41
51#ifndef GUM_LEARNING_GRAPH_CHANGE_H
52#define GUM_LEARNING_GRAPH_CHANGE_H
53
54#include <iostream>
55#include <string>
56
57#include <agrum/agrum.h>
58
60
61namespace gum {
62
63 namespace learning {
64
67
68 /* =========================================================================
69 */
70 /* === GRAPH CHANGE CLASS ===
71 */
72 /* =========================================================================
73 */
79 public:
80 // ##########################################################################
82 // ##########################################################################
84
87
89 GraphChange(const GraphChange& from) noexcept;
90
92 GraphChange(GraphChange&& from) noexcept;
93
95 ~GraphChange() noexcept;
96
98
99 // ##########################################################################
101 // ##########################################################################
103
105 GraphChange& operator=(const GraphChange& from) noexcept;
106
108 GraphChange& operator=(GraphChange&& from) noexcept;
109
111 bool operator==(const GraphChange& from) const noexcept;
112
114 bool operator!=(const GraphChange& from) const noexcept;
115
117
118 // ##########################################################################
120 // ##########################################################################
122
124 GraphChangeType type() const noexcept;
125
127 NodeId node1() const noexcept;
128
130 NodeId node2() const noexcept;
131
133 virtual std::string toString() const;
134
136
137 private:
140
143
146 };
147
148 /* =========================================================================
149 */
150 /* === ARC ADDITION CLASS ===
151 */
152 /* =========================================================================
153 */
163 class ArcAddition: public GraphChange {
164 public:
165 // ##########################################################################
167 // ##########################################################################
169
172
174 ArcAddition(const ArcAddition& from) noexcept;
175
177 ArcAddition(ArcAddition&& from) noexcept;
178
180 ~ArcAddition() noexcept;
181
183
184 // ##########################################################################
186 // ##########################################################################
188
190 ArcAddition& operator=(const ArcAddition& from) noexcept;
191
193 ArcAddition& operator=(ArcAddition&& from) noexcept;
194
196 bool operator==(const ArcAddition& from) const noexcept;
197
199 bool operator!=(const ArcAddition& from) const noexcept;
200
202
203 // ##########################################################################
205 // ##########################################################################
207
209 virtual std::string toString() const final;
210
212 };
213
214 /* =========================================================================
215 */
216 /* === ARC DELETION CLASS ===
217 */
218 /* =========================================================================
219 */
229 class ArcDeletion: public GraphChange {
230 public:
231 // ##########################################################################
233 // ##########################################################################
235
238
240 ArcDeletion(const ArcDeletion& from) noexcept;
241
243 ArcDeletion(ArcDeletion&& from) noexcept;
244
246 ~ArcDeletion() noexcept;
247
249
250 // ##########################################################################
252 // ##########################################################################
254
256 ArcDeletion& operator=(const ArcDeletion& from) noexcept;
257
259 ArcDeletion& operator=(ArcDeletion&& from) noexcept;
260
262 bool operator==(const ArcDeletion& from) const noexcept;
263
265 bool operator!=(const ArcDeletion& from) const noexcept;
266
268
269 // ##########################################################################
271 // ##########################################################################
273
275 virtual std::string toString() const final;
276
278 };
279
280 /* =========================================================================
281 */
282 /* === ARC REVERSAL CLASS ===
283 */
284 /* =========================================================================
285 */
295 class ArcReversal: public GraphChange {
296 public:
297 // ##########################################################################
299 // ##########################################################################
301
304
306 ArcReversal(const ArcReversal& from) noexcept;
307
309 ArcReversal(ArcReversal&& from) noexcept;
310
312 ~ArcReversal() noexcept;
313
315
316 // ##########################################################################
318 // ##########################################################################
320
322 ArcReversal& operator=(const ArcReversal& from) noexcept;
323
325 ArcReversal& operator=(ArcReversal&& from) noexcept;
326
328 bool operator==(const ArcReversal& from) const noexcept;
329
331 bool operator!=(const ArcReversal& from) const noexcept;
332
334
335 // ##########################################################################
337 // ##########################################################################
339
341 virtual std::string toString() const final;
342
344 };
345
346 /* =========================================================================
347 */
348 /* === EDGE ADDITION CLASS ===
349 */
350 /* =========================================================================
351 */
361 class EdgeAddition: public GraphChange {
362 public:
363 // ##########################################################################
365 // ##########################################################################
367
370
372 EdgeAddition(const EdgeAddition& from) noexcept;
373
375 EdgeAddition(EdgeAddition&& from) noexcept;
376
378 ~EdgeAddition() noexcept;
379
381
382 // ##########################################################################
384 // ##########################################################################
386
388 EdgeAddition& operator=(const EdgeAddition& from) noexcept;
389
391 EdgeAddition& operator=(EdgeAddition&& from) noexcept;
392
394 bool operator==(const EdgeAddition& from) const noexcept;
395
397 bool operator!=(const EdgeAddition& from) const noexcept;
398
400
401 // ##########################################################################
403 // ##########################################################################
405
407 virtual std::string toString() const final;
408
410 };
411
412 /* =========================================================================
413 */
414 /* === EDGE DELETION CLASS ===
415 */
416 /* =========================================================================
417 */
427 class EdgeDeletion: public GraphChange {
428 public:
429 // ##########################################################################
431 // ##########################################################################
433
436
438 EdgeDeletion(const EdgeDeletion& from) noexcept;
439
441 EdgeDeletion(EdgeDeletion&& from) noexcept;
442
444 ~EdgeDeletion() noexcept;
445
447
448 // ##########################################################################
450 // ##########################################################################
452
454 EdgeDeletion& operator=(const EdgeDeletion& from) noexcept;
455
457 EdgeDeletion& operator=(EdgeDeletion&& from) noexcept;
458
460 bool operator==(const EdgeDeletion& from) const noexcept;
461
463 bool operator!=(const EdgeDeletion& from) const noexcept;
464
466
467 // ##########################################################################
469 // ##########################################################################
471
473 virtual std::string toString() const final;
474
476 };
477
479 std::ostream& operator<<(std::ostream& stream, const GraphChange& change);
480
482 std::ostream& operator<<(std::ostream& stream, const ArcAddition& change);
483
485 std::ostream& operator<<(std::ostream& stream, const ArcDeletion& change);
486
488 std::ostream& operator<<(std::ostream& stream, const ArcReversal& change);
489
491 std::ostream& operator<<(std::ostream& stream, const EdgeAddition& change);
492
494 std::ostream& operator<<(std::ostream& stream, const EdgeDeletion& change);
495
496 } /* namespace learning */
497
499 template <>
501 public:
508
510 virtual Size operator()(const learning::GraphChange& key) const override final;
511 };
512
514 template <>
515 class HashFunc< learning::ArcAddition >: public HashFuncBase< learning::ArcAddition > {
516 public:
523
525 virtual Size operator()(const learning::ArcAddition& key) const override final;
526 };
527
529 template <>
530 class HashFunc< learning::ArcDeletion >: public HashFuncBase< learning::ArcDeletion > {
531 public:
538
540 virtual Size operator()(const learning::ArcDeletion& key) const override final;
541 };
542
544 template <>
545 class HashFunc< learning::ArcReversal >: public HashFuncBase< learning::ArcReversal > {
546 public:
553
555 virtual Size operator()(const learning::ArcReversal& key) const override final;
556 };
557
559 template <>
560 class HashFunc< learning::EdgeAddition >: public HashFuncBase< learning::EdgeAddition > {
567
569 virtual Size operator()(const learning::EdgeAddition& key) const override final;
570 };
571
573 template <>
574 class HashFunc< learning::EdgeDeletion >: public HashFuncBase< learning::EdgeDeletion > {
575 public:
582
584 virtual Size operator()(const learning::EdgeDeletion& key) const override final;
585 };
586
587} /* namespace gum */
588
589#ifndef GUM_NO_INLINE
591#endif // GU%_NO_INLINE
592
593#endif /* GUM_LEARNING_GRAPH_CHANGE_H */
All hash functions should inherit from this class.
Definition hashFunc.h:169
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
This class should be useless as only its specializations should be used.
Definition hashFunc.h:487
The class for notifying learning algorithms of new arc additions.
virtual std::string toString() const final
put the content of the ArcAddition into a string
ArcAddition(NodeId node1, NodeId node2) noexcept
default constructor
ArcAddition(const ArcAddition &from) noexcept
copy constructor
~ArcAddition() noexcept
destructor
ArcAddition(ArcAddition &&from) noexcept
move constructor
The class for notifying learning algorithms of arc removals.
ArcDeletion(const ArcDeletion &from) noexcept
copy constructor
ArcDeletion(ArcDeletion &&from) noexcept
move constructor
ArcDeletion(NodeId node1, NodeId node2) noexcept
default constructor
virtual std::string toString() const final
put the content of the ArcDeletion into a string
~ArcDeletion() noexcept
destructor
The class for notifying learning algorithms of arc reversals.
ArcReversal(const ArcReversal &from) noexcept
copy constructor
ArcReversal(NodeId node1, NodeId node2) noexcept
default constructor
~ArcReversal() noexcept
destructor
ArcReversal(ArcReversal &&from) noexcept
move constructor
virtual std::string toString() const final
put the content of the ArcReversal into a string
The class for notifying learning algorithms of new edge additions.
EdgeAddition(EdgeAddition &&from) noexcept
move constructor
virtual std::string toString() const final
put the content of the EdgeAddition into a string
EdgeAddition(NodeId node1, NodeId node2) noexcept
default constructor
EdgeAddition(const EdgeAddition &from) noexcept
copy constructor
~EdgeAddition() noexcept
destructor
The class for notifying learning algorithms of edge removals.
EdgeDeletion(NodeId node1, NodeId node2) noexcept
default constructor
virtual std::string toString() const final
put the content of the EdgeDeletion into a string
~EdgeDeletion() noexcept
destructor
EdgeDeletion(EdgeDeletion &&from) noexcept
move constructor
EdgeDeletion(const EdgeDeletion &from) noexcept
copy constructor
GraphChangeType _type_
the type of modification
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(const GraphChange &from) noexcept
copy constructor
NodeId node2() const noexcept
returns the second node involved in the modification
~GraphChange() noexcept
destructor
virtual std::string toString() const
put the content of the graph change into a string
GraphChange(GraphChange &&from) noexcept
move constructor
A class to account for changes in a graph.
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
STL namespace.
Base node set class for graphs.