aGrUM  0.14.2
structuralConstraintIndegree_inl.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Christophe GONZALES and Pierre-Henri WUILLEMIN *
3  * {prenom.nom}_at_lip6.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
27 #ifndef DOXYGEN_SHOULD_SKIP_THIS
28 
29 namespace gum {
30 
31  namespace learning {
32 
34  INLINE void StructuralConstraintIndegree::setGraphAlone(const DiGraph& graph) {
35  // check that the max_indegree corresponds to the graph
36  for (const auto id : graph) {
37  if (!_Indegree__max_parents.exists(id)) {
39  }
40  }
41  }
42 
44  INLINE bool
46  NodeId y) const {
47  return (_Indegree__max_parents[y] > _DiGraph__graph.parents(y).size());
48  }
49 
51  INLINE bool
53  NodeId y) const {
54  return true;
55  }
56 
58  INLINE bool
60  NodeId y) const {
61  return (_Indegree__max_parents[x] > _DiGraph__graph.parents(x).size());
62  }
63 
66  const ArcAddition& change) const {
67  return checkArcAdditionAlone(change.node1(), change.node2());
68  }
69 
72  const ArcDeletion& change) const {
73  return checkArcDeletionAlone(change.node1(), change.node2());
74  }
75 
78  const ArcReversal& change) const {
79  return checkArcReversalAlone(change.node1(), change.node2());
80  }
81 
84  const GraphChange& change) const {
85  switch (change.type()) {
87  return checkArcAdditionAlone(change.node1(), change.node2());
88 
90  return checkArcDeletionAlone(change.node1(), change.node2());
91 
93  return checkArcReversalAlone(change.node1(), change.node2());
94 
95  default:
96  GUM_ERROR(OperationNotAllowed,
97  "edge modifications are not "
98  "supported by StructuralConstraintIndegree");
99  }
100  }
101 
103  INLINE void
104  StructuralConstraintIndegree::modifyGraphAlone(const ArcAddition& change) {}
105 
107  INLINE void
108  StructuralConstraintIndegree::modifyGraphAlone(const ArcDeletion& change) {}
109 
111  INLINE void
112  StructuralConstraintIndegree::modifyGraphAlone(const ArcReversal& change) {}
113 
115  INLINE void
116  StructuralConstraintIndegree::modifyGraphAlone(const GraphChange& change) {}
117 
120  const GraphChange& change) const {
121  if ((change.type() == GraphChangeType::ARC_ADDITION)
122  && (_Indegree__max_parents[change.node2()] == 0)) {
123  return true;
124  } else if ((change.type() == GraphChangeType::ARC_REVERSAL)
125  && (_Indegree__max_parents[change.node1()] == 0)) {
126  return true;
127  } else {
128  return false;
129  }
130  }
131 
134  const NodeProperty< Size >& max_indegree) {
135  for (const auto& degree : max_indegree) {
136  _Indegree__max_parents.set(degree.first, degree.second);
137  }
138  }
139 
141  INLINE void StructuralConstraintIndegree::setMaxIndegree(Size max_indegree,
142  bool update_all) {
143  if (update_all) {
144  for (auto& degree : _Indegree__max_parents) {
145  degree.second = max_indegree;
146  }
147  }
148 
149  _Indegree__max_indegree = max_indegree;
150  }
151 
152 // include all the methods applicable to the whole class hierarchy
153 # define GUM_CONSTRAINT_CLASS_NAME StructuralConstraintIndegree
155 # undef GUM_CONSTRAINT_CLASS_NAME
156 
157  } /* namespace learning */
158 
159 } /* namespace gum */
160 
161 #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
gum is the global namespace for all aGrUM entities
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:45
void setGraphAlone(const DiGraph &graph)
sets a new graph from which we will perform checkings
Size NodeId
Type for node ids.
Definition: graphElements.h:97
#define GUM_ERROR(type, msg)
Definition: exceptions.h:52
bool checkArcReversalAlone(NodeId x, NodeId y) const
checks whether the constraints enable to reverse arc (x,y)