100% found this document useful (2 votes)
3K views14 pages

State Space Search: Water Jug Problem

The document describes the water jug problem state space search problem. The problem involves using a 4 liter jug and 3 liter jug to obtain exactly 2 liters of water in the 4 liter jug. The state is represented as (x,y) where x is the amount of water in the 4 liter jug and y is the amount in the 3 liter jug. There are 12 rules described that define the possible transitions between states by filling, emptying, or pouring water between jugs. Following the rules iteratively leads from the start state of (0,0) to the goal state of (2,0).

Uploaded by

Tariq Iqbal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
3K views14 pages

State Space Search: Water Jug Problem

The document describes the water jug problem state space search problem. The problem involves using a 4 liter jug and 3 liter jug to obtain exactly 2 liters of water in the 4 liter jug. The state is represented as (x,y) where x is the amount of water in the 4 liter jug and y is the amount in the 3 liter jug. There are 12 rules described that define the possible transitions between states by filling, emptying, or pouring water between jugs. Following the rules iteratively leads from the start state of (0,0) to the goal state of (2,0).

Uploaded by

Tariq Iqbal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 14

State Space Search: Water Jug Problem

“You are given two jugs, a 4-litre one and a 3-


litre one.
Neither has any measuring markers on it. There
is a
pump that can be used to fill the jugs with
water. How
can you get exactly 2 litres of water into 4-litre
jug.”
1
State Space Search: Water Jug Problem
• State: (x, y)
x = 0, 1, 2, 3, or 4 y = 0, 1, 2, 3
• Start state: (0, 0).
• Goal state: (2, n) for any n.
• Attempting to end up in a goal state.

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

State space representation

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

Initial state Goal state


10
States
• A state can be represented by the number of
missionaries and cannibals on each side of the
river
– Initial state: 3m,3c,canoe / 0m,0c
– Goal state: 0m,0c / 3m,3c,canoe
– We assume that crossing the river is a simple procedure
that always works (so we don’t have to represent the
canoe being in the middle of the river)
• However, this is redundant; we only need to
represent how many missionaries/cannibals are on
one side of the river
– Initial state: 3m,3c,canoe
11
– Goal state: 0m,0c
Operations
• An operation takes us from one state to another
• Here are five possible operations:
– Canoe takes 1 missionary across river (1m)
– Canoe takes 1 cannibal across river (1c)
– Canoe takes 2 missionaries across river (2m)
– Canoe takes 2 cannibals across river (2c)
– Canoe takes 1 missionary and 1 cannibal across river (1m1c)
• We don’t have to specify “west to east” or “east to
west” because only one of these will be possible at any
given time
12
13
The state space

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

You might also like