In my original program, I'm trying to traverse all paths from huge edge_list of length around 70K . the script never coming out (running more than a day)
Any tips on how to speed this operation ? It is working fine for smaller list like below (length 4)
Tried both functional and iterative programming.
import networkx as nx
edge_list =[(0, 1), (1, 2), (0, 3), (3, 2)]
G = nx.DiGraph(edge_list)
roots = (v for v, d in G.in_degree() if d == 0)
leaves = (v for v, d in G.out_degree() if d == 0)
Functional programmming approach
from itertools import chain
from itertools import product
from itertools import starmap
from functools import partial
chaini = chain.from_iterable
paths = partial(nx.all_simple_paths, G)
all_paths = list(chaini(starmap(paths, product(roots, leaves))))
print(all_paths)
Iterative programming approach
all_paths = []
for root in roots:
for leaf in leaves:
paths = nx.all_simple_paths(G, root, leaf)
all_paths.extend(paths)
print(all_paths)
Output :
[[0, 1, 2], [0, 3, 2]]