How to solve "Water Jug" Problem

 





In the water jug problem in Artificial Intelligence, we are provided with two jugs: one having the capacity to hold 3 liter of water and the other has the capacity to hold 4 liter of water. There is no other measuring equipment available and the jugs also do not have any kind of marking on them. So, the agent’s task here is to fill the 4-gallon jug with 2 gallons of water by using only these two jugs and no other material. Initially, both our jugs are empty.

So, to solve this problem, following set of rules were proposed:

Production rules for solving the water jug problem

Here, let x denote the 4-gallon jug and y denote the 3-gallon jug.

S.No.Initial StateConditionFinal stateDescription of action taken
1.(x,y)If x<4(4,y)Fill the 4 liter jug completely
2.(x,y)if y<3(x,3)Fill the 3 liter jug completely
3.(x,y)If x>0(x-d,y)Pour some part from the 4 liter jug
4.(x,y)If y>0(x,y-d)Pour some part from the 3 liter jug
5.(x,y)If x>0(0,y)Empty the 4 liter jug
6.(x,y)If y>0(x,0)Empty the 3 liter jug
7.(x,y)If (x+y)<7(4, y-[4-x])Pour some water from the 3 liter jug to fill the four liter jug
8.(x,y)If (x+y)<7(x-[3-y],y)Pour some water from the 4 liter jug to fill the 3 liter jug.
9.(x,y)If (x+y)<4(x+y,0)Pour all water from 3 liter jug to the 4 liter jug
10.(x,y)if (x+y)<3(0, x+y)Pour all water from the 4 liter jug to the 3 liter jug

Solution of water jug problem according to the production rules:

S.No.4 gallon jug contents3 gallon jug contentsRule followed
1.0 liter0 literInitial state
2.0 liter3 literRule no.2
3.3 liter0 literRule no. 9
4.3 liter3 literRule no. 2
5.4 liter2 literRule no. 7
6.0 liter2 literRule no. 5
7.2 liter0 literRule no. 9

On reaching the 7th attempt, we reach a state which is our goal state. Therefore, at this state, our problem is solved.

Comments