ATLAS Offline Software
Loading...
Searching...
No Matches
graphAlgs.DirectedCycle Class Reference
Collaboration diagram for graphAlgs.DirectedCycle:

Public Member Functions

 __init__ (self, G)
 has_cycle (self)
 cycle (self)
 dfs_ (self, G, v)

Public Attributes

list onStack = [False for i in range(G.V)]
list marked = [False for i in range(G.V)]
list edgeTo = [-1 for i in range(G.V)]
list cycle_ = []

Detailed Description

determine whether a digraph has a cycle

Definition at line 4 of file graphAlgs.py.

Constructor & Destructor Documentation

◆ __init__()

graphAlgs.DirectedCycle.__init__ ( self,
G )

Definition at line 7 of file graphAlgs.py.

7 def __init__(self, G):
8 self.onStack = [False for i in range(G.V)]
9 self.marked = [False for i in range(G.V)]
10 self.edgeTo = [-1 for i in range(G.V)]
11 self.cycle_ = []
12
13 GV = G.V
14 for v in range(GV):
15 if not self.marked[v]:
16 self.dfs_(G, v)
17

Member Function Documentation

◆ cycle()

graphAlgs.DirectedCycle.cycle ( self)

Definition at line 21 of file graphAlgs.py.

21 def cycle(self):
22 return self.cycle_
23
double cycle(double a, double b)

◆ dfs_()

graphAlgs.DirectedCycle.dfs_ ( self,
G,
v )

Definition at line 24 of file graphAlgs.py.

24 def dfs_(self, G, v):
25 self.onStack[v] = True
26 self.marked[v] = True
27
28 for w in G.adj(v):
29 if self.cycle_: return
30 if not self.marked[w]:
31 self.edgeTo[w] = w
32 self.dfs_(G, w)
33 elif self.onStack[w]:
34 x = v
35 while x != w:
36 self.cycle_.append(x)
37 x = self.edgeTo(x)
38 self.cycle_.append(w)
39 self.cycle_.append(v)
40
41 self.onStack[v] = False
42
43
44

◆ has_cycle()

graphAlgs.DirectedCycle.has_cycle ( self)

Definition at line 18 of file graphAlgs.py.

18 def has_cycle(self):
19 return len(self.cycle_) > 0
20

Member Data Documentation

◆ cycle_

graphAlgs.DirectedCycle.cycle_ = []

Definition at line 11 of file graphAlgs.py.

◆ edgeTo

list graphAlgs.DirectedCycle.edgeTo = [-1 for i in range(G.V)]

Definition at line 10 of file graphAlgs.py.

◆ marked

list graphAlgs.DirectedCycle.marked = [False for i in range(G.V)]

Definition at line 9 of file graphAlgs.py.

◆ onStack

list graphAlgs.DirectedCycle.onStack = [False for i in range(G.V)]

Definition at line 8 of file graphAlgs.py.


The documentation for this class was generated from the following file: