aGrUM  0.20.2
a C++ library for (probabilistic) graphical models
structuralConstraintDAG_inl.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 /** @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)
64  NodeId y) const {
66  }
67 
68  /// checks whether the constraints enable to remove arc (x,y)
70  NodeId y) const {
72  }
73 
74  /// checks whether the constraints enable to reverse arc (x,y)
76  NodeId y) const {
78  }
79 
80  /// checks whether the constraints enable to add an arc
82  const ArcAddition& change) const {
84  }
85 
86  /// checks whether the constraints enable to remove an arc
88  const ArcDeletion& change) const {
90  }
91 
92  /// checks whether the constraints enable to reverse an arc
94  const ArcReversal& change) const {
96  }
97 
98  /// checks whether the constraints enable to perform a graph change
100  const GraphChange& change) const {
101  switch (change.type()) {
104 
107 
110 
111  default:
113  "edge modifications are not "
114  "supported by StructuralConstraintDAG");
115  }
116  }
117 
118  /// notify the constraint of a modification of the graph
119  INLINE void
122  }
123 
124  /// notify the constraint of a modification of the graph
125  INLINE void
128  }
129 
130  /// notify the constraint of a modification of the graph
131  INLINE void
134  }
135 
136  /// notify the constraint of a modification of the graph
137  INLINE void
139  switch (change.type()) {
141  modifyGraphAlone(reinterpret_cast< const ArcAddition& >(change));
142  break;
143 
145  modifyGraphAlone(reinterpret_cast< const ArcDeletion& >(change));
146  break;
147 
149  modifyGraphAlone(reinterpret_cast< const ArcReversal& >(change));
150  break;
151 
152  default:
154  "edge modifications are not supported by DAG constraints");
155  }
156  }
157 
158  /// indicates whether a change will always violate the constraint
159  INLINE bool
161  return false;
162  }
163 
164  /// sets a new graph from which we will perform checkings
168  }
169 
170  /// sets a new graph from which we will perform checkings
174  }
175 
176 // include all the methods applicable to the whole class hierarchy
177 # define GUM_CONSTRAINT_CLASS_NAME StructuralConstraintDAG
178 # include <agrum/BN/learning/constraints/structuralConstraintPatternInline.h>
179 # undef GUM_CONSTRAINT_CLASS_NAME
180 
181  } /* namespace learning */
182 
183 } /* namespace gum */
184 
185 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:669
Database(const std::string &filename, const BayesNet< GUM_SCALAR > &bn, const std::vector< std::string > &missing_symbols)