javapddl

How to model a PDDL case in Java


I'm trying to model a normal PDDL case ,as the logistics example, into a different programming language(java). I'm doing this to understand what are the advantages or disvantages in using PDDL.

This is the PDDL original example

https://github.com/pellierd/pddl4j/wiki/Logistics:-a-simple-running-example

My result is an easy sequential program, shown in the code. My target is to automatize the calculation to obtain a real combinatorial calculation, not a sequential one.

public class logistics {

private static boolean airplaneInUse = false;
private static boolean truckInUse = false;
private static String airport;
private static String place;
private static String city;
private static String pack1;
private static String pack2;

static int state = 0;



public static void main(String args[]) {


    if(state == 0) {

        start();
        System.out.println("The city in the initial state is " + city + "\n");
        System.out.println("The airport in the initial state is " + airport + "\n");


    }

     if(city == "London") {

        load_plane();
        System.out.println("pk1 and pk2 are on the plane" +"\n");
        pack1 = "On Board";
        pack2 = "On Board";

    }

    if(pack1 == "On Board" && pack2 == "On Board") {

        fly();

        System.out.println("The city after the flight is " + city + "\n");
        System.out.println("The airport after the flight is " + airport + "\n");

    }

     if (city == "Paris") {

        unload_plane();
        System.out.println("pk1 and pk2 are unloaded from the plane " + "\n");
        pack1 = "Unloaded";
        pack2 = "Unloaded";

    }

     if (pack1 == "Unloaded" && pack2 == "Unloaded") {

        load_truck();
        System.out.println(pack1 + "\n");
        System.out.println(pack2 + "\n");


    }

     if(pack1 == "pk1 On the truck" || pack2 == "pk2 On the truck") {

        drive_truck();
        System.out.println("Driving to the first place " + "\n");
        System.out.println("Driving to the second place " + "\n");


    }

     if (truckInUse == true) {

        unload_truck1();

        System.out.println("pk1 delivered in the " + place + "\n");

        unload_truck2();

        System.out.println("pk2 delivered in the " + place + "\n");
    }



}




public static void start() {

    city = "London";
    airport = "lhr";

    return;

}

public static void load_plane() {

    city = "London";
    pack1 = " pk1 On board";
    pack2 = " pk2 On board";

    return;
}

public static void fly() {

        city = "Paris";
        airport = "cdg";
        airplaneInUse = true;

    return;

}

public static void unload_plane() {

    pack1 = "Arrived in Paris";
    pack2 = "Arrived in Paris";
    airplaneInUse = false;

    return;

}


public static void load_truck() {

    pack1 = "pk1 On the truck";
    pack2 = "pk2 On the truck";

    return;

}


public static void drive_truck() {

    truckInUse = true;

    return;

}

public static void unload_truck1() {

    truckInUse = false;
    pack1 = "Arrived in South";
    place = "South";

    return;

}

public static void unload_truck2() {

    truckInUse = false;
    pack1 = "Arrived in North";
    place = "North";

    return;

}




}

How can I reach my target? How can I obtain a combinatorial calculation to solve the problem?


Solution

  • I think you are getting at it the wrong way around. Do not try to implement any if/else imperative logic. Declare your actions (aka operators), domain, problem and call a planner to solve it. If you do want to create the domain and problem without encoding it into PDDL and letting the planner (e.g. pddl4j) parse it, you can code it out in Java and hand it over as a coded domain and coded problem.

    The structure of your code will be very similar as what you would have put into PDDL, so besides shaving off the parsing time and speeding up the solution time, I do not see much point doing it this way. If you do, keep reading...

    See a code example how you call the planner via the pddl4j APIs: https://github.com/pellierd/pddl4j/wiki/A-tutorial-to-develop-your-own-planner#step-6-searching-for-a-solution-plan

    Now, normally, you would let the PDDL parser do the job: https://github.com/pellierd/pddl4j/wiki/A-tutorial-to-develop-your-own-planner#step-5-parse-and-encode-the-pddl-domain-and-problem-files

    ...but if you want to code it out, you will need to declare your actions, domain and problem using the Op, Domain and Problem classes.

    Then you call encode the Problem and call one of the planners in pddl4j as indicated in one of the tutorials (links I pasted above). Does this help?