# Revision history [back]

I felt a little bit uncomfortable with 'cycle_basis' since it gives me a basis for all sets of disjoint cycles, but I actually want a set of all simple cycles (disjoint vertices).

A non optimal solution i came up with (using the implemented path function):

def simple_cycles(Gamma):
"""
Returns a list of all simple cycles in the given graph Gamma as lists of vertices.
"""
G = Graph(Gamma)    #make copy of given graph
edges = G.edges()
cycleList =[]
for edge in edges:
G.delete_edge(edge)        #delete starting edge to avoid duplicates
if edge==edge:         #if its loop
cycleList.append([edge, edge])
for path in G.all_paths(edge, edge):
if(len(path)>1):
cycleList.append([edge]+path)
return cycleList;


Optimizations or corrections will be appreciated (e.g. the description right now is horrible).

I felt a little bit uncomfortable with 'cycle_basis' since it gives me a basis for all sets of disjoint cycles, but I actually want a set of all simple cycles (disjoint vertices).

A non optimal solution i came up with (using the implemented path function):

def simple_cycles(Gamma):
"""
Returns a list of all simple cycles in the given graph Gamma as lists of vertices.
"""
G = Graph(Gamma)    #make copy of given graph
edges = G.edges()
cycleList =[]
for edge in edges:
G.delete_edge(edge)        #delete starting edge to avoid duplicates
if edge==edge:         #if its loop
cycleList.append([edge, edge])
for path in G.all_paths(edge, edge):
if(len(path)>1):
cycleList.append([edge]+path)
return cycleList;


Optimizations or corrections will be appreciated (e.g. the description right now is horrible).horrible). Also I am not sure how well this behaves with multiedges.