aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
structuralConstraintSetStatic_tpl.h
Go to the documentation of this file.
1 /**
2  *
3  * Copyright (c) 2005-2021 by 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 the "meta-programming" class for storing several structural
24  *constraints
25  *
26  * @author Christophe GONZALES(@AMU) and Pierre-Henri WUILLEMIN(@LIP6)
27  */
28 #ifndef DOXYGEN_SHOULD_SKIP_THIS
29 
30 # include <iostream>
31 
32 namespace gum {
33 
34  namespace learning {
35 
36  /// default constructor
37  template < typename CONSTRAINT1, typename... OTHER_CONSTRAINTS >
38  INLINE
39  _StructuralConstraintSetStatic_< CONSTRAINT1,
40  OTHER_CONSTRAINTS... >::_StructuralConstraintSetStatic_() {}
41 
42  /// copy constructor
43  template < typename CONSTRAINT1, typename... OTHER_CONSTRAINTS >
44  INLINE _StructuralConstraintSetStatic_< CONSTRAINT1, OTHER_CONSTRAINTS... >::
45  _StructuralConstraintSetStatic_(
46  const _StructuralConstraintSetStatic_< CONSTRAINT1, OTHER_CONSTRAINTS... >& from) :
47  CONSTRAINT1(from),
48  _StructuralConstraintSetStatic_< OTHER_CONSTRAINTS... >(from) {}
49 
50  /// destructor
51  template < typename CONSTRAINT1, typename... OTHER_CONSTRAINTS >
52  INLINE
53  _StructuralConstraintSetStatic_< CONSTRAINT1,
54  OTHER_CONSTRAINTS... >::~_StructuralConstraintSetStatic_() {
55  }
56 
57  /// copy operator
58  template < typename CONSTRAINT1, typename... OTHER_CONSTRAINTS >
59  INLINE _StructuralConstraintSetStatic_< CONSTRAINT1, OTHER_CONSTRAINTS... >&
60  _StructuralConstraintSetStatic_< CONSTRAINT1, OTHER_CONSTRAINTS... >::operator=(
61  const _StructuralConstraintSetStatic_< CONSTRAINT1, OTHER_CONSTRAINTS... >& from) {
62  if (this != &from) {
63  next_constraints::operator=(from);
64  first_constraint::operator=(from);
65  }
66 
67  return *this;
68  }
69 
70  /// sets a new graph from which we will perform checkings
71  template < typename CONSTRAINT1, typename... OTHER_CONSTRAINTS >
72  INLINE void _StructuralConstraintSetStatic_< CONSTRAINT1, OTHER_CONSTRAINTS... >::setGraph(
73  const DiGraph& graph) {
74  next_constraints::setGraph(graph);
75  first_constraint::setGraphAlone(graph);
76  }
77 
78  /// notify the constraint of a modification of the graph
79  template < typename CONSTRAINT1, typename... OTHER_CONSTRAINTS >
80  INLINE void _StructuralConstraintSetStatic_< CONSTRAINT1, OTHER_CONSTRAINTS... >::modifyGraph(
81  const ArcAddition& change) {
82  next_constraints::modifyGraph(change);
83  first_constraint::modifyGraphAlone(change);
84  }
85 
86  /// notify the constraint of a modification of the graph
87  template < typename CONSTRAINT1, typename... OTHER_CONSTRAINTS >
88  INLINE void _StructuralConstraintSetStatic_< CONSTRAINT1, OTHER_CONSTRAINTS... >::modifyGraph(
89  const ArcDeletion& change) {
90  next_constraints::modifyGraph(change);
91  first_constraint::modifyGraphAlone(change);
92  }
93 
94  /// notify the constraint of a modification of the graph
95  template < typename CONSTRAINT1, typename... OTHER_CONSTRAINTS >
96  INLINE void _StructuralConstraintSetStatic_< CONSTRAINT1, OTHER_CONSTRAINTS... >::modifyGraph(
97  const ArcReversal& change) {
98  next_constraints::modifyGraph(change);
99  first_constraint::modifyGraphAlone(change);
100  }
101 
102  /// notify the constraint of a modification of the graph
103  template < typename CONSTRAINT1, typename... OTHER_CONSTRAINTS >
104  INLINE void _StructuralConstraintSetStatic_< CONSTRAINT1, OTHER_CONSTRAINTS... >::modifyGraph(
105  const GraphChange& change) {
106  next_constraints::modifyGraph(change);
107  first_constraint::modifyGraphAlone(change);
108  }
109 
110  /// indicates whether a change will always violate the constraint
111  template < typename CONSTRAINT1, typename... OTHER_CONSTRAINTS >
112  INLINE bool
113  _StructuralConstraintSetStatic_< CONSTRAINT1, OTHER_CONSTRAINTS... >::isAlwaysInvalid(
114  const GraphChange& change) const {
115  return next_constraints::isAlwaysInvalid(change)
116  || first_constraint::isAlwaysInvalidAlone(change);
117  }
118 
119  /// checks whether the constraints enable to add arc (x,y)
120  template < typename CONSTRAINT1, typename... OTHER_CONSTRAINTS >
121  INLINE bool
122  _StructuralConstraintSetStatic_< CONSTRAINT1, OTHER_CONSTRAINTS... >::checkArcAddition(
123  NodeId x,
124  NodeId y) const {
125  return next_constraints::checkArcAddition(x, y)
126  && first_constraint::checkArcAdditionAlone(x, y);
127  }
128 
129  /// checks whether the constraints enable to remove arc (x,y)
130  template < typename CONSTRAINT1, typename... OTHER_CONSTRAINTS >
131  INLINE bool
132  _StructuralConstraintSetStatic_< CONSTRAINT1, OTHER_CONSTRAINTS... >::checkArcDeletion(
133  NodeId x,
134  NodeId y) const {
135  return next_constraints::checkArcDeletion(x, y)
136  && first_constraint::checkArcDeletionAlone(x, y);
137  }
138 
139  /// checks whether the constraints enable to reverse arc (x,y)
140  template < typename CONSTRAINT1, typename... OTHER_CONSTRAINTS >
141  INLINE bool
142  _StructuralConstraintSetStatic_< CONSTRAINT1, OTHER_CONSTRAINTS... >::checkArcReversal(
143  NodeId x,
144  NodeId y) const {
145  return next_constraints::checkArcReversal(x, y)
146  && first_constraint::checkArcReversalAlone(x, y);
147  }
148 
149  /// checks whether the constraints enable to add an arc
150  template < typename CONSTRAINT1, typename... OTHER_CONSTRAINTS >
151  INLINE bool
152  _StructuralConstraintSetStatic_< CONSTRAINT1, OTHER_CONSTRAINTS... >::checkModification(
153  const ArcAddition& change) const {
154  return next_constraints::checkModification(change)
155  && first_constraint::checkModificationAlone(change);
156  }
157 
158  /// checks whether the constraints enable to remove an arc
159  template < typename CONSTRAINT1, typename... OTHER_CONSTRAINTS >
160  INLINE bool
161  _StructuralConstraintSetStatic_< CONSTRAINT1, OTHER_CONSTRAINTS... >::checkModification(
162  const ArcDeletion& change) const {
163  return next_constraints::checkModification(change)
164  && first_constraint::checkModificationAlone(change);
165  }
166 
167  /// checks whether the constraints enable to reverse an arc
168  template < typename CONSTRAINT1, typename... OTHER_CONSTRAINTS >
169  INLINE bool
170  _StructuralConstraintSetStatic_< CONSTRAINT1, OTHER_CONSTRAINTS... >::checkModification(
171  const ArcReversal& change) const {
172  return next_constraints::checkModification(change)
173  && first_constraint::checkModificationAlone(change);
174  }
175 
176  /// checks whether the constraints enable to perform a graph change
177  template < typename CONSTRAINT1, typename... OTHER_CONSTRAINTS >
178  INLINE bool
179  _StructuralConstraintSetStatic_< CONSTRAINT1, OTHER_CONSTRAINTS... >::checkModification(
180  const GraphChange& change) const {
181  return next_constraints::checkModification(change)
182  && first_constraint::checkModificationAlone(change);
183  }
184 
185  // ===========================================================================
186 
187  /// default constructor
188  template < typename CONSTRAINT >
189  INLINE _StructuralConstraintSetStatic_< CONSTRAINT >::_StructuralConstraintSetStatic_() {}
190 
191  /// copy constructor
192  template < typename CONSTRAINT >
193  INLINE _StructuralConstraintSetStatic_< CONSTRAINT >::_StructuralConstraintSetStatic_(
194  const _StructuralConstraintSetStatic_< CONSTRAINT >& from) :
195  CONSTRAINT(from) {}
196 
197  /// destructor
198  template < typename CONSTRAINT >
199  INLINE _StructuralConstraintSetStatic_< CONSTRAINT >::~_StructuralConstraintSetStatic_() {}
200 
201  /// copy operator
202  template < typename CONSTRAINT >
203  INLINE _StructuralConstraintSetStatic_< CONSTRAINT >&
204  _StructuralConstraintSetStatic_< CONSTRAINT >::operator=(
205  const _StructuralConstraintSetStatic_< CONSTRAINT >& from) {
206  if (this != &from) { CONSTRAINT::operator=(from); }
207 
208  return *this;
209  }
210 
211  /// sets a new graph from which we will perform checkings
212  template < typename CONSTRAINT >
213  INLINE void _StructuralConstraintSetStatic_< CONSTRAINT >::setGraph(const DiGraph& graph) {
214  first_constraint::setGraphAlone(graph);
215  }
216 
217  /// notify the constraint of a modification of the graph
218  template < typename CONSTRAINT >
219  INLINE void
220  _StructuralConstraintSetStatic_< CONSTRAINT >::modifyGraph(const ArcAddition& change) {
221  first_constraint::modifyGraphAlone(change);
222  }
223 
224  /// notify the constraint of a modification of the graph
225  template < typename CONSTRAINT >
226  INLINE void
227  _StructuralConstraintSetStatic_< CONSTRAINT >::modifyGraph(const ArcDeletion& change) {
228  first_constraint::modifyGraphAlone(change);
229  }
230 
231  /// notify the constraint of a modification of the graph
232  template < typename CONSTRAINT >
233  INLINE void
234  _StructuralConstraintSetStatic_< CONSTRAINT >::modifyGraph(const ArcReversal& change) {
235  first_constraint::modifyGraphAlone(change);
236  }
237 
238  /// notify the constraint of a modification of the graph
239  template < typename CONSTRAINT >
240  INLINE void
241  _StructuralConstraintSetStatic_< CONSTRAINT >::modifyGraph(const GraphChange& change) {
242  first_constraint::modifyGraphAlone(change);
243  }
244 
245  /// indicates whether a change will always violate the constraint
246  template < typename CONSTRAINT >
247  INLINE bool _StructuralConstraintSetStatic_< CONSTRAINT >::isAlwaysInvalid(
248  const GraphChange& change) const {
249  return first_constraint::isAlwaysInvalidAlone(change);
250  }
251 
252  /// checks whether the constraints enable to add arc (x,y)
253  template < typename CONSTRAINT >
254  INLINE bool _StructuralConstraintSetStatic_< CONSTRAINT >::checkArcAddition(NodeId x,
255  NodeId y) const {
256  return first_constraint::checkArcAdditionAlone(x, y);
257  }
258 
259  /// checks whether the constraints enable to remove arc (x,y)
260  template < typename CONSTRAINT >
261  INLINE bool _StructuralConstraintSetStatic_< CONSTRAINT >::checkArcDeletion(NodeId x,
262  NodeId y) const {
263  return first_constraint::checkArcDeletionAlone(x, y);
264  }
265 
266  /// checks whether the constraints enable to reverse arc (x,y)
267  template < typename CONSTRAINT >
268  INLINE bool _StructuralConstraintSetStatic_< CONSTRAINT >::checkArcReversal(NodeId x,
269  NodeId y) const {
270  return first_constraint::checkArcReversalAlone(x, y);
271  }
272 
273  /// checks whether the constraints enable to add an arc
274  template < typename CONSTRAINT >
275  INLINE bool _StructuralConstraintSetStatic_< CONSTRAINT >::checkModification(
276  const ArcAddition& change) const {
277  return first_constraint::checkModificationAlone(change);
278  }
279 
280  /// checks whether the constraints enable to remove an arc
281  template < typename CONSTRAINT >
282  INLINE bool _StructuralConstraintSetStatic_< CONSTRAINT >::checkModification(
283  const ArcDeletion& change) const {
284  return first_constraint::checkModificationAlone(change);
285  }
286 
287  /// checks whether the constraints enable to reverse an arc
288  template < typename CONSTRAINT >
289  INLINE bool _StructuralConstraintSetStatic_< CONSTRAINT >::checkModification(
290  const ArcReversal& change) const {
291  return first_constraint::checkModificationAlone(change);
292  }
293 
294  /// checks whether the constraints enable to perform a graph change
295  template < typename CONSTRAINT >
296  INLINE bool _StructuralConstraintSetStatic_< CONSTRAINT >::checkModification(
297  const GraphChange& change) const {
298  return first_constraint::checkModificationAlone(change);
299  }
300 
301  // ===========================================================================
302 
303  /// default constructor
304  template < typename CONSTRAINT1, typename... OTHER_CONSTRAINTS >
305  INLINE StructuralConstraintSetStatic< CONSTRAINT1,
306  OTHER_CONSTRAINTS... >::StructuralConstraintSetStatic() {
307  GUM_CONSTRUCTOR(StructuralConstraintSetStatic);
308  }
309 
310  /// copy constructor
311  template < typename CONSTRAINT1, typename... OTHER_CONSTRAINTS >
312  INLINE StructuralConstraintSetStatic< CONSTRAINT1, OTHER_CONSTRAINTS... >::
313  StructuralConstraintSetStatic(
314  const StructuralConstraintSetStatic< CONSTRAINT1, OTHER_CONSTRAINTS... >& from) :
315  constraints(from) {
316  GUM_CONS_CPY(StructuralConstraintSetStatic);
317  }
318 
319  /// destructor
320  template < typename CONSTRAINT1, typename... OTHER_CONSTRAINTS >
321  INLINE StructuralConstraintSetStatic< CONSTRAINT1,
322  OTHER_CONSTRAINTS... >::~StructuralConstraintSetStatic() {
323  GUM_DESTRUCTOR(StructuralConstraintSetStatic);
324  }
325 
326  /// copy operator
327  template < typename CONSTRAINT1, typename... OTHER_CONSTRAINTS >
328  INLINE StructuralConstraintSetStatic< CONSTRAINT1, OTHER_CONSTRAINTS... >&
329  StructuralConstraintSetStatic< CONSTRAINT1, OTHER_CONSTRAINTS... >::operator=(
330  const StructuralConstraintSetStatic< CONSTRAINT1, OTHER_CONSTRAINTS... >& from) {
331  if (this != &from) { constraints::operator=(from); }
332 
333  return *this;
334  }
335 
336  /// sets a new graph from which we will perform checkings
337  template < typename CONSTRAINT1, typename... OTHER_CONSTRAINTS >
338  INLINE void StructuralConstraintSetStatic< CONSTRAINT1, OTHER_CONSTRAINTS... >::setGraph(
339  const DiGraph& graph) {
340  constraints::setGraph(graph);
341  }
342 
343  /// checks whether the constraints enable to add arc (x,y)
344  template < typename CONSTRAINT1, typename... OTHER_CONSTRAINTS >
345  INLINE bool
346  StructuralConstraintSetStatic< CONSTRAINT1, OTHER_CONSTRAINTS... >::checkArcAddition(
347  NodeId x,
348  NodeId y) const {
349  return constraints::checkArcAddition(x, y);
350  }
351 
352  /// checks whether the constraints enable to remove arc (x,y)
353  template < typename CONSTRAINT1, typename... OTHER_CONSTRAINTS >
354  INLINE bool
355  StructuralConstraintSetStatic< CONSTRAINT1, OTHER_CONSTRAINTS... >::checkArcDeletion(
356  NodeId x,
357  NodeId y) const {
358  return constraints::checkArcDeletion(x, y);
359  }
360 
361  /// checks whether the constraints enable to reverse arc (x,y)
362  template < typename CONSTRAINT1, typename... OTHER_CONSTRAINTS >
363  INLINE bool
364  StructuralConstraintSetStatic< CONSTRAINT1, OTHER_CONSTRAINTS... >::checkArcReversal(
365  NodeId x,
366  NodeId y) const {
367  return constraints::checkArcReversal(x, y);
368  }
369 
370  /// checks whether the constraints enable to add an arc
371  template < typename CONSTRAINT1, typename... OTHER_CONSTRAINTS >
372  INLINE bool
373  StructuralConstraintSetStatic< CONSTRAINT1, OTHER_CONSTRAINTS... >::checkModification(
374  const ArcAddition& change) const {
375  return constraints::checkModification(change);
376  }
377 
378  /// checks whether the constraints enable to remove an arc
379  template < typename CONSTRAINT1, typename... OTHER_CONSTRAINTS >
380  INLINE bool
381  StructuralConstraintSetStatic< CONSTRAINT1, OTHER_CONSTRAINTS... >::checkModification(
382  const ArcDeletion& change) const {
383  return constraints::checkModification(change);
384  }
385 
386  /// checks whether the constraints enable to reverse an arc
387  template < typename CONSTRAINT1, typename... OTHER_CONSTRAINTS >
388  INLINE bool
389  StructuralConstraintSetStatic< CONSTRAINT1, OTHER_CONSTRAINTS... >::checkModification(
390  const ArcReversal& change) const {
391  return constraints::checkModification(change);
392  }
393 
394  /// checks whether the constraints enable to perform a graph change
395  template < typename CONSTRAINT1, typename... OTHER_CONSTRAINTS >
396  INLINE bool
397  StructuralConstraintSetStatic< CONSTRAINT1, OTHER_CONSTRAINTS... >::checkModification(
398  const GraphChange& change) const {
399  return constraints::checkModification(change);
400  }
401 
402  /// notify the constraint of a modification of the graph
403  template < typename CONSTRAINT1, typename... OTHER_CONSTRAINTS >
404  INLINE void StructuralConstraintSetStatic< CONSTRAINT1, OTHER_CONSTRAINTS... >::modifyGraph(
405  const ArcAddition& change) {
406  if (checkModification(change)) {
407  constraints::modifyGraph(change);
408  } else {
409  GUM_ERROR(OperationNotAllowed,
410  "the constraint set does not allow this arc addition between "
411  << change.node1() << " and " << change.node2());
412  }
413  }
414 
415  /// notify the constraint of a modification of the graph
416  template < typename CONSTRAINT1, typename... OTHER_CONSTRAINTS >
417  INLINE void StructuralConstraintSetStatic< CONSTRAINT1, OTHER_CONSTRAINTS... >::modifyGraph(
418  const ArcDeletion& change) {
419  if (checkModification(change)) {
420  constraints::modifyGraph(change);
421  } else {
422  GUM_ERROR(OperationNotAllowed,
423  "the constraint set does not allow this arc deletion between "
424  << change.node1() << " and " << change.node2());
425  }
426  }
427 
428  /// notify the constraint of a modification of the graph
429  template < typename CONSTRAINT1, typename... OTHER_CONSTRAINTS >
430  INLINE void StructuralConstraintSetStatic< CONSTRAINT1, OTHER_CONSTRAINTS... >::modifyGraph(
431  const ArcReversal& change) {
432  if (checkModification(change)) {
433  constraints::modifyGraph(change);
434  } else {
435  GUM_ERROR(OperationNotAllowed,
436  "the constraint set does not allow this arc reversal between "
437  << change.node1() << " and " << change.node2());
438  }
439  }
440 
441  /// notify the constraint of a modification of the graph
442  template < typename CONSTRAINT1, typename... OTHER_CONSTRAINTS >
443  INLINE void StructuralConstraintSetStatic< CONSTRAINT1, OTHER_CONSTRAINTS... >::modifyGraph(
444  const GraphChange& change) {
445  switch (change.type()) {
446  case GraphChangeType::ARC_ADDITION:
447  modifyGraph(reinterpret_cast< const ArcAddition& >(change));
448  break;
449 
450  case GraphChangeType::ARC_DELETION:
451  modifyGraph(reinterpret_cast< const ArcDeletion& >(change));
452  break;
453 
454  case GraphChangeType::ARC_REVERSAL:
455  modifyGraph(reinterpret_cast< const ArcReversal& >(change));
456  break;
457 
458  default:
459  GUM_ERROR(OperationNotAllowed,
460  "edge modifications are not "
461  "currently supported by constraint sets");
462  }
463  }
464 
465  /// indicates whether a change will always violate the constraint
466  template < typename CONSTRAINT1, typename... OTHER_CONSTRAINTS >
467  INLINE bool StructuralConstraintSetStatic< CONSTRAINT1, OTHER_CONSTRAINTS... >::isAlwaysInvalid(
468  const GraphChange& change) const {
469  return constraints::isAlwaysInvalid(change);
470  }
471 
472  // ===========================================================================
473 
474  /// default constructor
475  template < typename CONSTRAINT >
476  INLINE StructuralConstraintSetStatic< CONSTRAINT >::StructuralConstraintSetStatic() {
477  GUM_CONSTRUCTOR(StructuralConstraintSetStatic);
478  }
479 
480  /// copy constructor
481  template < typename CONSTRAINT >
482  INLINE StructuralConstraintSetStatic< CONSTRAINT >::StructuralConstraintSetStatic(
483  const StructuralConstraintSetStatic< CONSTRAINT >& from) :
484  constraints(from) {
485  GUM_CONS_CPY(StructuralConstraintSetStatic);
486  }
487 
488  /// destructor
489  template < typename CONSTRAINT >
490  INLINE StructuralConstraintSetStatic< CONSTRAINT >::~StructuralConstraintSetStatic() {
491  GUM_DESTRUCTOR(StructuralConstraintSetStatic);
492  }
493 
494  /// copy operator
495  template < typename CONSTRAINT >
496  INLINE StructuralConstraintSetStatic< CONSTRAINT >&
497  StructuralConstraintSetStatic< CONSTRAINT >::operator=(
498  const StructuralConstraintSetStatic< CONSTRAINT >& from) {
499  if (this != &from) { constraints::operator=(from); }
500 
501  return *this;
502  }
503 
504  /// sets a new graph from which we will perform checkings
505  template < typename CONSTRAINT >
506  INLINE void StructuralConstraintSetStatic< CONSTRAINT >::setGraph(const DiGraph& graph) {
507  constraints::setGraph(graph);
508  }
509 
510  /// checks whether the constraints enable to add arc (x,y)
511  template < typename CONSTRAINT >
512  INLINE bool StructuralConstraintSetStatic< CONSTRAINT >::checkArcAddition(NodeId x,
513  NodeId y) const {
514  return constraints::checkArcAddition(x, y);
515  }
516 
517  /// checks whether the constraints enable to remove arc (x,y)
518  template < typename CONSTRAINT >
519  INLINE bool StructuralConstraintSetStatic< CONSTRAINT >::checkArcDeletion(NodeId x,
520  NodeId y) const {
521  return constraints::checkArcDeletion(x, y);
522  }
523 
524  /// checks whether the constraints enable to reverse arc (x,y)
525  template < typename CONSTRAINT >
526  INLINE bool StructuralConstraintSetStatic< CONSTRAINT >::checkArcReversal(NodeId x,
527  NodeId y) const {
528  return constraints::checkArcReversal(x, y);
529  }
530 
531  /// checks whether the constraints enable to add an arc
532  template < typename CONSTRAINT >
533  INLINE bool StructuralConstraintSetStatic< CONSTRAINT >::checkModification(
534  const ArcAddition& change) const {
535  return constraints::checkModification(change);
536  }
537 
538  /// checks whether the constraints enable to remove an arc
539  template < typename CONSTRAINT >
540  INLINE bool StructuralConstraintSetStatic< CONSTRAINT >::checkModification(
541  const ArcDeletion& change) const {
542  return constraints::checkModification(change);
543  }
544 
545  /// checks whether the constraints enable to reverse an arc
546  template < typename CONSTRAINT >
547  INLINE bool StructuralConstraintSetStatic< CONSTRAINT >::checkModification(
548  const ArcReversal& change) const {
549  return constraints::checkModification(change);
550  }
551 
552  /// checks whether the constraints enable to perform a graph change
553  template < typename CONSTRAINT >
554  INLINE bool StructuralConstraintSetStatic< CONSTRAINT >::checkModification(
555  const GraphChange& change) const {
556  return constraints::checkModification(change);
557  }
558 
559  /// notify the constraint of a modification of the graph
560  template < typename CONSTRAINT >
561  INLINE void
562  StructuralConstraintSetStatic< CONSTRAINT >::modifyGraph(const ArcAddition& change) {
563  if (checkModification(change)) {
564  constraints::modifyGraph(change);
565  } else {
566  GUM_ERROR(OperationNotAllowed,
567  "the constraint set does not allow this arc addition between "
568  << change.node1() << " and " << change.node2());
569  }
570  }
571 
572  /// notify the constraint of a modification of the graph
573  template < typename CONSTRAINT >
574  INLINE void
575  StructuralConstraintSetStatic< CONSTRAINT >::modifyGraph(const ArcDeletion& change) {
576  if (checkModification(change)) {
577  constraints::modifyGraph(change);
578  } else {
579  GUM_ERROR(OperationNotAllowed,
580  "the constraint set does not allow this arc deletion between "
581  << change.node1() << " and " << change.node2());
582  }
583  }
584 
585  /// notify the constraint of a modification of the graph
586  template < typename CONSTRAINT >
587  INLINE void
588  StructuralConstraintSetStatic< CONSTRAINT >::modifyGraph(const ArcReversal& change) {
589  if (checkModification(change)) {
590  constraints::modifyGraph(change);
591  } else {
592  GUM_ERROR(OperationNotAllowed,
593  "the constraint set does not allow this arc reversal between "
594  << change.node1() << " and " << change.node2());
595  }
596  }
597 
598  /// notify the constraint of a modification of the graph
599  template < typename CONSTRAINT >
600  INLINE void
601  StructuralConstraintSetStatic< CONSTRAINT >::modifyGraph(const GraphChange& change) {
602  switch (change.type()) {
603  case GraphChangeType::ARC_ADDITION:
604  modifyGraph(reinterpret_cast< const ArcAddition& >(change));
605  break;
606 
607  case GraphChangeType::ARC_DELETION:
608  modifyGraph(reinterpret_cast< const ArcDeletion& >(change));
609  break;
610 
611  case GraphChangeType::ARC_REVERSAL:
612  modifyGraph(reinterpret_cast< const ArcReversal& >(change));
613  break;
614 
615  default:
616  GUM_ERROR(OperationNotAllowed,
617  "edge modifications are not "
618  "currently supported by constraint sets");
619  }
620  }
621 
622  /// indicates whether a change will always violate the constraint
623  template < typename CONSTRAINT >
624  INLINE bool StructuralConstraintSetStatic< CONSTRAINT >::isAlwaysInvalid(
625  const GraphChange& change) const {
626  return constraints::isAlwaysInvalid(change);
627  }
628 
629  } /* namespace learning */
630 
631 } /* namespace gum */
632 
633 #endif /* DOXYGEN_SHOULD_SKIP_THIS */