Repository navigation
perf: path_BFS, path_UCS and path_Astar no longer scan lists - #54
Merged
Merged
Conversation
The frontier and explored sets were lists searched with 'in', and UCS and A* took np.argmin over the whole frontier at every expansion, so the cost grew roughly as V*E (1.8 power of V in the benchmark). BFS now uses a deque and a set of vertices seen; UCS and A* use a heap with a dict as ordered frontier, reparented vertices being pushed again and stale entries skipped. The path is built by appending and reversing rather than inserting at the front. The ties are broken as before, by the order vertices first joined the frontier, so results and verbose transcripts are unchanged: identical on 10 800 random tie-heavy cases against the previous code, and pinned by tests/test_planner_choices.py. On 10 000 vertices (directed, ~6 edges/vertex), per query: BFS 145 -> 3.1 ms, UCS 160 -> 6.7 ms, A* 17 -> 3.3 ms. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 15 |
| Duplication | 0 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #54 +/- ##
==========================================
+ Coverage 96.41% 96.61% +0.19%
==========================================
Files 3 3
Lines 1339 1358 +19
==========================================
+ Hits 1291 1312 +21
+ Misses 48 46 -2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
The three planners kept the frontier and explored sets as lists searched with
in, and UCS and A* tooknp.argminover the whole frontier at every expansion, so the cost grew roughly as V·E. The newexamples/benchmark.py(#55) showed it: BFS was slower than uniform-cost search at 10 000 vertices.Change
deque, and a set of vertices seen replaces the list scans.insert(0, …).Ties are still broken by the order vertices first joined the frontier (each keeps its original position when reparented), so results and
verbosetranscripts are unchanged.Verification
verbose/summarytranscripts against the previous code on 10 800 random cases (directed and undirected, integer costs so ties are common, loops, parallel edges).tests/test_planner_choices.pypins the old output, including a reparenting case.Effect
Per query on 10 000 vertices (directed, about 6 edges per vertex):
Growth exponent from N=100 to 10 000: BFS 1.8 → 1.1, UCS 1.6 → 1.0, A* 1.2 → 0.9.
🤖 Generated with Claude Code