#planning #task #htn #reentrant #model #efficent #success

whim

An efficent reëntrant HTN planner

1 release (0 unstable)

Uses new Rust 2024

1.0.0-beta.1 Dec 7, 2025

#1 in #reentrant

MIT license

20KB
199 lines

Whim

Whim is a simple reëntrant HTN planner, based loosely on IPyHOP.


lib.rs:

Whim is a simple reëntrant HTN planner, based loosely on IPyHOP.

Usage

To use whim, you will need to set up Model and Task types for your planning domain. Once that's done, you simply need to pass a EstrMap naming all valid tasks into Planner::new.

Using a planner should look something like this:

// Create your world model.
let mut model = MyModel::new();
// Create a planner (assuming you have already set up `my_tasks`).
let root_task = TaskRef {
    name: "root_task".into(),
    data: (),
};
let mut planner = Planner::new(my_tasks, root_task);

// Start a run/simulate loop.
loop {
    // Poll the planner for the next action. This may result in a replan, if
    // the ground-truth model state differs significantly from what the planner
    // expected to see.
    match planner.run(&model) {
        // If the planner returns an action, you execute it.
        Outcome::Action(task) => {
            // This performs the action, and mutates the world according to
            // it's actual observed effects. If the action turns out to fail or be impossible,
            // we return false.
            let success = model.simulate_action(task);
            // If the simulation encountered a problem running that task,
            // inform the planner that it needs to create a new plan.
            if !success {
                planner.replan(&model)
            }
        },
        // This indicates we ran the plan to completion. In this example, we simply exit.
        Outcome::Complete => return true,
        // This indicates that the plan cannot currently progress, given the
        // provided world state. In this example, we'll treat that as an
        // unrecoverable error and simply exit as well.
        Outcome::Failure => return false,
    }     
}

Dependencies

~1.5MB
~24K SLoC