wting / python-graph

Automatically exported from code.google.com/p/python-graph
Other
5 stars 4 forks source link

Enhancement: find_all_cycles function #98

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I created a function that returns all cycles in a graph (instead of returning 
the first cycle encounters). It is based on core.pygraph.algorithms.cycles.py.

I imaginatively call this function find_all_cycles. find_all_cycles reuses 
find_cycle_to_ancestor, which should therefore be moved out of find_cycle. I 
also propose that visited be implemented as a set instead of a dict mapping 1 
to visited nodes, as it seems simpler to me (set being hashed as well as dict, 
performance should not be affected).

I also apologize for not providing a proper patch but a complete file. I also 
stripped all *recursionlimit changes, while working on it. But I do believe 
that find_all_cycles is close enough to find_cycle so that it can be merged 
without difficulties.

In any case, I hope this may be useful.

Original issue reported on code.google.com by Mathias....@gmail.com on 21 Aug 2011 at 11:05

Attachments:

GoogleCodeExporter commented 9 years ago
I also wanted to state explicitly that this function may be added to 
python-graph under python-graph's license (or whatever you see fit).

Original comment by Mathias....@gmail.com on 21 Aug 2011 at 1:05