# Water Jug Problem in Artificial Intelligence

[wptelegram-join-channel]

### Water Jug Problem in Artificial Intelligence – State Space Search

Water Jug Problem Definition,

“You are given two jugs, a 4-liter one and a 3-liter 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 liters of water into a 4-liter jug.”

### Video Tutorial:

Representation of water Jug Problem in terms of state-space search,

State: (x, y)

where x represents the quantity of water in a 4-liter jug and y represents the quantity of water in a 3-liter jug.

That is, x = 0, 1, 2, 3, or 4  y = 0, 1, 2, 3

Start state: (0, 0).

Goal state: (2, n) for any n.

Here need to start from the current state and end up in a goal state.

Production Rules for Water Jug Problem in Artificial Intelligence

The solution to Water Jug Problem in Artificial Intelligence

1. Current state = (0, 0)

2. Loop until the goal state (2, 0) reached

– Apply a rule whose left side matches the current state

– Set the new current state to be the resulting state

(0, 0) – Start State

(0, 3) – Rule 2, Fill the 3-liter jug

(3, 0) – Rule 9, Pour all the water from the 3-liter jug into the 4-liter jug.

(3, 3) – Rule 2, Fill the 3-liter jug

(4, 2) – Rule 7, Pour water from the 3-liter jug into the 4-liter jug until the 4-liter jug is full.

(0, 2) –  Rule 5, Empty the 4-liter jug on the ground

(2, 0) – Rule 9, Pour all the water from the 3-liter jug into the 4-liter jug.

Goal State reached

Another solution to Water Jug Problem in Artificial Intelligence

(0, 0) – Start State

(4, 0) – Rule 1, Fill the 4-liter jug

(1, 3) – Rule 8, Pour water from the 4-liter jug into the 3-liter jug until the 3-liter jug is full.

(1, 0) – Rule 6, Empty the 3-liter jug on the ground

(0, 1) – Rule 10, Pour all the water from the 4-liter jug into the 3-liter jug.

(4, 1) –  Rule 1, Fill the 4-liter jug

(2, 3) – Rule 8, Pour water from the 4-liter jug into the 3-liter jug until the 3-liter jug is full.

Goal State reached