Skip to main content

Crate heuristic_search

Crate heuristic_search 

Source
Expand description

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 most w times the cheapest cost.
  • gbfs: greedy best-first search, fast and unbounded.
  • fringe_search: fringe search, cheapest path with an admissible heuristic through f threshold 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_dfs and iddfs: depth-limited and iterative deepening, fewest edges.
  • ida_star: IDA*, cheapest path with an admissible heuristic; ida_star_tt adds 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 free FocalKey among f <= 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 only h.

Bidirectional searches need Predecessors as well (a BidirectionalGraph) and explicit goal states:

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_star and lazy_theta_star (feature float): Theta* and Lazy Theta*, any-angle paths between cell centres on a LineOfSight grid, 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 (feature float): Field D*, D* Lite over the corners of a CostGrid with 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_star and rta_star: LRTA* and RTA*, a lookahead of one expansion.
  • lss_lrta_star: LSS-LRTA*, an A* lookahead of n expansions and a Dijkstra update.
  • lhb_lrta_star: the same agent with the limited-horizon Bellman update of Hadar et al.; lhb_update is 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 cost NonNegF64 from search-core, and enables the any-angle grid searches theta_star and lazy_theta_star and the Field D* planner FieldDStar with its CostGrid, 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.
AdStarMulti
AdStar from several fixed starts: each compute returns a path from the best start within the current weight of the optimum. The starts cannot move.
AnytimeResult
What an anytime search returns: the best solution found and whether the search ran to completion.
DStarLite
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.
DStarLiteMulti
DStarLite from 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 K decimal places.
EesEstimates
The three estimates ees combines.
EightConnected
A UniformGrid as an 8-connected graph with Octile costs, for the general searches (a_star and the others) on the same moves that jps() uses.
FieldDStar
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 by focal_fn.
FocalList
Open items under an admissible order f with a focal sublist ordered by a second key.
HeuristicFn
A closure used as a Heuristic; created by heuristic_fn.
LearnedHeuristic
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.
LpaStarMulti
LpaStar from several fixed starts to one goal: the cheapest path from any start, repaired after edge changes.
MeetFn
A MeetRelation from a closure meets(forward_state, backward_node) -> bool, checked against every node of the opposite side; created by meet_fn.
MhaWeights
The two weights of mha_star. The solution costs at most heuristic * anchor times the optimum.
NonNegF64
A non-negative, non-NaN f64 cost; +∞ 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.
OctileDistance
The octile distance to a fixed goal cell, as a Heuristic over cells: admissible and consistent on every 8-connected grid.
ReplayError
A _meet search could not turn its meet into a path of real states: state has no successor edge labelled action, although the backward search used that action.
SearchResult
The result of one search run.
Solution
A path from the start state to a goal state.
Stats
Counters collected during one search run.
TrialResult
The result of one real-time trial.
TrialStats
Counters of one real-time trial, beyond the search Stats.
Weight
A rational heuristic weight w = numerator / denominator for Weighted A*.
Zero
The blind heuristic: estimates Cost::ZERO everywhere. Turns A* into Dijkstra’s algorithm and is admissible and consistent for every non-negative cost.

Enums§

EdgeSelector
Which unevaluated edges of a candidate path lazy_sp evaluates next.
Outcome
How a search ended.
TieBreak
How equal keys are ordered, after the primary and (for the focal sublist) the focal key.

Traits§

BidirectionalGraph
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 Cost lacks: subtraction and conversion to f64.
CostGrid
A UniformGrid whose passable cells have traversal costs, for Field D* (FieldDStar, feature float).
DynamicGraph
A graph with stable vertices whose edge costs may change between searches.
EdgeEvaluator
Computes the true cost of an edge, which is expensive (a collision check, a simulation).
FocalKey
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 S to the nearest goal, in cost type C.
LineOfSight
A UniformGrid that can tell whether the straight segment between two cell centres is free, for any-angle searches such as theta_star (feature float).
MeetRelation
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.
RegressionGraph
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.
UniformGrid
A rectangular grid of cells that are passable or blocked, for 8-connected searches with uniform costs.

Functions§

a_star
A* search from start to the first state that satisfies goal.
a_star_multi
a_star from 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_star from 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_star from several start states at once.
bae_star
Bidirectional A* with error (BAE*, Sadhukhan 2013).
bae_star_meet
bae_star that meets by a MeetRelation instead of state equality, from several starts at once.
bae_star_multi
bae_star from 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_search from several start states at once: the starts form the first layer, pruned to width like 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 about width states per layer.
beam_stack_search_multi
beam_stack_search from several start states at once: the starts form the first layer, to the cheapest goal from any of them.
bfs
Breadth-first search from start to 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_bfs that meets by a MeetRelation instead of state equality, from several starts at once: the path with the fewest edges through a meet.
bidirectional_bfs_multi
bidirectional_bfs from several start states at once.
bidirectional_dijkstra
Bidirectional Dijkstra: uniform-cost search from both ends, cheapest path.
bidirectional_dijkstra_meet
bidirectional_dijkstra that meets by a MeetRelation instead of state equality, from several starts at once.
bidirectional_dijkstra_multi
bidirectional_dijkstra from several start states at once.
depth_limited_dfs
Depth-limited depth-first tree search: a path of at most limit edges.
depth_limited_dfs_multi
depth_limited_dfs from 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
dfs from several start states at once.
dibbs
Dynamically Improved Bounds Bidirectional Search (DIBBS, Sewell and Jacobson 2021).
dibbs_meet
dibbs that meets by a MeetRelation instead of state equality, from several starts at once.
dibbs_multi
dibbs from several start states at once.
dijkstra
Dijkstra’s algorithm (uniform-cost search) from start to the cheapest goal.
dijkstra_multi
dijkstra from 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 weight times the optimum.
dps_multi
dps from several start states at once.
ees
Explicit Estimation Search (EES): bounded suboptimal search guided by inadmissible estimates, within weight times the optimum.
ees_multi
ees from several start states at once.
focal_fn
Turns a closure FnMut(&S) -> K into a FocalKey that depends on the state alone.
focal_search
Focal search (A*ε, Pearl and Kim 1982): a solution within weight times the optimum, expanding by a free secondary key.
focal_search_multi
focal_search from several start states at once.
fringe_search
Fringe search from start to the first state that satisfies goal: optimal with an admissible heuristic, without a priority queue.
fringe_search_multi
fringe_search from 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
gbfs from several start states at once.
heuristic_fn
Turns a closure FnMut(&S) -> Option<C> into a Heuristic.
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_star from several start states at once.
ida_star_tt
IDA* with a bounded transposition table of capacity states: ida_star that searches below a state at most once per iteration and path cost.
ida_star_tt_multi
ida_star_tt from several start states at once, as ida_star_multi does.
iddfs
Iterative deepening depth-first search (IDDFS): the path with the fewest edges, in memory linear in its length.
iddfs_multi
iddfs from several start states at once.
jps
Jump Point Search from start to goal on an 8-connected grid: a cheapest path, usually after far fewer expansions than A*.
jps_multi
jps from 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_sp from several start states at once.
lazy_theta_star
Lazy Theta*: theta_star with far fewer line-of-sight checks.
lazy_theta_star_multi
lazy_theta_star from several start cells at once, with the start handling of theta_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 start to a state that satisfies goal, learning in table.
lss_lrta_star
One trial of LSS-LRTA* (Koenig and Sun 2009) from start to a state that satisfies goal, learning in table.
meet_fn
Turns a closure Fn(&S, &N) -> bool (forward state, backward node) into a scanning MeetRelation.
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_star from 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 a MeetRelation instead of state equality, from several starts at once.
nbs_multi
nbs from 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
rbfs from several start states at once, to the cheapest goal from any of them.
rta_star
One trial of RTA* (Korf 1990) from start to a state that satisfies goal, learning in table.
rtaa_star
One trial of RTAA* (Koenig and Likhachev 2006) from start to a state that satisfies goal, learning in table.
sma_star
SMA* from start with at most memory search nodes in memory: A* that forgets its worst leaves when memory runs out and regenerates them when needed.
sma_star_multi
sma_star from several start states at once.
theta_star
Theta* from start to goal: a short any-angle path between cell centres.
theta_star_multi
theta_star from 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_star from several start states at once.

Type Aliases§

AnyAngleResult
The result type of the any-angle searches: a path of cell centres joined by straight segments, with its Euclidean length.
AnytimeGraphResult
The result type of anytime searches over graph G.
DynamicResult
The result of an incremental search: a path of vertices. Edges carry no labels, so the solution’s actions are ().
FieldResult
The result of FieldDStar::compute: the path as points (x, y) in grid coordinates, joined by straight segments, with its cost.
GraphResult
The result type of searches over graph G.
GridCell
A cell of a grid: (x, y), column first.
GridStep
A unit step (dx, dy) between neighbouring cells, each component -1, 0 or 1.
MeetResult
What a _meet search returns: the search result, or the ReplayError if its solution could not be replayed as real states.