Expand description
§Heuristic search
Explicit-state heuristic graph search: A*, weighted and anytime, bounded-suboptimal, bidirectional, incremental and real-time search.
A problem is described by small capability traits instead of one universal problem
trait: a graph implements Successors, the goal test is a Goal and the estimate a
Heuristic. Goal tests can be closures; heuristic_fn wraps a closure as a
heuristic. Searches own their heuristic; pass &mut h to lend one and keep its
workspace. Every search returns a SearchResult with an Outcome (a Solution
path, unsolvable, or limit reached) and Stats. A Budget (such as Limits, or a
closure that checks a clock) stops a search early.
The crate is no_std and needs only alloc.
§Algorithms
bfs(): breadth-first search, fewest edges.dijkstra: uniform-cost search, cheapest path.a_star: A*, cheapest path with an admissible heuristic.weighted_a_star: Weighted A*, at mostwtimes the cheapest cost.gbfs: greedy best-first search, fast and unbounded.fringe_search: fringe search, cheapest path with an admissible heuristic throughfthreshold iterations over a cache of every state, without a priority queue.
Each has a *_multi variant (a_star_multi and so on) that searches from several
start states at once. So does every other search below; the incremental planners have
multi-start types (LpaStarMulti and so on) with fixed starts.
Depth-first searches need memory only for the current path (except dfs):
dfs: graph depth-first search, some path.depth_limited_dfsandiddfs: depth-limited and iterative deepening, fewest edges.ida_star: IDA*, cheapest path with an admissible heuristic;ida_star_ttadds a bounded transposition table for graphs with many paths to each state.rbfs(): recursive best-first search (RBFS), cheapest path with an admissible heuristic, in best-first order with memory linear in the depth.
sma_star (SMA*) is A* within a fixed number of nodes: it forgets its worst leaves
and regenerates them when needed, and returns the cheapest path among those that fit in
memory, or Outcome::Cutoff when none does.
Anytime searches report each improved solution and return an AnytimeResult:
ara_star: ARA*, Weighted A* with a falling weight schedule.ana_star: ANA*, anytime without parameters.beam_stack_search: beam-stack search, a beam of fixed width that backtracks over what it pruned; optimal once complete, in memory bounded by the width per layer.
beam_search is breadth-first beam search: a fixed number of states per layer, fast
but incomplete (Outcome::Cutoff when the width may have pruned the goal away).
Bounded-suboptimal searches return a solution within w times the optimum:
focal_search: expands by a freeFocalKeyamongf <= w * f_min. Its open list,FocalList, is public for searches with their own loop.ees: Explicit Estimation Search, guided by inadmissible estimates.dps: Dynamic Potential Search, needs onlyh.
Bidirectional searches need Predecessors as well (a BidirectionalGraph) and
explicit goal states:
bidirectional_bfsandbidirectional_dijkstra: blind baselines.nbs: Near-Optimal Bidirectional Search, pairs of expansions.dibbsandbae_star: DIBBS and BAE*, ordered by2g + h - h_opposite.
The frontiers meet by state equality. The *_meet variants (nbs_meet,
bidirectional_bfs_meet and so on) meet by a MeetRelation instead, such as a
state satisfying a subgoal for regression over partial states of their own type (a
RegressionGraph), and replay the backward actions to return a path of real states
or a ReplayError.
Grid searches work on a UniformGrid, 8-connected without corner cutting (see
UniformGrid), with the exact octile cost Octile:
jps: Jump Point Search, cheapest path, expanding only jump points.theta_starandlazy_theta_star(featurefloat): Theta* and Lazy Theta*, any-angle paths between cell centres on aLineOfSightgrid, with Euclidean float costs; never longer than the cheapest 8-connected path (Theta*).
EightConnected makes a grid a plain graph for the other searches.
mha_star (shared multi-heuristic A*) combines one consistent anchor heuristic with
any number of inadmissible ones, within w1 * w2 times the optimum.
lazy_sp (LazySP) finds cheapest paths when true edge costs are expensive, evaluating
them through an EdgeEvaluator only on candidate paths.
Incremental planners keep their search tree while edge costs of a DynamicGraph
change, and repair only what the changes affect:
LpaStar: Lifelong Planning A*, fixed start and goal.DStarLite: D* Lite, fixed goal and a moving start.AdStar: Anytime D*, D* Lite with an inflated heuristic the caller lowers.FieldDStar(featurefloat): Field D*, D* Lite over the corners of aCostGridwith per-cell costs, whose paths cross cells at any angle through points on cell edges.
Real-time searches plan a bounded amount, move, and learn values in a
LearnedHeuristic the caller keeps across trials; each call runs one trial and
returns a TrialResult:
lrta_starandrta_star: LRTA* and RTA*, a lookahead of one expansion.lss_lrta_star: LSS-LRTA*, an A* lookahead ofnexpansions and a Dijkstra update.lhb_lrta_star: the same agent with the limited-horizon Bellman update of Hadar et al.;lhb_updateis that update on its own, for offline learning.rtaa_star: RTAA*, the A* lookahead with a cheaper update.
Costs are generic over Cost. For planning, u32 is the intended default: action
costs are small integers and heuristics over them stay exact. Cost, Heuristic,
Goal and Budget come from search-core and are re-exported here; CostExt
adds the subtraction and float conversion a few searches need.
§Features
float: re-exports the checked float costNonNegF64fromsearch-core, and enables the any-angle grid searchestheta_starandlazy_theta_starand the Field D* plannerFieldDStarwith itsCostGrid, whose Euclidean costs are floats.
§Example
use heuristic_search::{Limits, Successors, dijkstra};
/// A directed graph as adjacency lists of `(target, cost)` pairs.
struct Graph(Vec<Vec<(usize, u32)>>);
impl Successors for Graph {
type State = usize;
type Action = usize;
type Cost = u32;
fn successors(&self, state: &usize, mut emit: impl FnMut(usize, usize, u32)) {
for &(target, cost) in &self.0[*state] {
emit(target, target, cost);
}
}
}
let graph = Graph(vec![vec![(1, 5), (2, 1)], vec![(3, 1)], vec![(1, 1)], vec![]]);
let result = dijkstra(&graph, 0, &|state: &usize| *state == 3, Limits::NONE);
let solution = result.solution().expect("3 is reachable");
assert_eq!(solution.states, [0, 2, 1, 3]);
assert_eq!(solution.cost, 3);§Naming
Searches are snake-case functions; every A* variant ends in _star (a_star,
weighted_a_star, ida_star, ara_star, ana_star, mha_star,
bae_star). Suffixes compose in this order: _tt (a variant of the algorithm),
_multi (several starts), _meet (a meet relation, always with several starts).
Incremental planners keep state between calls, so they are types (LpaStar,
DStarLite, AdStar, FieldDStar).
See docs/design.md in the repository for the design.
Repository: https://github.com/sunsided/heuristic-search
Structs§
- AdStar
- Anytime Dynamic A* (AD*, Likhachev, Ferguson, Gordon, Stentz and Thrun 2005): D* Lite with an inflated heuristic, so a first path comes fast and improves as time allows, while the start moves and edges change.
- AdStar
Multi AdStarfrom several fixed starts: eachcomputereturns a path from the best start within the current weight of the optimum. The starts cannot move.- Anytime
Result - What an anytime search returns: the best solution found and whether the search ran to completion.
- DStar
Lite - D* Lite (Koenig and Likhachev 2002): incremental search towards a fixed goal from a start that moves, as when a robot replans while it drives and discovers obstacles.
- DStar
Lite Multi DStarLitefrom several fixed starts: the search runs from the goal towards a super-start joined to every start, so it repairs the cheapest path from any start after edge changes. The starts cannot move.- Decimal
- A non-negative fixed-point decimal cost with
Kdecimal places. - EesEstimates
- The three estimates
eescombines. - Eight
Connected - A
UniformGridas an 8-connected graph withOctilecosts, for the general searches (a_starand the others) on the same moves thatjps()uses. - FieldD
Star - Field D* (Ferguson and Stentz 2005, 2006): D* Lite over the corners of a
CostGrid, with costs interpolated along cell edges, so paths cross cells at any angle instead of in 45 degree steps. - FocalFn
- A closure used as a state-only
FocalKey; created byfocal_fn. - Focal
List - Open items under an admissible order
fwith a focal sublist ordered by a second key. - Heuristic
Fn - A closure used as a
Heuristic; created byheuristic_fn. - Learned
Heuristic - A heuristic that real-time searches learn: a table of learned values in front of a base heuristic.
- Limits
- Simple counter limits. The default is unlimited.
- LpaStar
- Lifelong Planning A* (LPA*, Koenig, Likhachev and Furcy 2004): A* that repairs its search tree after edge-cost changes instead of starting over.
- LpaStar
Multi LpaStarfrom several fixed starts to one goal: the cheapest path from any start, repaired after edge changes.- MeetFn
- A
MeetRelationfrom a closuremeets(forward_state, backward_node) -> bool, checked against every node of the opposite side; created bymeet_fn. - MhaWeights
- The two weights of
mha_star. The solution costs at mostheuristic * anchortimes the optimum. - NonNeg
F64 - A non-negative, non-NaN
f64cost;+∞is allowed and acts as the largest cost. - Octile
- An exact octile cost
straight + diagonal * √2: a number of straight and of diagonal unit moves. - Octile
Distance - The octile distance to a fixed goal cell, as a
Heuristicover cells: admissible and consistent on every 8-connected grid. - Replay
Error - A
_meetsearch could not turn its meet into a path of real states:statehas no successor edge labelledaction, although the backward search used that action. - Search
Result - The result of one search run.
- Solution
- A path from the start state to a goal state.
- Stats
- Counters collected during one search run.
- Trial
Result - The result of one real-time trial.
- Trial
Stats - Counters of one real-time trial, beyond the search
Stats. - Weight
- A rational heuristic weight
w = numerator / denominatorfor Weighted A*. - Zero
- The blind heuristic: estimates
Cost::ZEROeverywhere. Turns A* into Dijkstra’s algorithm and is admissible and consistent for every non-negative cost.
Enums§
- Edge
Selector - Which unevaluated edges of a candidate path
lazy_spevaluates next. - Outcome
- How a search ended.
- TieBreak
- How equal keys are ordered, after the primary and (for the focal sublist) the focal key.
Traits§
- Bidirectional
Graph - A graph that can be searched in both directions over the same states.
- Budget
- Decides when a search must stop before it finishes, given its counters so far.
- Cost
- A non-negative scalar edge or path cost.
- CostExt
- Priority arithmetic that
Costlacks: subtraction and conversion tof64. - Cost
Grid - A
UniformGridwhose passable cells have traversal costs, for Field D* (FieldDStar, featurefloat). - Dynamic
Graph - A graph with stable vertices whose edge costs may change between searches.
- Edge
Evaluator - Computes the true cost of an edge, which is expensive (a collision check, a simulation).
- Focal
Key - The focal key of a search node, computed along the path that reaches it.
- Goal
- A goal test over states of type
S. - Heuristic
- An estimate of the cost from a state of type
Sto the nearest goal, in cost typeC. - Line
OfSight - A
UniformGridthat can tell whether the straight segment between two cell centres is free, for any-angle searches such astheta_star(featurefloat). - Meet
Relation - Which forward states (
S) meet which backward nodes (N) in a bidirectional search. - Predecessors
- A graph that can enumerate the predecessors of a node, for backward and bidirectional search.
- Regression
Graph - A graph searched forwards over its states and backwards over its own node type.
- Successors
- A graph that can enumerate the successors of a state.
- Uniform
Grid - A rectangular grid of cells that are passable or blocked, for 8-connected searches with uniform costs.
Functions§
- a_star
- A* search from
startto the first state that satisfiesgoal. - a_
star_ multi a_starfrom several start states at once, to the cheapest goal from any of them.- ana_
star - Anytime Nonparametric A* (ANA*): anytime search without a weight schedule.
- ana_
star_ multi ana_starfrom several start states at once.- ara_
star - Anytime Repairing A* (ARA*): a series of Weighted A* searches with falling weights that reuse each other’s work.
- ara_
star_ multi ara_starfrom several start states at once.- bae_
star - Bidirectional A* with error (BAE*, Sadhukhan 2013).
- bae_
star_ meet bae_starthat meets by aMeetRelationinstead of state equality, from several starts at once.- bae_
star_ multi bae_starfrom several start states at once.- beam_
search - Breadth-first beam search with beam width
width: fast and memory-light, but incomplete and not optimal. - beam_
search_ multi beam_searchfrom several start states at once: the starts form the first layer, pruned towidthlike every other layer.- beam_
stack_ search - Beam-stack search with beam width
width: complete, and optimal for an admissible heuristic once it runs to completion, in memory of aboutwidthstates per layer. - beam_
stack_ search_ multi beam_stack_searchfrom several start states at once: the starts form the first layer, to the cheapest goal from any of them.- bfs
- Breadth-first search from
startto the goal with the fewest edges. - bfs_
multi - Breadth-first search from several start states at once, to the goal with the fewest edges from any of them.
- bidirectional_
bfs - Bidirectional breadth-first search: the path with the fewest edges.
- bidirectional_
bfs_ meet bidirectional_bfsthat meets by aMeetRelationinstead of state equality, from several starts at once: the path with the fewest edges through a meet.- bidirectional_
bfs_ multi bidirectional_bfsfrom several start states at once.- bidirectional_
dijkstra - Bidirectional Dijkstra: uniform-cost search from both ends, cheapest path.
- bidirectional_
dijkstra_ meet bidirectional_dijkstrathat meets by aMeetRelationinstead of state equality, from several starts at once.- bidirectional_
dijkstra_ multi bidirectional_dijkstrafrom several start states at once.- depth_
limited_ dfs - Depth-limited depth-first tree search: a path of at most
limitedges. - depth_
limited_ dfs_ multi depth_limited_dfsfrom several start states at once.- dfs
- Graph depth-first search: follows the newest successor first and finds some path, not necessarily a short or cheap one.
- dfs_
multi dfsfrom several start states at once.- dibbs
- Dynamically Improved Bounds Bidirectional Search (DIBBS, Sewell and Jacobson 2021).
- dibbs_
meet dibbsthat meets by aMeetRelationinstead of state equality, from several starts at once.- dibbs_
multi dibbsfrom several start states at once.- dijkstra
- Dijkstra’s algorithm (uniform-cost search) from
startto the cheapest goal. - dijkstra_
multi dijkstrafrom several start states at once, to the cheapest goal from any of them.- dps
- Dynamic Potential Search (DPS): bounded suboptimal search without a second estimate,
within
weighttimes the optimum. - dps_
multi dpsfrom several start states at once.- ees
- Explicit Estimation Search (EES): bounded suboptimal search guided by inadmissible
estimates, within
weighttimes the optimum. - ees_
multi eesfrom several start states at once.- focal_
fn - Turns a closure
FnMut(&S) -> Kinto aFocalKeythat depends on the state alone. - focal_
search - Focal search (A*ε, Pearl and Kim 1982): a solution within
weighttimes the optimum, expanding by a free secondary key. - focal_
search_ multi focal_searchfrom several start states at once.- fringe_
search - Fringe search from
startto the first state that satisfiesgoal: optimal with an admissible heuristic, without a priority queue. - fringe_
search_ multi fringe_searchfrom several start states at once, to the cheapest goal from any of them.- gbfs
- Greedy best-first search: always expands the state with the smallest heuristic value.
- gbfs_
multi gbfsfrom several start states at once.- heuristic_
fn - Turns a closure
FnMut(&S) -> Option<C>into aHeuristic. - ida_
star - Iterative deepening A* (IDA*, Korf 1985): cheapest path with an admissible heuristic, in memory linear in the path length.
- ida_
star_ multi ida_starfrom several start states at once.- ida_
star_ tt - IDA* with a bounded transposition table of
capacitystates:ida_starthat searches below a state at most once per iteration and path cost. - ida_
star_ tt_ multi ida_star_ttfrom several start states at once, asida_star_multidoes.- iddfs
- Iterative deepening depth-first search (IDDFS): the path with the fewest edges, in memory linear in its length.
- iddfs_
multi iddfsfrom several start states at once.- jps
- Jump Point Search from
starttogoalon an 8-connected grid: a cheapest path, usually after far fewer expansions than A*. - jps_
multi jpsfrom several start cells at once, to the cheapest path from any of them.- lazy_sp
- Lazy shortest path (LazySP): the cheapest path while evaluating as few true edge costs as possible.
- lazy_
sp_ multi lazy_spfrom several start states at once.- lazy_
theta_ star - Lazy Theta*:
theta_starwith far fewer line-of-sight checks. - lazy_
theta_ star_ multi lazy_theta_starfrom several start cells at once, with the start handling oftheta_star_multi.- lhb_
lrta_ star - One trial of LSS-LRTA*’s agent with the limited-horizon Bellman update (LHB) of Hadar
et al. 2025 (“Beyond Single-Step Updates”, arXiv 2511.10264), learning in
table. - lhb_
update - The limited-horizon Bellman update (LHB) of Hadar et al. 2025, Algorithm 1, on the
states around
sample; returns how many table values changed. - lrta_
star - One trial of LRTA* (Korf 1990) from
startto a state that satisfiesgoal, learning intable. - lss_
lrta_ star - One trial of LSS-LRTA* (Koenig and Sun 2009) from
startto a state that satisfiesgoal, learning intable. - meet_fn
- Turns a closure
Fn(&S, &N) -> bool(forward state, backward node) into a scanningMeetRelation. - mha_
star - Shared multi-heuristic A* (SMHA*): Weighted A* over one anchor queue and one queue per inadmissible heuristic, sharing path costs.
- mha_
star_ multi mha_starfrom several start states at once.- nbs
- Near-Optimal Bidirectional Search (NBS): expands pairs of states, one per side, and never expands more than twice the states any admissible front-to-end bidirectional search must.
- nbs_
meet nbs()that meets by aMeetRelationinstead of state equality, from several starts at once.- nbs_
multi nbsfrom several start states at once.- rbfs
- Recursive best-first search (RBFS) from
start: cheapest path with an admissible heuristic, in memory linear in the search depth. - rbfs_
multi rbfsfrom several start states at once, to the cheapest goal from any of them.- rta_
star - One trial of RTA* (Korf 1990) from
startto a state that satisfiesgoal, learning intable. - rtaa_
star - One trial of RTAA* (Koenig and Likhachev 2006) from
startto a state that satisfiesgoal, learning intable. - sma_
star - SMA* from
startwith at mostmemorysearch nodes in memory: A* that forgets its worst leaves when memory runs out and regenerates them when needed. - sma_
star_ multi sma_starfrom several start states at once.- theta_
star - Theta* from
starttogoal: a short any-angle path between cell centres. - theta_
star_ multi theta_starfrom several start cells at once.- weighted_
a_ star - Weighted A*: A* ordered by
g + w * h, trading solution quality for speed. - weighted_
a_ star_ multi weighted_a_starfrom several start states at once.
Type Aliases§
- AnyAngle
Result - The result type of the any-angle searches: a path of cell centres joined by straight segments, with its Euclidean length.
- Anytime
Graph Result - The result type of anytime searches over graph
G. - Dynamic
Result - The result of an incremental search: a path of vertices. Edges carry no labels, so the
solution’s actions are
(). - Field
Result - The result of
FieldDStar::compute: the path as points(x, y)in grid coordinates, joined by straight segments, with its cost. - Graph
Result - The result type of searches over graph
G. - Grid
Cell - A cell of a grid:
(x, y), column first. - Grid
Step - A unit step
(dx, dy)between neighbouring cells, each component-1,0or1. - Meet
Result - What a
_meetsearch returns: the search result, or theReplayErrorif its solution could not be replayed as real states.