2

I have a directed cyclic graph with more than one cycle in it and I need a way to detect (and list) each cycle present in the digraph.

The graph can be seen here: http://img412.imageshack.us/img412/3327/schematic.gif

This is a dummy graph put together for the sake of debugging my python script. It contains the cycles:

[n13, n14], [n6, n8, n15, n16, n7], [n6, n8, n9, n7]

The algorithm must detect every cycle in the digraph, not just the smallest nor the first it encounters.

MSalters
  • 173,980
  • 10
  • 155
  • 350
R Brown
  • 21
  • 1
  • 2

3 Answers3

2

You didn't really specify how you represent the Directed graph, but you can have a look at Neopythonic:Detecting Cycles in directed graph.

Yoni H
  • 453
  • 2
  • 7
1

AFAIK, python-graph only finds one cycle, not all posible cycles. See:

http://groups.google.com/group/python-graph/browse_thread/thread/9170926f1bdd097b

This other article seems to solve the problem presented in this question:

http://www.bitformation.com/art/python_toposort.html

It's using the algorithm devised by R. E. Tarjan in 1972

gnrfan
  • 19,071
  • 1
  • 21
  • 12
0

You might want to try and use this library. It has a cycle detection algorithm.

the_drow
  • 18,571
  • 25
  • 126
  • 193