Astar
A* search traversal.
AStarTraversal
dataclass
AStarTraversal(
heuristic: HeuristicFunction,
cost: CostFunction | None = None,
)
Bases: TraversalStrategyABC
A* traversal policy.
search
search(
*,
tree: ConfigurationTree,
generator: MoveGenerator,
goal: GoalPredicate,
max_expansions: int | None = None,
max_depth: int | None = None
) -> SearchResult
Execute search over the tree using the supplied generator.
Source code in .venv/lib/python3.12/site-packages/bloqade/lanes/search/traversal/astar.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | |
astar
astar(
tree: ConfigurationTree,
generator: MoveGenerator,
goal: GoalPredicate,
heuristic: HeuristicFunction,
cost: CostFunction | None = None,
max_expansions: int | None = None,
) -> SearchResult
A* search.
Expands the node with the lowest cost(node) + heuristic(node)
first. With an admissible heuristic (never overestimates), A*
guarantees finding the optimal (lowest cost) solution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tree
|
ConfigurationTree
|
The configuration tree to search. |
required |
generator
|
MoveGenerator
|
Move generator for producing candidates. |
required |
goal
|
GoalPredicate
|
Predicate that returns True for goal configurations. |
required |
heuristic
|
HeuristicFunction
|
Estimates cost to goal. Must be admissible for optimality. Lower is better. |
required |
cost
|
CostFunction | None
|
Accumulated cost function. Defaults to node depth if None. |
None
|
max_expansions
|
int | None
|
Maximum nodes to expand. None means no limit. |
None
|
Returns:
| Type | Description |
|---|---|
SearchResult
|
SearchResult with the goal node (or None if not found). |
Source code in .venv/lib/python3.12/site-packages/bloqade/lanes/search/traversal/astar.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | |