Hello Everyone,
I have been for the last couple of days,well two weeks to be precise, been trying to implement Yen's k shortest path algorithm. The algorithm is described in a paper from the 1970s
The link K-th Shortest Path Problem has the paper and a few previous papers in case someone is interested in learning more about the algorithm and its alternatives.
Basically, Yen's algorithm is a mutation algorithm which gets rids of segments(called arcs in the paper) of the previously shortest paths and recomputes the shortest path. I have been using dijkstra's algorithm in order to get the shortest paths.(it works just fine, I ran multiple tests on it.)
So, I have been trying to get Yen's algorithm working, and I have run into a theoretical question. Let us assume that we have a random graph in which the first 6 paths between nodes 0 and 50 are as follows: (Generated via a BFS algorithm to get all the paths connecting the two nodes which are then sorted)
0 375 45 46 47 49 50 1.160189
0 375 45 47 49 50 1.16443
0 375 45 46 47 48 50 1.164553
0 375 45 47 48 50 1.168793
0 375 45 46 47 48 49 50 1.174494
0 375 45 47 48 49 50 1.178735
here the floating point number at the end of each line is the "distance" of the path. My question is, how does the Yen's algorithm get the 6th path. From my understanding of the paper it checks if the the first i nodes of the k-1th path correspond to the first i nodes of the previously found paths, if so then d[i][q]=infinity where q is the next node in the path.
Practically speaking to get from the 1st path to the 2nd path, we remove 45-46 in the first path and it recomputes the path. To get from 2nd to 3rd, we get rid of 47-49 in the second path forcing the algorithm to find a new path linking 0 through 47 and 47 through 50 which can then stored.
But when we get to the 6th path, it removes 45-46 but it has to also remove 45-47 since the first 3 nodes of the 5th path also matches the first 3 nodes of the 2nd path( if we don't set this to infinity, then the alogrithm starts cycling between shortest found paths). I do not see how we can get the 6th shortest path.
Any ideas? Am I missing something completely obvious from the paper? Can anyone recommend any books/articles that I can go through which might better explain this. I would prefer not to look through other people's implementation(I have found some MATLAB implementation online but I have been having problems getting through the syntax--it also doesn't help that the documentation for the code is in mandarin). In case someone coded up a solution in C which has some documentation in english that would be helpful too.
Message me in case you guys need more information, and Thanks for all the help.
-H