aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
structuralConstraintSliceOrder_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 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
47 
48  /// checks whether the constraints enable to add arc (x,y)
50  try {
52  } catch (const Exception&) { return true; }
53  }
54 
55  /// checks whether the constraints enable to remove arc (x,y)
57  return true;
58  }
59 
60  /// checks whether the constraints enable to reverse arc (x,y)
62  try {
64  } catch (const Exception&) { return true; }
65  }
66 
67  /// notify the constraint of a modification of the graph
69 
70  /// notify the constraint of a modification of the graph
72 
73  /// notify the constraint of a modification of the graph
75 
76  /// notify the constraint of a modification of the graph
78 
79  /// indicates whether a change will always violate the constraint
80  INLINE bool
82  switch (change.type()) {
84  try {
86  } catch (const Exception&) { return false; }
87 
89  return false;
90 
92  try {
94  } catch (const Exception&) { return false; }
95 
96  default:
98  "edge modifications are not "
99  "supported by SliceOrder constraints");
100  }
101  }
102 
103  /// checks whether the constraints enable to add an arc
104  INLINE bool
107  }
108 
109  /// checks whether the constraints enable to remove an arc
110  INLINE bool
113  }
114 
115  /// checks whether the constraints enable to reverse an arc
116  INLINE bool
119  }
120 
121  /// checks whether the constraints enable to perform a graph change
122  INLINE bool
124  switch (change.type()) {
127 
130 
133 
134  default:
136  "edge modifications are not "
137  "supported by StructuralConstraintSliceOrder");
138  }
139  }
140 
141  /// sets the time slices of all the nodes in the property
144  }
145 
146  /// sets the default time slice
148  for (auto& node: _SliceOrder_order_) {
149  node.second = slice;
150  }
151  }
152 
153  /// adds a new node in the slice order
156  }
157 
158  /// returns the current slice order
160  return _SliceOrder_order_;
161  }
162 
163 // include all the methods applicable to the whole class hierarchy
164 # define GUM_CONSTRAINT_CLASS_NAME StructuralConstraintSliceOrder
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)