Water Jug Problem
Water Jug Problem
1. Fill a jug
2. Empty a jug
3. (x, y) if x>0 -> (x-d, d) Pour some water from a 4-litre jug
4. (x, y) if Y>0 -> (d, y-d) Pour some water from a 3-litre jug
12. (2, Y) -> (0, y) Empty 2-litre in the 4-litre jug on the ground.
Algorithm to Solve Water Jug Problem
using BFS
• Start with the initial state where both jugs are empty.
• Create a queue. Next, add the initial state to it.
• While the queue is not empty, opt for the following:
– Pop the front state from the queue.
– Apply all possible production rules to generate new states.
– Check if any of these new states match the goal state.
– If a goal state is found, the problem is solved.
– If not, add the new states to the queue for further
exploration.
• BFS ensures that you find the shortest path to the goal
state, which is efficient for solving the Water Jug
Problem.
Mirror to Practical Scenarios
• Resource Management: In practical situations, it often relates to
resource management. The water in the jugs can represent resources,
such as time, money, or materials. The goal is to manage these
resources to meet specific needs or objectives efficiently. For example,
in project management, you may need to allocate time and budget
effectively to achieve project goals.