heuristic-search
Explicit-state heuristic graph search: A*, weighted and anytime, bounded-suboptimal, bidirectional, incremental and real-time search.
Part of the planning and search crates; see also this crate's overview page.
Who this is for
Anyone who has a graph, or a problem that can be phrased as one, and needs a path through
it: a planner that generates its states on the fly, a robot or a game character on a grid.
The graph stays in your code; you describe it through small traits (Successors, and
Predecessors for the bidirectional searches), pass the goal test and the heuristic as
separate values, and get back a path, an outcome and the expansion counters. The crate
knows nothing about PDDL, SAS+ or any other model, so domain-specific representations sit
on top of it rather than in it.
It is also meant for comparing algorithms on the same problem: every search uses the same traits, budgets and statistics, so trying IDA* or Weighted A* instead of A* changes the call, not the problem description. Symbolic (BDD), multi-objective, stochastic and width-based search are out of scope.
What's included
See docs/design.md for the design behind it.
- Foundational: BFS, Dijkstra, A*, greedy best-first search (GBFS); DFS, depth-limited DFS,
iterative deepening DFS, IDA*, IDA* with a bounded transposition table; depth cutoffs
are reported apart from budget stops (
Outcome::Cutoff) - Fringe search (
fringe_search): optimal with an admissible heuristic, threshold iterations over a cache ofgper state, no priority queue - RBFS (
rbfs): recursive best-first search, optimal with an admissible heuristic in memory linear in the depth, iterative so deep paths cannot overflow the stack - SMA* (
sma_star): A* within a node budget, forgetting and regenerating leaves; the cheapest path that fits in memory,Cutoffwhen none does - Beam search (
beam_search, incomplete;Cutoffwhen the width pruned) and beam-stack search (beam_stack_search): complete and anytime, optimal once it completes, with a fixed beam width - Grids: Jump Point Search (
jps) on anyUniformGrid, 8-connected without corner cutting, with the exact octile costOctile(a + b√2, compared without rounding);EightConnectedmakes a grid a graph for the other searches; any-angle Theta* and Lazy Theta* (theta_star,lazy_theta_star, featurefloat) on aLineOfSightgrid - Every search also from several start states (
*_multi; the incremental planners asLpaStarMulti,DStarLiteMulti,AdStarMultiwith fixed starts) - Weighted and anytime: Weighted A*, ARA*, ANA*
- Bounded-suboptimal: focal search (with a public focal list and tie-breaking), EES, DPS
- Bidirectional: bidirectional BFS and Dijkstra, NBS, DIBBS, BAE*; meets by a user
relation (
MeetRelation) between states and backward nodes of their own type (such as subgoals), with path replay or a typedReplayError - Multiple heuristics: shared MHA*
- Expensive edge evaluation: LazySP
- Dynamic graphs: LPA*, D* Lite, AD* (start moves keyed by D* Lite's
km); Field D* (FieldDStar, featurefloat) over the corners of aCostGridwith per-cell costs, interpolated any-angle paths through cell edges, cell-change repair and a moving start - Real-time search with learned tables that persist across trials (
LearnedHeuristic): LRTA*, RTA*, LSS-LRTA* (A* lookahead, Dijkstra update), RTAA*, and the limited-horizon Bellman update of Hadar et al. 2025 (lhb_updateoffline,lhb_lrta_starinside the LSS-LRTA* agent); learning curves inbenches/learning.rsand the design notes - Naming: every A* variant is
*_star(a_star,weighted_a_star, ...) - Shared traits:
Cost,Heuristic,GoalandBudget<Stats>come fromsearch-coreand are re-exported from the crate root. Costs are the unsigned integers,Decimal<K>and (featurefloat)NonNegF64.
Usage
Add the crate with cargo add heuristic-search, or in Cargo.toml:
[]
= "0.1"
Then describe the graph and run a search:
use ;
/// A directed graph as adjacency lists of `(target, cost)` pairs.
>>);
let graph = Graph;
let result = dijkstra;
let solution = result.solution.expect;
assert_eq!;
assert_eq!;
The crate is no_std and needs only alloc. The feature float adds the float cost
NonNegF64, the any-angle grid searches Theta* and Lazy Theta*, and Field D*.
MSRV
Rust 1.85 (rust-version in Cargo.toml). The MSRV is a signal, not a contract: it may
rise in a minor release.
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE)
- MIT license (LICENSE-MIT)
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions. See CONTRIBUTING.md.