The water Jug Problem, as the name suggests, is a problem where two jugs of water are given, say one is a 4-litre one, and the other one is a 3-litre one, but none of the measuring markers is mentioned on any of it. There is a pump available to fill the jugs with water. How can you exactly pour 2 litres of water into a 4-litre jug? Assuming that both the jugs are empty, the task is to find a solution to pour 2-litre water into a 4-litre jug.Â

## Production Rules for the Water Jug Problem in Artificial Intelligence

To solve the water jug problem, many algorithms can be used. These include:Â

• Breadth-First Search: BFS or Breadth First Search visits the nodes in order of their distance from the starting node. This implies that it will visit the nearest node first.Â
• Depth First Search: DFS or Depth First Search visits the nodes in order of their depth.Â

In production rules for the water jug problem, let x denote a 4-litre jug, and y denote a 3-litre jug, i.e. x=0,1,2,3,4 or y=0,1,2,3

Start state (0,0)

Goal state (2,n) from any n

Start from the start state and end up at the goal state. Production rules for the water jug problem in AI are as follows:Â

 1. (x,y) is X<4 -> (4, Y)Â Fill the 4-litre jug 2. (x, y) if Y<3 -> (x, 3) Fill the 3-litre 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 5.Â (x, y) if x>0 -> (0, y) Empty 4-litre jug on the ground 6. (x, y) if y>0 -> (x,0) Empty 3-litre jug on the ground 7. (x, y) if X+Y >= 4 and y>0 -> (4, y-(4-x Pour water from a 3-litre jug into a 4-litre jug until it is full 8. (x, y) if X+Y>=3 and x>0 -> (x-(3-y), 3)) Pour water from a 3-litre jug into a 4-litre jug until it is full 9. (x, y) if X+Y <=4 and y>0 -> (x+y, 0 Pour all the water from a 3-litre jug into a 4-litre jug 10. (x, y) if X+Y<=3 and x>0 -> (0, x+ Pour all the water from a 4-litre jug into a 3-litre jug 11. (0, 2) -> (2, 0) Pour 2-litre water from 3-litre jug into 4-litre jug 12. (2, Y) -> (0, y) Empty 2-litre in the 4-litre jug on the ground.

## The Solution to the Water Jug Problem in Artificial Intelligence

Here is the water jug problem solution in AI is as follows:Â

Current state (0,0)

Loop till the goal state (2,0) is reached.Â

• Apply a rule when the left side matches the current state
• Set the new current state to the resulting stateÂ

Start state (0,0)

(0,3) Apply Rule 2, Fill the 3-litre Jug

(3,0) Apply Rule 9: Pour all the water from a 3-litre jug into a 4-litre jug

(3,3) Apply Rule 2, Fill the 3-litre Jug

(4,2) Apply Rule 7: Pour water from a 3-litre jug into a 4-litre jug until it is full

(0,2) Apply Rule 5, Empty 4-litre jug on the ground

(2,0) Apply Rule 9: Pour all the water from a 3-litre jug into a 4-litre jug

Another water jug problem solution is:Â

(0, 0) â€“ Start State

(4, 0) â€“ Rule 1: Fill the 4-litre jug

(1, 3) â€“ Rule 8: Pour water from the 4-litre jug into the 3-litre jug until the 3-litre jug is full.

(1, 0) â€“ Rule 6: Empty the 3-litre jug on the ground

(0, 1) â€“ Rule 10: Pour all the water from the 4-litre jug into the 3-litre jug.

(4, 1) â€“Â  Rule 1: Fill the 4-litre jug

.(2, 3) â€“ Rule 8: Pour water from the 4-litre jug into the 3-litre jug until the 3-litre jug is full.

Goal State reached

## Choose the Right Program

Unlock the potential of AI and ML with Simplilearn's comprehensive programs. Choose the right AI/ML program to master cutting-edge technologies and propel your career forward.

#### Post Graduate Program In Artificial Intelligence

Program Available In All Geos All Geos IN/ROW
University Simplilearn Purdue Caltech
Course Duration 11 Months 11 Months 11 Months
Coding Experience Required Basic Basic No
Skills You Will Learn 10+ skills including data structure, data manipulation, NumPy, Scikit-Learn, Tableau and more. 16+ skills including
chatbots, NLP, Python, Keras and more.
8+ skills including
Supervised & Unsupervised Learning
Deep Learning
Data Visualization, and more.
Applied learning via 3 Capstone and 12 Industry-relevant Projects
Purdue Alumni Association Membership Free IIMJobs Pro-Membership of 6 months Resume Building Assistance Upto 14 CEU Credits Caltech CTME Circle Membership
Cost \$\$ \$\$\$\$ \$\$\$\$
Explore Program Explore Program Explore Program

## ConclusionÂ

The water jug problem in AI is an important strategy for solving difficult problems efficiently in search algorithms. It shows the importance of expressing the problem in equations to select appropriate algorithms for achieving solutions. By using methods like BFS or DFS, the problem can be solved.Â

As AI is taking over the entire digital world, learning AI skills can be very helpful in the future. Enrol in our Postgraduate Program inÂ  AI and Machine Learning. Â Learn in-demand skills such as machine learning, deep learning, NLP, computer vision, reinforcement learning, generative AI, prompt engineering, ChatGPT, and many more.

## FAQs

### 1. What is a water jug problem in AI?

The water jug problem in AI is a complex problem where it is important to find a way to measure the amount of water using two jugs of different capacities.Â

### 2. How do you solve the water jug problem in AI?

To solve the water jug problem in AI, Breadth First Search is the best water jug problem solution.

### 3. Which algorithm is used for water jug problems?Â

Algorithms like Breadth-First Search, Depth-First Search, Heuristic Search, and Stace-Space Representation can be used to solve the water jug problem.

## Our AI & Machine Learning Courses Duration And Fees

AI & Machine Learning Courses typically range from a few weeks to several months, with fees varying based on program and institution.

Program NameDurationFees
Applied Generative AI Specialization

Cohort Starts: 30 Jul, 2024

4 months\$ 2,995
No Code AI and Machine Learning Specialization

Cohort Starts: 7 Aug, 2024

4 months\$ 2,565
Post Graduate Program in AI and Machine Learning

Cohort Starts: 8 Aug, 2024

11 Months\$ 4,300
Generative AI for Business Transformation

Cohort Starts: 18 Aug, 2024

4 months\$ 2,995
AI & Machine Learning Bootcamp

Cohort Starts: 26 Aug, 2024

6 Months\$ 10,000
Artificial Intelligence Engineer11 Months\$ 1,449

### Get Free Certifications with free video courses

• #### AI & Machine Learning

Machine Learning using Python

7 hours4.5148K learners
• #### AI & Machine Learning

Artificial Intelligence Beginners Guide: What is AI?

1 hours4.510.5K learners
prevNext

### Learn from Industry Experts with free Masterclasses

• #### AI & Machine Learning

Navigating the GenAI Frontier

16th Jul, Tuesday9:00 PM IST
• #### AI & Machine Learning

Prompt Engineering Unlocked: Uncover the Secrets to Effective AI Conversations

8th Jul, Monday9:00 PM IST
• #### AI & Machine Learning

The Future of Work with ChatGPT: Applications for Every Professional

28th Jun, Friday9:00 PM IST
prevNext