0% found this document useful (0 votes)
39 views4 pages

Debremarkos University Institution of Technology Departmentt of Information Technoology

This document describes an assignment to solve the water jug problem using artificial intelligence. It involves two jugs, one that holds 4 gallons and one that holds 3 gallons. The goal is to fill the 4 gallon jug with 2 gallons using only these jugs and no other equipment. It then lists 10 production rules that define the possible actions and provides the specific sequence of 7 rules needed to reach the goal state. Finally, it discusses implementing the solution in Prolog logic programming language.

Uploaded by

adnan mussa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views4 pages

Debremarkos University Institution of Technology Departmentt of Information Technoology

This document describes an assignment to solve the water jug problem using artificial intelligence. It involves two jugs, one that holds 4 gallons and one that holds 3 gallons. The goal is to fill the 4 gallon jug with 2 gallons using only these jugs and no other equipment. It then lists 10 production rules that define the possible actions and provides the specific sequence of 7 rules needed to reach the goal state. Finally, it discusses implementing the solution in Prolog logic programming language.

Uploaded by

adnan mussa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

DEBREMARKOS UNIVERSITY

INSTITUTION OF TECHNOLOGY
DEPARTMENTT OF INFORMATION TECHNOOLOGY

Artificial Intelligence Group Assignment


Water Jug Problem
BY

NAME OF STUDENTS ID NUMBER


1. MUHAMMED MUSSA ------------------------------------------------ TER/1451/10
2. WORKU WORKABEB ------------------------------------------------ TER/1405/10
3. YESHAMU NEGA ------------------------------------------------ TER/1469/10
4. GETASEW GETENET ------------------------------------------------- TER/1383/10
5. WORKU DEREJE ------------------------------------------------- TER/1467/10
6. ZEWDU GETE ------------------------------------------------- TER/1412/10
7. BOKU ADEM ------------------------------------------------- TER/1371/10

Debremarkos, Ethiopia

(Mar 15, 2022)


In the water jug problem in Artificial Intelligence, we are provided with two jugs: one
having the capacity to hold 3 gallons of water and the other has the capacity to hold 4
gallons of water. There is no other measuring equipment available and the jugs also do not
have any kind of marking on them. So, the agent’s task here is to fill the 4-gallon jug with 2
gallons of water by using only these two jugs and no other material. Initially, both our jugs
are empty. So, to solve this problem, following set of rules were proposed:

Production rules for solving the water jug problem

Here, let x denote the 4-gallon jug and y denote the 3-gallon jug.

No Initial Condition Final Description of action taken


. State state
1. (x,y) If x<4 (4,y) Fill the 4 gallon jug completely
2. (x,y) if y<3 (x,3) Fill the 3 gallon jug completely
3. (x,y) If x>0 (x-d,y) Pour some part from the 4 gallon jug
4. (x,y) If y>0 (x,y-d) Pour some part from the 3 gallon jug
5. (x,y) If x>0 (0,y) Empty the 4 gallon jug
6. (x,y) If y>0 (x,0) Empty the 3 gallon jug
7. (x,y) If (x+y)<7 (4, y-[4-x]) Pour some water from the 3 gallon jug to fill the four
gallon jug
8. (x,y) If (x+y)<7 (x-[3-y],y) Pour some water from the 4 gallon jug to fill the 3 gallon
jug.
9. (x,y) If (x+y)<4 (x+y,0) Pour all water from 3 gallon jug to the 4 gallon jug
10. (x,y) if (x+y)<3 (0, x+y) Pour all water from the 4 gallon jug to the 3 gallon jug

The listed production rules contain all the actions that could be performed by the agent in
transferring the contents of jugs. But, to solve the water jug problem in a minimum number
of moves, following set of rules in the given sequence should be performed:

Solution of water jug problem according to the production rules:

S.No. 4 gallon jug contents 3 gallon jug contents Rule followed


1. 0 gallon 0 gallon Initial state
2. 0 gallon 3 gallons Rule no.2
3. 3 gallons 0 gallon Rule no. 9
4. 3 gallons 3 gallons Rule no. 2
5. 4 gallons 2 gallons Rule no. 7
6. 0 gallon 2 gallons Rule no. 5
7. 2 gallons 0 gallon Rule no. 9
On reaching the 7th attempt, we reach a state which is our goal state. Therefore, at this state,
our problem is solved.

Implementation in Prolog

%database
visited_state(integer,integer).
%predicates
state(integer,integer).
%clauses
state(2,0).
state(X,Y):- X < 4,
not(visited_state(4,Y)),
assert(visited_state(X,Y)),
write("Fill the 4-Gallon Jug: (",X,",",Y,") --> (", 4,",",Y,")\n"),
state(4,Y).
state(X,Y):- Y < 3,
not(visited_state(X,3)),
assert(visited_state(X,Y)),
write("Fill the 3-Gallon Jug: (", X,",",Y,") --> (", X,",",3,")\n"),
state(X,3).
state(X,Y):- X > 0,
not(visited_state(0,Y)),
assert(visited_state(X,Y)),
write("Empty the 4-Gallon jug on ground: (", X,",",Y,") --> (",
0,",",Y,")\n"),
state(0,Y).
state(X,Y):- Y > 0,
not(visited_state(X,0)),
assert(visited_state(X,0)),
write("Empty the 3-Gallon jug on ground: (", X,",",Y,") --> (",
X,",",0,")\n"),
state(X,0).
state(X,Y):- X + Y >= 4,
Y > 0,
NEW_Y = Y - (4 - X),
not(visited_state(4,NEW_Y)),
assert(visited_state(X,Y)),
write("Pour water from 3-Gallon jug to 4-gallon until it is full: (",
X,",",Y,") --> (", 4,",",NEW_Y,")\n"),
state(4,NEW_Y).
state(X,Y):- X + Y >=3,
X > 0,
NEW_X = X - (3 - Y),
not(visited_state(X,3)),
assert(visited_state(X,Y)),
write("Pour water from 4-Gallon jug to 3-gallon until it is full: (",
X,",",Y,") --> (", NEW_X,",",3,")\n"),
state(NEW_X,3).
state(X,Y):- X + Y>=4,
Y > 0,
NEW_X = X + Y,
not(visited_state(NEW_X,0)),
assert(visited_state(X,Y)),
write("Pour all the water from 3-Gallon jug to 4-gallon: (", X,",",Y,")
--> (", NEW_X,",",0,")\n"),
state(NEW_X,0).
state(X,Y):- X+Y >=3,
X > 0,
NEW_Y = X + Y,
not(visited_state(0,NEW_Y)),
assert(visited_state(X,Y)),
write("Pour all the water from 4-Gallon jug to 3-gallon: (", X,",",Y,")
--> (", 0,",",NEW_Y,")\n"),
state(0,NEW_Y).
state(0,2):- not(visited_state(2,0)),
assert(visited_state(0,2)),
write("Pour 2 gallons from 3-Gallon jug to 4-gallon: (", 0,",",2,") -->
(", 2,",",0,")\n"),
state(2,0).
state(2,Y):- not(visited_state(0,Y)),
assert(visited_state(2,Y)),
write("Empty 2 gallons from 4-Gallon jug on the ground: (",
2,",",Y,") --> (", 0,",",Y,")\n"),
state(0,Y).
goal:-
makewindow(1,2,3,"4-3 Water Jug Problem",0,0,25,80),
state(0,0).

You might also like