Instantiating Planning Problems

The instantiation of a planning problem consists in transforming the operators of the planning domain into ground actions. Some planners use the instantiation in order to encode planning problems into different formalisms such as SAT or CSP for instance. However most planners use the instantiation to efficiently compute heuristics, speedup the search algorithm by using a compact encoding. In this tutorial, we present how to used PDDL4J to instantiate planning problems.

Pre-requisite Installations

For this tutorial you need:

In the following, we will give the commands line so that the tutorial can be done independently of any IDE.

Step 1. Create a simple Java project with PDDL4J

First, open a terminal and create your development directory

mkdir ProblemInstantiationExample

Then, create the sub-directories of your project

cd ProblemInstantiationExample
mkdir -p src/fr/uga/pddl4j/examples
mkdir classes
mkdir lib

Finally, get the last binary of PDDL4J and save it in the lib directory

wget http://pddl4j.imag.fr/repository/pddl4j/binaries/pddl4j-4.0.0.jar
mv pddl4j-4.0.0.jar lib/pddl4j-4.0.0.jar

Step 2. Create the main class of our example

Create and edit a file called ProblemInstantiationExample.java in the directory src/fr/uga/pddl4j/examples/. The skeleton of this class is given bellow:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package fr.uga.pddl4j.examples;

import fr.uga.pddl4j.parser.DefaultParsedProblem;
import fr.uga.pddl4j.parser.ErrorManager;
import fr.uga.pddl4j.parser.Message;
import fr.uga.pddl4j.parser.Parser;
import fr.uga.pddl4j.problem.DefaultProblem;
import fr.uga.pddl4j.problem.Problem;
import fr.uga.pddl4j.problem.operator.Action;

import java.io.FileNotFoundException;

/**
 * The class is an example class. It shows how to use the library to create to ground planning problem.
 *
 * @author D. Pellier
 * @version 4.0 - 06.12.2021
 */
public class ProblemInstantiationExample {

    /**
     * The main method the class. The first argument must be the path to the PDDL domain description and the second
     * argument the path to the PDDL problem description.
     *
     * @param args the command line arguments.
     */
    public static void main(final String[] args) {

        // Checks the number of arguments from the command line
        if (args.length != 2) {
            System.out.println("Invalid command line");
            return;
        }

        try {
            // Creates an instance of the PDDL parser
            final Parser parser = new Parser();
            // Parses the domain and the problem files.
            final DefaultParsedProblem parsedProblem = parser.parse(args[0], args[1]);
            // Gets the error manager of the parser
            final ErrorManager errorManager = parser.getErrorManager();
            // Checks if the error manager contains errors
            if (!errorManager.isEmpty()) {
                // Prints the errors
                for (Message m : errorManager.getMessages()) {
                    System.out.println(m.toString());
                }
            } else {
                // Prints that the domain and the problem were successfully parsed
                System.out.print("\nparsing domain file \"" + args[0] + "\" done successfully");
                System.out.print("\nparsing problem file \"" + args[1] + "\" done successfully\n\n");
                // Create a problem
                final Problem problem = new DefaultProblem(parsedProblem);
                // Instantiate the planning problem
                problem.instantiate();
                // Print the list of actions of the instantiated problem
                for (Action a : problem.getActions()) {
                    System.out.println(problem.toString(a));
                }
            }
            // This exception could happen if the domain or the problem does not exist
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }
}

The first part of the main method parses the domain and the problem from the PDDL files (see for more details). If the parser succeeds, then a new DefaultProblem is created from the parsed problem. Then, the method ``instantiate()``is called to instantiate the problem.

Warning

The call to the instantiate method can be long for complex problems.

The rest of the code print the list of actions of the instantiated problem.

Step 3. Compile and Run the example

To test the above code use the following command line to compile the example:

javac -d classes -cp classes:lib/pddl4j-4.0.0.jar src/fr/uga/pddl4j/examples/ProblemInstantiationExample.java

and then the following command line to run the example:

java -cp classes:lib/pddl4j-4.0.0.jar fr.uga.pddl4j.examples.ProblemInstantiationExample \\
    src/test/resources/benchmarks/pddl/ipc2000/logistics/strips-typed/domain.pddl \\
    src/test/resources/benchmarks/pddl/ipc2000/logistics/strips-typed/p01.pddl