PageRenderTime 51ms CodeModel.GetById 2ms app.highlight 46ms RepoModel.GetById 1ms app.codeStats 0ms

/examples/rocket_graph.pl

http://github.com/Mortimerp9/Prolog-Graphplan
Perl | 86 lines | 70 code | 16 blank | 0 comment | 1 complexity | f2bbe879df69947356ad3708b11c631e MD5 | raw file
 1%    This file is part of the Prolog Graplan project.
 2%
 3%    The Prolog Graplan project is free software: you can redistribute it and/or modify
 4%    it under the terms of the GNU General Public License as published by
 5%    the Free Software Foundation, either version 3 of the License, or
 6%    (at your option) any later version.
 7%
 8%    The Prolog Graplan project is distributed in the hope that it will be useful,
 9%    but WITHOUT ANY WARRANTY; without even the implied warranty of
10%    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11%    GNU General Public License for more details.
12%
13%    You should have received a copy of the GNU General Public License
14%    along with the Prolog Graplan project.  If not, see <http://www.gnu.org/licenses/>.
15
16% (C) 2011 Pierre Andrews 
17
18rocket(rocket1).
19place(london).
20place(paris).
21cargo(a).
22cargo(b).
23cargo(c).
24cargo(d).
25
26%move(Rocket, From, To).
27can(move(Rocket,From,To),[at(Rocket,From), has_fuel(Rocket)], rocket) :- %vehicle move only within city
28	rocket(Rocket),
29	place(From),
30	place(To),
31	From \= To.
32
33adds(move(Rocket,_From,To),[at(Rocket, To)], at(Rocket,To), rocket):-
34	rocket(Rocket),
35	place(To).
36
37deletes(move(Rocket,From,_To),[at(Rocket,From), has_fuel(Rocket)], rocket):-
38	rocket(Rocket),
39	place(From).
40
41
42%unload(Rocket, Place, Cargo).
43can(unload(Rocket, Place, Cargo),[at(Rocket,Place),in(Cargo,Rocket)], rocket) :-
44	rocket(Rocket),
45	cargo(Cargo),
46	place(Place).
47
48adds(unload(Rocket, Place, Cargo),[at(Cargo,Place)], _, rocket) :-
49	rocket(Rocket),
50	cargo(Cargo),
51	place(Place).
52
53deletes(unload(Rocket, _Place, Cargo),[in(Cargo,Rocket)], rocket) :-
54	rocket(Rocket),
55	cargo(Cargo).
56
57
58
59%load(Rocket, Place, Cargo).
60can(load(Rocket, Place, Cargo),[at(Rocket,Place),at(Cargo,Place)], rocket) :-
61	rocket(Rocket),
62	cargo(Cargo),
63	place(Place).
64
65adds(load(Rocket, _Place, Cargo),[in(Cargo,Rocket)], _, rocket) :-
66	rocket(Rocket),
67	cargo(Cargo).
68
69deletes(load(Rocket, Place, Cargo),[at(Cargo,Place)], rocket) :-
70	rocket(Rocket),
71	cargo(Cargo),
72	place(Place).
73
74
75test(P) :-
76	plan([at(a, london), at(rocket1, london), has_fuel(rocket1)],
77	     [at(a, paris)], rocket,
78	     P).
79test2(P) :-
80	plan([at(a, london), at(b,london), at(rocket1, london), has_fuel(rocket1)],
81	     [at(a, paris), at(b,paris)], rocket,
82	     P).
83test3(P) :-
84	plan([at(a, london), at(b,london), at(c,london), at(rocket1, london), has_fuel(rocket1)],
85	     [at(a, paris), at(b,paris), at(c,paris)], rocket,
86	     P).