graphplan 0.6.1

Implementation of the Graphplan planning algorithm from Avrim L. Blum and Merrick L. Furst in Rust
Documentation
/// An attempt at translating PDDL concepts for use with this library
/// https://www.cs.toronto.edu/~sheila/2542/s14/A1/introtopddl2.pdf

use std::collections::HashSet;
#[macro_use] extern crate graphplan;
use graphplan::{Proposition, Action, GraphPlan, SimpleSolver};

#[derive(Hash, Debug, Eq, PartialEq, PartialOrd, Ord, Clone)]
enum Props {
    At(Object, Object),
}

fn at(obj1: Object, obj2: Object) -> HashSet<Proposition<Props>> {
    match obj1 {
        Object::Robot => (),
        Object::BallA => (),
        Object::BallB => (),
        _ => panic!("Object can not be at location")
    }

    match obj2 {
        Object::RoomA => (),
        Object::RoomB => (),
        _ => panic!("Object is not a location")
    }

    hashset!{
        Proposition::new(Props::At(obj1, obj2), false)
    }
}

#[derive(Hash, Debug, Eq, PartialEq, PartialOrd, Ord, Clone)]
enum Object {
    Robot,
    Gripper,
    BallA,
    BallB,
    RoomA,
    RoomB,
}

enum Predicate {
    Room(Object),
    Ball(Object),
    Gripper(Object),
    AtRobot(Object),
    AtBall(Object, Object),
    Free(Object),
    Carry(Object, Object)
}


fn main() {
    let p1 = Proposition::from("tired");
    let not_p1 = p1.negate();

    let p2 = Proposition::from("dog needs to pee");
    let not_p2 = p2.negate();

    let p3 = Proposition::from("at work");
    let p4 = p3.negate();

    let a1 = Action::new(
        "drink coffee",
        hashset!{&p1},
        hashset!{&not_p1}
    );

    let a2 = Action::new(
        "walk dog",
        hashset!{&p2, &not_p1},
        hashset!{&not_p2},
    );

    let a3 = Action::new(
        "go to work",
        hashset!{&not_p1, &not_p2},
        hashset!{&p3},
    );

    let domain = GraphPlan::create_domain(
        hashset!{&p1, &p2, &p4},
        hashset!{&not_p1, &not_p2, &p3},
        hashset!{&a1, &a2, &a3}
    );
    let mut pg = GraphPlan::from_domain(&domain);

    println!("Plan:");

    for step in pg.search::<SimpleSolver>().unwrap() {
        for action in step {
            println!("- {:?}", action.id);
        }
    }
}