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