40 #ifndef GUM_LEARNING_STRUCTURAL_CONSTRAINT_SET_STATIC_H 41 #define GUM_LEARNING_STRUCTURAL_CONSTRAINT_SET_STATIC_H 43 #include <type_traits> 45 #include <agrum/agrum.h> 46 #include <agrum/tools/graphs/diGraph.h> 47 #include <agrum/BN/learning/structureUtils/graphChange.h> 53 #ifndef DOXYGEN_SHOULD_SKIP_THIS 57 struct StructuralRoot__ {};
61 template <
typename FIRST_CONSTRAINT,
typename... OTHER_CONSTRAINTS >
62 struct ConstraintSet__;
66 template <
typename SET1,
typename SET2 >
67 struct ConcatConstraintSet__;
72 template <
typename FIRST_CONSTRAINT,
typename... OTHER_CONSTRAINTS >
73 class StructuralConstraintSetStatic__;
78 template <
typename CONSTRAINT,
typename SET >
79 struct IsInConstraintSet__;
81 template <
typename CONSTRAINT,
typename SET >
82 struct IsInConstraintSet__< CONSTRAINT, ConstraintSet__< SET > > {
83 constexpr static bool value = std::is_same< CONSTRAINT, SET >::value;
86 template <
typename CONSTRAINT,
typename SET1,
typename... SETS >
87 struct IsInConstraintSet__< CONSTRAINT, ConstraintSet__< SET1, SETS... > > {
88 constexpr static bool value
89 = std::is_same< CONSTRAINT, SET1 >::value
90 || IsInConstraintSet__< CONSTRAINT, ConstraintSet__< SETS... > >::value;
104 template <
typename FIRST_CONSTRAINT,
typename... OTHER_CONSTRAINTS >
105 struct ConstraintSet__:
public ConstraintSet__< OTHER_CONSTRAINTS... > {
106 using minset =
typename std::conditional<
107 IsInConstraintSet__< FIRST_CONSTRAINT,
108 ConstraintSet__< OTHER_CONSTRAINTS... > >::value,
109 typename ConstraintSet__< OTHER_CONSTRAINTS... >::minset,
110 typename ConcatConstraintSet__<
112 typename ConstraintSet__< OTHER_CONSTRAINTS... >::minset >::type >::
114 using set = StructuralConstraintSetStatic__< FIRST_CONSTRAINT,
115 OTHER_CONSTRAINTS... >;
118 template <
typename CONSTRAINT >
119 struct ConstraintSet__< CONSTRAINT > {
120 using minset = ConstraintSet__< CONSTRAINT >;
121 using set = StructuralConstraintSetStatic__< CONSTRAINT >;
127 template <
typename SET1,
typename SET2 >
128 struct ConcatConstraintSet__;
130 template <
typename CONSTRAINT1,
typename CONSTRAINT2 >
131 struct ConcatConstraintSet__< CONSTRAINT1, ConstraintSet__< CONSTRAINT2 > > {
132 using type = ConstraintSet__< CONSTRAINT1, CONSTRAINT2 >;
135 template <
typename CONSTRAINT1,
typename CONSTRAINT2 >
136 struct ConcatConstraintSet__< ConstraintSet__< CONSTRAINT1 >,
137 ConstraintSet__< CONSTRAINT2 > > {
138 using type = ConstraintSet__< CONSTRAINT1, CONSTRAINT2 >;
141 template <
typename CONSTRAINT1,
142 typename CONSTRAINT2,
143 typename... OTHER_CONSTRAINT2 >
144 struct ConcatConstraintSet__<
146 ConstraintSet__< CONSTRAINT2, OTHER_CONSTRAINT2... > > {
148 = ConstraintSet__< CONSTRAINT1, CONSTRAINT2, OTHER_CONSTRAINT2... >;
151 template <
typename CONSTRAINT1,
152 typename CONSTRAINT2,
153 typename... OTHER_CONSTRAINT1 >
154 struct ConcatConstraintSet__<
155 ConstraintSet__< CONSTRAINT1, OTHER_CONSTRAINT1... >,
156 ConstraintSet__< CONSTRAINT2 > > {
158 = ConstraintSet__< CONSTRAINT1, OTHER_CONSTRAINT1..., CONSTRAINT2 >;
161 template <
typename CONSTRAINT1,
162 typename CONSTRAINT2,
163 typename... OTHER_CONSTR1,
164 typename... OTHER_CONSTR2 >
165 struct ConcatConstraintSet__<
166 ConstraintSet__< CONSTRAINT1, OTHER_CONSTR1... >,
167 ConstraintSet__< CONSTRAINT2, OTHER_CONSTR2... > > {
168 using type = ConstraintSet__< CONSTRAINT1,
178 template <
typename CONSTRAINT1,
typename... OTHER_CONSTRAINTS >
179 class StructuralConstraintSetStatic__:
180 public virtual CONSTRAINT1,
181 public virtual StructuralConstraintSetStatic__< OTHER_CONSTRAINTS... > {
184 using first_constraint = CONSTRAINT1;
187 using next_constraints
188 = StructuralConstraintSetStatic__< OTHER_CONSTRAINTS... >;
192 using allConstraints =
typename ConcatConstraintSet__<
193 typename std::conditional<
194 std::is_base_of< StructuralRoot__, CONSTRAINT1 >::value,
195 typename ConcatConstraintSet__<
197 typename CONSTRAINT1::allConstraints >::type,
198 ConstraintSet__< CONSTRAINT1 > >::type,
199 typename next_constraints::allConstraints >::type;
209 using minConstraints =
typename allConstraints::minset::set;
217 StructuralConstraintSetStatic__();
220 StructuralConstraintSetStatic__(
221 const StructuralConstraintSetStatic__< CONSTRAINT1,
222 OTHER_CONSTRAINTS... >&);
225 ~StructuralConstraintSetStatic__();
235 StructuralConstraintSetStatic__< CONSTRAINT1, OTHER_CONSTRAINTS... >&
236 operator=(
const StructuralConstraintSetStatic__< CONSTRAINT1,
237 OTHER_CONSTRAINTS... >&);
247 void setGraph(
const DiGraph& graph);
250 void modifyGraph(
const ArcAddition& change);
253 void modifyGraph(
const ArcDeletion& change);
256 void modifyGraph(
const ArcReversal& change);
259 void modifyGraph(
const GraphChange& change);
262 bool isAlwaysInvalid(
const GraphChange& change)
const;
265 bool checkArcAddition(NodeId x, NodeId y)
const;
268 bool checkArcDeletion(NodeId x, NodeId y)
const;
271 bool checkArcReversal(NodeId x, NodeId y)
const;
274 bool checkModification(
const ArcAddition& change)
const;
277 bool checkModification(
const ArcDeletion& change)
const;
280 bool checkModification(
const ArcReversal& change)
const;
283 bool checkModification(
const GraphChange& change)
const;
288 template <
typename CONSTRAINT >
289 class StructuralConstraintSetStatic__< CONSTRAINT >:
290 public virtual CONSTRAINT,
291 public virtual StructuralRoot__ {
294 using first_constraint = CONSTRAINT;
297 using next_constraints = StructuralRoot__;
303 using allConstraints =
typename std::conditional<
304 std::is_base_of< StructuralRoot__, CONSTRAINT >::value,
305 typename ConcatConstraintSet__<
307 typename CONSTRAINT::allConstraints >::type,
308 ConstraintSet__< CONSTRAINT > >::type;
318 using minConstraints =
typename allConstraints::minset::set;
326 StructuralConstraintSetStatic__();
329 StructuralConstraintSetStatic__(
330 const StructuralConstraintSetStatic__< CONSTRAINT >&);
333 ~StructuralConstraintSetStatic__();
343 StructuralConstraintSetStatic__< CONSTRAINT >&
344 operator=(
const StructuralConstraintSetStatic__< CONSTRAINT >&);
354 void setGraph(
const DiGraph& graph);
357 void modifyGraph(
const ArcAddition& change);
360 void modifyGraph(
const ArcDeletion& change);
363 void modifyGraph(
const ArcReversal& change);
366 void modifyGraph(
const GraphChange& change);
369 bool isAlwaysInvalid(
const GraphChange& change)
const;
372 bool checkArcAddition(NodeId x, NodeId y)
const;
375 bool checkArcDeletion(NodeId x, NodeId y)
const;
378 bool checkArcReversal(NodeId x, NodeId y)
const;
381 bool checkModification(
const ArcAddition& change)
const;
384 bool checkModification(
const ArcDeletion& change)
const;
387 bool checkModification(
const ArcReversal& change)
const;
390 bool checkModification(
const GraphChange& change)
const;
424 template <
typename CONSTRAINT1,
typename... OTHER_CONSTRAINTS >
426 public virtual StructuralConstraintSetStatic__<
428 OTHER_CONSTRAINTS... >::minConstraints {
430 using constraints =
typename StructuralConstraintSetStatic__<
432 OTHER_CONSTRAINTS... >::minConstraints;
445 OTHER_CONSTRAINTS... >&);
460 OTHER_CONSTRAINTS... >&);
470 void setGraph(
const DiGraph& graph);
511 #ifndef DOXYGEN_SHOULD_SKIP_THIS 513 template <
typename CONSTRAINT >
515 public virtual StructuralConstraintSetStatic__<
516 CONSTRAINT >::minConstraints {
519 typename StructuralConstraintSetStatic__< CONSTRAINT >::minConstraints;
527 StructuralConstraintSetStatic();
530 StructuralConstraintSetStatic(
534 ~StructuralConstraintSetStatic();
555 void setGraph(
const DiGraph& graph);
558 void modifyGraph(
const ArcAddition& change);
561 void modifyGraph(
const ArcDeletion& change);
564 void modifyGraph(
const ArcReversal& change);
567 void modifyGraph(
const GraphChange& change);
570 bool isAlwaysInvalid(
const GraphChange& change)
const;
573 bool checkArcAddition(NodeId x, NodeId y)
const;
576 bool checkArcDeletion(NodeId x, NodeId y)
const;
579 bool checkArcReversal(NodeId x, NodeId y)
const;
582 bool checkModification(
const ArcAddition& change)
const;
585 bool checkModification(
const ArcDeletion& change)
const;
588 bool checkModification(
const ArcReversal& change)
const;
591 bool checkModification(
const GraphChange& change)
const;
603 #include <agrum/BN/learning/constraints/structuralConstraintSetStatic_tpl.h> bool isAlwaysInvalid(const GraphChange &change) const
indicates whether a change will always violate the constraint
INLINE void emplace(Args &&... args)
StructuralConstraintSetStatic()
default constructor
StructuralConstraintSetStatic(const StructuralConstraintSetStatic< CONSTRAINT1, OTHER_CONSTRAINTS... > &)
copy constructor
~StructuralConstraintSetStatic()
destructor
bool checkArcDeletion(NodeId x, NodeId y) const
checks whether the constraints enable to remove arc (x,y)
the "meta-programming" class for storing structural constraintsIn aGrUM, there are two ways to store ...
void setGraph(const DiGraph &graph)
sets a new graph from which we will perform checkings
bool checkArcReversal(NodeId x, NodeId y) const
checks whether the constraints enable to reverse arc (x,y)
StructuralConstraintSetStatic< CONSTRAINT1, OTHER_CONSTRAINTS... > & operator=(const StructuralConstraintSetStatic< CONSTRAINT1, OTHER_CONSTRAINTS... > &)
copy operator
bool checkModification(const GraphChange &change) const
checks whether the constraints enable to perform a graph change
Database(const std::string &filename, const BayesNet< GUM_SCALAR > &bn, const std::vector< std::string > &missing_symbols)
bool checkArcAddition(NodeId x, NodeId y) const
checks whether the constraints enable to add arc (x,y)
void modifyGraph(const GraphChange &change)
notify the constraint of a modification of the graph