aGrUM  0.20.2
a C++ library for (probabilistic) graphical models
structuralConstraintPattern4UndiGraphInline.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 StructuralConstraintDegree 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 StructuralConstraintPattern4UndiGraphRootInline.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 UndiGraph& graph) {
32  constraints::setGraph(graph);
33  setGraphAlone(graph);
34 }
35 
36 /// checks whether the constraints enable to add edge (x,y)
37 INLINE bool GUM_CONSTRAINT_CLASS_NAME::checkEdgeAddition(NodeId x,
38  NodeId y) const {
39  return constraints::checkEdgeAddition(x, y) && checkEdgeAdditionAlone(x, y);
40 }
41 
42 /// checks whether the constraints enable to remove edge (x,y)
43 INLINE bool GUM_CONSTRAINT_CLASS_NAME::checkEdgeDeletion(NodeId x,
44  NodeId y) const {
45  return constraints::checkEdgeDeletion(x, y) && checkEdgeDeletionAlone(x, y);
46 }
47 
48 /// notify the constraint of a modification of the graph
49 INLINE void GUM_CONSTRAINT_CLASS_NAME::modifyGraph(const EdgeAddition& change) {
50  constraints::modifyGraph(change);
51  modifyGraphAlone(change);
52 }
53 
54 /// notify the constraint of a modification of the graph
55 INLINE void GUM_CONSTRAINT_CLASS_NAME::modifyGraph(const EdgeDeletion& change) {
56  constraints::modifyGraph(change);
57  modifyGraphAlone(change);
58 }
59 
60 /// notify the constraint of a modification of the graph
61 INLINE void GUM_CONSTRAINT_CLASS_NAME::modifyGraph(const GraphChange& change) {
62  constraints::modifyGraph(change);
63  modifyGraphAlone(change);
64 }
65 
66 /// indicates whether a change will always violate the constraint
67 INLINE bool GUM_CONSTRAINT_CLASS_NAME::isAlwaysInvalid(const GraphChange&) const {
68  return constraints::isAlwaysInvalid(change) || isAlwaysInvalidAlone(change);
69 }
70 
71 /// checks whether the constraints enable to add an edge
72 INLINE bool
73  GUM_CONSTRAINT_CLASS_NAME::checkModification(const EdgeAddition& change) const {
74  return checkEdgeAddition(change.node1(), change.node2());
75 }
76 
77 /// checks whether the constraints enable to remove an edge
78 INLINE bool
79  GUM_CONSTRAINT_CLASS_NAME::checkModification(const EdgeDeletion& change) const {
80  return checkEdgeDeletion(change.node1(), change.node2());
81 }
82 
83 /// checks whether the constraints enable to perform a graph change
84 INLINE bool
85  GUM_CONSTRAINT_CLASS_NAME::checkModification(const GraphChange& change) const {
86  switch (change.type()) {
87  case GraphChangeType::EDGE_ADDITION:
88  return checkEdgeAddition(change.node1(), change.node2());
89 
90  case GraphChangeType::EDGE_DELETION:
91  return checkEdgeDeletion(change.node1(), change.node2());
92 
93  default:
94  GUM_ERROR(OperationNotAllowed,
95  "arc modifications are not supported by the constraint");
96  }
97 }
98 
99 #endif /* GUM_CONSTRAINT_CLASS_NAME */