This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
yap-6.3/Logtalk/examples/searching/water_jug.lgt
pmoura 75392e54c7 Logtalk 2.15.0 release files.
git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@757 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
2003-02-05 00:15:28 +00:00

60 lines
917 B
Plaintext

:- object(water_jug,
instantiates(state_space)).
:- info([
version is 1.0,
author is 'Paulo Moura',
date is 1998/3/23,
comment is 'Water jug state space search problem.']).
initial_state(start, (0, 0)).
goal_state(end1, (2, 0)).
goal_state(end2, (0, 2)).
next_state((X, Y), (4, Y)) :-
X < 4.
next_state((X, Y),(X, 3)) :-
Y < 3.
next_state((X, Y), (4, Z)) :-
Y > 0, X < 4,
Aux is X + Y, Aux >= 4,
Z is Y - (4 - X).
next_state((X, Y), (Z, 3)) :-
X > 0, Y < 3,
Aux is X + Y, Aux >= 3,
Z is X - (3 - Y).
next_state((X, Y),(Z, 0)) :-
Y > 0,
Aux is X + Y, Aux =< 4,
Z is Y + X.
next_state((X, Y),(0, Z)) :-
X > 0,
Aux is X + Y, Aux =< 3,
Z is Y + X.
next_state((X, Y), (0, Y)) :-
X > 0.
next_state((X, Y), (X, 0)) :-
Y > 0.
print_state((X, Y)) :-
write('4-gallon jug: '), write(X), nl,
write('3-gallon jug: '), write(Y), nl, nl.
:- end_object.