root/trunk/examples/searching/water_jug.lgt

Revision 4601, 0.9 KB (checked in by pmoura, 7 weeks ago)

Added svn:mime-type property to source files (set to text/x-logtalk).

  • Property svn:mime-type set to text/x-logtalk
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1
2:- object(water_jug,
3    instantiates(state_space)).
4
5
6    :- info([
7        version is 1.0,
8        author is 'Paulo Moura',
9        date is 1998/3/23,
10        comment is 'Water jug state space search problem.']).
11
12
13    initial_state(start, (0, 0)).
14
15
16    goal_state(end1, (2, 0)).
17
18    goal_state(end2, (0, 2)).
19
20
21    next_state((X, Y), (4, Y)) :-
22        X < 4.
23
24    next_state((X, Y),(X, 3)) :-
25        Y < 3.
26
27    next_state((X, Y), (4, Z)) :-
28        Y > 0, X < 4,
29        Aux is X + Y, Aux >= 4,
30        Z is Y - (4 - X).
31
32    next_state((X, Y), (Z, 3)) :-
33        X > 0, Y < 3,
34        Aux is X + Y, Aux >= 3,
35        Z is X - (3 - Y).
36
37    next_state((X, Y),(Z, 0)) :-
38        Y > 0,
39        Aux is X + Y, Aux =< 4,
40        Z is Y + X.
41
42    next_state((X, Y),(0, Z)) :-
43        X > 0,
44        Aux is X + Y, Aux =< 3,
45        Z is Y + X.
46
47    next_state((X, Y), (0, Y)) :-
48        X > 0.
49
50    next_state((X, Y), (X, 0)) :-
51        Y > 0.
52
53
54    print_state((X, Y)) :-
55        write('4-gallon jug: '), write(X), nl,
56        write('3-gallon jug: '), write(Y), nl, nl.
57
58
59:- end_object.
Note: See TracBrowser for help on using the browser.