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.

Program Name

AI Engineer

Post Graduate Program In Artificial Intelligence

Post Graduate Program In Artificial Intelligence

Program Available InAll GeosAll GeosIN/ROW
UniversitySimplilearnPurdueCaltech
Course Duration11 Months11 Months11 Months
Coding Experience RequiredBasicBasicNo
Skills You Will Learn10+ 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.
Additional BenefitsGet access to exclusive Hackathons, Masterclasses and Ask-Me-Anything sessions by IBM
Applied learning via 3 Capstone and 12 Industry-relevant Projects
Purdue Alumni Association Membership Free IIMJobs Pro-Membership of 6 months Resume Building AssistanceUpto 14 CEU Credits Caltech CTME Circle Membership
Cost$$$$$$$$$$
Explore ProgramExplore ProgramExplore 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 & ML 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
Post Graduate Program in AI and Machine Learning

Cohort Starts: 24 Oct, 2024

11 months$ 4,300
Applied AI & Data Science

Cohort Starts: 29 Oct, 2024

14 weeks$ 2,624
Applied Generative AI Specialization

Cohort Starts: 29 Oct, 2024

16 weeks$ 2,995
Generative AI for Business Transformation

Cohort Starts: 31 Oct, 2024

16 weeks$ 2,499
AI & Machine Learning Bootcamp

Cohort Starts: 4 Nov, 2024

24 weeks$ 8,000
No Code AI and Machine Learning Specialization

Cohort Starts: 12 Nov, 2024

16 weeks$ 2,565
Artificial Intelligence Engineer11 Months$ 1,449

Get Free Certifications with free video courses

  • Machine Learning using Python

    AI & Machine Learning

    Machine Learning using Python

    7 hours4.5159.5K learners
  • Artificial Intelligence Beginners Guide: What is AI?

    AI & Machine Learning

    Artificial Intelligence Beginners Guide: What is AI?

    1 hours4.513.5K learners
prevNext

Learn from Industry Experts with free Masterclasses

  • How to Succeed as an AI/ML Engineer in 2024: Tools, Techniques, and Trends

    AI & Machine Learning

    How to Succeed as an AI/ML Engineer in 2024: Tools, Techniques, and Trends

    24th Oct, Thursday9:00 PM IST
  • Why Generative AI Skills Are Essential for Business Leaders in 2024

    AI & Machine Learning

    Why Generative AI Skills Are Essential for Business Leaders in 2024

    9th Oct, Wednesday9:00 PM IST
  • Fast-Track Your Gen AI & ML Career to Success in 2024 with IIT Kanpur

    AI & Machine Learning

    Fast-Track Your Gen AI & ML Career to Success in 2024 with IIT Kanpur

    25th Sep, Wednesday7:00 PM IST
prevNext