-
-
Notifications
You must be signed in to change notification settings - Fork 503
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
faster bidirectional dijkstra using pairing heap #39228
base: develop
Are you sure you want to change the base?
faster bidirectional dijkstra using pairing heap #39228
Conversation
a few timings to see the advantage of the new implementation sage: G = graphs.PetersenGraph()
sage: %timeit G._backend.bidirectional_dijkstra_old(0, 1)
10.6 µs ± 31.9 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each)
sage: %timeit G._backend.bidirectional_dijkstra(0, 1)
10.4 µs ± 10.4 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each)
sage: G = graphs.RandomGNP(10, .5)
sage: %timeit G._backend.bidirectional_dijkstra_old(0, 1)
23.2 µs ± 65 ns per loop (mean ± std. dev. of 7 runs, 10,000 loops each)
sage: %timeit G._backend.bidirectional_dijkstra(0, 1)
20.6 µs ± 105 ns per loop (mean ± std. dev. of 7 runs, 10,000 loops each)
sage: G = graphs.RandomGNP(10, .3)
sage: %timeit G._backend.bidirectional_dijkstra_old(0, 1)
17.2 µs ± 41.8 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each)
sage: %timeit G._backend.bidirectional_dijkstra(0, 1)
15.6 µs ± 41.6 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each)
sage: G = graphs.RandomGNP(100, .05)
sage: %timeit G._backend.bidirectional_dijkstra_old(0, 1)
309 µs ± 908 ns per loop (mean ± std. dev. of 7 runs, 1,000 loops each)
sage: %timeit G._backend.bidirectional_dijkstra(0, 1)
259 µs ± 677 ns per loop (mean ± std. dev. of 7 runs, 1,000 loops each)
sage: G = graphs.RandomGNP(100, .1)
sage: %timeit G._backend.bidirectional_dijkstra_old(0, 1)
587 µs ± 1.48 µs per loop (mean ± std. dev. of 7 runs, 1,000 loops each)
sage: %timeit G._backend.bidirectional_dijkstra(0, 1)
437 µs ± 1.2 µs per loop (mean ± std. dev. of 7 runs, 1,000 loops each)
sage: G = graphs.RandomGNP(100, .3)
sage: %timeit G._backend.bidirectional_dijkstra_old(0, 1)
1.61 ms ± 3.18 µs per loop (mean ± std. dev. of 7 runs, 1,000 loops each)
sage: %timeit G._backend.bidirectional_dijkstra(0, 1)
1.2 ms ± 1.67 µs per loop (mean ± std. dev. of 7 runs, 1,000 loops each)
sage: G = graphs.RandomGNP(10000, .0005)
sage: %timeit G._backend.bidirectional_dijkstra_old(0, 1)
35.6 ms ± 170 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)
sage: %timeit G._backend.bidirectional_dijkstra(0, 1)
31.7 ms ± 311 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)
sage: G = graphs.RandomGNP(10000, .001)
sage: %timeit G._backend.bidirectional_dijkstra_old(0, 1)
61.8 ms ± 137 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)
sage: %timeit G._backend.bidirectional_dijkstra(0, 1)
52.5 ms ± 615 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)
sage: G = graphs.RandomGNP(10000, .005)
sage: %timeit G._backend.bidirectional_dijkstra_old(0, 1)
119 ms ± 542 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)
sage: %timeit G._backend.bidirectional_dijkstra(0, 1)
103 ms ± 1 ms per loop (mean ± std. dev. of 7 runs, 10 loops each) |
Documentation preview for this PR (built with commit 13c7a89; changes) is ready! 🎉 |
It does seem to be faster indeed. Is there a theoretical guarantee for this? Can you remove the |
With a priority queue, insertion is done in With a pairing heap, insertion is done in |
We improve method
bidirectional_dijkstra
fromc_graph.py
by using the new pairing heap data structure (see #39046) instead of apriority_queue
.For the duration of the review, I have renamed the former method
bidirectional_dijkstra_old
and it can be accessed usingG._backend.bidirectional_dijkstra_old(...)
. It will be removed at the end of the review process.I also plan to do similar changes to
bidirectional_dijkstra_special
in a follow-up PR.📝 Checklist
⌛ Dependencies