aGrUM 3.2.0
a C++ library for (probabilistic) graphical models
graphChange.cpp
Go to the documentation of this file.
1/****************************************************************************
2 * This file is part of the aGrUM/pyAgrum library. *
3 * *
4 * Copyright (c) 2005-2026 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-2026 *
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
50
52
53#ifdef GUM_NO_INLINE
55#endif // GUM_NO_INLINE
56
57namespace gum {
58
59 namespace learning {
60
61 // -------------------------------------------------------------------------
62 // Constructors, destructors and assignment operators of GraphChange and of
63 // its subclasses are defined out-of-line (not INLINE) on purpose: under
64 // MSVC, a non-template dllexport'ed class has its inline-defined special
65 // members promoted to strong/eager symbol emission (instead of COMDAT),
66 // which causes LNK2005 duplicate-definition errors once several
67 // translation units include the inline body.
68 // -------------------------------------------------------------------------
69
74 NodeId node3) noexcept : type_{type} {
75 nodes_[0] = LearnNodeId(node1);
76 nodes_[1] = LearnNodeId(node2);
77 nodes_[2] = LearnNodeId(node3);
78 GUM_CONSTRUCTOR(GraphChange);
79 }
80
82 GraphChange::GraphChange(const GraphChange& from) noexcept {
83 std::memcpy(nodes_, from.nodes_, 4 * sizeof(LearnNodeId));
84 GUM_CONS_CPY(GraphChange);
85 }
86
89 std::memcpy(nodes_, from.nodes_, 4 * sizeof(LearnNodeId));
90 GUM_CONS_MOV(GraphChange);
91 }
92
94 GraphChange::~GraphChange() noexcept { GUM_DESTRUCTOR(GraphChange); }
95
98 if (this != &from) { std::memcpy(nodes_, from.nodes_, 4 * sizeof(LearnNodeId)); }
99 return *this;
100 }
101
104 if (this != &from) { std::memcpy(nodes_, from.nodes_, 4 * sizeof(LearnNodeId)); }
105 return *this;
106 }
107
111
113 ArcAddition::ArcAddition(const ArcAddition& from) noexcept : GraphChange(from) {}
114
116 ArcAddition::ArcAddition(ArcAddition&& from) noexcept : GraphChange(std::move(from)) {}
117
120
122 ArcAddition& ArcAddition::operator=(const ArcAddition& from) noexcept = default;
123
126 GraphChange::operator=(std::move(from));
127 return *this;
128 }
129
133
135 ArcDeletion::ArcDeletion(const ArcDeletion& from) noexcept : GraphChange(from) {}
136
138 ArcDeletion::ArcDeletion(ArcDeletion&& from) noexcept : GraphChange(std::move(from)) {}
139
142
144 ArcDeletion& ArcDeletion::operator=(const ArcDeletion& from) noexcept = default;
145
148 GraphChange::operator=(std::move(from));
149 return *this;
150 }
151
155
157 ArcReversal::ArcReversal(const ArcReversal& from) noexcept : GraphChange(from) {}
158
160 ArcReversal::ArcReversal(ArcReversal&& from) noexcept : GraphChange(std::move(from)) {}
161
164
166 ArcReversal& ArcReversal::operator=(const ArcReversal& from) noexcept = default;
167
170 GraphChange::operator=(std::move(from));
171 return *this;
172 }
173
177
181
185
188
191 = default;
192
195 GraphChange::operator=(std::move(from));
196 return *this;
197 }
198
202
206
210
213
216 = default;
217
220 GraphChange::operator=(std::move(from));
221 return *this;
222 }
223
229
231 EdgeAddition::EdgeAddition(const EdgeAddition& from) noexcept : GraphChange(from) {}
232
234 EdgeAddition::EdgeAddition(EdgeAddition&& from) noexcept : GraphChange(std::move(from)) {}
235
238
240 EdgeAddition& EdgeAddition::operator=(const EdgeAddition& from) noexcept = default;
241
244 GraphChange::operator=(std::move(from));
245 return *this;
246 }
247
253
255 EdgeDeletion::EdgeDeletion(const EdgeDeletion& from) noexcept : GraphChange(from) {}
256
258 EdgeDeletion::EdgeDeletion(EdgeDeletion&& from) noexcept : GraphChange(std::move(from)) {}
259
262
264 EdgeDeletion& EdgeDeletion::operator=(const EdgeDeletion& from) noexcept = default;
265
268 GraphChange::operator=(std::move(from));
269 return *this;
270 }
271
273 std::string GraphChange::toString() const {
274 switch (type()) {
276 return std::format("ArcAddition ( {} , {} )", node1(), node2());
277
279 return std::format("ArcDeletion ( {} , {} )", node1(), node2());
280
282 return std::format("ArcReversal ( {} , {} )", node1(), node2());
283
285 return std::format("ArcTriangleDeletion1 ( {} , {} , {} )", node1(), node2(), node3());
286
288 return std::format("ArcTriangleDeletion2 ( {} , {} , {} )", node1(), node2(), node3());
289
291 return std::format("EdgeAddition ( {} , {} )", node1(), node2());
292
294 return std::format("EdgeDeletion ( {} , {} )", node1(), node2());
295 }
296
298 "Graph modification " << (int)type() << " is not supported yet in method toString")
299 }
300
302 std::string GraphChange::typeAsString() const {
303 switch (type()) {
304 case GraphChangeType::ARC_ADDITION : return "ArcAddition";
305
306 case GraphChangeType::ARC_DELETION : return "ArcDeletion";
307
308 case GraphChangeType::ARC_REVERSAL : return "ArcReversal";
309
310 case GraphChangeType::ARC_TRIANGLE_DELETION1 : return "ArcTriangleDeletion1";
311
312 case GraphChangeType::ARC_TRIANGLE_DELETION2 : return "ArcTriangleDeletion2";
313
314 case GraphChangeType::EDGE_ADDITION : return "EdgeAddition";
315
316 case GraphChangeType::EDGE_DELETION : return "EdgeDeletion";
317 }
318
320 "Graph modification " << (int)type()
321 << " is not supported yet in method typeAsString")
322 }
323
325 std::ostream& operator<<(std::ostream& stream, const GraphChange& change) {
326 return stream << change.toString();
327 }
328
329 } /* namespace learning */
330
331} /* namespace gum */
Exception : operation not allowed.
The class for notifying learning algorithms of new arc additions.
ArcAddition & operator=(const ArcAddition &from) noexcept
copy constructor
ArcAddition(NodeId node1, NodeId node2) noexcept
default constructor
~ArcAddition() noexcept
destructor
The class for notifying learning algorithms of arc removals.
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
ArcReversal(NodeId node1, NodeId node2) noexcept
default constructor
~ArcReversal() noexcept
destructor
The graph change substituting a triangle node1->node2->node3 + node1->node3 into v-structure node2->n...
ArcTriangleDeletion1(NodeId node1, NodeId node2, NodeId node3) noexcept
default constructor
ArcTriangleDeletion1 & operator=(const ArcTriangleDeletion1 &from) noexcept
copy constructor
NodeId node3() const
returns the third node involved in the modification (if any)
~ArcTriangleDeletion1() noexcept
destructor
The graph change substituting a triangle node1->node2->node3 + node1->node3 into v-structure node1->n...
ArcTriangleDeletion2 & operator=(const ArcTriangleDeletion2 &from) noexcept
copy constructor
~ArcTriangleDeletion2() noexcept
destructor
NodeId node3() const
returns the third node involved in the modification (if any)
ArcTriangleDeletion2(NodeId node1, NodeId node2, NodeId node3) noexcept
default constructor
The class for notifying learning algorithms of new edge additions.
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
GraphChange(GraphChangeType type, NodeId node1, NodeId node2, NodeId node3=0) noexcept
default constructor
std::string typeAsString() const
returns a string corresponding to the type of the change
GraphChangeType type_
the type of modification
NodeId node1() const noexcept
returns the first node involved in the modification
GraphChangeType type() const noexcept
returns the type of the operation
GraphChange & operator=(const GraphChange &from) noexcept
copy constructor
LearnNodeId nodes_[3]
the nodes involved in the edge or arc to be modified
NodeId node2() const noexcept
returns the second node involved in the modification
NodeId node3() const
returns the third node involved in the modification (if any)
~GraphChange() noexcept
destructor
std::string toString() const
put the content of the graph change into a string
#define GUM_ERROR(type, msg)
Definition exceptions.h:76
the classes to account for structure changes in a graph
A class to account for changes in a graph.
Size NodeId
Type for node ids.
include the inlined functions if necessary
Definition CSVParser.h:55
std::ostream & operator<<(std::ostream &stream, const IdCondSet &idset)
the display operator
GraphChangeType
the type of modification that can be applied to the graph
Definition graphChange.h:74
uint32_t LearnNodeId
the internal type of the nodes involved in the arc/edge modifications
Definition graphChange.h:71
gum is the global namespace for all aGrUM entities
Definition agrum.h:46