/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. % (C) 2011 Pierre Andrews
  16. rocket(rocket1).
  17. place(london).
  18. place(paris).
  19. cargo(a).
  20. cargo(b).
  21. cargo(c).
  22. cargo(d).
  23. %move(Rocket, From, To).
  24. can(move(Rocket,From,To),[at(Rocket,From), has_fuel(Rocket)], rocket) :- %vehicle move only within city
  25. rocket(Rocket),
  26. place(From),
  27. place(To),
  28. From \= To.
  29. adds(move(Rocket,_From,To),[at(Rocket, To)], at(Rocket,To), rocket):-
  30. rocket(Rocket),
  31. place(To).
  32. deletes(move(Rocket,From,_To),[at(Rocket,From), has_fuel(Rocket)], rocket):-
  33. rocket(Rocket),
  34. place(From).
  35. %unload(Rocket, Place, Cargo).
  36. can(unload(Rocket, Place, Cargo),[at(Rocket,Place),in(Cargo,Rocket)], rocket) :-
  37. rocket(Rocket),
  38. cargo(Cargo),
  39. place(Place).
  40. adds(unload(Rocket, Place, Cargo),[at(Cargo,Place)], _, rocket) :-
  41. rocket(Rocket),
  42. cargo(Cargo),
  43. place(Place).
  44. deletes(unload(Rocket, _Place, Cargo),[in(Cargo,Rocket)], rocket) :-
  45. rocket(Rocket),
  46. cargo(Cargo).
  47. %load(Rocket, Place, Cargo).
  48. can(load(Rocket, Place, Cargo),[at(Rocket,Place),at(Cargo,Place)], rocket) :-
  49. rocket(Rocket),
  50. cargo(Cargo),
  51. place(Place).
  52. adds(load(Rocket, _Place, Cargo),[in(Cargo,Rocket)], _, rocket) :-
  53. rocket(Rocket),
  54. cargo(Cargo).
  55. deletes(load(Rocket, Place, Cargo),[at(Cargo,Place)], rocket) :-
  56. rocket(Rocket),
  57. cargo(Cargo),
  58. place(Place).
  59. test(P) :-
  60. plan([at(a, london), at(rocket1, london), has_fuel(rocket1)],
  61. [at(a, paris)], rocket,
  62. P).
  63. test2(P) :-
  64. plan([at(a, london), at(b,london), at(rocket1, london), has_fuel(rocket1)],
  65. [at(a, paris), at(b,paris)], rocket,
  66. P).
  67. test3(P) :-
  68. plan([at(a, london), at(b,london), at(c,london), at(rocket1, london), has_fuel(rocket1)],
  69. [at(a, paris), at(b,paris), at(c,paris)], rocket,
  70. P).