networkx - unique combinations of paths code example
Example: networkx - unique combinations of paths
gg = nx.complete_graph(6)
nx.draw(gg, with_labels = True)
source = 0
target = 3
gg.remove_edge(0, 3)
paths = nx.all_simple_paths(gg, source=source, target=target, cutoff=5)
s = set(map(frozenset, paths))
non_redundant_paths = [[source, *[*p-{source,target}],target] for p in s]
non_redundant_paths = []
seen = []
for p in paths:
if set(p) not in seen:
non_redundant_paths.append(p)
seen.append({*p})
print(non_redundant_paths)