aGrUM  0.21.0
a C++ library for (probabilistic) graphical models
structuralConstraintPatternHeader.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 all the StructuralConstraints
23 // header files (see StructuralConstraintDAG to see how it should be included).
24 
25 #ifdef GUM_CONSTRAINT_CLASS_NAME
26 
27 // ##########################################################################
28 /// @name Accessors / Modifiers
29 // ##########################################################################
30 /// @{
31 
32 /// sets a new graph from which we will perform checkings
33 void setGraph(const DiGraph& graph);
34 
35 /// notify the constraint of a modification of the graph
36 /** @warning If an already existing arc is added nothing is done. In
37  * particular, no exception is raised. */
38 void modifyGraph(const ArcAddition& change);
39 
40 /// notify the constraint of a modification of the graph
41 /** @warning If a nonexisting arc is removed, nothing is done. In
42  * particular, no exception is raised. */
43 void modifyGraph(const ArcDeletion& change);
44 
45 /// notify the constraint of a modification of the graph
46 /** @warning If an already existing arc is added, or if a nonexisting arc
47  * is removed, nothing is done. In particular, no exception is raised. */
48 void modifyGraph(const ArcReversal& change);
49 
50 /// notify the constraint of a modification of the graph
51 /** @warning If an already existing arc is added, or if a nonexisting arc
52  * is removed, nothing is done. In particular, no exception is raised. */
53 void modifyGraph(const GraphChange& change);
54 
55 /// indicates whether a change will always violate the constraint
56 /** Some learning algorithms need examine several times whether a given
57  * graph change can be applied. For instance, the first time arc (X,Y)
58  * addition is considered, the learning algorithm may discard this change
59  * because it violates the structural constraint (e.g., if the latter
60  * enforces a DAG structure, this arc addition might induce a directed
61  * cycle), but, later on, other arc removal may induce that the arc addition
62  * is now possible. Such change is thus not always invalid. Conversely,
63  * there are changes that can be discarded once and for all. For instance,
64  * in a 2TBN structure, it is always impossible to add a backward-time arc.
65  * Such graph changes are always invalid and are therefore tagged as such
66  * by the isAlwaysInvalid method. */
67 bool isAlwaysInvalid(const GraphChange& change) const;
68 
69 /// checks whether the constraints enable to add arc (x,y)
70 bool checkArcAddition(NodeId x, NodeId y) const;
71 
72 /// checks whether the constraints enable to remove arc (x,y)
73 bool checkArcDeletion(NodeId x, NodeId y) const;
74 
75 /// checks whether the constraints enable to reverse arc (x,y)
76 bool checkArcReversal(NodeId x, NodeId y) const;
77 
78 /// checks whether the constraints enable to add an arc
79 bool checkModification(const ArcAddition& change) const;
80 
81 /// checks whether the constraints enable to remove an arc
82 bool checkModification(const ArcDeletion& change) const;
83 
84 /// checks whether the constraints enable to reverse an arc
85 bool checkModification(const ArcReversal& change) const;
86 
87 /// checks whether the constraints enable to perform a graph change
88 bool checkModification(const GraphChange& change) const;
89 
90 /// @}
91 
92 #endif /* GUM_CONSTRAINT_CLASS_NAME */