Saturday 15 June 2013

Water Jug Problem

WaterJugProblem

Statement :- We are given 2 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 we get exactly 2 liters of water in to the 4-liter jugs?
Solution:-
The state space for this problem can be defined as

{ ( i ,j ) i = 0,1,2,3,4 j = 0,1,2,3}

‘i’ represents the number of liters of water in the 4-liter jug and ‘j’ represents the number of liters of water in the 3-liter jug. The initial state is ( 0,0) that is no water on each jug. The goal state is to get ( 2,n) for any value of ‘n’.

To solve this we have to make some assumptions not mentioned in the problem. They are

1. We can fill a jug from the pump.

2. we can pour water out of a jug to the ground.

3. We can pour water from one jug to another.

4. There is no measuring device available.

The various operators (Production Rules) that are available to solve this problem may be stated as given in the following figure .






19 comments:

  1. Liters in 4 lt jug - Liters in 3 lt jug
    4 - 0
    1 - 3
    0 - 1
    4 - 1
    2 - 3
    This is the optimal solution
    Anchor Charan

    ReplyDelete
    Replies
    1. No, this is -
      0 - 3
      3 - 0
      3 - 3
      4 - 2
      ------
      0 - 2
      2 - 0

      Delete
  2. Litres in 4 ltr jug - litres in 3 ltr jug
    0-3
    3-0
    3-3
    4-2
    0-2
    2-0
    .
    This also a possible solution

    ReplyDelete
  3. What is a “Water Jug” Problem? Explain with an Example.
    Solve the following Water Jug problem with step by step representation.

    You have a 5 liter can and 3 liter can. Fill exact 4 liters in 5 liter can.

    ReplyDelete
    Replies
    1. 5ltr jug. 3 ltr jug
      5 0
      2 3
      2 0
      0 2
      5 2
      4 3

      Here is 4 ltr water in 5ltr jug.

      Delete
  4. This comment has been removed by the author.

    ReplyDelete
  5. What techniques are used to solve this problem in AI??

    ReplyDelete
  6. Good Explanation to Water jug problem.

    ReplyDelete
  7. This comment has been removed by the author.

    ReplyDelete
  8. can anyone write program for this solution....

    ReplyDelete
  9. That's interesting! Can you please share more about it? Thank you.
    click here

    ReplyDelete