aGrUM  0.20.2
a C++ library for (probabilistic) graphical models
structuralConstraintPatternInline.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 // this file should be included at the end of the StructuralConstraints inline
23 // files (see StructuralConstraintDAG to see how it should be included).
24 // This concerns only StructuralConstraints that derive from other
25 // StructuralConstraints. If your class does not derive from anoter constraint,
26 // include file StructuralConstraintPatternRootInline.h instead.
27 
28 #ifdef GUM_CONSTRAINT_CLASS_NAME
29 
30 /// sets a new graph from which we will perform checkings
31 INLINE void GUM_CONSTRAINT_CLASS_NAME::setGraph(const DiGraph& graph) {
32  constraints::setGraph(graph);
33  setGraphAlone(graph);
34 }
35 
36 /// checks whether the constraints enable to add arc (x,y)
37 INLINE bool GUM_CONSTRAINT_CLASS_NAME::checkArcAddition(NodeId x, NodeId y) const {
38  return constraints::checkArcAddition(x, y) && checkArcAdditionAlone(x, y);
39 }
40 
41 /// checks whether the constraints enable to remove arc (x,y)
42 INLINE bool GUM_CONSTRAINT_CLASS_NAME::checkArcDeletion(NodeId x, NodeId y) const {
43  return constraints::checkArcDeletion(x, y) && checkArcDeletionAlone(x, y);
44 }
45 
46 /// checks whether the constraints enable to reverse arc (x,y)
47 INLINE bool GUM_CONSTRAINT_CLASS_NAME::checkArcReversal(NodeId x, NodeId y) const {
48  return constraints::checkArcReversal(x, y) && checkArcReversalAlone(x, y);
49 }
50 
51 /// notify the constraint of a modification of the graph
52 INLINE void GUM_CONSTRAINT_CLASS_NAME::modifyGraph(const ArcAddition& change) {
53  constraints::modifyGraph(change);
54  modifyGraphAlone(change);
55 }
56 
57 /// notify the constraint of a modification of the graph
58 INLINE void GUM_CONSTRAINT_CLASS_NAME::modifyGraph(const ArcDeletion& change) {
59  constraints::modifyGraph(change);
60  modifyGraphAlone(change);
61 }
62 
63 /// notify the constraint of a modification of the graph
64 INLINE void GUM_CONSTRAINT_CLASS_NAME::modifyGraph(const ArcReversal& change) {
65  constraints::modifyGraph(change);
66  modifyGraphAlone(change);
67 }
68 
69 /// notify the constraint of a modification of the graph
70 INLINE void GUM_CONSTRAINT_CLASS_NAME::modifyGraph(const GraphChange& change) {
71  constraints::modifyGraph(change);
72  modifyGraphAlone(change);
73 }
74 
75 /// indicates whether a change will always violate the constraint
76 INLINE bool
77  GUM_CONSTRAINT_CLASS_NAME::isAlwaysInvalid(const GraphChange& change) const {
78  return constraints::isAlwaysInvalid(change) || isAlwaysInvalidAlone(change);
79 }
80 
81 /// checks whether the constraints enable to add an arc
82 INLINE bool
83  GUM_CONSTRAINT_CLASS_NAME::checkModification(const ArcAddition& change) const {
84  return checkArcAddition(change.node1(), change.node2());
85 }
86 
87 /// checks whether the constraints enable to remove an arc
88 INLINE bool
89  GUM_CONSTRAINT_CLASS_NAME::checkModification(const ArcDeletion& change) const {
90  return checkArcDeletion(change.node1(), change.node2());
91 }
92 
93 /// checks whether the constraints enable to reverse an arc
94 INLINE bool
95  GUM_CONSTRAINT_CLASS_NAME::checkModification(const ArcReversal& change) const {
96  return checkArcReversal(change.node1(), change.node2());
97 }
98 
99 /// checks whether the constraints enable to perform a graph change
100 INLINE bool
101  GUM_CONSTRAINT_CLASS_NAME::checkModification(const GraphChange& change) const {
102  switch (change.type()) {
103  case GraphChangeType::ARC_ADDITION:
104  return checkArcAddition(change.node1(), change.node2());
105 
106  case GraphChangeType::ARC_DELETION:
107  return checkArcDeletion(change.node1(), change.node2());
108 
109  case GraphChangeType::ARC_REVERSAL:
110  return checkArcReversal(change.node1(), change.node2());
111 
112  default:
113  GUM_ERROR(OperationNotAllowed,
114  "edge modifications are not supported by the constraint");
115  }
116 }
117 
118 #endif /* GUM_CONSTRAINT_CLASS_NAME */