PDDL walkthrough
From an empty workspace to a validated plan, then from a plan to a better model. It takes about ten minutes and uses nothing but your browser.
1. Open a workspace
Sign in to Autoplan Studio with a Google account. Your first workspace is created for you, with examples in a folder called demos. The examples of this guide are in demos/pddl-guide. If your workspace is older than this guide, it will not have them: copy the files below to your computer and open them with the Open button beside the domain and problem names at the top.
2. Read the domain
Open demos/pddl-guide/courier/domain.pddl. It says that vans, parcels and locations exist, what can be true of them, and that there are three actions.
; A van carries parcels along roads. PDDL 1.2: STRIPS with types.
(define (domain courier)
(:requirements :strips :typing)
(:types van parcel location)
(:predicates
(road ?from ?to - location)
(van-at ?v - van ?l - location)
(parcel-at ?p - parcel ?l - location)
(in ?p - parcel ?v - van))
(:action drive
:parameters (?v - van ?from ?to - location)
:precondition (and (van-at ?v ?from) (road ?from ?to))
:effect (and (not (van-at ?v ?from)) (van-at ?v ?to)))
(:action load
:parameters (?p - parcel ?v - van ?l - location)
:precondition (and (van-at ?v ?l) (parcel-at ?p ?l))
:effect (and (not (parcel-at ?p ?l)) (in ?p ?v)))
(:action unload
:parameters (?p - parcel ?v - van ?l - location)
:precondition (and (van-at ?v ?l) (in ?p ?v))
:effect (and (not (in ?p ?v)) (parcel-at ?p ?l))))Look at drive. It needs the van at ?from and a road to ?to. Its effect deletes one location and adds the other. That pair is the heart of a PDDL action: what must be true, and what changes.
3. Read the problem
; Two parcels at the depot, one for the market, one for the harbour.
(define (problem two-parcels)
(:domain courier)
(:objects
van1 - van
book lamp - parcel
depot market harbour - location)
(:init
(van-at van1 depot)
(parcel-at book depot)
(parcel-at lamp depot)
(road depot market) (road market depot)
(road market harbour) (road harbour market))
(:goal (and (parcel-at book market) (parcel-at lamp harbour))))The roads run depot to market to harbour, with no direct road from the depot to the harbour, and both directions are listed. The goal does not mention the van: it may end anywhere.
4. Solve it
With both files open, press Solve. The result opens in the Plan tab, with its steps. A plan is reported only once it has been checked against the model, so what you see is valid.
(load book van1 depot)
(load lamp van1 depot)
(drive van1 depot market)
(unload book van1 market)
(drive van1 market harbour)
(unload lamp van1 harbour)5. Change the world
Models are for changing. Try these in the problem file and solve again:
- Delete
(road market harbour). No plan exists now, and the planner says so. - Add a second van at the harbour. Does the plan use it?
- Add another parcel at the market, bound for the depot.
6. Add time
Open demos/pddl-guide/courier-durative. It is the same world with durations, and two vans at different speeds. It is a different domain, so the studio asks before closing the one you have open.
; PDDL 2.1 durative actions: actions take time, and two vans work at once.
(define (domain courier-durative)
(:requirements :typing :fluents :durative-actions)
(:types van parcel location)
(:predicates
(road ?from ?to - location)
(van-at ?v - van ?l - location)
(parcel-at ?p - parcel ?l - location)
(in ?p - parcel ?v - van))
(:functions
(distance ?from ?to - location)
(speed ?v - van))
(:durative-action drive
:parameters (?v - van ?from ?to - location)
:duration (= ?duration (/ (distance ?from ?to) (speed ?v)))
:condition (and (at start (van-at ?v ?from))
(over all (road ?from ?to)))
:effect (and (at start (not (van-at ?v ?from)))
(at end (van-at ?v ?to))))
(:durative-action load
:parameters (?p - parcel ?v - van ?l - location)
:duration (= ?duration 2)
:condition (and (at start (parcel-at ?p ?l))
(over all (van-at ?v ?l)))
:effect (and (at start (not (parcel-at ?p ?l)))
(at end (in ?p ?v))))
(:durative-action unload
:parameters (?p - parcel ?v - van ?l - location)
:duration (= ?duration 2)
:condition (and (at start (in ?p ?v))
(over all (van-at ?v ?l)))
:effect (and (at start (not (in ?p ?v)))
(at end (parcel-at ?p ?l)))))Each action now has a :duration, and each condition and effect says when it applies. Solving gives a schedule, with the two vans working at once:
0: (load book fast depot) [2]
0: (load lamp slow depot) [2]
2.001: (drive fast depot market) [4]
2.001: (drive slow depot harbour) [15]
6.002: (unload book fast market) [2]
17.002: (unload lamp slow harbour) [2]The studio draws this as a timeline. The thousandths are the small gap the planner leaves between steps that depend on each other.
Where next
- Numbers and continuous change: fuel, charge and metrics.
- Derived predicates and deadlines.
- Constraints on the whole plan.
- The syntax reference, when you start your own domain.