Classical planning

Intelligent Systems for Robotics · Week 6

This week

  • You turn the skill catalogue into a planning domain
  • You turn the map and the belief graph into a planning problem
  • You solve a fetch, and measure how much a heuristic saves over blind search

What a planner takes

The domain

The actions, each with its parameters, preconditions and effects

The problem

The objects, the initial state and the goal

You already have both. The domain comes from isfr/skills/catalogue.py. The problem comes from week 5's map and belief graph, and from a task that says where the robot starts and who wants which drink.

Which skills become actions

SkillSpec has a field plannable. The catalogue sets it false for three skills.

SkillWhy it stays out
go-toIt drives one edge of the map, and the planner never chooses edges
ik-solveIt declares no effects
detectNo skill's precondition uses the one atom it makes true

The six that remain are navigate-to, place-base-for, reach-to, grasp, release and hand-over.

navigate-to in, go-to out

  • navigate-to runs week 5's route search, then drives each edge of the route with go-to
  • The planner sees navigate-to and never go-to
  • The route search therefore stays outside the planning problem

navigate-to has the preconditions (at ?from) and (reachable ?from ?to). The planner has no map, so it cannot decide reachability itself.

The generator decides reachability

  • reachable(kg) returns every ordered pair of places joined by a route of unblocked edges
  • The generator writes one reachable fact for each pair, when it writes the problem
  • This week the pairs include each place with itself

Week 7's meta-actions start by driving to the drink. With the reflexive pair they still apply when the robot already stands there.

The price is one navigate-to from each place to itself. It changes nothing, and no shortest plan contains it.

STRIPS

A state is a set of atoms

  • A ground atom such as (at worktop_place) is true when it is in the set
  • An atom outside the set is false

Block 4 returns to that second line.

An operator

  • An operator has preconditions and two lists
  • The delete list holds the clauses that might no longer be true after the operator is applied
  • The add list holds the clauses that are true afterwards
  • An operator applies in a state when its preconditions hold there

Fikes & Nilsson (1971), section 3.2, Artificial Intelligence 2(3–4), 189–208. Their example is push(k, m, n).

A skill already has this shape

Skill declarationSTRIPS operatornavigate-to
PreconditionsPreconditions(at ?from), (reachable ?from ?to)
Positive effectsAdd list(at ?to)
Negated effectsDelete list(at ?from)

One application, before

s (at bed_place) (reachable bed_place counter_place) (gripper-empty)

Apply (navigate-to bed_place counter_place).

Its preconditions, in bold, are both in \( s \), so it applies.

One application, after

s s′ (at bed_place) (reachable bed_place counter_place) (gripper-empty) (at counter_place) (reachable bed_place counter_place) (gripper-empty)
  • Delete (at bed_place), struck out, then add (at counter_place), shaded
  • The other two atoms are in \( s' \) because they were in \( s \)

The STRIPS assumption

A feature that an action does not mention is unchanged by it.

  • That is why a skill can declare two effects and leave the rest of the apartment alone
  • navigate-to says nothing about the gripper, so the gripper holds what it held before the drive

Poole & Mackworth (2023), section 6.1.2.

Schemas and grounding

  • The catalogue's entries contain variables, so each is an action schema
  • Grounding substitutes an object of the right type for each variable
  • Each substitution gives one ground action

The planner grounds the schemas over the problem's objects before it searches.

Grounding navigate-to

navigate-to has two place parameters. The apartment's map has 22 places, so grounding gives 484 navigate-to actions.

\[ 22 \times 22 = 484 \]

22 of them drive from a place to itself.

The registry is a set of schemas

  • The registry resolves a skill by name, and each plannable skill is one schema
  • The search runs over their groundings

place-base-for has a drink and a place as parameters. How many ground actions does it give with \( d \) drinks?

PDDL

Two files

  • PDDL, the Planning Domain Definition Language, writes STRIPS down in two files
  • The domain file declares types, predicates and actions
  • The problem file declares objects, the initial state and the goal
  • One domain serves many problems

Fox & Long (2003), Journal of Artificial Intelligence Research 20, 61–124, credit PDDL to McDermott and the committee of the 1998 planning competition.

Gripper's domain


(define (domain gripper)
  (:requirements :strips :typing)
  (:types room ball gripper)
  (:predicates (at-robby ?r - room) (at ?b - ball ?r - room)
               (free ?g - gripper) (carry ?b - ball ?g - gripper))
  (:action move
    :parameters (?from - room ?to - room)
    :precondition (at-robby ?from)
    :effect (and (at-robby ?to) (not (at-robby ?from))))
  (:action pick
    :parameters (?b - ball ?r - room ?g - gripper)
    :precondition (and (at ?b ?r) (at-robby ?r) (free ?g))
    :effect (and (carry ?b ?g) (not (at ?b ?r)) (not (free ?g))))
  (:action drop
    :parameters (?b - ball ?r - room ?g - gripper)
    :precondition (and (carry ?b ?g) (at-robby ?r))
    :effect (and (at ?b ?r) (free ?g) (not (carry ?b ?g)))))
					

After the 1998 planning competition. A robot with two grippers carries balls between two rooms.

Reading the domain

  • :requirements names the parts of the language the domain uses, here STRIPS and types
  • Each parameter has a type, and grounding substitutes only objects of that type. Without types, pick would also be grounded with a room in the place of the ball.
  • Each (not ...) in an effect is an entry in the delete list
  • pick deletes (at ?b ?r) and (free ?g), so the ball leaves the room and the gripper is no longer free

One problem


(define (problem gripper-problem)
  (:domain gripper)
  (:objects rooma roomb - room left right - gripper ball1 ball2 - ball)
  (:init (at ball1 rooma) (at ball2 rooma) (free left) (free right) (at-robby rooma))
  (:goal (and (at ball1 roomb) (at ball2 roomb))))
					
  • Two balls, two grippers, two rooms
  • The goal names the balls only. Where the robot ends up is left open.

release, from its SkillSpec to PDDL


SkillSpec(
    name="release",
    parameters=("obj",),
    preconditions=(Atom("holding", ("?obj",)),),
    effects=(Atom("gripper-empty"), Atom("holding", ("?obj",), negated=True)),
    ...
)
					

(:action release
  :parameters (?obj - drink)
  :precondition (holding ?obj)
  :effect (and (gripper-empty) (not (holding ?obj))))
					

The parameter's type follows from its name. In the catalogue obj is always a drink, and from, to and place are always places.

A semantics for PDDL

  • The original definition of PDDL gave its syntax without a formal semantics
  • Fox and Long supply one
  • Their Definition 13, in section 7.1, gives the state that follows a set of actions executed together

Fox & Long (2003), page 64 and section 7.1, Journal of Artificial Intelligence Research 20, 61–124.

The transition

For one action \( a \) executed in a state \( s \), Definition 13 reduces to

\[ s' = (s \setminus \mathit{Del}(a)) \cup \mathit{Add}(a) \]

The deletes apply first, then the adds.

The order decides what happens when one atom is on both lists.

Deletes first

Take (navigate-to p p), which the reflexive reachable pairs allow.

Its add list and its delete list are both \( \{(\mathit{at}\ p)\} \).

\[ (s \setminus \{(\mathit{at}\ p)\}) \cup \{(\mathit{at}\ p)\} \ni (\mathit{at}\ p) \]

The robot stays where it was.

Listed order loses the robot

  • The catalogue lists navigate-to's add, then its delete
  • Applied in that order, the same effects would leave \( (\mathit{at}\ p) \) false, and the robot would be nowhere
  • Week 5's derivation applied a step's effects in listed order. It now applies the deletes first, for the same reason.

The closed world

Two assumptions

  • Under the complete knowledge assumption, an agent concludes that an atom is false when it cannot derive that the atom is true
  • Poole and Mackworth name this the closed-world assumption
  • Under the open-world assumption, the agent cannot draw conclusions from a lack of knowledge

Poole & Mackworth (2023), section 5.7.

Week 4 is open, PDDL is closed

  • The OWL reasoner of week 4 works in the open world. When no sink has been seen from any of a room's places, the room's type is unknown.
  • A PDDL initial state works in the closed world. Every atom the problem file does not state is false.

A state is a set of atoms, and a set has no third value for an atom the file left out.

The generator makes the assumption

  • It reads an open-world graph and writes a closed-world state
  • Every atom it leaves out becomes an atom the planner treats as false
  • A drink the robot has not grounded has no object-at atom, so no plan fetches it
  • A person the task does not name is at no place, so no plan hands them anything

A blocked edge in the belief graph


:hatch isfr:blocked true .
					
  • Week 5 blocked the flat's hatch, and the route went round through the arch and the hall door
  • reachable(kg) skips the hatch and still finds a route for every pair

The problem keeps (reachable bed_place counter_place). No fact is lost.

Two blocked edges, six missing facts

Belief graph, open world


:hatch isfr:blocked true .
:arch_to_bed_place isfr:blocked true .
							

Initial state, closed world


; no atom for a blocked edge, and absent:
(reachable bed_place arch)
(reachable bed_place hall_door)
(reachable bed_place counter_place)
; and the three reverse pairs
							

The fetch domain has no predicate for a blocked edge. A pair of places that only blocked edges joined loses its reachable fact.

Task c of the micro-project shuts off the kitchen. The third written question asks you which fact the problem then lacks.

Gripper with the robot nowhere

The example removes (at-robby rooma) from the initial state and asks again.


without (at-robby rooma): no plan
					

Every action needs the robot in a room, and no action can put it in one from nowhere.

State-space search

Forward planning

  • Forward planning is search in the state space. Each node is a state.
  • A node's neighbours are the states the actions applicable in it lead to, each computed by slide 22's transition
  • The search starts at the initial state and stops at a state that satisfies the goal
  • The path to that state is the plan

Poole & Mackworth (2023), section 6.2.

Two blind searches

  • Breadth-first search expands nodes in order of depth. When every action costs the same, the first goal state it reaches ends a shortest plan.
  • Uniform-cost search orders the frontier by path cost. Week 5 used it for routes, as lowest-cost-first search.
  • With every action at cost 1, path cost equals depth, and the two searches differ only in how they break ties

Both are blind. Neither uses the goal to choose which node to expand next.

Poole & Mackworth (2023), section 3.5.4.

Breadth-first on two balls, 1 of 3

Write a state as where ball1, ball2 and the robot are. A and B are the rooms, L and R the grippers.

Expand the initial state, A A A. Six ground actions apply, four picks and two moves.

move rooma rooma leads back to A A A by slide 23, so it adds nothing.

Frontier, depth 1Reached by
A A Bmove rooma roomb
L A Apick ball1 rooma left
R A Apick ball1 rooma right
A L Apick ball2 rooma left
A R Apick ball2 rooma right

Breadth-first on two balls, 2 of 3

Expand the five states at depth 1.

From A A B the robot can only move. Either move gives a state already seen, A A A or A A B.

A drop in rooma gives A A A again. Duplicate detection keeps one copy of each state.

Frontier, depth 2Reached from
L R AL A A or A R A
R L AR A A or A L A
L A BL A A
R A BR A A
A L BA L A
A R BA R A

Breadth-first on two balls, 3 of 3

Depth012345
New states156465
  • The first goal state, B B B, lies at depth 5
  • Breadth-first search expands all 22 states at depths 0 to 4 before it expands any state at depth 5
  • The plan is the path to B B B. It picks twice, moves, and drops twice.

The branching factor

The branching factor is the number of actions applicable in a state.

  • The apartment's map is connected, so 22 navigate-to actions apply wherever the robot stands, one to each place, its own included
  • The manipulation skills add a few more where a drink or a person is

The apartment, blind

With the reference encoding of the apartment problem, blind search expands

  • 2583 nodes on the one-drink task
  • 95770 nodes on the two-drink task

Your own counts depend on your encoding.

Part 3 of the micro-project asks you why the second count is so much larger.

Gripper's growth, blind

BallsShortest planExpandedSeconds
25250.00
4112530.00
61718530.01
823117730.08
1029686050.59
  • The plan grows by six steps for every two balls, since each trip carries two
  • From 4 balls on, the nodes expanded grow by a factor of 5.8 to 7.3 for every two balls added

The blind rows of the example's table. Node counts are the same on every machine. Seconds vary.

Why it grows

  • Each ball is in one of four positions, either room or either gripper
  • At most one ball is in each gripper
  • So the number of states grows exponentially with the number of balls

Blind search has nothing to tell it which of those states lead towards the goal.

Other ways to plan

  • Regression planning, Poole and Mackworth section 6.3
  • Planning as a CSP, section 6.4
  • Partial-order planning, section 6.5

The planners you run this week all search forwards, and the course uses forward search only.

Heuristics by relaxation

A heuristic from the domain

  • A heuristic for a state estimates the cost of solving the goal from that state
  • On week 5's map the problem was the lack of a common frame. A planner has a different problem, since no geometry relates its states.
  • So the estimate has to come from the domain itself. Solve an easier problem, and use its cost.

Poole & Mackworth (2023), section 6.2.

The delete relaxation

Ignore the delete lists of all actions. Apply (move rooma roomb).

s s′ s s′ real relaxed (at-robby rooma) (at ball1 rooma) (at-robby rooma) (at-robby roomb) (at ball1 rooma) (at-robby rooma) (at ball1 rooma) (at-robby rooma) (at-robby roomb) (at ball1 rooma)

In the relaxed task the robot is in both rooms. Nothing an action does can undo another action's work.

Hoffmann & Nebel (2001), Definition 4, Journal of Artificial Intelligence Research 14, 253–302.

Solve the relaxed task

Gripper with 10 balls in rooma, the robot in rooma, both grippers free. The goal is all 10 in roomb.

In the relaxed task, what is the shortest plan?

  • Pick all 10, since a gripper that picks a ball never stops being free
  • Move once
  • Drop all 10, since the robot is still in roomb after each drop

Count it

\[ 10 \text{ picks} + 1 \text{ move} + 10 \text{ drops} = 21 \]

  • That number is \( h^{+} \), the length of an optimal relaxed plan
  • Every plan for the real task is also a plan for the relaxed one, since ignoring deletes only leaves more atoms true
  • So \( h^{+} \) never exceeds the length of an optimal real plan, \( h^{*} \). It is admissible: it never overestimates.

The shortest real plan has 29 steps, from slide 38. And \( 21 \le 29 \).

So why not just use \( h^{+} \)?

  • Computing \( h^{+} \) is NP-hard
  • A planner would solve an NP-hard problem at every state it evaluates, to decide which state to look at next
  • So planners estimate \( h^{+} \), two ways:
  1. Cost each atom, then combine the costs of a set — slides 46 and 47
  2. Find a relaxed plan without insisting it is the shortest — slide 48

Hoffmann & Nebel (2001), section 4, citing Bylander (1994).

One action, two preconditions

A drop in roomb needs two atoms, and from the start each costs 1. Pay for the worse one, or pay for both?

take the worse one (at ball1 roomb) 2 drop ball1 roomb left +1 (carry ball1 left) 1 (at-robby roomb) 1 hmax = 1 + max(1, 1) = 2 add them up (at ball1 roomb) 3 drop ball1 roomb left +1 (carry ball1 left) 1 (at-robby roomb) 1 hadd = 1 + (1 + 1) = 3

Everything else in the two definitions is the same.

Bonet & Geffner (2001), section 4, Artificial Intelligence 129(1–2), 5–33.

Ten balls, one move

ten goal atoms one shared action (at ball1 roomb) (at ball2 roomb) (at ball3 roomb) (at ball4 roomb) (at ball5 roomb) (at ball6 roomb) (at ball7 roomb) (at ball8 roomb) (at ball9 roomb) (at ball10 roomb) (move rooma roomb) costs 1 each needs its own drop, and every drop needs the move

\( h_{\max} = \max(2, \dots, 2) = 2 \)

It sees one ball.

\( h_{\mathrm{add}} = 10 \times 3 = 30 \)

It pays for the move ten times.

Or find a relaxed plan: \( h_{\mathrm{FF}} \)

  • FF works back from the goal and extracts one relaxed plan, counting a shared action once
  • On this state it extracts exactly the 21 of slide 44, so \( h_{\mathrm{FF}} = 21 \)
  • Its relaxed plan is not guaranteed to be the shortest one, so \( h_{\mathrm{FF}} \) is not admissible

Hoffmann & Nebel (2001), footnote 2. Ghallab, Nau & Traverso (2025), section 3.2.2, give the algorithm.

Against the shortest plan of 29

EstimateValueAgainst 29
\( h_{\max} \)2Below. It counts one ball.
\( h^{+} \)21Below. It counts one move.
\( h_{\mathrm{FF}} \)21Below here, since it equals \( h^{+} \) on this state
\( h_{\mathrm{add}} \)30Above. It counts the move once for every ball.

Only \( h_{\max} \) and \( h^{+} \) are guaranteed below the true cost on every state. Those two are the admissible ones.

\( h_{\max} \) reports 2 here whatever the number of balls, so it is admissible and nearly useless.

A* and greedy best-first

  • A* orders the frontier by \( f(n) = g(n) + h(n) \), the cost so far plus the heuristic
  • With an admissible heuristic it returns a shortest plan whenever a plan exists
  • Greedy best-first search orders the frontier by \( h(n) \) alone. It ignores the cost so far, and it gives no guarantee on plan length.
  • FF itself searches by enforced hill-climbing. When that fails, it starts again with complete greedy best-first search.

Poole & Mackworth (2023), Proposition 3.1. Hoffmann & Nebel (2001), section 5.1 and page 267.

The example's table

BallsLengthExpandedSeconds
25 / 5 / 525 / 12 / 60.00 / 0.00 / 0.00
411 / 11 / 13253 / 208 / 260.00 / 0.02 / 0.00
617 / 17 / 211853 / 1760 / 540.01 / 0.24 / 0.01
823 / 23 / 2911773 / 11616 / 900.08 / 2.34 / 0.03
1029 / 29 / 3768605 / 68368 / 1340.59 / 17.73 / 0.07

Each cell gives blind, A* with \( h_{\max} \) and greedy with \( h_{\mathrm{FF}} \), in that order. From the example's README. Node counts are the same on every machine. Seconds vary.

Reading the table

  • A* with \( h_{\max} \) returns the shortest plan for every number of balls
  • For 10 balls it expands 68368 nodes, against blind search's 68605, and takes 17.73 s, against 0.59 s
  • It computes \( h_{\max} \) at every state it evaluates, and blind search computes nothing
  • Greedy best-first search with \( h_{\mathrm{FF}} \) expands at most 134 nodes up to 10 balls. For 10 balls it returns 37 steps where the shortest plan has 29.

Planners as tools

From skills to a plan

skill catalogue map, beliefs, and the task skill calls, bound to IRIs domain() problem() domain.pddl problem.pddl solve() steps() plan Shaded: the four functions you write this week.

Three tools

You do not write a search this week. Three tools do it.

  • unified-planning, a Python library
  • pyperplan, a planner written in Python. The course installs version 2.1.
  • Fast Downward, a planner run through unified-planning

pyperplan names its searches and its heuristics separately, so you can combine them: bfs, astar, gbf against blind, hmax, hadd, hff.

Micheli et al. (2025), SoftwareX 29, 102012. Alkhazraji et al. (2020), Pyperplan (Version 1.3), Zenodo.

Call a planner

Gripper's two files, read back and solved.


from unified_planning.io import PDDLReader
from unified_planning.shortcuts import OneshotPlanner, get_environment

get_environment().credits_stream = None
problem = PDDLReader().parse_problem("gripper.pddl", "gripper-2.pddl")

with OneshotPlanner(name="fast-downward") as planner:
    result = planner.solve(problem, output_stream=None)
					

parse_problem_string takes the two files as text instead, which is what you want once you generate them.

Read what came back


result.status          # SOLVED_SATISFICING, SOLVED_OPTIMALLY, UNSOLVABLE_PROVEN, ...
result.plan            # None when no plan exists
result.log_messages    # the engine's own output
					

if result.plan is None:
    print("unsolvable")
else:
    for step in result.plan.actions:
        print(step.action.name, [p.object().name for p in step.actual_parameters])
					

When it does not work

What you seeWhat it means
result.plan is NoneThe planner proved there is no plan. That is a result rather than an error.
A PDDLReader parse errorThe file you wrote is malformed. check.py names it and skips that task.
A step whose precondition fails on replayYour action dropped a precondition the skill declares
No such engineThe engine name is wrong, or the package is not installed
A configuration past its limitcompare.py stops it and prints timeout

Task c of the micro-project is unsolvable by design, so a traceback there is a defect in your code rather than in the planner.

Fast Downward

  • A progression planner based on heuristic search (Helmert, 2006)
  • It translates the PDDL task into a multi-valued planning task before it searches, and computes its causal graph heuristic from hierarchical decompositions of that task
  • It runs in configurations that have names. The engine fast-downward runs lama-first, which returns a plan without a guarantee that it is the shortest.
  • The engine fast-downward-opt runs A* with the LM-cut heuristic and guarantees a shortest plan

Helmert (2006), Journal of Artificial Intelligence Research 26, 191–246, for the first two lines. The configurations are not described there.

A configuration is a choice

A configuration is a choice of search and heuristic, and the choice decides what the planner guarantees. Part 3 runs four.

ConfigurationSearchShortest plan guaranteed
blindBreadth-firstYes, when every action costs the same
admissibleA* with \( h_{\max} \)Yes
greedyGreedy best-first with \( h_{\mathrm{FF}} \)No
fast-downwardlama-firstNo

What a plan is not, and the project

A plan is a sequence of skill calls

  • Each step is a skill with its arguments
  • The planner assumed that each call has its declared effects
  • On the robot, any call can terminate in failure, as week 2's skill model allows. The rest of the plan then rests on a state that does not hold.

Week 8 executes plans, detects the failure and repairs it.

Valid for the domain, useless for the robot

  • While the course's planner was being built, grasp(?obj ?place) had only the preconditions (gripper-at ?obj) and (gripper-empty)
  • Nothing bound ?place. The planner returned a fetch that placed the base at the drink, drove away, and reached and grasped with ?place bound to a place the robot was not at.
  • Adding (at ?place) and (object-at ?obj ?place) to grasp's preconditions fixed it

A replay against the same model cannot find such a gap, since it checks the plan against the preconditions that let it through.

Week 7

  • Week 7 adds meta-actions, fixed compositions of skills, each one action in the domain with its preconditions and effects derived from its steps
  • It compares plans with and without them

This week varies the search with the domain fixed. Week 7 varies the domain with the search fixed.

The micro-project

  • Write the domain from the six plannable skills, and the problem from the apartment's map, its belief graph and a task file
  • Solve four fetch tasks, and map each plan step back to a registered skill with its arguments as IRIs
  • A provided script replays every plan against the catalogue. One task shuts off the kitchen and has no plan.
  • Run four search configurations on two of the tasks, and explain what the table shows

In exercises/06-classical-planning/. Nothing in it needs Webots.

The project is marked on two things

  1. Integration, meaning how far separately built parts have been made into one system
  2. The understanding you can demonstrate of why your system is put together the way it is

The course page has stated both since week 1. The rest of the project's detail follows separately.

Before week 7

  • Run the example
  • Read Poole and Mackworth, sections 6.1 and 6.2
  • Start the micro-project with the domain

PYTHONPATH=. python3 examples/06-classical-planning/main.py