aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
structuralConstraintDAG_inl.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 /** @file
23  * @brief the base class for structural constraints imposed by DAGs
24  *
25  * @author Christophe GONZALES(@AMU) and Pierre-Henri WUILLEMIN(@LIP6)
26  */
27 #ifndef DOXYGEN_SHOULD_SKIP_THIS
28 
29 # include <agrum/agrum.h>
30 # include <agrum/tools/graphs/algorithms/DAGCycleDetector.h>
31 # include <agrum/BN/learning/constraints/structuralConstraintDiGraph.h>
32 
33 namespace gum {
34 
35  namespace learning {
36 
37  /// sets a new graph from which we will perform checkings
39  // check that the digraph has no cycle
40  DAG g;
41 
42  for (auto node: graph)
44 
45  for (auto& arc: graph.arcs())
46  g.addArc(arc.tail(), arc.head());
47 
49  }
50 
51  /// sets a new graph from which we will perform checkings
53  DAG g;
54 
55  for (NodeId i = 0; i < nb_nodes; ++i) {
56  g.addNodeWithId(i);
57  }
58 
60  }
61 
62  /// checks whether the constraints enable to add arc (x,y)
65  }
66 
67  /// checks whether the constraints enable to remove arc (x,y)
70  }
71 
72  /// checks whether the constraints enable to reverse arc (x,y)
75  }
76 
77  /// checks whether the constraints enable to add an arc
80  }
81 
82  /// checks whether the constraints enable to remove an arc
85  }
86 
87  /// checks whether the constraints enable to reverse an arc
90  }
91 
92  /// checks whether the constraints enable to perform a graph change
94  switch (change.type()) {
97 
100 
103 
104  default:
106  "edge modifications are not "
107  "supported by StructuralConstraintDAG");
108  }
109  }
110 
111  /// notify the constraint of a modification of the graph
114  }
115 
116  /// notify the constraint of a modification of the graph
119  }
120 
121  /// notify the constraint of a modification of the graph
124  }
125 
126  /// notify the constraint of a modification of the graph
128  switch (change.type()) {
130  modifyGraphAlone(reinterpret_cast< const ArcAddition& >(change));
131  break;
132 
134  modifyGraphAlone(reinterpret_cast< const ArcDeletion& >(change));
135  break;
136 
138  modifyGraphAlone(reinterpret_cast< const ArcReversal& >(change));
139  break;
140 
141  default:
142  GUM_ERROR(OperationNotAllowed, "edge modifications are not supported by DAG constraints")
143  }
144  }
145 
146  /// indicates whether a change will always violate the constraint
148  return false;
149  }
150 
151  /// sets a new graph from which we will perform checkings
155  }
156 
157  /// sets a new graph from which we will perform checkings
161  }
162 
163 // include all the methods applicable to the whole class hierarchy
164 # define GUM_CONSTRAINT_CLASS_NAME StructuralConstraintDAG
165 # include <agrum/BN/learning/constraints/structuralConstraintPatternInline.h>
166 # undef GUM_CONSTRAINT_CLASS_NAME
167 
168  } /* namespace learning */
169 
170 } /* namespace gum */
171 
172 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:643
Database(const std::string &filename, const BayesNet< GUM_SCALAR > &bn, const std::vector< std::string > &missing_symbols)