Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
306 views1 page

Water Jug Problem

The document describes the water jug problem, which involves using two jugs of capacities a and b liters to obtain a target volume t liters. The problem is solvable only if t is a multiple of the greatest common divisor (gcd) of a and b. The problem can be modeled as a state space search with states represented by the contents (x, y) of the two jugs. Six production rules are given to generate successor states by filling jugs, emptying jugs, or pouring between jugs. A breadth-first or depth-first search can then solve the problem by traversing this state space from the initial state (0,0) to a goal state with content t liters.

Uploaded by

Ryan Davis
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
306 views1 page

Water Jug Problem

The document describes the water jug problem, which involves using two jugs of capacities a and b liters to obtain a target volume t liters. The problem is solvable only if t is a multiple of the greatest common divisor (gcd) of a and b. The problem can be modeled as a state space search with states represented by the contents (x, y) of the two jugs. Six production rules are given to generate successor states by filling jugs, emptying jugs, or pouring between jugs. A breadth-first or depth-first search can then solve the problem by traversing this state space from the initial state (0,0) to a goal state with content t liters.

Uploaded by

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

Water Jug Problem

October 11, 2013 by Kartik Kukreja

The Water Jug problem can be stated as follows: Given two unmarked jugs having
capacities a and b liters respectively and a target volume t liters, find the moves
that get exactly t liters in any of the two jugs.

The problem is solvable only when t is a multiple of gcd(a, b) and can be modeled as
search through a state space. The state space for this problem can be described as the
set of ordered pair of integers (x, y) such that x {0, 1, 2, , a} and
y {0, 1, 2, , b}. The initial state is (0, 0) and the goal states are (t, y) and
(x, t) x, y.

All we need now for a search procedure to work is a way to generate new states
(successors) from a given state. This is captured by production rules that specify how
and when a new state can be generated from a given state. For the water jug problem,
the following production rules are sufficient:

1. (x, y) -> (a, y) if x < a i.e., Fill the first jug if it is not already full

2. (x, y) -> (x, b) if y < b i.e., Fill the second jug if it is not already full

3. (x, y) -> (0, y) if x > 0 i.e., Empty the first jug

4. (x, y) -> (x, 0) if y > 0 i.e, Empty the second jug

5. (x, y) -> (min(x + y, a), max(0, x + y a)) if y > 0 i.e., Pour from second jug into
first jug until the first jug is full or the second jug is empty

6. (x, y) -> (max(0, x + y b), min(x + y, b)) if x > 0 i.e., Pour from first jug into
second jug until the second jug is full or the first jug is empty

Strictly speaking, the conditions in the production rules are not required e.g., we could
fill an already full jug except that it wont lead us anywhere and would be wasteful in a
tree search procedure where the visited states are not saved to prevent revisiting.

Now, a search procedure like BFS or DFS can be applied to systematically search from
the initial state to one of the goal states through the state space.

You might also like