Skip to content
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

Custom priority queues for Dijkstra & Co #129

Open
gdalle opened this issue May 19, 2022 · 7 comments
Open

Custom priority queues for Dijkstra & Co #129

gdalle opened this issue May 19, 2022 · 7 comments
Assignees
Labels
enhancement New feature or request

Comments

@gdalle
Copy link
Member

gdalle commented May 19, 2022

At the moment, shortest path algorithms such as Dijkstra and A* rely on the standard PriorityQueue from DataStructures.jl, partly because it supports updating the priority value of a stored element.

However, there are alternative implementations that do not require this property, and those can be faster in many cases.
Would it make sense to add a method that lets the user choose the priority queue they want, along with the version of the algorithm (with or without priority updates)?

@gdalle gdalle added the enhancement New feature or request label May 19, 2022
@gdalle gdalle self-assigned this May 19, 2022
@gdalle
Copy link
Member Author

gdalle commented May 19, 2022

Here is an example of benchmark that shows the promise of this idea
https://gdalle.github.io/FastPriorityQueues.jl/dev/benchmarks/
ping @etiennedeg if you want to add some more tests when you have time

@simonschoelly
Copy link
Contributor

Is there really a good use case for letting the user choose their own priority queue? Maybe we should just pick the fasted one for them.

Also, currently the priority queue used for a_star is parametrized with Integer, an abstract data type - we might already be able to improve performance by using a concrete type there:

open_set = PriorityQueue{Integer, T}()

@gdalle
Copy link
Member Author

gdalle commented May 19, 2022

It doesn't cost much to define dijkstra!(queue, ...) internally and then add a default choice

@gdalle
Copy link
Member Author

gdalle commented May 20, 2022

See https://discourse.julialang.org/t/fast-er-priority-queues/81269 for a discussion and some benchmarks

@etiennedeg
Copy link
Member

Seems we can get about a 2x acceleration based on the HeapPriorityQueue. For unweighted graphs, it would also be nice to specialize the code. Because the priority queue at any given point will only hold two different values, I think we can avoid priority queue by storing vertices in two queues: one with the vertices at the currently evaluated distance, and one with vertices one unit further.

@gdalle
Copy link
Member Author

gdalle commented May 20, 2022

For unweighted graphs, isn't Dijkstra just BFS?

@gdalle
Copy link
Member Author

gdalle commented May 20, 2022

For which, by the way, an iterator would be nice (see #106)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants