I'm trying to find all pair shortest path in very large scale graph. I tried floyd-warshall but it is not fast enough because of very large scale of the graph. Number of vertices is more than 100k. Maybe it will take more than a week... Actually I don't need all of the paths. I only need the longest one.
Asked
Active
Viewed 504 times
0
-
Is the graph acyclic? Otherwise you'll run into infinite longest path (repeat the cycle ad infinitum) – Dani Mesejo Nov 13 '20 at 10:48
-
Yes it is. You can assume there is no cycle. – Hyungjoo Chae Nov 13 '20 at 10:49
-
Finding the shortest path is in a DAG has complexity ∅(V+E). Code and algorithm available all over on the net. – Tarik Nov 13 '20 at 11:04
-
You say you want the shortest path in the title, but in the end of the description you want the longest one? – Dani Mesejo Nov 13 '20 at 11:09
-
1@DaniMesejo He wants the longest of all those shortest paths. – SpaceTrucker Nov 13 '20 at 13:01
1 Answers
0
You might want to implement the all-pair-shortest-path variant of Hagerup. The time bound of O(nm + n^2 log log n)
might be much better than Floyd–Warshalls O(n^3)
depending on how many edges your graphs have.
You might also be able to set up Neo4j and use it to calculate that path: https://neo4j.com/docs/graph-data-science/current/alpha-algorithms/all-pairs-shortest-path/#algorithm-all-pairs-shortest-path-sample
CALL gds.alpha.allShortestPaths.stream({
nodeProjection: 'Loc',
relationshipProjection: {
ROAD: {
type: 'ROAD',
properties: 'cost'
}
},
relationshipWeightProperty: 'cost'
})
I don't know that, but depending on the syntax you might be able to select only specific paths from the stream.

SpaceTrucker
- 13,377
- 6
- 60
- 99
-
If there are no cycles, the edges are `n - 1` (assuming `n` are the number of nodes), right? – Dani Mesejo Nov 13 '20 at 13:44
-