State Space Search: Water Jug Problem
State Space Search: Water Jug Problem
2
State Space Search: Water Jug Problem
1. (x, y) (4, y)
if x 4 fill 4L jug
2. (x, y) (x, 3)
if y 3 fill 3L jug
3. (x, y) (x d, y)
if x 0 remove water from 4L
4. (x, y) (x, y d)
if y 0 remove water from 3 L
3
State Space Search: Water Jug Problem
5. (x, y) (0, y)
if x 0 empty 4L
6. (x, y) (x, 0)
if y 0 Empty 3L
7. (x, y) (4, y (4 x))
if x y 4, y 0 3L to 4L until 4l full
8. (x, y) (x (3 y), 3)
if x y 3, x 0 4L to 3L until 3L is full
4
State Space Search: Water Jug Problem
9. (x, y) (x y, 0)
if x y 4, y 0 3L->4l add water
10.(x, y) (0, x y)
if x y 3, x 0 4L->3L add water
11.(0, 2) (2, 0)
12.(2, y) (0, y)
5
State Space Search: Water Jug Problem
1. current state = (0, 0)
2. Loop until reaching the goal state (2, 0)
Apply a rule whose left side matches the current state
Set the new current state to be the resulting state
(0, 0)
(0, 3)
(3, 0)
(3, 3)
(4, 2)
(0, 2)
(2, 0)
6
State Space Search: Water Jug Problem
The role of the condition in the left side of a rule
restrict the application of the rule
more efficient
1. (x, y) (4, y)
if x 4
2. (x, y) (x, 3)
if y 3
7
State Space Search: Water Jug Problem
Special-purpose rules to capture special-case
knowledge that can be used at some stage in
solving a
problem
11.(0, 2) (2, 0)
12.(2, y) (0, y)
8
Example: Water jug problem
9
Example 2: Missionaries and cannibals
• An old puzzle is the “Missionaries and cannibals” problem (in various
guises)
• The missionaries and cannibals wish to cross a river
• They have a canoe that can hold two people
• It is unsafe to have cannibals outnumber missionaries
M C
M M C
C C M
M C C
M
3m, 2c etc.
1c etc.
2c 3m, 1c
3m, 3c, 1m
2m, 3c
canoe
2m
3m, 2c, etc.
1m, 3c
1m1c 1m canoe
2m, 2c
1c 2m, 3c, etc.
canoe
1m1c
14