A13 Solved
A13 Solved
Solution: Yes: The solution must contain at least one separate drop action
for each ball that is not yet currently in room B.
2. Say that the robot has only one gripper, so that it can only hold one ball at a
time. Is the number of balls still in room A, multiplied by 4, an admissible
heuristic?
Solution: No: For example, in the initial state for 𝑛 = 1, the length of an
optimal solution is 3 (pick, move A B, drop), whereas the value of this heuristic
is 4.
3. Say now the robot has two grippers, and it takes only one action to pick up
two balls, and only one action to drop two balls. Is the number of balls not
yet in room B an admissible heuristic?
Solution: No: For example, if all but 2 balls are already in room B, and the
robot is in room B and holds the 2 remaining balls, then the length of an
optimal solution is 1, whereas the value of this heuristic is 2.
4. Say now the robot has two grippers, but picks up/drops each ball individually,
so that it needs two actions to take two balls, and two actions to drop two balls.
Is the number of balls not yet in room B an admissible heuristic?
1
Problem 13.2 (Partial Order Planning)
Consider the planning task (𝑃, 𝐴, 𝐼, 𝐺) where
• facts 𝑃 = {𝑝, 𝑞, 𝑟, 𝑠}
• actions 𝐴 = {𝑋, 𝑌, 𝑍} where the preconditions (above the box) and effects
(below the box) of the actions are given by
𝑝 𝑞 𝑝
X Y Z
𝑞 ¬𝑝, 𝑟 ¬𝑝, 𝑠
𝑟, 𝑠
Solution: Start
Finish
𝑝
𝑝 𝑝 𝑞 𝑟 𝑠
Solution: 𝑆𝑡𝑎𝑟𝑡 → 𝑋, 𝑆𝑡𝑎𝑟𝑡 → 𝑍, 𝑋 → 𝑌, 𝑌 → 𝐹𝑖𝑛𝑖𝑠ℎ, 𝑍 → 𝐹𝑖𝑛𝑖𝑠ℎ
𝑝
Solution: Both steps 𝑌 and 𝑍 clobber both of the links →.
4. Give the temporal ordering that yields a partially ordered plan that solves the
task.
Solution: 𝑋 ≺ 𝑍 and 𝑍 ≺ 𝑌
2
Consider a set of objects 𝑂𝑏𝑗 = {1, 2, 3, 4, 5, 6} that can be at location A or B.
Currently all objects are at location 𝐴 and unpainted. Eventually all objects are
needed in location 𝐴 and painted. At location 𝐵, a painting station is available that
can paint up to 3 objects at a time. A robot is available (currently at location 𝐴) that
can move up to 2 objects at a time from one location to another.
Robot
OO Painter
𝐴 𝐵 O
123456 O
O
We formalize this problem as a STRIPS task (𝑃, 𝐴, 𝐼, 𝐺) where the set 𝑃 of facts
contains
• at(𝑙, 𝑜) for 𝑙 ∈ {𝐴, 𝐵} and 𝑜 ∈ (𝑂𝑏𝑗 ∪ {𝑅𝑜𝑏𝑜𝑡})
• painted(𝑜) for 𝑜 ∈ 𝑂𝑏𝑗
and the set 𝐴 of actions contains
• move(𝑙, 𝑚, 𝑂) for 𝑙, 𝑚 ∈ {𝐴, 𝐵}, 𝑂 ⊆ 𝑂𝑏𝑗, #(𝑂) ≤ 2 given by
– precondition: at(𝑙, 𝑜) for all 𝑜 ∈ (𝑂 ∪ {𝑅𝑜𝑏𝑜𝑡})
– add list: at(𝑚, 𝑜) for all 𝑜 ∈ (𝑂 ∪ {𝑅𝑜𝑏𝑜𝑡})
– delete list: same as precondition
• paint(𝑂) for 𝑂 ⊆ 𝑂𝑏𝑗, #(𝑂) ≤ 3 given by
– precondition: at(𝐵, 𝑜) for all 𝑜 ∈ 𝑂
– add list: painted(𝑜) for all 𝑜 ∈ 𝑂
– delete list: nothing
1. Give the initial state 𝐼 and the goal 𝐺.
Solution: at(𝐴, 𝑜) for all 𝑜 ∈ (𝑂𝑏𝑗 ∪ {𝑅𝑜𝑏𝑜𝑡}), goal: at(𝐴, 𝑜), painted(𝑜) for
all 𝑜 ∈ 𝑂𝑏𝑗
2. After applying move(𝐴, 𝐵, {1, 2}) in 𝐼, multiple actions are applicable. Give
two of them.
Solution: The applicable actions are move(𝐵, 𝐴, 𝑂) and paint(𝑂) for any
𝑂 ⊆ {1, 2}. Note: Among those, move(𝐵, 𝐴, ∅) and paint({1, 2}) are the not-
obviously-suboptimal ones and pondering those helps with the next subques-
tion.
3
3. Give the value ℎ∗ (𝐼).
5. Let 𝑈𝑠 (𝑙) and 𝑃𝑠 (𝑙) be the numbers of unpainted and painted objects at loca-
tion 𝑙 in state 𝑠. For each of the following heuristic ℎ(𝑠), say if it is admissible.
1. 2 ⋅ 𝑈𝑠 (𝐴) + 𝑈𝑠 (𝐵)
2. 0
3. 𝑈𝑠 (𝐴)+roundDown((𝑈𝑠 (𝐴)+𝑈𝑠 (𝐵))∕3)+roundDown((𝑃𝑠 (𝐵)+𝑈𝑠 (𝐵))∕2)
Solution: 2 and 3.
1. too pessimistic, e.g., two unpainted objects in location 𝐴 need 3 steps,
heuristic yields 4
2. trivially admissible but useless
3. a good heuristic: unpainted objects in location 𝐴 (resp. any objects in
location 𝐵) need to be moved at least twice (resp. once) in groups of at
most 2; unpainted objects must be painted in groups of at most 3.
Problem 13.4
Encode the Tower of Hanoi task below into PDDL. There are five discs and the
goal is to move them from left to right according to the rules of Tower of Hanoi.
Solve the PDDL encoding using FF. As your solution, submit a print-out of the
following 3 files: The PDDL domain file “towersofhanoi-domain.pddl”; the PDDL
problem file “towersofhanoi-problem.pddl”, as well as a file “towersofhanoi-output.txt”
containing FF’s output.
4
Solution: PDDL Domain file:
(define (domain hanoi)
(:requirements :strips)
(:predicates (clear ?x)
(on ?x ?y)
(smaller ?x ?y)
)
(:action move
:parameters (?disc ?from ?to)
:precondition (and (smaller ?disc ?to)
(on ?disc ?from)
(clear ?disc)
(clear ?to)
)
:effect (and (clear ?from)
(on ?disc ?to)
(not (on ?disc ?from))
(not (clear ?to))
)
)
)
PDDL Problem file:
(define (problem hanoi)
(:domain hanoi)
(:objects p1 p2 p3 d1 d2 d3 d4 d5)
(:init
(smaller d1 p1)(smaller d1 p2)(smaller d1 p3)
(smaller d2 p1)(smaller d2 p2)(smaller d2 p3)
(smaller d3 p1)(smaller d3 p2)(smaller d3 p3)
(smaller d4 p1)(smaller d4 p2)(smaller d4 p3)
(smaller d5 p1)(smaller d5 p2)(smaller d5 p3)
(smaller d1 d2)(smaller d1 d3)(smaller d1 d4)(smaller d1 d5)
(smaller d2 d3)(smaller d2 d4)(smaller d2 d5)
(smaller d3 d4)(smaller d3 d5)
(smaller d4 d5)
5
(clear p2)(clear p3)(clear d1)
(on d1 d2)(on d2 d3)(on d3 d4)
(on d4 d5)(on d5 p1)
)
(:goal
(and (on d1 d2)(on d2 d3)(on d3 d4)(on d4 d5)(on d5 p3) )
)
)
The output of FF: (some white spaces removed)
parsing domain file
domain 'HANOI' defined
... done.
ff: parsing problem file
problem 'HANOI' defined
... done.
6
23: MOVE D4 P2 D5
24: MOVE D1 D2 D4
25: MOVE D2 D3 P2
26: MOVE D1 D4 D2
27: MOVE D3 P1 D4
28: MOVE D1 D2 P1
29: MOVE D2 P2 D3
30: MOVE D1 P1 D2
time spent: 0.00 seconds instantiating 200 easy, 0 hard action templates
0.00 seconds reachability analysis, yielding 33 facts and 135 actions
0.00 seconds creating final representation with 32 relevant facts
0.00 seconds building connectivity graph
0.00 seconds searching, evaluating 101 states, to a max depth of 4
0.00 seconds total time
The task is formalized in STRIPS as follows. Facts are 𝑎𝑡(𝑥) and 𝑣𝑖𝑠𝑖𝑡𝑒𝑑(𝑥)
where 𝑥 ∈ {𝐴𝑑𝑒𝑙𝑎𝑖𝑑𝑒, 𝐵𝑟𝑖𝑠𝑏𝑎𝑛𝑒, 𝐷𝑎𝑟𝑤𝑖𝑛, 𝑃𝑒𝑟𝑡ℎ, 𝑆𝑦𝑑𝑛𝑒𝑦}. The initial state is {𝑎𝑡(𝑆𝑦𝑑𝑛𝑒𝑦), 𝑣𝑖𝑠𝑖𝑡𝑒𝑑(𝑆𝑦𝑑𝑛𝑒𝑦)},
the goal is {𝑣𝑖𝑠𝑖𝑡𝑒𝑑(𝐵𝑟𝑖𝑠𝑏𝑎𝑛𝑒), 𝑣𝑖𝑠𝑖𝑡𝑒𝑑(𝐷𝑎𝑟𝑤𝑖𝑛), 𝑣𝑖𝑠𝑖𝑡𝑒𝑑(𝑃𝑒𝑟𝑡ℎ)}. The actions move
along the roads, i.e., they are of the form
𝑑𝑟𝑖𝑣𝑒(𝑥, 𝑦) ∶ ({𝑎𝑡(𝑥)}, {𝑎𝑡(𝑦), 𝑣𝑖𝑠𝑖𝑡𝑒𝑑(𝑦)}, {𝑎𝑡(𝑥)})
where 𝑥 and 𝑦 have a direct connection according to the road map. Each road
can be driven in both directions, except for the road between Adelaide and
7
Perth, which can only be driven from Adelaide to Perth, not in the opposite
direction. In your answers to the following questions, use the abbreviations “v”
for “visited”, and “Ad”, “Br”, “Da”, “Pe”, “Sy” for the cities.
1. Give an optimal (shortest) plan for the initial state, if one exists; if no plan
exists, argue why that is the case. Give an optimal (shortest) relaxed plan for
the initial state, if one exists; if no relaxed plan exists, argue why that is the
case. What is the ℎ∗ value and the ℎ+ value of the initial state? (When writing
up a plan or relaxed plan, it suffices to give the sequence of action names.)
Solution: Optimal plan: 𝑑𝑟𝑖𝑣𝑒(𝑆𝑦, 𝐵𝑟), 𝑑𝑟𝑖𝑣𝑒(𝐵𝑟, 𝑆𝑦), 𝑑𝑟𝑖𝑣𝑒(𝑆𝑦, 𝐴𝑑), 𝑑𝑟𝑖𝑣𝑒(𝐴𝑑, 𝐷𝑎),
𝑑𝑟𝑖𝑣𝑒(𝐷𝑎, 𝐴𝑑), 𝑑𝑟𝑖𝑣𝑒(𝐴𝑑, 𝑃𝑒). Optimal relaxed plan: 𝑑𝑟𝑖𝑣𝑒(𝑆𝑦, 𝐵𝑟), 𝑑𝑟𝑖𝑣𝑒(𝑆𝑦, 𝐴𝑑),
𝑑𝑟𝑖𝑣𝑒(𝐴𝑑, 𝐷𝑎), 𝑑𝑟𝑖𝑣𝑒(𝐴𝑑, 𝑃𝑒). ℎ∗ = 6, ℎ+ = 4.
2. Do the same in the modified task where the road between Sydney and Bris-
bane is also one-way, i.e., it can only be driven from Sydney to Brisbane, not
in the opposite direction.
Solution: Optimal plan: Does not exist because we must visit both Brisbane
and Perth, but once we moved to either of these two, we cannot get back out
again. Optimal relaxed plan: 𝑑𝑟𝑖𝑣𝑒(𝑆𝑦, 𝐵𝑟), 𝑑𝑟𝑖𝑣𝑒(𝑆𝑦, 𝐴𝑑), 𝑑𝑟𝑖𝑣𝑒(𝐴𝑑, 𝐷𝑎),
𝑑𝑟𝑖𝑣𝑒(𝐴𝑑, 𝑃𝑒). ℎ∗ = ∞, ℎ+ = 4.
3. Write up, in STRIPS notation, all states reachable from the initial state in
at most two steps. Start at the initial state, and insert successors. Indicate
successor states by edges. Annotate the states with their ℎ∗ values as well as
their ℎ+ values.
4. Do the same in the modified task where the road between Sydney and Bris-
bane is one-way, i.e., it can only be driven from Sydney to Brisbane, not in the
opposite direction.
Solution: A relaxed problem is easier to solve than the original problem. Then
the length of its optimal plan of the relaxed problem can be used as a heuristic
for the original problem.
8
2. Explain (in about 2 sentences) why it is bad to relax too much or too little.
Solution: If we relax too little, the relaxed problem is still too difficult to solve.
If we relax too much, the relaxed problem is so easy that it does not induce a
useful heuristic.
4. Let ℎ+ be the heuristic obtained from the only-adds relaxation. Give the value
of ℎ+ (𝐼).