I\'m using networkx to work with graphs. I have pretty large graph (it\'s near 200 nodes in it) and I try to find all possible paths between two nodes. But, as I understand,
This one actually works with networkx, and it's non-recursive, which may be nice for large graphs.
def find_all_paths(graph, start, end):
path = []
paths = []
queue = [(start, end, path)]
while queue:
start, end, path = queue.pop()
print 'PATH', path
path = path + [start]
if start == end:
paths.append(path)
for node in set(graph[start]).difference(path):
queue.append((node, end, path))
return paths