Skip to content

Commit

Permalink
works
Browse files Browse the repository at this point in the history
  • Loading branch information
harisbal committed Nov 13, 2023
1 parent 7df22ce commit 18d1d5c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 29 deletions.
17 changes: 11 additions & 6 deletions networkx/algorithms/simple_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,10 @@ def _all_simple_paths_multigraph(G, source, targets, cutoff):
if child in visited:
continue
if child in targets:
yield list(visited) + [child]
path = list(visited) + [child]
if _path_under_cutoff(G, path, cutoff):
yield path

visited[child] = True
if targets - set(visited.keys()):
stack.append((v for u, v in G.edges(child)))
Expand Down Expand Up @@ -477,7 +480,7 @@ def _all_simple_edge_paths_multigraph(G, source, targets, cutoff):
if cutoff.get(None, 1) < 1:
return []
else:
raise TypeError("cutoff should either be int or dict")
raise TypeError("cutoff should be either int or dict")

visited = [source]
stack = [iter(G.edges(source, keys=True))]
Expand All @@ -490,18 +493,20 @@ def _all_simple_edge_paths_multigraph(G, source, targets, cutoff):
visited.pop()
elif _path_under_cutoff(G, visited, cutoff):
if child[1] in targets:
path = visited[1:] + [child]
edge_path = visited[1:] + [child]
path = [u for u, v, k in edge_path] + [edge_path[-1][1]]
if _path_under_cutoff(G, path, cutoff):
yield path
yield edge_path
elif child[1] not in [v[0] for v in visited[1:]]:
visited.append(child)
stack.append(iter(G.edges(child[1], keys=True)))
else: # len(visited) == cutoff:
for u, v, k in [child] + list(children):
if v in targets:
path = visited[1:] + [(u, v, k)]
edge_path = visited[1:] + [(u, v, k)]
path = [u for u, v, k in edge_path] + edge_path[-1][1]
if _path_under_cutoff(G, path, cutoff):
yield path
yield edge_path
stack.pop()
visited.pop()

Expand Down
23 changes: 0 additions & 23 deletions tmp.py

This file was deleted.

0 comments on commit 18d1d5c

Please sign in to comment.