-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
shortestPathTo sometimes returns incorrect answer due to incorrect node visit order #9
Comments
This is an example graph which gives the wrong answer: |
On larger graphs, just adding nodes to the priority queue with the correct weight causes a crippling slowdown for me (but at least it's giving the right answer). Probably because the same node may be added to the priority queue potentially many times. What is really wanted is a way of updating the ordering of the queue as the tentative distance of a node changes, like what is described in http://algorithms.soc.srcf.net/notes/dijkstra_with_heaps.pdf |
Hi Gary, thanks for reporting and even providing a test and the accompanying fix! Would you mind creating a pull request later on? |
No problem! I've opened a pull request (now that I understand the problem, there's a better test case included). |
It seems we can close this issue due to your fix documented in #10. Any objectives? |
I think it's fixed, thanks for reviewing/accepting the changes! |
shortestPathTo implements Dijkstra's algorithm for selecting the shortest path between two nodes. It appears that the implementation is incorrect, and the wrong answer is sometimes given.
From http://en.wikipedia.org/wiki/Dijkstra's_algorithm
However, the priority queue used to select the next node uses the node's distance from one of its predecessors, not the current smallest tentative distance from the start. This may mean that new nodes (which should already have a large distance) may be visited before earlier nodes, and the algorithm may terminate incorrectly.
The text was updated successfully, but these errors were encountered: