aGrUM  0.21.0
a C++ library for (probabilistic) graphical models
structuralConstraintPatternInline.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 // 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 GUM_CONSTRAINT_CLASS_NAME::isAlwaysInvalid(const GraphChange& change) const {
77  return constraints::isAlwaysInvalid(change) || isAlwaysInvalidAlone(change);
78 }
79 
80 /// checks whether the constraints enable to add an arc
81 INLINE bool GUM_CONSTRAINT_CLASS_NAME::checkModification(const ArcAddition& change) const {
82  return checkArcAddition(change.node1(), change.node2());
83 }
84 
85 /// checks whether the constraints enable to remove an arc
86 INLINE bool GUM_CONSTRAINT_CLASS_NAME::checkModification(const ArcDeletion& change) const {
87  return checkArcDeletion(change.node1(), change.node2());
88 }
89 
90 /// checks whether the constraints enable to reverse an arc
91 INLINE bool GUM_CONSTRAINT_CLASS_NAME::checkModification(const ArcReversal& change) const {
92  return checkArcReversal(change.node1(), change.node2());
93 }
94 
95 /// checks whether the constraints enable to perform a graph change
96 INLINE bool GUM_CONSTRAINT_CLASS_NAME::checkModification(const GraphChange& change) const {
97  switch (change.type()) {
98  case GraphChangeType::ARC_ADDITION:
99  return checkArcAddition(change.node1(), change.node2());
100 
101  case GraphChangeType::ARC_DELETION:
102  return checkArcDeletion(change.node1(), change.node2());
103 
104  case GraphChangeType::ARC_REVERSAL:
105  return checkArcReversal(change.node1(), change.node2());
106 
107  default:
108  GUM_ERROR(OperationNotAllowed, "edge modifications are not supported by the constraint")
109  }
110 }
111 
112 #endif /* GUM_CONSTRAINT_CLASS_NAME */