0

I have a database that describes a huge network. It consists of about 18000 vertices. Now I need to find all possible shortest paths between a pair of nodes. I have tried implementing the iterative DFS, but the problem there is the exponential growth.The amount of time needed gets huge, since there vertices having a high out-degree. Can you suggest of some algorithm that would work faster. The complex network that I have is directed and weighted.Any suggestions would be great help.

Thanks, Ekta

Ekta
  • 3
  • 2
  • Do you really want to implement it? Or would an existing tool be ok? – Vincent Labatut Apr 05 '15 at 06:50
  • Yes I need to implement it. Are there any existing tools to find the paths? If yes I would also like to have a look at them – Ekta Apr 05 '15 at 11:31
  • There are many graph-related libraries you could use. The first that comes to mind is igraph (available for C, R and Python at http://igraph.org/redirect.html). Regarding your data, are the links weighted, and if yes, can those weights be negative values? – Vincent Labatut Apr 05 '15 at 21:35
  • Yes the links are weighted but the weights are all positive. – Ekta Apr 06 '15 at 08:08

1 Answers1

0

For a weighted graph with positive weights, one generally uses uniform-cost search, aka Dijkstra's algorithm. Other algorithms can be faster in specific cases. For example, if your data allow you to define a heuristic function, you could use A* instead. Or if your network is scale-free (i.e. its degree is power law distributed), you can use a variant of Dijkstra's algorithm described in Peng et al.'12.

There are also a bunch of related SO questions you might want to look at, such as Is there better way than a Dijkstra algorithm for finding fastest path that do not exceed specified cost or Are there faster algorithms than Dijkstra?.

EDIT: to find all shortest paths between a given pair of nodes, you can still use Dijkstra, with a few changes:

  • Use a searching tree to apply the algorithm (by opposition to applying the algorithm based directly on the graph you explore). This way, you can easily represent several paths leading to the same node. See the WP Breadth-first search article to see an example of searching tree. So this is more a matter of data structure.
  • Allow an already visited node to be visited again, provided 1) the path leading to this node is different from the one already represented in the tree, and 2) is not longer than this existing path. In terms of searching tree, this means allowing one graph-node to be represented as two distinct tree-nodes, each one in a different branch.
  • Develop the tree until you find a first optimal solution, then go on developing the tree using the length of this solution as a limit (i.e. you stop developping a branch when it reaches this length).
  • In the end, each branch containing the targeted node should correspond to an optimal shortest path.

You can also have a look at this question (although it concerns unweighted graphs): Finding all the shortest paths between two nodes in unweighted undirected graph

Community
  • 1
  • 1
Vincent Labatut
  • 1,788
  • 1
  • 25
  • 38
  • Yes using Dijkstra's algorithm is a solution but I need to find all possible shortest paths, not the single shortest path – Ekta Apr 07 '15 at 07:29
  • Then I suggest you edit your question and its title, in which you state you look for the shortest path between *a* pair of nodes. Also, I edited my answer. – Vincent Labatut Apr 07 '15 at 10:35
  • I actually have a pair of nodes and I am looking for all the possible shortest paths between them. For a given pair of nodes, there can exist multiple paths of the same lengths and that is what I wish to find. Floyd-Warshall is for all-pair shortest paths, isn't it? Do you think looking at some k-shortest paths algorithms would be helpful? – Ekta Apr 08 '15 at 08:53
  • Ok, now I understand what you mean. I edited my answer accordingly. – Vincent Labatut Apr 08 '15 at 11:21