9

Could you recommend any java library which implements k-shortest algorithm -> searching for alternative ways, not the only shortest one in directed multigraph ?

I found only JGraphT but there is actually bug (which i submitted) but it will take a lot of time to fix it i guess, are there any other available implementations ? Except JGraphT i found only small one-man projects :/

OR would be hard to modify Disjktra shortest path alg to show alternative paths ?

Thanks

Martin V.
  • 3,560
  • 6
  • 31
  • 47
  • Are you interested in `k`-shortest edge disjoint or node disjoint paths? For the first, look into min cost max flow algorithms. – IVlad Oct 07 '12 at 22:56

3 Answers3

5

2 Possible Options:

Option 1. The class KshortestPath from the MascOpt Package is a good option for a Java implementation of k-shortest paths.

Option 2. You can also try this from code.google.com This seems to be a one person's effort, but the good thing is that the algorithm is shared: Yen's Ranking - the details are here.(http://www.ohloh.net/p/k-shortest-paths)

Note: Finding the shortest-paths between all pairs of nodes in a given graph is a different problem. See this SO question on Dijkstra vs. Floyd-Warshall.

Also note that k-shortest paths for rich graphs tend to be slight variations of the (Dijkstra) shortest path - alternative paths between vertices on the shortest-path with slightly higher costs.

I know the OP asked for Java implementations but if people have a choice and R is an option, then the kBestShortestPaths package from CRAN is a very good option as well.

Hope that helps.

Community
  • 1
  • 1
Ram Narasimhan
  • 22,341
  • 5
  • 49
  • 55
  • 1
    I just tried Option 2: Yen's algorithm and it worked wonders! Execution time for a graph with ~400 nodes ~1000 links went down from 3000 ms (for JGrapht's implementation) to 0.3 ms for Yen's algorithm implementation. Yeah, 3000 -> 0.3. It's not a typo. – gjain Aug 18 '14 at 13:01
2

Finding the k-shortest paths is related but not the exact same problem as alternative paths. Good alternative paths are more complicated. Have a read where other similar approaches are outlined:

  • k-Shortest Paths
  • Pareto optimality
  • Plateau method
  • Penalty approach

The plateau method is a bit illustrated here.

If it is possible for you to read German then this lecture is nice:

  • e.g. optimizing regarding time or distance => problem: interesting alternatives are missing
  • dijunct paths => same problem
  • k-shortest paths => problem: the real alternative is probably NOT under the first 1000 paths

Page 5

So intuition tells us: an alternative should have nearly identical distance or time. but should be significant different. so the first idea: find a path which minizes length AND similarity. Problem: there could be local detours.

Page 6

we introduce a 3rd criterion: local optimumality: every short subpath needs to be a shortest path.

Karussell
  • 17,085
  • 16
  • 97
  • 197
0

There has been a similar request before, but looking for all paths on StackOverflow. Find all paths in a graph with DFS

Hope this helps, it was answered but not with the exact solution, but more of a guide

Community
  • 1
  • 1
Gigaquad
  • 153
  • 4