![]() |
|
#1
|
|||
|
|||
Finding alternate paths using Dijkstra algorithmI am pasting here code for finding path using Dijkstra algorithm
CPP / C++ / C Code:
This is the output you get when you run the program: Code:
I want other paths which are also shortest should be printed. that is, below path should also be printed Code:
Thanks in advance Vikash |
|||
|
#2
|
|||
|
|||
Re: Finding alternate paths using Dijkstra algorithmFirstly, you have to find all paths from "source" to "destination", after you have to select all paths with minimum number of hops.
|
|
#3
|
|||
|
|||
Re: Finding alternate paths using Dijkstra algorithmThanks for your reply, but I know this that I have to find out all paths from "source" to "destination", then I have to select all paths with minimum number of hops.
Question is what change should be made to the code pasted above to achieve the desired result ? Thanks Vikash |
|
#4
|
|||
|
|||
Re: Finding alternate paths using Dijkstra algorithmHere, I am attaching a picture of the matrix shown in code. Please help me out in solving the above scenario.
Thanks Vikash |
|
#5
|
||||
|
||||
Re: Finding alternate paths using Dijkstra algorithmIf you're looking for every alternate shortest path, you're out of luck. The reason is that the number of shortest paths can be exponential in the number of edges in the graph. (Or even infinite if there are zero weight cycles). If you want to find a subset of all the shortest paths, given any shortest path, you know that an alternate shortest path must omit at least one edge that is on your original shortest path. Thus you can remove one edge at a time from one of the original shortest paths in your graph, re-run the algorithm, and see if the new path you get has the same length. If you only get longer paths each time, the shortest path you've found must be unique. Otherwise, you will have a new shortest path.
__________________
www.blake-foster.com |
|
#6
|
|||
|
|||
Re: Finding alternate paths using Dijkstra algorithmI am looking for every alternate shortest path, as I have explaned in my first post. that is,
Code:
Suppose, I have a static graph as shown in the matrix in the above code, & I don't want to re-run code everytime by removing one edge at a time. Just it should print all the alternate paths. Thanks Vikash |
|
#7
|
||||
|
||||
Re: Finding alternate paths using Dijkstra algorithmIf you don't want to re-run the code every time, you should just use depth-first search and cut off the search when the distance reaches the length of the shortest path. I suggested re-running Dijkstra because you asked how to modify the existing code.
Normally, depth-first search will keep track of visited nodes and cut off when you come to a node you have already visited. In this case you should not do that, since you want every path. Just keep in mind that due to the (possibly) exponential number of shortest paths, on some inputs this algorithm will still be running when we're all dead and buried. __________________
www.blake-foster.com |
Recent GIDBlog
Once again, no time for hobbies by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| all paths on Dijkstra - handle vector | cpit | C++ Forum | 1 | 13-Jul-2006 09:23 |
| all shortest paths with dijkstra | cpit | C++ Forum | 0 | 05-Jun-2006 11:07 |
| Algorithm Help Please! | daking_09 | C++ Forum | 0 | 24-May-2006 20:12 |
| bug finding in searching algorithm! | robin1977 | C Programming Language | 0 | 24-Mar-2005 21:30 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The