File: water_jug.lgt

package info (click to toggle)
yap 5.1.1-3
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 16,124 kB
  • ctags: 14,650
  • sloc: ansic: 122,796; perl: 22,545; sh: 3,768; java: 1,277; makefile: 1,191; xml: 739; tcl: 624; lisp: 142; awk: 9
file content (59 lines) | stat: -rw-r--r-- 917 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59

:- 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.