Planning means finding a sequence of actions that will take an agent from the current situation to a goal.

The Planning Problem

A planner is given an initial state, a goal, and a set of actions described by their preconditions and effects, and must produce a plan, a sequence of actions that achieves the goal. Compared with ordinary search, planning uses a factored representation of states (sets of logical facts), so it can reason about parts of a state and exploit structure. Plans may be built forward from the initial state (progression) or backward from the goal (regression), and may be total-order (strict sequence) or partial-order (steps ordered only where necessary).

STRIPS

STRIPS (Stanford Research Institute Problem Solver, 1971) represents a state as a set of ground atomic facts and an action as an operator with three lists: preconditions (facts that must hold before), an add list (facts that become true) and a delete list (facts that become false). An action is applicable if its preconditions are in the state; applying it removes the delete list and adds the add list. Facts not mentioned stay unchanged (the STRIPS assumption that avoids the frame problem of stating what does not change). The goal is a set of facts to be achieved. Its successors are the languages PDDL and the basis of modern planners.

Definition: STRIPS. A planning representation in which a state is a set of facts and each action has preconditions, an add list and a delete list, so that applying it updates the state by removing the delete list and adding the add list.

The Blocks World

The Blocks World has table-top blocks that can be stacked. Predicates: On(x, y) block x is on y; OnTable(x); Clear(x) nothing on x; HandEmpty; Holding(x). Operators: Pickup(x): preconditions OnTable(x), Clear(x), HandEmpty; add Holding(x); delete OnTable(x), Clear(x), HandEmpty. Putdown(x): precondition Holding(x); add OnTable(x), Clear(x), HandEmpty; delete Holding(x). Stack(x, y): preconditions Holding(x), Clear(y); add On(x, y), Clear(x), HandEmpty; delete Holding(x), Clear(y). Unstack(x, y): preconditions On(x, y), Clear(x), HandEmpty; add Holding(x), Clear(y); delete On(x, y), Clear(x), HandEmpty.

Planning Methods

Forward state-space planning searches from the initial state with heuristics; goal regression works back from the goal; partial-order planning (POP) adds ordering constraints only as needed, leaving flexibility; Sussman's anomaly, a Blocks World problem with interacting sub-goals, showed that solving goals one by one (linear planning) can fail.

Table 3.7: Blocks World operators

Operator Preconditions Effect
Pickup(x) OnTable(x), Clear(x), HandEmpty Holding(x)
Putdown(x) Holding(x) OnTable(x), HandEmpty
Stack(x, y) Holding(x), Clear(y) On(x, y), HandEmpty
Unstack(x, y) On(x, y), Clear(x), HandEmpty Holding(x), Clear(y)

Example 3.7: Planning in the Blocks World

Problem: Initially C is on A, A and B are on the table. Goal: On(A, B). Find a plan.

Solution:

  1. Unstack(C, A): hand holds C; A becomes clear.
  2. Putdown(C): C on the table; hand empty.
  3. Pickup(A): A is on the table and clear, so it can be picked up.
  4. Stack(A, B): B is clear, so A is placed on B.

Result: The plan Unstack(C, A), Putdown(C), Pickup(A), Stack(A, B) reaches On(A, B) in 4 steps.

from collections import deque
def ops(s):
    out = []
    for x in "ABC":
        if f"OnTable({x})" in s and f"Clear({x})" in s \
                and "HandEmpty" in s:
            out.append((f"Pickup({x})", s - {f"OnTable({x})",
                f"Clear({x})", "HandEmpty"} | {f"Holding({x})"}))
        if f"Holding({x})" in s:
            out.append((f"Putdown({x})", s - {f"Holding({x})"}
                | {f"OnTable({x})", f"Clear({x})", "HandEmpty"}))
        for y in "ABC":
            if x != y and f"Holding({x})" in s and f"Clear({y})" in s:
                out.append((f"Stack({x},{y})", s - {f"Holding({x})",
                    f"Clear({y})"} | {f"On({x},{y})", f"Clear({x})",
                    "HandEmpty"}))
            if f"On({x},{y})" in s and f"Clear({x})" in s \
                    and "HandEmpty" in s:
                out.append((f"Unstack({x},{y})", s - {f"On({x},{y})",
                    f"Clear({x})", "HandEmpty"} | {f"Holding({x})",
                    f"Clear({y})"}))
    return out
start = frozenset({"On(C,A)", "OnTable(A)", "OnTable(B)",
                   "Clear(C)", "Clear(B)", "HandEmpty"})
q, seen = deque([(start, [])]), {start}
while q:
    s, plan = q.popleft()
    if "On(A,B)" in s:
        print(plan)
        break
    for name, t in ops(s):
        t = frozenset(t)
        if t not in seen:
            seen.add(t)
            q.append((t, plan + [name]))

Output

['Unstack(C,A)', 'Putdown(C)', 'Pickup(A)', 'Stack(A,B)']

Common mistakes

  • Applying an operator whose preconditions are not satisfied.
  • Forgetting to delete facts that no longer hold, such as Clear(y) after stacking on y.
  • Trying to pick up a block that has another block on it.
  • Assuming goals can always be achieved one at a time without interference.

Key takeaways

  • A plan is an action sequence from the initial state to the goal.
  • STRIPS operator = preconditions + add list + delete list.
  • Blocks World operators: Pickup, Putdown, Stack, Unstack.
  • Unmentioned facts stay unchanged, which avoids the frame problem.

Practice questions

  1. What are the three parts of a STRIPS operator?
  2. What does Unstack(x, y) require?
  3. What is the frame problem?

Answers to the practice questions

  1. Preconditions, add list and delete list.
  2. On(x, y), Clear(x) and HandEmpty.
  3. Specifying what does not change when an action is performed.

Sources

  • Official BCA syllabus Artificial Intelligence, course code 26BCA404DS04, Unit III