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:
1package fr.uga.pddl4j.examples;
2
3import fr.uga.pddl4j.parser.DefaultParsedProblem;
4import fr.uga.pddl4j.parser.ErrorManager;
5import fr.uga.pddl4j.parser.Message;
6import fr.uga.pddl4j.parser.Parser;
7import fr.uga.pddl4j.problem.DefaultProblem;
8import fr.uga.pddl4j.problem.Problem;
9import fr.uga.pddl4j.problem.operator.Action;
10
11import java.io.FileNotFoundException;
12
13/**
14 * The class is an example class. It shows how to use the library to create to ground planning problem.
15 *
16 * @author D. Pellier
17 * @version 4.0 - 06.12.2021
18 */
19public class ProblemInstantiationExample {
20
21 /**
22 * The main method the class. The first argument must be the path to the PDDL domain description and the second
23 * argument the path to the PDDL problem description.
24 *
25 * @param args the command line arguments.
26 */
27 public static void main(final String[] args) {
28
29 // Checks the number of arguments from the command line
30 if (args.length != 2) {
31 System.out.println("Invalid command line");
32 return;
33 }
34
35 try {
36 // Creates an instance of the PDDL parser
37 final Parser parser = new Parser();
38 // Parses the domain and the problem files.
39 final DefaultParsedProblem parsedProblem = parser.parse(args[0], args[1]);
40 // Gets the error manager of the parser
41 final ErrorManager errorManager = parser.getErrorManager();
42 // Checks if the error manager contains errors
43 if (!errorManager.isEmpty()) {
44 // Prints the errors
45 for (Message m : errorManager.getMessages()) {
46 System.out.println(m.toString());
47 }
48 } else {
49 // Prints that the domain and the problem were successfully parsed
50 System.out.print("\nparsing domain file \"" + args[0] + "\" done successfully");
51 System.out.print("\nparsing problem file \"" + args[1] + "\" done successfully\n\n");
52 // Create a problem
53 final Problem problem = new DefaultProblem(parsedProblem);
54 // Instantiate the planning problem
55 problem.instantiate();
56 // Print the list of actions of the instantiated problem
57 for (Action a : problem.getActions()) {
58 System.out.println(problem.toString(a));
59 }
60 }
61 // This exception could happen if the domain or the problem does not exist
62 } catch (FileNotFoundException e) {
63 e.printStackTrace();
64 }
65 }
66}
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