aGrUM  0.14.2
DAGCycleDetector.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  ***************************************************************************/
32 #ifndef GUM_DAG_CYCLE_DETECTOR_H
33 #define GUM_DAG_CYCLE_DETECTOR_H
34 
35 #include <vector>
36 
37 #include <agrum/graphs/DAG.h>
38 
39 namespace gum {
40 
41  /* ===========================================================================
42  */
43  // DAG CYCLE DETECTOR
44  /* ===========================================================================
45  */
60  public:
61  // the type of modification that can be applied to the graph
63 
65  class Change {
66  public:
67  Change(ChangeType type, NodeId tail, NodeId head) noexcept;
68  Change(const Change& from) noexcept;
69  Change(Change&& from) noexcept;
70  virtual ~Change() noexcept;
71 
72  protected:
73  Change& operator=(const Change& from) noexcept;
74  Change& operator=(Change&& from) noexcept;
75 
76  public:
77  // ##########################################################################
79  // ##########################################################################
81 
83  ChangeType type() const noexcept;
84 
86  NodeId tail() const noexcept;
87 
89  NodeId head() const noexcept;
90 
92 
93  private:
96 
99 
102  };
103 
110  class ArcAdd : public Change {
111  public:
112  // ##########################################################################
114  // ##########################################################################
117  ArcAdd(NodeId tail, NodeId head) noexcept;
118 
120  ArcAdd(const ArcAdd& from) noexcept;
121 
123  ArcAdd(ArcAdd&& from) noexcept;
124 
126  ~ArcAdd() noexcept;
127 
129 
130  // ##########################################################################
132  // ##########################################################################
134 
136  ArcAdd& operator=(const ArcAdd& from) noexcept;
137 
139  ArcAdd& operator=(ArcAdd&& from) noexcept;
140 
142  };
143 
150  class ArcDel : public Change {
151  public:
152  // ##########################################################################
154  // ##########################################################################
157  ArcDel(NodeId tail, NodeId head) noexcept;
158 
160  ArcDel(const ArcDel& from) noexcept;
161 
163  ArcDel(ArcDel&& from) noexcept;
164 
166  ~ArcDel() noexcept;
167 
169 
170  // ##########################################################################
172  // ##########################################################################
174 
176  ArcDel& operator=(const ArcDel& from) noexcept;
177 
179  ArcDel& operator=(ArcDel&& from) noexcept;
180 
182  };
183 
189  class ArcReverse : public Change {
190  public:
191  // ##########################################################################
193  // ##########################################################################
196  ArcReverse(NodeId tail, NodeId head) noexcept;
197 
199  ArcReverse(const ArcReverse& from) noexcept;
200 
202  ArcReverse(ArcReverse&& from) noexcept;
203 
205  ~ArcReverse() noexcept;
206 
208 
209  // ##########################################################################
211  // ##########################################################################
213 
215  ArcReverse& operator=(const ArcReverse& from) noexcept;
216 
218  ArcReverse& operator=(ArcReverse&& from) noexcept;
219 
221  };
222 
223  // ############################################################################
225  // ############################################################################
227 
229  DAGCycleDetector() noexcept;
230 
232  DAGCycleDetector(const DAGCycleDetector& from);
233 
236 
239 
241 
242  // ############################################################################
244  // ############################################################################
246 
249 
252 
254 
255  bool operator==(const DAGCycleDetector& from) const;
256 
258 
259  bool operator!=(const DAGCycleDetector& from) const;
260 
262 
263  // ############################################################################
265  // ############################################################################
267 
269  void setDAG(const DAG& dag);
270 
272 
275  void addArc(NodeId x, NodeId y);
276 
278 
279  void eraseArc(NodeId x, NodeId y);
280 
282 
285  void reverseArc(NodeId x, NodeId y);
286 
288 
289  bool hasCycleFromAddition(NodeId x, NodeId y) const noexcept;
290 
292 
293  bool hasCycleFromReversal(NodeId x, NodeId y) const noexcept;
294 
296 
297  bool hasCycleFromDeletion(NodeId x, NodeId y) const noexcept;
298 
300 
307  bool hasCycleFromModifications(const std::vector< Change >& modifs) const;
308 
310 
311  private:
314 
316 
318 
320 
322 
325  const NodeProperty< Size >& set_to_add,
326  Size multiplier) const;
327 
330  const NodeProperty< Size >& set_to_del,
331  Size multiplier) const;
332 
337  const NodeProperty< Size >& set_to_restrict,
338  const NodeSet& extrmities) const;
339  };
340 
341 } /* namespace gum */
342 
343 #ifndef GUM_NO_INLINE
345 #endif // GUM_NOINLINE
346 
347 #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
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
The class for generic Hash Tables.
Definition: hashTable.h:676
A class for detecting directed cycles in DAGs when trying to apply many changes to the graph...
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:108
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:45
DAGCycleDetector() noexcept
default constructor
the class to indicate that we wish to remove an arc
Base class for dag.
Definition: DAG.h:99
bool operator==(const DAGCycleDetector &from) const
check the equality between two DAGCycleDetectors
Size NodeId
Type for node ids.
Definition: graphElements.h:97
Base classes for directed acyclic graphs.
void reverseArc(NodeId x, NodeId y)
reverses an arc from the DAG