aGrUM  0.16.0
DAGCycleDetector.h
Go to the documentation of this file.
1 
35 #ifndef GUM_DAG_CYCLE_DETECTOR_H
36 #define GUM_DAG_CYCLE_DETECTOR_H
37 
38 #include <vector>
39 
40 #include <agrum/graphs/DAG.h>
41 
42 namespace gum {
43 
44  /* ===========================================================================
45  */
46  // DAG CYCLE DETECTOR
47  /* ===========================================================================
48  */
63  public:
64  // the type of modification that can be applied to the graph
66 
68  class Change {
69  public:
70  Change(ChangeType type, NodeId tail, NodeId head) noexcept;
71  Change(const Change& from) noexcept;
72  Change(Change&& from) noexcept;
73  virtual ~Change() noexcept;
74 
75  protected:
76  Change& operator=(const Change& from) noexcept;
77  Change& operator=(Change&& from) noexcept;
78 
79  public:
80  // ##########################################################################
82  // ##########################################################################
84 
86  ChangeType type() const noexcept;
87 
89  NodeId tail() const noexcept;
90 
92  NodeId head() const noexcept;
93 
95 
96  private:
99 
102 
105  };
106 
113  class ArcAdd : public Change {
114  public:
115  // ##########################################################################
117  // ##########################################################################
120  ArcAdd(NodeId tail, NodeId head) noexcept;
121 
123  ArcAdd(const ArcAdd& from) noexcept;
124 
126  ArcAdd(ArcAdd&& from) noexcept;
127 
129  ~ArcAdd() noexcept;
130 
132 
133  // ##########################################################################
135  // ##########################################################################
137 
139  ArcAdd& operator=(const ArcAdd& from) noexcept;
140 
142  ArcAdd& operator=(ArcAdd&& from) noexcept;
143 
145  };
146 
153  class ArcDel : public Change {
154  public:
155  // ##########################################################################
157  // ##########################################################################
160  ArcDel(NodeId tail, NodeId head) noexcept;
161 
163  ArcDel(const ArcDel& from) noexcept;
164 
166  ArcDel(ArcDel&& from) noexcept;
167 
169  ~ArcDel() noexcept;
170 
172 
173  // ##########################################################################
175  // ##########################################################################
177 
179  ArcDel& operator=(const ArcDel& from) noexcept;
180 
182  ArcDel& operator=(ArcDel&& from) noexcept;
183 
185  };
186 
192  class ArcReverse : public Change {
193  public:
194  // ##########################################################################
196  // ##########################################################################
199  ArcReverse(NodeId tail, NodeId head) noexcept;
200 
202  ArcReverse(const ArcReverse& from) noexcept;
203 
205  ArcReverse(ArcReverse&& from) noexcept;
206 
208  ~ArcReverse() noexcept;
209 
211 
212  // ##########################################################################
214  // ##########################################################################
216 
218  ArcReverse& operator=(const ArcReverse& from) noexcept;
219 
221  ArcReverse& operator=(ArcReverse&& from) noexcept;
222 
224  };
225 
226  // ############################################################################
228  // ############################################################################
230 
232  DAGCycleDetector() noexcept;
233 
235  DAGCycleDetector(const DAGCycleDetector& from);
236 
239 
242 
244 
245  // ############################################################################
247  // ############################################################################
249 
252 
255 
257 
258  bool operator==(const DAGCycleDetector& from) const;
259 
261 
262  bool operator!=(const DAGCycleDetector& from) const;
263 
265 
266  // ############################################################################
268  // ############################################################################
270 
272  void setDAG(const DAG& dag);
273 
275 
278  void addArc(NodeId x, NodeId y);
279 
281 
282  void eraseArc(NodeId x, NodeId y);
283 
285 
288  void reverseArc(NodeId x, NodeId y);
289 
291 
292  bool hasCycleFromAddition(NodeId x, NodeId y) const noexcept;
293 
295 
296  bool hasCycleFromReversal(NodeId x, NodeId y) const noexcept;
297 
299 
300  bool hasCycleFromDeletion(NodeId x, NodeId y) const noexcept;
301 
303 
310  bool hasCycleFromModifications(const std::vector< Change >& modifs) const;
311 
313 
314  private:
317 
319 
321 
323 
325 
328  const NodeProperty< Size >& set_to_add,
329  Size multiplier) const;
330 
333  const NodeProperty< Size >& set_to_del,
334  Size multiplier) const;
335 
340  const NodeProperty< Size >& set_to_restrict,
341  const NodeSet& extrmities) const;
342  };
343 
344 } /* namespace gum */
345 
346 #ifndef GUM_NO_INLINE
348 #endif // GUM_NOINLINE
349 
350 #endif // GUM_DAG_CYCLE_DETECTOR_H
A class for detecting directed cycles in DAGs when trying to apply many changes to the graph...
DiGraph __dag
the initial dag from which modifications are applied
the base class indicating the possible changes
void eraseArc(NodeId x, NodeId y)
removes an arc from the current DAG
void __addWeightedSet(NodeProperty< Size > &nodeset, const NodeProperty< Size > &set_to_add, Size multiplier) const
adds a weighted nodeset to another (weights are added)
void addArc(NodeId x, NodeId y)
adds a new arc to the current DAG
void __delWeightedSet(NodeProperty< Size > &nodeset, const NodeProperty< Size > &set_to_del, Size multiplier) const
removes a weighted nodeset from another (weights are subtracted)
void __restrictWeightedSet(NodeProperty< Size > &result_set, const NodeProperty< Size > &set_to_restrict, const NodeSet &extrmities) const
put into a weighted nodeset the nodes of another weighted set that belong to a set of arc extremities...
ChangeType __type
the type of modification
the class to indicate that we wish to reverse an arc
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
The class for generic Hash Tables.
Definition: hashTable.h:679
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
bool hasCycleFromModifications(const std::vector< Change > &modifs) const
indicates whether a set of modifications would create a cycle
DAGCycleDetector & operator=(const DAGCycleDetector &from)
copy operator
void setDAG(const DAG &dag)
sets the initial DAG from which changes shall be applied
the class to indicate that we wish to add a new arc
Base class for all oriented graphs.
Definition: diGraph.h:111
NodeId __head
the head of the arc to be modified
bool operator!=(const DAGCycleDetector &from) const
check the inequality between two DAGCycleDetectors
bool hasCycleFromAddition(NodeId x, NodeId y) const noexcept
indicates whether an arc addition would create a cycle
NodeId __tail
the tail of the arc to be modified
NodeProperty< NodeProperty< Size > > __descendants
the set of descendants of each node in the dag
NodeProperty< NodeProperty< Size > > __ancestors
the set of ancestors of each node in the dag
bool hasCycleFromReversal(NodeId x, NodeId y) const noexcept
indicates wether an arc reversal would create a cycle
bool hasCycleFromDeletion(NodeId x, NodeId y) const noexcept
indicates whether an arc deletion would create a cycle
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
DAGCycleDetector() noexcept
default constructor
the class to indicate that we wish to remove an arc
Base class for dag.
Definition: DAG.h:102
bool operator==(const DAGCycleDetector &from) const
check the equality between two DAGCycleDetectors
Size NodeId
Type for node ids.
Definition: graphElements.h:98
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
void reverseArc(NodeId x, NodeId y)
reverses an arc from the DAG