Skip to main content

Crate width_search

Crate width_search 

Source
Expand description

crates.io docs.rs CI codecov MSRV License unsafe forbidden

Width-based search (Lipovetzky & Geffner): novelty tables, IW(k), iterated width, and BFWS(⟨w_{#g}, #g⟩).

Anything that can enumerate successors and describe states as integer features implements WidthProblem: planning atoms, grid cells, RAM bytes. The sas-plus feature adds an adapter for sas_plus::Task.

§Usage

Implement WidthProblem and run a search. Here, walking from 0 to 5 on a line has width 1:

use width_search::{WidthProblem, iw};

/// Walk along the integers 0..=5, one step at a time.
struct Line;

impl WidthProblem for Line {
    type State = u32;
    type Action = i8;

    fn initial_state(&self) -> u32 {
        0
    }

    fn successors(&self, s: &u32, out: &mut Vec<(i8, u32)>) {
        if *s < 5 {
            out.push((1, s + 1));
        }
        if *s > 0 {
            out.push((-1, s - 1));
        }
    }

    // One feature per position.
    fn features(&self, s: &u32, out: &mut Vec<u32>) {
        out.push(*s);
    }

    fn num_features(&self) -> usize {
        6
    }

    fn is_goal(&self, s: &u32) -> bool {
        *s == 5
    }
}

let plan = iw(&Line, 1).plan.expect("IW(1) solves it");
assert_eq!(plan, [1, 1, 1, 1, 1]);

A grid with a key and a door needs width 2, because the agent revisits cells after picking up the key:

cargo run --example key_door         # IW(1) fails, IW(2) succeeds

§Features

  • sas-plus: sas::SasProblem, an adapter that runs width-based search on a sas_plus::Task.

Tested: end to end on a Fast Downward output.sas (gripper: IW needs width 3 for the conjunctive goal, finding the optimal 5-step plan). Also: IW with k = #variables is complete and optimal on unit-cost random tasks; IW and BFWS plans are validated.

Roadmap: SIW, BFWS with #r, Rollout IW, node-count comparison against LAPKT.

References: Lipovetzky & Geffner, ECAI 2012 and AAAI 2017.

§MSRV

Rust 1.86. Raising it is a minor release.

§Contributing

See CONTRIBUTING.md.

§License

Licensed under either of Apache License, Version 2.0 or MIT license at your option. The examples in examples/ are public domain (CC0-1.0), so you can copy them into anything. Test fixtures carry their own licenses; see REUSE.toml.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this work by you shall be dual licensed as above, without any additional terms or conditions.

Modules§

sas
Adapter that runs width-based search on a sas_plus::Task. Adapter: run width-based search directly on a sas_plus::Task. Features are the task’s facts var = value; plans are operator ids.

Structs§

NoveltyTable
Records every feature tuple of size <= k seen so far.
SearchResult
The outcome of a search: a plan, if one was found, and node counts.

Traits§

GoalCount
Goal-directed information used by BFWS.
WidthProblem
A search problem described by successors and integer features.

Functions§

bfws
BFWS(f) with f = ⟨w_{#g}, #g⟩: best-first search ordered by novelty (computed separately for each goal-count value #g, capped at k + 1), breaking ties by #g. Complete on finite state spaces.
iterated_width
Runs IW(1), IW(2), … up to max_k; returns the width that succeeded (if any) and the accumulated statistics.
iw
IW(k): breadth-first search that prunes every generated state whose novelty exceeds k. Runs in O(n^k) expansions for n features.