0

我正在尝试将普通的 PDDL 案例(作为物流示例)建模为不同的编程语言(java)。我这样做是为了了解使用 PDDL 的优点或缺点。

这是 PDDL 原始示例

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

我的结果是一个简单的顺序程序,如代码所示。我的目标是使计算自动化以获得真正的组合计算,而不是顺序计算。

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;

}




}

我怎样才能达到我的目标?如何获得组合计算来解决问题?

4

1 回答 1

0

我认为你的方法是错误的。不要尝试实现任何 if/else 命令式逻辑。声明您的操作(也称为操作员)、域、问题并调用计划者来解决它。如果您确实想创建域和问题而不将其编码为 PDDL 并让规划器(例如 pddl4j)解析它,您可以用 Java 对其进行编码并将其作为编码域和编码问题移交。

您的代码结构将与您放入 PDDL 的结构非常相似,因此除了缩短解析时间和加快求解时间之外,我认为这样做没有多大意义。如果你这样做,请继续阅读......

查看如何通过 pddl4j API 调用规划器的代码示例:https ://github.com/pellierd/pddl4j/wiki/A-tutorial-to-develop-your-own-planner#step-6-searching-for-解决方案计划

现在,通常情况下,您会让 PDDL 解析器完成这项工作:https ://github.com/pellierd/pddl4j/wiki/A-tutorial-to-develop-your-own-planner#step-5-parse-and-编码 pddl 域和问题文件

...但是如果你想把它编码出来,你需要使用OpDomainProblem类来声明你的操作、域和问题。

然后你调用编码问题并调用 pddl4j 中的一个规划器,如其中一个教程中所示(我在上面粘贴的链接)。这有帮助吗?

于 2019-10-16T13:38:20.823 回答