Answer the question
In order to leave comments, you need to log in
How to find the longest path/path_length in a graph?
Good morning Toaster.
I'm writing a script that uses network - https://networkx.readthedocs.io/
All input data is enclosed in a file. I figured out how to solve all typical tasks, such as building a graph, finding a short path, but I can’t find how to calculate the longest path in a graph.
The input data is for example:
Graph:
N1,N8
N2,N6
N3,N7,N1
N4,N2
N5,N8
N7,N2,N5,N4
N8,N7,N4
N1, *
N1,N8,N4,N2,N6 и N1,N8,N7,N2,N6
path_length = 4
all_paths = []
for node in G:
all_paths.extend(find_paths(G, node, 6))
print all_paths
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question