Repository navigation
test(hexmap): measure A* against the bit-parallel BFS (L2) - #138
Merged
Merged
Conversation
A* with the hex distance as heuristic, open list as three bitmap buckets (f, f + 1, f + 2), neighbour classes from the signs of the cube offset, chained backtracking. Measured with a Felt252Dict heap, a sorted array and a scanned array as open lists, a greedy best-first search and the BFS pruned by the hex distance with iterative deepening, on the L1 fixtures and pairs at hex distance 1, 2, 5 and 10. No formulation beats Bfs::search by more than 5 % on a realistic class: the best A* is +16 % to +24 % on open boards and up to 11x on unreachable targets; it only wins on adjacent endpoints (-7 %). Everything stays test-only in tests/bench_astar.cairo; the numbers close the question in GAS.md, section L2. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Summary
Lot L2: why
origami_hexmaphas no A*, answered with measurements. Result: no A* formulation beatsBfs::searchby more than 5 % on a realistic class of inputs, so nothing is exported. Everything is test-only incrates/hexmap/src/tests/bench_astar.cairo. The numbers are inGAS.md, section "L2 A*" (it replaces the "L2 A* baseline" stub).Astar::search(best formulation, test-only). The hex distance is the heuristic. With unit costs, a neighbour'sfis the parent'sfplus 0, 1 or 2, so the open list is three bitmap buckets onu128limbs. Neighbours are split into closer / same-distance / farther classes by 3 field products, chosen by the signs of the cube offset to the target (12 cases, computed withbounded_int). The path is rebuilt from the list of expanded tiles, following chained closer neighbours without a scan. It has the same contract asBfs::search, edge endpoints and panics included.Felt252Dict, a sorted array, and an unsorted array that is scanned.Bfs::searchand a valid path. It is checked on the fixtures, CAVE/MAZE/EMPTY/SERPENTINE samples, random caves and mazes (7x7, 17x14, 19x13), board sizes 3x3 to 83x3 / 3x83, and edge endpoints.Astar::searchvsBfs::searchOne expansion costs 35.5k gas: about 320 CASM steps for index, coordinates, classes, buckets, log and backtracking. A BFS layer costs 19.3k and advances the whole frontier. The dict heap, sorted array and scanned array run at 1.5x to 228x the BFS, greedy at 1.7x to 15x, and the pruned BFS at 1.7x to 40x.
origami_mapA* on 18x14 (17-tile path) costs 17.9M for reference.Only additions:
pub mod bench_astar;inlib.cairo, the bench file, and the GAS.md section. No public API change.Test plan
snforge test -p origami_hexmap astar: 201 tests passed (184 budgeted benchmarks, oracle, panics)scarb fmt --checkTest origami_hexmap🤖 Generated with Claude Code