60#ifndef GUM_LEARNING_STRUCTURAL_CONSTRAINT_SET_STATIC_H
61#define GUM_LEARNING_STRUCTURAL_CONSTRAINT_SET_STATIC_H
74#ifndef DOXYGEN_SHOULD_SKIP_THIS
78 struct _StructuralRoot_ {};
82 template <
typename FIRST_CONSTRAINT,
typename... OTHER_CONSTRAINTS >
83 struct _ConstraintSet_;
87 template <
typename SET1,
typename SET2 >
88 struct _ConcatConstraintSet_;
93 template <
typename FIRST_CONSTRAINT,
typename... OTHER_CONSTRAINTS >
94 class _StructuralConstraintSetStatic_;
99 template <
typename CONSTRAINT,
typename SET >
100 struct _IsInConstraintSet_;
102 template <
typename CONSTRAINT,
typename SET >
103 struct _IsInConstraintSet_< CONSTRAINT, _ConstraintSet_< SET > > {
104 constexpr static bool value = std::is_same< CONSTRAINT, SET >::value;
107 template <
typename CONSTRAINT,
typename SET1,
typename... SETS >
108 struct _IsInConstraintSet_< CONSTRAINT, _ConstraintSet_< SET1, SETS... > > {
109 constexpr static bool value
110 = std::is_same< CONSTRAINT, SET1 >::value
111 || _IsInConstraintSet_< CONSTRAINT, _ConstraintSet_< SETS... > >::value;
125 template <
typename FIRST_CONSTRAINT,
typename... OTHER_CONSTRAINTS >
126 struct _ConstraintSet_:
public _ConstraintSet_< OTHER_CONSTRAINTS... > {
127 using minset =
typename std::conditional<
128 _IsInConstraintSet_< FIRST_CONSTRAINT, _ConstraintSet_< OTHER_CONSTRAINTS... > >::value,
129 typename _ConstraintSet_< OTHER_CONSTRAINTS... >::minset,
130 typename _ConcatConstraintSet_<
132 typename _ConstraintSet_< OTHER_CONSTRAINTS... >::minset >::type >::type;
133 using set = _StructuralConstraintSetStatic_< FIRST_CONSTRAINT, OTHER_CONSTRAINTS... >;
136 template <
typename CONSTRAINT >
137 struct _ConstraintSet_< CONSTRAINT > {
138 using minset = _ConstraintSet_< CONSTRAINT >;
139 using set = _StructuralConstraintSetStatic_< CONSTRAINT >;
145 template <
typename SET1,
typename SET2 >
146 struct _ConcatConstraintSet_;
148 template <
typename CONSTRAINT1,
typename CONSTRAINT2 >
149 struct _ConcatConstraintSet_< CONSTRAINT1, _ConstraintSet_< CONSTRAINT2 > > {
150 using type = _ConstraintSet_< CONSTRAINT1, CONSTRAINT2 >;
153 template <
typename CONSTRAINT1,
typename CONSTRAINT2 >
154 struct _ConcatConstraintSet_< _ConstraintSet_< CONSTRAINT1 >, _ConstraintSet_< CONSTRAINT2 > > {
155 using type = _ConstraintSet_< CONSTRAINT1, CONSTRAINT2 >;
158 template <
typename CONSTRAINT1,
typename CONSTRAINT2,
typename... OTHER_CONSTRAINT2 >
159 struct _ConcatConstraintSet_< CONSTRAINT1,
160 _ConstraintSet_< CONSTRAINT2, OTHER_CONSTRAINT2... > > {
161 using type = _ConstraintSet_< CONSTRAINT1, CONSTRAINT2, OTHER_CONSTRAINT2... >;
164 template <
typename CONSTRAINT1,
typename CONSTRAINT2,
typename... OTHER_CONSTRAINT1 >
165 struct _ConcatConstraintSet_< _ConstraintSet_< CONSTRAINT1, OTHER_CONSTRAINT1... >,
166 _ConstraintSet_< CONSTRAINT2 > > {
167 using type = _ConstraintSet_< CONSTRAINT1, OTHER_CONSTRAINT1..., CONSTRAINT2 >;
170 template <
typename CONSTRAINT1,
171 typename CONSTRAINT2,
172 typename... OTHER_CONSTR1,
173 typename... OTHER_CONSTR2 >
174 struct _ConcatConstraintSet_< _ConstraintSet_< CONSTRAINT1, OTHER_CONSTR1... >,
175 _ConstraintSet_< CONSTRAINT2, OTHER_CONSTR2... > > {
176 using type = _ConstraintSet_< CONSTRAINT1, OTHER_CONSTR1..., CONSTRAINT2, OTHER_CONSTR2... >;
183 template <
typename CONSTRAINT1,
typename... OTHER_CONSTRAINTS >
184 class _StructuralConstraintSetStatic_:
185 public virtual CONSTRAINT1,
186 public virtual _StructuralConstraintSetStatic_< OTHER_CONSTRAINTS... > {
189 using first_constraint = CONSTRAINT1;
192 using next_constraints = _StructuralConstraintSetStatic_< OTHER_CONSTRAINTS... >;
196 using allConstraints =
typename _ConcatConstraintSet_<
197 typename std::conditional<
198 std::is_base_of< _StructuralRoot_, CONSTRAINT1 >::value,
199 typename _ConcatConstraintSet_< CONSTRAINT1,
200 typename CONSTRAINT1::allConstraints >::type,
201 _ConstraintSet_< CONSTRAINT1 > >::type,
202 typename next_constraints::allConstraints >::type;
212 using minConstraints =
typename allConstraints::minset::set;
220 _StructuralConstraintSetStatic_();
223 _StructuralConstraintSetStatic_(
224 const _StructuralConstraintSetStatic_< CONSTRAINT1, OTHER_CONSTRAINTS... >&);
227 ~_StructuralConstraintSetStatic_()
override;
237 _StructuralConstraintSetStatic_< CONSTRAINT1, OTHER_CONSTRAINTS... >&
238 operator=(
const _StructuralConstraintSetStatic_< CONSTRAINT1, OTHER_CONSTRAINTS... >&);
248 void setGraph(
const DiGraph& graph);
251 void modifyGraph(
const ArcAddition& change);
254 void modifyGraph(
const ArcDeletion& change);
257 void modifyGraph(
const ArcReversal& change);
263 void modifyGraph(
const ArcTriangleDeletion1& change);
269 void modifyGraph(
const ArcTriangleDeletion2& change);
272 void modifyGraph(
const GraphChange& change);
275 bool isAlwaysInvalid(
const GraphChange& change)
const;
278 bool checkArcAddition(NodeId x, NodeId y)
const;
281 bool checkArcDeletion(NodeId x, NodeId y)
const;
284 bool checkArcReversal(NodeId x, NodeId y)
const;
290 bool checkArcTriangleDeletion1(NodeId node1, NodeId node2, NodeId node3)
const;
296 bool checkArcTriangleDeletion2(NodeId node1, NodeId node2, NodeId node3)
const;
299 bool checkModification(
const ArcAddition& change)
const;
302 bool checkModification(
const ArcDeletion& change)
const;
305 bool checkModification(
const ArcReversal& change)
const;
311 bool checkModification(
const ArcTriangleDeletion1& change)
const;
317 bool checkModification(
const ArcTriangleDeletion2& change)
const;
320 bool checkModification(
const GraphChange& change)
const;
325 template <
typename CONSTRAINT >
326 class _StructuralConstraintSetStatic_< CONSTRAINT >:
327 public virtual CONSTRAINT,
328 public virtual _StructuralRoot_ {
331 using first_constraint = CONSTRAINT;
334 using next_constraints = _StructuralRoot_;
338 using allConstraints =
typename std::conditional<
339 std::is_base_of< _StructuralRoot_, CONSTRAINT >::value,
340 typename _ConcatConstraintSet_< CONSTRAINT, typename CONSTRAINT::allConstraints >::type,
341 _ConstraintSet_< CONSTRAINT > >::type;
351 using minConstraints =
typename allConstraints::minset::set;
359 _StructuralConstraintSetStatic_();
362 _StructuralConstraintSetStatic_(
const _StructuralConstraintSetStatic_< CONSTRAINT >&);
365 ~_StructuralConstraintSetStatic_()
override;
375 _StructuralConstraintSetStatic_< CONSTRAINT >&
376 operator=(
const _StructuralConstraintSetStatic_< CONSTRAINT >&);
386 void setGraph(
const DiGraph& graph);
389 void modifyGraph(
const ArcAddition& change);
392 void modifyGraph(
const ArcDeletion& change);
395 void modifyGraph(
const ArcReversal& change);
401 void modifyGraph(
const ArcTriangleDeletion1& change);
407 void modifyGraph(
const ArcTriangleDeletion2& change);
410 void modifyGraph(
const GraphChange& change);
413 bool isAlwaysInvalid(
const GraphChange& change)
const;
416 bool checkArcAddition(NodeId x, NodeId y)
const;
419 bool checkArcDeletion(NodeId x, NodeId y)
const;
422 bool checkArcReversal(NodeId x, NodeId y)
const;
428 bool checkArcTriangleDeletion1(NodeId node1, NodeId node2, NodeId node3)
const;
434 bool checkArcTriangleDeletion2(NodeId node1, NodeId node2, NodeId node3)
const;
437 bool checkModification(
const ArcAddition& change)
const;
440 bool checkModification(
const ArcDeletion& change)
const;
443 bool checkModification(
const ArcReversal& change)
const;
449 bool checkModification(
const ArcTriangleDeletion1& change)
const;
455 bool checkModification(
const ArcTriangleDeletion2& change)
const;
458 bool checkModification(
const GraphChange& change)
const;
492 template <
typename CONSTRAINT1,
typename... OTHER_CONSTRAINTS >
494 public virtual _StructuralConstraintSetStatic_< CONSTRAINT1,
495 OTHER_CONSTRAINTS... >::minConstraints {
498 typename _StructuralConstraintSetStatic_< CONSTRAINT1,
499 OTHER_CONSTRAINTS... >::minConstraints;
612#ifndef DOXYGEN_SHOULD_SKIP_THIS
614 template <
typename CONSTRAINT >
616 public virtual _StructuralConstraintSetStatic_< CONSTRAINT >::minConstraints {
618 using constraints =
typename _StructuralConstraintSetStatic_< CONSTRAINT >::minConstraints;
Base class for all oriented graphs.
The class for notifying learning algorithms of new arc additions.
The class for notifying learning algorithms of arc removals.
The class for notifying learning algorithms of arc reversals.
The graph change substituting a triangle node1->node2->node3 + node1->node3 into v-structure node2->n...
The graph change substituting a triangle node1->node2->node3 + node1->node3 into v-structure node1->n...
the "meta-programming" class for storing structural constraints
bool checkModification(const GraphChange &change) const
checks whether the constraints enable to perform a graph change
bool checkArcReversal(NodeId x, NodeId y) const
checks whether the constraints enable to reverse arc (x,y)
void modifyGraph(const ArcDeletion &change)
notify the constraint of a modification of the graph
void modifyGraph(const ArcTriangleDeletion2 &change)
notify the constraint of a modification of the graph
void modifyGraph(const ArcAddition &change)
notify the constraint of a modification of the graph
bool checkModification(const ArcAddition &change) const
checks whether the constraints enable to add an arc
bool checkModification(const ArcReversal &change) const
checks whether the constraints enable to reverse an arc
void modifyGraph(const ArcTriangleDeletion1 &change)
notify the constraint of a modification of the graph
typename _StructuralConstraintSetStatic_< CONSTRAINT1, OTHER_CONSTRAINTS... >::minConstraints constraints
void modifyGraph(const ArcReversal &change)
notify the constraint of a modification of the graph
StructuralConstraintSetStatic< CONSTRAINT1, OTHER_CONSTRAINTS... > & operator=(const StructuralConstraintSetStatic< CONSTRAINT1, OTHER_CONSTRAINTS... > &)
copy operator
void modifyGraph(const GraphChange &change)
notify the constraint of a modification of the graph
bool isAlwaysInvalid(const GraphChange &change) const
indicates whether a change will always violate the constraint
bool checkArcDeletion(NodeId x, NodeId y) const
checks whether the constraints enable to remove arc (x,y)
bool checkModification(const ArcTriangleDeletion1 &change) const
checks whether the constraints enable to apply an ArcTriangleDeletion1
bool checkModification(const ArcTriangleDeletion2 &change) const
checks whether the constraints enable to apply an ArcTriangleDeletion2
StructuralConstraintSetStatic()
default constructor
bool checkArcTriangleDeletion1(NodeId node1, NodeId node2, NodeId node3) const
checks whether the constraints enable to apply an ArcTriangleDeletion1
bool checkArcAddition(NodeId x, NodeId y) const
checks whether the constraints enable to add arc (x,y)
void setGraph(const DiGraph &graph)
sets a new graph from which we will perform checkings
~StructuralConstraintSetStatic() override
destructor
bool checkModification(const ArcDeletion &change) const
checks whether the constraints enable to remove an arc
StructuralConstraintSetStatic(const StructuralConstraintSetStatic< CONSTRAINT1, OTHER_CONSTRAINTS... > &)
copy constructor
bool checkArcTriangleDeletion2(NodeId node1, NodeId node2, NodeId node3) const
checks whether the constraints enable to apply an ArcTriangleDeletion2
Base classes for oriented graphs.
the classes to account for structure changes in a graph
Size NodeId
Type for node ids.
include the inlined functions if necessary
gum is the global namespace for all aGrUM entities
the "meta-programming" class for storing several structural constraints