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