Skip to main content

Crate stochastic_search

Crate stochastic_search 

Source
Expand description

Planning under probabilistic outcomes: value iteration, RTDP, labeled RTDP, BRTDP, FRTDP, VPI-RTDP, LAO*, iLAO* and CG-iLAO* for fully observable problems, MOLAO*, iMOLAO* and MOLRTDP for multi-objective ones; POMCP and DESPOT for partially observable ones.

A problem is a stochastic shortest path (SSP) problem: reach a goal state with minimal expected total cost, where every action has a cost and a probability distribution over successor states. It is described by small capability traits instead of one universal problem trait: the MDP implements Mdp, the goal test is a Goal and the initial value estimate a Heuristic. Closures work for both (wrap heuristic closures in heuristic_fn). Every algorithm takes a Config and returns a Solution: a value function and a greedy policy, plus a Status and Stats.

Partially observable problems are generative models (Pomdp): a step samples successor, observation and reward from a rand_core generator. The online planners pomcp() and despot() take a particle belief and return a Plan for one decision.

The crate is no_std and needs only alloc.

§Algorithms

  • lrtdp(): labeled real-time dynamic programming (Bonet and Geffner 2003). Explores only the states a good policy visits; epsilon-consistent on them when it converges.
  • rtdp(): plain RTDP (Barto, Bradtke and Singh 1995), with LRTDP’s solved check as its stopping rule. The classic baseline.
  • brtdp(): bounded RTDP (McMahan, Likhachev and Gordon 2005). Keeps a lower and an upper bound and samples where they are far apart; anytime, with a known gap.
  • frtdp(): focused RTDP (Smith and Simmons 2006). The same bounds; trials follow the successor of highest priority with an adaptive depth limit.
  • vpi_rtdp(): VPI-RTDP (Sanner et al. 2009). The same bounds; trials follow the value of perfect information about successors where the bounds are informative.
  • lao_star(): classic LAO* (Hansen and Zilberstein 2001), one tip per expansion step with value iteration on its ancestors. The paper’s original; slower than iLAO*.
  • cg_ilao_star(): CG-iLAO* (Schmalz and Trevizan 2024). iLAO* over a partial SSP that adds an action only when constraint generation finds it necessary.
  • ilao_star(): improved LAO* (Hansen and Zilberstein 2001). Grows the best partial solution graph in depth-first passes; no sampling.
  • value_iteration(): value iteration over every reachable state. The exact reference.
  • pomcp(): partially observable Monte-Carlo planning (Silver and Veness 2010). UCT over action-observation histories with rollouts.
  • despot(): anytime regularized DESPOT (Somani et al. 2013, Ye et al. 2017). Bound guided search over a tree of K determinized scenarios.
  • molrtdp(), molao_star(), imolao_star() and mo_value_iteration(): multi-objective SSPs (Chen, Trevizan and Thiébaux 2023) over an MoMdp with cost vectors. They return an MoSolution, a convex coverage set of deterministic policies; heuristics are ZeroVector, IdealPoint and Abstraction (also over Determinized).
  • Pomcp and Despot: the same planners kept between decisions, reusing the subtree after the action taken and the observation received; update_belief is POMCP’s particle filter with reinvigoration.

§The heuristic contract

Goal, Heuristic, heuristic_fn and Budget are re-exported from search-core, shared with the other planning crates. The algorithms here use Heuristic<S, f64> (closures infer f64) under this contract:

  • estimate is called once per state, when the state is first stored; never for goals. It takes &mut self, so a heuristic can keep a workspace; algorithms take it by value, pass &mut h to keep h.
  • None (or an infinite estimate) means no proper policy exists from the state, a proven dead end that is never expanded. Return it only when that is certain.
  • NaN and negative infinity are rejected with Error::InvalidHeuristic.
  • The optimality guarantees need an admissible heuristic (never above the optimal expected cost). Inadmissible ones never panic; they only void the guarantee.

Zero, the blind heuristic, is search-core’s too; it estimates 0.0 for f64. The multi-objective algorithms take cost-vector sets and use ZeroVector instead.

§Dead ends

States from which no policy reaches a goal with probability 1 are valued per DeadEnds: at infinity (the default, exact SSP semantics), or at a finite give-up penalty that makes every input solvable. The bounded algorithms (brtdp(), frtdp(), vpi_rtdp()) need finite upper bounds, so under infinite dead ends their lower bound must prove the dead ends they meet.

§Events

An Observer set with Config::with_observer receives Events while a run progresses: progress, proven dead ends, and suspected divergence (a heuristic signal, never a verdict). The default observer () costs nothing.

§Example

use stochastic_search::{Config, Mdp, heuristic_fn, lrtdp};

/// A die roll: action `roll` (cost 1) ends on a six; action `pay` (cost 4) ends always.
struct Dice;

impl Mdp for Dice {
    type State = bool;
    type Action = &'static str;

    fn actions(&self, _done: &bool, mut emit: impl FnMut(&'static str, f64)) {
        emit("roll", 1.0);
        emit("pay", 4.0);
    }

    fn outcomes(&self, _done: &bool, action: &&'static str, mut emit: impl FnMut(bool, f64)) {
        match *action {
            "roll" => {
                emit(true, 1.0 / 6.0);
                emit(false, 5.0 / 6.0);
            }
            _ => emit(true, 1.0),
        }
    }
}

let heuristic = heuristic_fn(|_: &bool| Some(1.0));
let solution = lrtdp(&Dice, false, &|done: &bool| *done, heuristic, Config::default())?;

// Rolling takes 6 attempts in expectation, so paying 4 is cheaper.
assert_eq!(solution.initial_action(), Some(&"pay"));
assert!((solution.initial_value() - 4.0).abs() < 1e-5);

See docs/design.md in the repository for the design.

Repository: https://github.com/sunsided/stochastic-search

Re-exports§

pub use mo::Abstraction;
pub use mo::Determinized;
pub use mo::IdealPoint;
pub use mo::MoMdp;
pub use mo::MoPolicy;
pub use mo::MoSolution;
pub use mo::MoSolveResult;
pub use mo::Objectives;
pub use mo::ZeroVector;
pub use mo::imolao_star;
pub use mo::mo_value_iteration;
pub use mo::molao_star;
pub use mo::molrtdp;

Modules§

mo
Multi-objective stochastic shortest path problems (MOSSPs) and the heuristic search algorithms of Chen, Trevizan and Thiébaux (2023): MOLAO*, iMOLAO* and MOLRTDP, with multi-objective value iteration (MOVI) as the exact reference.

Structs§

BeliefFilter
Settings of update_belief.
BeliefUpdate
The posterior particles of update_belief and how they came about.
BrtdpConfig
Settings of brtdp: the shared Config and BRTDP’s trial-end ratio.
Config
Settings shared by all algorithms.
Despot
A DESPOT planner that keeps its tree between decisions.
DespotConfig
Settings of despot.
FrtdpConfig
Settings of frtdp: the shared Config and FRTDP’s adaptive maximum depth.
HeuristicFn
A closure used as a Heuristic; created by heuristic_fn.
Limits
Simple counter limits.
ObserverFn
A closure used as an Observer; created by observer_fn.
Plan
The answer of an online POMDP planner for one decision.
Pomcp
A POMCP planner that keeps its search tree between decisions.
PomcpConfig
Settings of pomcp.
Solution
A value function and a greedy policy over the states a run touched.
SplitMix64
The SplitMix64 generator (Steele, Lea and Flood 2014).
Stats
Counters collected during one run of an algorithm.
Step
One sampled transition of a Pomdp.
TreeStats
Counters collected during one call of a tree planner (pomcp, despot), returned in Plan::stats and given to the budget.
UniformRandom
The rollout policy that picks every action with equal probability.
VpiRtdpConfig
Settings of vpi_rtdp: the shared Config and VPI-RTDP’s two thresholds.
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§

DeadEnds
How states without a proper policy are valued.
Error
Invalid input found while solving. Each variant names the state where it was found.
Event
Something worth reporting while an algorithm runs.
Status
How a run ended.

Constants§

PROBABILITY_TOLERANCE
The tolerance on the sum of an action’s outcome probabilities.

Traits§

Budget
Decides when a search must stop before it finishes, given its counters so far.
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.
Mdp
A finite Markov decision process with action costs.
Observer
Receives Events while an algorithm runs.
Pomdp
A partially observable Markov decision process, given as a generative model.
RolloutPolicy
Picks actions for simulations below the search tree: POMCP’s rollout policy and DESPOT’s default policy (whose simulated value is DESPOT’s lower bound).

Functions§

brtdp
Solves an SSP from initial with bounded RTDP, keeping a lower and an upper bound on every stored state’s optimal value.
cg_ilao_star
Solves an SSP from initial with CG-iLAO*.
despot
Plans one action from the particle belief belief with anytime regularized DESPOT.
frtdp
Solves an SSP from initial with focused RTDP, keeping a lower and an upper bound on every stored state’s optimal value.
heuristic_fn
Turns a closure FnMut(&S) -> Option<C> into a Heuristic.
ilao_star
Solves an SSP from initial with iLAO*.
lao_star
Solves an SSP from initial with classic LAO*, one tip at a time.
lrtdp
Solves an SSP from initial with labeled RTDP.
observer_fn
Turns a closure FnMut(Event) into an Observer.
pomcp
Plans one action from the particle belief belief with POMCP.
pomcp_exploration
The paper’s exploration constant c = R_hi - R_lo for PomcpConfig::exploration: runs simulations simulations of POMCP from belief with c = 0 and returns the highest discounted return of a simulation minus the lowest discounted return of a rollout (Silver and Veness 2010, Section 6: “R_hi was the highest return achieved during sample runs of POMCP with c = 0, and R_lo was the lowest return achieved during sample rollouts”).
rtdp
Solves an SSP from initial with plain RTDP: greedy trials without solved labels.
unit_interval
Returns a uniform sample from [0, 1) with 53 random bits drawn from rng.
update_belief
Updates the particle belief belief after taking action and receiving observation, with the Monte-Carlo particle filter of POMCP (Silver and Veness 2010, Section 3.2).
value_iteration
Solves an SSP from initial with Gauss-Seidel value iteration over every reachable state.
vpi_rtdp
Solves an SSP from initial with VPI-RTDP, keeping a lower and an upper bound on every stored state’s optimal value.

Type Aliases§

SolveResult
The result of solving the MDP M: a Solution or the Error that stopped the run.