Question
Implement the Water Jug problem in Python.
Answer :
Word Count : 1447
_________ __________ ______ __________ ___ __________ ___.
_______ ___ ___ _________ ___ _______ _______ __________ ___ _______.
_____ _____ _________ ________ ______.
________ _____ ______ _______ _______ ___ __________ _______.
_______ _____ __________ _________ _______ _________ __________.
_________ ________ ____ _________ ________ ____ _________ ______ ________ _____.
_______ _____ _______ ___ ____ _________ __________ _________ ______ ________ ________ __________.
_____ ______ __________ ____ _________.
_____ _______ _________ ________ ____ ______ __________ _________ ___ ____ __________.
___ _______ ________ ___ ___ __________ _____ __________ ______ ________ _________.
______ _____ ____ _______ _________ ____ ________ ___ ___ ______.
_________ _____ _____ _______ ________ _____ _____ _________ _______ ________ _________ ________.
________ ______ _____ _____ ________ __________ ________ ___ ___ _____.
_____ ________ ______ _________ ____ ______ ________ _____.
_________ ____ ______ ____ __________ ___ __________ _______ _________ ___ __________ ______.
______ ____ _____ ________ ____ _______ ____ _________.
________ __________ ___ ______ _____ _______.
____ ___ ___ _________ ___ _______ ________ ___ ____ ___.
______ ___ __________ __________ _______ __________ _______ _____ ___.
___ ________ ____ __________ ________.
____ ______ _________ ______ ____ _______.
______ _______ ____ ______ _______.
___ _______ ___ __________ _________ __________ ______.
_____ _____ ____ ___ ________ ____ _____ _____ _____ __________ ________ ___.
__________ ___ ______ _____ ___ ___ _________ _______ ________ ___ ____ _______.
_________ _________ _____ ____ ___ ___ _____ ________.
_________ ______ __________ _____ ________ _________ _____ ____ _______ ________ ___.
_____ _____ _____ __________ __________ ___.
_____ __________ _______ _________ ____ _________ _____ ________ _______ ________.
____ ____ ______ _____ ________ _______.
__________ ___ _________ ________ ____ __________ _______.
____ ________ _____ ____ ___ _________ ________ ___ ______ __________ __________.
__________ ______ ___ ____ ____ _____ ____ ____ __________ ________ ___ ___.
___ _____ _________ ____ ____ _______ ___ _________ ____.
___ ______ _____ __________ ______ ________ _______.
_______ __________ ____ __________ ___.
______ _______ ________ ____ _______ _____ ______ _________ ______ ________ ___ _________.
_________ __________ _________ ___ _______ ______ ____.
_______ ___ ________ _____ __________.
________ _________ ______ _________ _________.
________ __________ ______ ________ _________ _______ __________ ___.
_____ ___ __________ _________ __________.
_____ ________ _____ ____ __________ ________ _______ ________ ______ __________ ___ __________.
______ ________ ______ ___ _________ ______ ____ __________ _______.
_________ _______ _____ _______ ______ ________.
_____ ___ __________ _________ ______ ____ _______ ________ ______ _______ ______ ____.
_____ ____ _____ _____ ____ ___ _________ _______ _______.
________ ________ _____ _____ ______ ________.
___ _____ _____ ___ ______.
______ ___ _____ ______ _____ ______ ____ _________ _________.
__________ _____ _____ ____ _________ _______ _________ _________.
_____ ________ ___ ____ ______ _________ _____.
____ ___ _______ ______ __________ _________ _____ _______ _________ _____ __________.
____ ________ ___ _________ _________ ________ _____ ___ _______ _____ _______.
______ ____ _________ ____ __________ _____ ______ __________.
_______ ______ ________ _________ _________ __________ ________ _____.
_______ _____ _______ ___ _________ _____ __________ ________ _____ _________ ________ _________.
___ ____ _________ _____ ________ ___.
__________ _________ ______ __________ _____ _____ ____ _________ ______ _____ ________.
__________ ________ __________ __________ ___ _______ ___ ___.
_______ _____ _________ _______ _____ ________ _______.
__________ ____ _______ ________ _________ _____ ________.
____ ___ __________ ______ ____ __________ _______ ______ __________.
_________ __________ _______ ________ _______ _______ ____ ______.
____ _____ ______ ________ ___.
___ _______ ___ __________ _______ ______ ________ ________ ________ ________ ______ ____.
_____ ___ __________ _____ _________ __________ _______ ____ ________.
________ ___ __________ ____ _______ ________.
______ ____ _________ _____ _______ _________ _______ _______ ____ __________ ______.
________ ________ ___ ______ ________ ______.
______ ____ _________ _________ ___ ______ _____ _________ ____ __________.
______ _____ __________ ______ _________ _________ ______.
____ _________ __________ _______ ________ _____ _______ ____ ________.
______ ____ _________ _______ _________ __________ __________ _____.
___ ______ _______ ___ ______ __________ ______ __________ _________ _______ _______ __________.
___ _________ ________ _________ ____ ______ ________ ___ __________ ______.
________ _____ ___ ____ ____ __________ __________ ____ ______ __________ _____ _____.
_________ ___ _____ _______ ___ _______ _______ ____ _________ _________.
____ _____ _________ ___ _____ __________ ________.
_____ _____ ______ _______ ______ ______ ______.
___ ____ __________ _________ _____ ________ _________.
________ _______ ___ ___ ____ ____ ______ ___ ______ _____ _______.
_____ _________ __________ _______ ____ _____ _____ ___ ___ _____ ____.
________ _______ __________ ____ ____ ______ ________ __________ ___ ________ ____.
_______ _______ _____ ___ ________ ____ __________ _________ ________ _______ ___.
_________ ______ _____ ______ ________ __________ ______ ________ ______ __________.
________ _______ _______ ____ __________ _____ ______ ______ ______ _________ _______.
________ __________ ____ _____ _________ ________ __________.
___ _____ ______ ____ ___.
______ ____ ________ ______ ___ ___ ___.
________ ________ ________ _______ ___ ______ _________ _____ __________.
__________ ___ ___ ____ ___ ___ ________ ________ ____.
__________ _______ ____ _________ ___ ______ ________ ________ _____ _______ ____.
____ _______ ______ _____ _________ _______ _______ _______.
_______ _________ ____ _________ _____ ____ _____ ___ ____ _____ ______ ________.
___ _____ ___ ______ ______ _____ ___ ____ _______ _________ ________.
___ ____ _______ ______ ____.
_____ ______ _________ ________ __________ _____ ______ _________ ___ __________ __________.
_________ ____ ____ _________ ____ ______ _______ ___ ______.
__________ __________ ____ _________ _____ ___ ___ _______ _________ _____ ____ _________.
_________ __________ ____ _________ ____ ____ ____.
______ _____ ______ _______ ___ ___ ______.
_________ ___ __________ _________ _________ _____ _____ __________ _____ _______ ______ ___.
__________ ______ __________ __________ ___ ____ ____.
____ ____ ____ ___ ________ ______ ____.
______ __________ ________ ____ __________ _______ _________ _______ _________ ______.
_________ __________ ___ ____ _________ ___ ___ _______ _____ _____ ____ _______.
___ _________ ___ ______ _____ _________ _________ ______ _____.
_______ _____ ____ _______ _________ _______ __________ ______ ________ ________.
________ ____ ______ ______ ________.
______ _________ ______ ____ _____ __________ __________.
___ ______ ______ ____ ________ _________ ______ ____.
_______ ____ ________ _________ _______ _____ ___.
______ ____ ______ _____ __________ ___ __________ __________ ______ _____ __________ _____.
________ ____ ___ ________ ________.
________ ____ __________ ________ ________ ____ __________ _________ ____ __________ ______.
______ ___ _____ __________ ____ _________ __________ ___ ________ _____ _________ ________.
____ _________ ______ ________ ________ ___ __________ ____ _______ _______ ________ ______.
_________ ______ _______ __________ __________ _________ _______ _______ _______.
____ ______ _________ ________ ____ _____.
______ _____ _______ ________ __________ _______ _____ _______ _________ ___ _________ _________.
___ ___ _________ ________ ______ ______ ____ _______ _________ __________.
_________ _________ ______ ___ _________ __________ __________ ________ ____.
_____ ___ ______ _______ _________ _____.
__________ ___ ___ _________ _____ ____ _______ _________.
_____ __________ _________ _________ _____.
________ ___ __________ __________ ___ _________ ________.
_______ ____ ________ _______ __________.
_________ ______ ____ __________ _______ ____ ____ ___ ___.
______ ________ __________ _________ _____ ______ __________ ___.
Skip in 10
The Water Jug Problem is a classical problem-solving problem in Artificial Intelligence that demonstrates how a computer can find a sequence of actions to reach a desired state from an initial state. The problem consists of two jugs with known capacities and no measurement markings. The objective is to obtain a specified quantity of water by filling, emptying, and transferring water between the jugs. In a Programming and AI Lab, this problem is useful for understanding state-space representation, search algorithms, problem formulation, and implementation using Python. Consider two jugs, one having a capacity of 4 litres and another having a capacity of 3 litres. Initially, both jugs are empty. The objective is to measure exactly 2 litres of water. A state can be represented as a pair `(x, y)`, where `x` represents the amount of water in the 4-litre jug and `y` represents the amount of water in the 3-litre jug. Therefore, the initial state is `(0, 0)`. The goal is any state in which either jug contains exactly 2 litres, such as `(2, 0)`, `(2, 3)`, `(4, 2)`, or `(0, 2)`. The possible operations in the Water Jug Problem are filling either jug completely, emptying either jug completely, pouring water from one jug into the other until the source jug becomes empty or the destination jug becomes full. Each operation generates a new state. These states can be explored systematically using a search technique. A Breadth-First Search (BFS) approach is suitable because it explores states level by level and can find the shortest sequence of operations when every operation has equal cost. The following Python program implements the Water Jug Problem using BFS: ```python from collections import deque def water_jug_problem(capacity_a, capacity_b, target): initial_state = (0, 0) queue = deque() queue.append(initial_state) visited = set() visited.add(initial_state) parent = {} action = {} while queue: current = queue.popleft() a, b = current if a == target or b == target:
_______ _______ _________ ________ _____._________ __________ ______ __________ ___ __________ ___.
_______ ___ ___ _________ ___ _______ _______ __________ ___ _______.
_____ _____ _________ ________ ______.
________ _____ ______ _______ _______ ___ __________ _______.
_______ _____ __________ _________ _______ _________ __________.
_________ ________ ____ _________ ________ ____ _________ ______ ________ _____.
_______ _____ _______ ___ ____ _________ __________ _________ ______ ________ ________ __________.
_____ ______ __________ ____ _________.
_____ _______ _________ ________ ____ ______ __________ _________ ___ ____ __________.
___ _______ ________ ___ ___ __________ _____ __________ ______ ________ _________.
______ _____ ____ _______ _________ ____ ________ ___ ___ ______.
_________ _____ _____ _______ ________ _____ _____ _________ _______ ________ _________ ________.
________ ______ _____ _____ ________ __________ ________ ___ ___ _____.
_____ ________ ______ _________ ____ ______ ________ _____.
_________ ____ ______ ____ __________ ___ __________ _______ _________ ___ __________ ______.
______ ____ _____ ________ ____ _______ ____ _________.
________ __________ ___ ______ _____ _______.
____ ___ ___ _________ ___ _______ ________ ___ ____ ___.
______ ___ __________ __________ _______ __________ _______ _____ ___.
___ ________ ____ __________ ________.
____ ______ _________ ______ ____ _______.
______ _______ ____ ______ _______.
___ _______ ___ __________ _________ __________ ______.
_____ _____ ____ ___ ________ ____ _____ _____ _____ __________ ________ ___.
__________ ___ ______ _____ ___ ___ _________ _______ ________ ___ ____ _______.
_________ _________ _____ ____ ___ ___ _____ ________.
_________ ______ __________ _____ ________ _________ _____ ____ _______ ________ ___.
_____ _____ _____ __________ __________ ___.
_____ __________ _______ _________ ____ _________ _____ ________ _______ ________.
____ ____ ______ _____ ________ _______.
__________ ___ _________ ________ ____ __________ _______.
____ ________ _____ ____ ___ _________ ________ ___ ______ __________ __________.
__________ ______ ___ ____ ____ _____ ____ ____ __________ ________ ___ ___.
___ _____ _________ ____ ____ _______ ___ _________ ____.
___ ______ _____ __________ ______ ________ _______.
_______ __________ ____ __________ ___.
______ _______ ________ ____ _______ _____ ______ _________ ______ ________ ___ _________.
_________ __________ _________ ___ _______ ______ ____.
_______ ___ ________ _____ __________.
________ _________ ______ _________ _________.
________ __________ ______ ________ _________ _______ __________ ___.
_____ ___ __________ _________ __________.
_____ ________ _____ ____ __________ ________ _______ ________ ______ __________ ___ __________.
______ ________ ______ ___ _________ ______ ____ __________ _______.
_________ _______ _____ _______ ______ ________.
_____ ___ __________ _________ ______ ____ _______ ________ ______ _______ ______ ____.
_____ ____ _____ _____ ____ ___ _________ _______ _______.
________ ________ _____ _____ ______ ________.
___ _____ _____ ___ ______.
______ ___ _____ ______ _____ ______ ____ _________ _________.
__________ _____ _____ ____ _________ _______ _________ _________.
_____ ________ ___ ____ ______ _________ _____.
____ ___ _______ ______ __________ _________ _____ _______ _________ _____ __________.
____ ________ ___ _________ _________ ________ _____ ___ _______ _____ _______.
______ ____ _________ ____ __________ _____ ______ __________.
_______ ______ ________ _________ _________ __________ ________ _____.
_______ _____ _______ ___ _________ _____ __________ ________ _____ _________ ________ _________.
___ ____ _________ _____ ________ ___.
__________ _________ ______ __________ _____ _____ ____ _________ ______ _____ ________.
__________ ________ __________ __________ ___ _______ ___ ___.
_______ _____ _________ _______ _____ ________ _______.
__________ ____ _______ ________ _________ _____ ________.
____ ___ __________ ______ ____ __________ _______ ______ __________.
_________ __________ _______ ________ _______ _______ ____ ______.
____ _____ ______ ________ ___.
___ _______ ___ __________ _______ ______ ________ ________ ________ ________ ______ ____.
_____ ___ __________ _____ _________ __________ _______ ____ ________.
________ ___ __________ ____ _______ ________.
______ ____ _________ _____ _______ _________ _______ _______ ____ __________ ______.
________ ________ ___ ______ ________ ______.
______ ____ _________ _________ ___ ______ _____ _________ ____ __________.
______ _____ __________ ______ _________ _________ ______.
____ _________ __________ _______ ________ _____ _______ ____ ________.
______ ____ _________ _______ _________ __________ __________ _____.
___ ______ _______ ___ ______ __________ ______ __________ _________ _______ _______ __________.
___ _________ ________ _________ ____ ______ ________ ___ __________ ______.
________ _____ ___ ____ ____ __________ __________ ____ ______ __________ _____ _____.
_________ ___ _____ _______ ___ _______ _______ ____ _________ _________.
____ _____ _________ ___ _____ __________ ________.
_____ _____ ______ _______ ______ ______ ______.
___ ____ __________ _________ _____ ________ _________.
________ _______ ___ ___ ____ ____ ______ ___ ______ _____ _______.
_____ _________ __________ _______ ____ _____ _____ ___ ___ _____ ____.
________ _______ __________ ____ ____ ______ ________ __________ ___ ________ ____.
_______ _______ _____ ___ ________ ____ __________ _________ ________ _______ ___.
_________ ______ _____ ______ ________ __________ ______ ________ ______ __________.
________ _______ _______ ____ __________ _____ ______ ______ ______ _________ _______.
________ __________ ____ _____ _________ ________ __________.
___ _____ ______ ____ ___.
______ ____ ________ ______ ___ ___ ___.
________ ________ ________ _______ ___ ______ _________ _____ __________.
__________ ___ ___ ____ ___ ___ ________ ________ ____.
__________ _______ ____ _________ ___ ______ ________ ________ _____ _______ ____.
____ _______ ______ _____ _________ _______ _______ _______.
_______ _________ ____ _________ _____ ____ _____ ___ ____ _____ ______ ________.
___ _____ ___ ______ ______ _____ ___ ____ _______ _________ ________.
___ ____ _______ ______ ____.
_____ ______ _________ ________ __________ _____ ______ _________ ___ __________ __________.
_________ ____ ____ _________ ____ ______ _______ ___ ______.
__________ __________ ____ _________ _____ ___ ___ _______ _________ _____ ____ _________.
_________ __________ ____ _________ ____ ____ ____.
______ _____ ______ _______ ___ ___ ______.
_________ ___ __________ _________ _________ _____ _____ __________ _____ _______ ______ ___.
__________ ______ __________ __________ ___ ____ ____.
____ ____ ____ ___ ________ ______ ____.
______ __________ ________ ____ __________ _______ _________ _______ _________ ______.
_________ __________ ___ ____ _________ ___ ___ _______ _____ _____ ____ _______.
___ _________ ___ ______ _____ _________ _________ ______ _____.
_______ _____ ____ _______ _________ _______ __________ ______ ________ ________.
________ ____ ______ ______ ________.
______ _________ ______ ____ _____ __________ __________.
___ ______ ______ ____ ________ _________ ______ ____.
_______ ____ ________ _________ _______ _____ ___.
______ ____ ______ _____ __________ ___ __________ __________ ______ _____ __________ _____.
________ ____ ___ ________ ________.
________ ____ __________ ________ ________ ____ __________ _________ ____ __________ ______.
______ ___ _____ __________ ____ _________ __________ ___ ________ _____ _________ ________.
____ _________ ______ ________ ________ ___ __________ ____ _______ _______ ________ ______.
_________ ______ _______ __________ __________ _________ _______ _______ _______.
____ ______ _________ ________ ____ _____.
______ _____ _______ ________ __________ _______ _____ _______ _________ ___ _________ _________.
___ ___ _________ ________ ______ ______ ____ _______ _________ __________.
_________ _________ ______ ___ _________ __________ __________ ________ ____.
_____ ___ ______ _______ _________ _____.
__________ ___ ___ _________ _____ ____ _______ _________.
_____ __________ _________ _________ _____.
________ ___ __________ __________ ___ _________ ________.
_______ ____ ________ _______ __________.
_________ ______ ____ __________ _______ ____ ____ ___ ___.
______ ________ __________ _________ _____ ______ __________ ___.
IGNOU ACADEMY
Your IGNOU journey, made easier.
- Solved Assignments
- Study Notes
- Guess Papers
- Question Papers
Continue Reading — It's Free
Sign in with Google to unlock more of this answer.
✓ Free access
✓ Unlock up to 60% of the answer
✓ No payment required
✓ Unlock up to 60% of the answer
✓ No payment required
Quick Google sign-in. No separate registration form.