75392e54c7
git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@757 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
60 lines
917 B
Plaintext
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.
|