Yen's Algorithm - root path comparison off by one
Glirastes opened this issue · comments
Consider the problem of finding 5 shortest loopless paths from A to D in the following graph:
There are exactly five shortest loopless paths, but the implementation of Yen's Algorithm finds only four.
Yen's Algorithm compares all previously found shortest paths to the current root path and if they are equal, the next edge of the path is removed so that Dijkstra does not find the same spur path again.
That equality check is off by one - the root path is only compared until one vertex before the spur node, it does not include the spur node itself.
This leads to the false elimination of an edge, that the path normally found last in this example (one of the two using vertices B and C) would contain.
PR is on the way.
This is fixed in pathfinding 4.3.3.