aGrUM  0.20.2
a C++ library for (probabilistic) graphical models
structuralConstraintSliceOrder_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 structural constraint imposing a partial order over nodes
24  *
25  * In DBNs, it is forbidden to add arcs from nodes at time slice t to nodes at
26  * time slice s, where s < t. This class allows for taking this kind of
27  *constraint
28  * into account by imposing a partial order over the nodes: arcs (X,Y) can then
29  * only be added if X <= Y in the partial order.
30  * @warning: there may exist free variables, that is variables whose order
31  * w.r.t. the other variables is unspecified. In this case, arcs adjacent
32  * to them can be constructed. The partial order is specified by assigning
33  * numbers to nodes (through a NodeProperty). Nodes without number (i.e., that
34  * do not belong to the property) are free.
35  *
36  * @author Christophe GONZALES(@AMU) and Pierre-Henri WUILLEMIN(@LIP6)
37  */
38 
39 #ifndef DOXYGEN_SHOULD_SKIP_THIS
40 
41 namespace gum {
42 
43  namespace learning {
44 
45  /// sets a new graph from which we will perform checkings
46  INLINE void
48 
49  /// checks whether the constraints enable to add arc (x,y)
50  INLINE bool
52  NodeId y) const {
53  try {
55  } catch (const Exception&) { return true; }
56  }
57 
58  /// checks whether the constraints enable to remove arc (x,y)
59  INLINE bool
61  NodeId y) const {
62  return true;
63  }
64 
65  /// checks whether the constraints enable to reverse arc (x,y)
66  INLINE bool
68  NodeId y) const {
69  try {
71  } catch (const Exception&) { return true; }
72  }
73 
74  /// notify the constraint of a modification of the graph
76  const ArcAddition& change) {}
77 
78  /// notify the constraint of a modification of the graph
80  const ArcDeletion& change) {}
81 
82  /// notify the constraint of a modification of the graph
84  const ArcReversal& change) {}
85 
86  /// notify the constraint of a modification of the graph
88  const GraphChange& change) {}
89 
90  /// indicates whether a change will always violate the constraint
92  const GraphChange& change) const {
93  switch (change.type()) {
95  try {
98  } catch (const Exception&) { return false; }
99 
101  return false;
102 
104  try {
105  return (SliceOrder__order_[change.node1()]
107  } catch (const Exception&) { return false; }
108 
109  default:
111  "edge modifications are not "
112  "supported by SliceOrder constraints");
113  }
114  }
115 
116  /// checks whether the constraints enable to add an arc
118  const ArcAddition& change) const {
120  }
121 
122  /// checks whether the constraints enable to remove an arc
124  const ArcDeletion& change) const {
126  }
127 
128  /// checks whether the constraints enable to reverse an arc
130  const ArcReversal& change) const {
132  }
133 
134  /// checks whether the constraints enable to perform a graph change
136  const GraphChange& change) const {
137  switch (change.type()) {
140 
143 
146 
147  default:
149  "edge modifications are not "
150  "supported by StructuralConstraintSliceOrder");
151  }
152  }
153 
154  /// sets the time slices of all the nodes in the property
156  const NodeProperty< NodeId >& order) {
158  }
159 
160  /// sets the default time slice
162  for (auto& node: SliceOrder__order_) {
163  node.second = slice;
164  }
165  }
166 
167  /// adds a new node in the slice order
169  NodeId slice) {
171  }
172 
173  /// returns the current slice order
174  INLINE const NodeProperty< NodeId >&
176  return SliceOrder__order_;
177  }
178 
179 // include all the methods applicable to the whole class hierarchy
180 # define GUM_CONSTRAINT_CLASS_NAME StructuralConstraintSliceOrder
181 # include <agrum/BN/learning/constraints/structuralConstraintPatternInline.h>
182 # undef GUM_CONSTRAINT_CLASS_NAME
183 
184  } /* namespace learning */
185 
186 } /* namespace gum */
187 
188 #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)