use ferroplan::{Options, Session};
const DOM: &str = "
(define (domain homestead) (:requirements :strips :typing :numeric-fluents)
(:types agent place)
(:predicates (at ?a - agent ?p - place) (road ?x ?y - place) (fertile ?p - place))
(:functions (grain))
(:action walk :parameters (?a - agent ?from ?to - place)
:precondition (and (at ?a ?from) (road ?from ?to))
:effect (and (not (at ?a ?from)) (at ?a ?to)))
(:action harvest :parameters (?a - agent ?p - place)
:precondition (and (at ?a ?p) (fertile ?p))
:effect (increase (grain) 1)))";
const PRB: &str = "
(define (problem morning) (:domain homestead)
(:objects vera - agent hut field barn - place)
(:init (at vera hut) (road hut field) (road field hut)
(road field barn) (road barn field) (fertile field) (= (grain) 0))
(:goal (>= (grain) 3)))";
fn main() -> Result<(), String> {
let mut world = Session::new(DOM, PRB, &Options::default())?;
let think = world.replan_budgeted(100_000, Some(256));
assert!(think.solved);
let plan = think.plan.as_ref().unwrap();
println!(
"think 1: {} steps within {} evals",
plan.length, think.statistics.evaluated_states
);
world.set_fact("(at vera hut)", false)?;
world.set_fact("(at vera field)", true)?;
world.set_fluent("(grain)", 1.0)?;
world.set_fluent("(grain)", 0.0)?;
let rethink = world.replan_budgeted(100_000, Some(256));
assert!(rethink.solved);
println!(
"rethink after drift: {} steps from the CURRENT state",
rethink.plan.as_ref().unwrap().length
);
let tiny = world.replan_budgeted(1, Some(1));
println!(
"tiny think: solved={} after {} evals (bounded, deterministic)",
tiny.solved, tiny.statistics.evaluated_states
);
Ok(())
}