Skip to content

perf: path_BFS, path_UCS and path_Astar no longer scan lists - #54

Merged
petercorke merged 2 commits into
mainfrom
perf/path-planners
Oct 12, 2026
Merged

petercorke merged 2 commits into
mainfrom
perf/path-planners

Conversation

@petercorke

Copy link
Copy Markdown
Owner

The three planners kept the frontier and explored sets as 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. The new examples/benchmark.py (#55) showed it: BFS was slower than uniform-cost search at 10 000 vertices.

Change

  • BFS: the frontier is a deque, and a set of vertices seen replaces the list scans.
  • UCS, A*: the frontier is an insertion-ordered dict plus a heap. A reparented vertex is pushed again and stale heap entries are skipped when popped.
  • The path is built by appending and reversing, not insert(0, …).

Ties are still broken by the order vertices first joined the frontier (each keeps its original position when reparented), so results and verbose transcripts are unchanged.

Verification

  • Identical paths, lengths and full verbose/summary transcripts 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.py pins the old output, including a reparenting case.
  • 611 tests pass, mypy clean.

Effect

Per query on 10 000 vertices (directed, about 6 edges per vertex):

before after
BFS 145 ms 3.1 ms
UCS 160 ms 6.7 ms
A* 17 ms 3.3 ms

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

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>
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 15 complexity · 0 duplication

Metric Results
Complexity 15
Duplication 0

View in Codacy

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

codecov Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.61%. Comparing base (149abc1) to head (e1c3db2).
⚠️ Report is 3 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@petercorke
petercorke merged commit e658676 into main Oct 12, 2026
12 checks passed
@petercorke
petercorke deleted the perf/path-planners branch October 12, 2026 23:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant