aGrUM  0.16.0
structuralConstraintIndegree_inl.h
Go to the documentation of this file.
1 
30 #ifndef DOXYGEN_SHOULD_SKIP_THIS
31 
32 namespace gum {
33 
34  namespace learning {
35 
37  INLINE void StructuralConstraintIndegree::setGraphAlone(const DiGraph& graph) {
38  // check that the max_indegree corresponds to the graph
39  for (const auto id : graph) {
40  if (!_Indegree__max_parents.exists(id)) {
42  }
43  }
44  }
45 
47  INLINE bool
49  NodeId y) const {
50  return (_Indegree__max_parents[y] > _DiGraph__graph.parents(y).size());
51  }
52 
54  INLINE bool
56  NodeId y) const {
57  return true;
58  }
59 
61  INLINE bool
63  NodeId y) const {
64  return (_Indegree__max_parents[x] > _DiGraph__graph.parents(x).size());
65  }
66 
69  const ArcAddition& change) const {
70  return checkArcAdditionAlone(change.node1(), change.node2());
71  }
72 
75  const ArcDeletion& change) const {
76  return checkArcDeletionAlone(change.node1(), change.node2());
77  }
78 
81  const ArcReversal& change) const {
82  return checkArcReversalAlone(change.node1(), change.node2());
83  }
84 
87  const GraphChange& change) const {
88  switch (change.type()) {
90  return checkArcAdditionAlone(change.node1(), change.node2());
91 
93  return checkArcDeletionAlone(change.node1(), change.node2());
94 
96  return checkArcReversalAlone(change.node1(), change.node2());
97 
98  default:
99  GUM_ERROR(OperationNotAllowed,
100  "edge modifications are not "
101  "supported by StructuralConstraintIndegree");
102  }
103  }
104 
106  INLINE void
107  StructuralConstraintIndegree::modifyGraphAlone(const ArcAddition& change) {}
108 
110  INLINE void
111  StructuralConstraintIndegree::modifyGraphAlone(const ArcDeletion& change) {}
112 
114  INLINE void
115  StructuralConstraintIndegree::modifyGraphAlone(const ArcReversal& change) {}
116 
118  INLINE void
119  StructuralConstraintIndegree::modifyGraphAlone(const GraphChange& change) {}
120 
123  const GraphChange& change) const {
124  if ((change.type() == GraphChangeType::ARC_ADDITION)
125  && (_Indegree__max_parents[change.node2()] == 0)) {
126  return true;
127  } else if ((change.type() == GraphChangeType::ARC_REVERSAL)
128  && (_Indegree__max_parents[change.node1()] == 0)) {
129  return true;
130  } else {
131  return false;
132  }
133  }
134 
137  const NodeProperty< Size >& max_indegree) {
138  for (const auto& degree : max_indegree) {
139  _Indegree__max_parents.set(degree.first, degree.second);
140  }
141  }
142 
144  INLINE void StructuralConstraintIndegree::setMaxIndegree(Size max_indegree,
145  bool update_all) {
146  if (update_all) {
147  for (auto& degree : _Indegree__max_parents) {
148  degree.second = max_indegree;
149  }
150  }
151 
152  _Indegree__max_indegree = max_indegree;
153  }
154 
155 // include all the methods applicable to the whole class hierarchy
156 # define GUM_CONSTRAINT_CLASS_NAME StructuralConstraintIndegree
158 # undef GUM_CONSTRAINT_CLASS_NAME
159 
160  } /* namespace learning */
161 
162 } /* namespace gum */
163 
164 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
void setIndegree(const NodeProperty< Size > &max_indegree)
sets the default max indegree for all the nodes in the property
bool checkModificationAlone(const ArcAddition &change) const
checks whether the constraints enable to add an arc
void setMaxIndegree(Size max_indegree, bool update_all_node=false)
resets the default max indegree and possibly updates the indegree of all nodes
bool isAlwaysInvalidAlone(const GraphChange &change) const
indicates whether a change will always violate the constraint
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
Size _Indegree__max_indegree
a default max indegree to assign for nodes without specified indegree
bool checkArcDeletionAlone(NodeId x, NodeId y) const
checks whether the constraints enable to remove arc (x,y)
bool checkArcAdditionAlone(NodeId x, NodeId y) const
checks whether the constraints enable to add arc (x,y)
NodeProperty< Size > _Indegree__max_parents
the max number of parents per node
void modifyGraphAlone(const ArcAddition &change)
notify the constraint of a modification of the graph
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
void setGraphAlone(const DiGraph &graph)
sets a new graph from which we will perform checkings
Size NodeId
Type for node ids.
Definition: graphElements.h:98
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55
bool checkArcReversalAlone(NodeId x, NodeId y) const
checks whether the constraints enable to reverse arc (x,y)