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
38  NodeId node1,
39  NodeId node2) noexcept :
40  type__{type},
43  }
44 
45  /// copy constructor
46  INLINE GraphChange::GraphChange(const GraphChange& from) noexcept :
49  }
50 
51  /// move constructor
55  }
56 
57  /// destructor
59 
60  /// copy constructor
61  INLINE GraphChange& GraphChange::operator=(const GraphChange& from) noexcept {
62  type__ = from.type__;
65  return *this;
66  }
67 
68  /// move operator
70  type__ = from.type__;
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
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
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 {
128  return *this;
129  }
130 
131  /// move operator
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
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
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 {
179  return *this;
180  }
181 
182  /// move operator
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
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
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 {
230  return *this;
231  }
232 
233  /// move operator
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
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
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
280  EdgeAddition::operator=(const EdgeAddition& from) noexcept {
282  return *this;
283  }
284 
285  /// move operator
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
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
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
333  EdgeDeletion::operator=(const EdgeDeletion& from) noexcept {
335  return *this;
336  }
337 
338  /// move operator
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
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.
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
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.
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
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.
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
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.
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
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.
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
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 */
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:669
Database(const std::string &filename, const BayesNet< GUM_SCALAR > &bn, const std::vector< std::string > &missing_symbols)