From plqueiroz@hotmail.com  Sat Apr 15 17:45:23 2000
Received: from hotmail.com (f113.law8.hotmail.com [216.33.241.113])
	by swi.psy.uva.nl (8.9.3/8.9.3) with SMTP id RAA19206
	for <prolog@swi.psy.uva.nl>; Sat, 15 Apr 2000 17:45:22 +0200 (MET DST)
Received: (qmail 20190 invoked by uid 0); 15 Apr 2000 15:45:19 -0000
Message-ID: <20000415154519.20189.qmail@hotmail.com>
Received: from 161.24.1.173 by www.hotmail.com with HTTP;
	Sat, 15 Apr 2000 08:45:19 PDT
X-Originating-IP: [161.24.1.173]
From: "Albert Fox" <plqueiroz@hotmail.com>
To: jan@swi.psy.uva.nl, jhinds@mtsu.edu, prolog@swi.psy.uva.nl
Subject: question
Date: Sat, 15 Apr 2000 15:45:19 GMT
Mime-Version: 1.0
Content-Type: text/plain; format=flowed


How is the query for this program work ??

/* Problem Solving :- Water Jugs Problem */


	initial_state(jugs,jugs(0,0)).

     final_state(jugs(4,0)).
     final_state(jugs(0,4)).

     move(jugs(V1,V2),fill(1)).
     move(jugs(V1,V2),fill(2)).
     move(jugs(V1,V2),empty(1)).
     move(jugs(V1,V2),empty(2)).
     move(jugs(V1,V2),transfer(2,1)).
     move(jugs(V1,V2),transfer(1,2)).

     update(jugs(V1,V2),fill(1),jugs(C1,V2)) :- capacity(1,C1).
     update(jugs(V1,V2),fill(2),jugs(V1,C2)) :- capacity(2,C2).
     update(jugs(V1,V2),empty(1),jugs(0,V2)).
     update(jugs(V1,V2),empty(2),jugs(V1,0)).
     update(jugs(V1,V2),transfer(2,1),jugs(W1,W2)) :-
	capacity(1,C1),
	Liquid is V1 + V2,
	Excess is Liquid - C1,
	adjust(Liquid,Excess,W1,W2).
     update(jugs(V1,V2),transfer(1,2),jugs(W1,W2)) :-
	capacity(2,C2),
        Liquid is V1 + V2,
        Excess is Liquid - C2,
        adjust(Liquid,Excess,W2,W1).

     adjust(Liquid, Excess,Liquid,0) :- Excess =< 0.
     adjust(Liquid,Excess,V,Excess) :- Excess > 0, V is Liquid - Excess.

     legal(jugs(V1,V2)).

     capacity(1,8).
     capacity(2,5).

%  Program 20.3    Solving the water jugs problem

______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com

