Repository navigation
Add a distance cutoff to Dijkstra path lengths - #1702
Open
Ge Li (galleonli) wants to merge 1 commit into
Open
Ge Li (galleonli) wants to merge 1 commit into
Ge Li (galleonli) wants to merge 1 commit into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1674.
Add an optional
cutofftodijkstra_shortest_path_lengthsand its graph/digraph variants. The boundary is inclusive, including zero-cost paths when the cutoff is zero. A goal beyond the cutoff returns an empty mapping. Negative and NaN cutoffs raiseValueError.The bounded path uses the existing Rust Dijkstra traversal, with a Rust visitor that stops when the next finalized distance exceeds the cutoff. It records results in a sparse mapping rather than allocating and scanning a graph-sized distance array. This avoids Python visitor callbacks; the edge-cost callable still runs in Python. Omitting the cutoff keeps the existing Dijkstra implementation. No Rust core API changes are needed.
Local validation on macOS arm64: the Python suite passed with 2,390 tests and 20 skips. Another 16,800 queries on 800 seeded multigraphs matched NetworkX, covering directed and undirected graphs, removed nodes, parallel edges, zero weights, and goals. Rust workspace tests, strict Clippy, stubtest, Ruff, rustfmt and the Rust core documentation build passed.
In same-environment release-build comparisons, a 100,000-node path queried to distance 10 took about 1.14 µs, versus 4.08 µs with a Python visitor. A 200-by-200 grid queried to distance 8 took 15.5 µs versus 84.6 µs. These are synthetic graph-query timings, not application benchmarks. Unbounded calls measured 3–7% slower across the two builds, despite retaining the original algorithm; this remains a performance limitation of the current patch. The existing node-bound visit bitset is also retained, so the query does not use strictly radius-only memory.
Codex assisted with implementation, tests, benchmarking, and this description.