Share Pastebin
Guest
Public paste!

Untitled

By: a guest | Mar 22nd, 2010 | Syntax: Prolog | Size: 2.07 KB | Hits: 60 | Expires: Never
Copy text to clipboard
  1. :- multifile  at/3, visited/2, money/2.
  2.  
  3.  
  4.  
  5. % --- Primitive control actions ---------------------------------------
  6. % this section defines the name and the number of parameters of the
  7. % actions available to the planner
  8. %
  9. % primitive_action( dosomething(_,_) ). % underscore means 'anything'
  10.  
  11.  
  12. primitive_action( fly(_,_) ).
  13. primitive_action( drive(_,_,_) ).
  14. primitive_action( bus(_,_) ).
  15. primitive_action( visit(_) ).
  16.  
  17. % --- Precondition for primitive actions ------------------------------
  18. % describe when an action can be carried out, in a generic situation S
  19. %
  20. % poss( doSomething(...), S ) :- preconditions(..., S).
  21.  
  22. poss( fly(From, To), S ) :-
  23.   at(agent,From, S),
  24.   flight(From, To),
  25.   money(X, S), X >= 10.
  26.  
  27. poss( bus(From, To), S ) :-
  28.   at(agent,From, S),
  29.   road(From, To),
  30.   money(X,S), X >= 5.
  31.  
  32. poss( drive(What, From, To), S ) :-
  33.   at(agent, From, S),
  34.   What = car,
  35.   at(What,From, S),
  36.   road(From, To),
  37.   money(X, S), X >= 1.
  38.  
  39.  
  40.  
  41. poss(visit(City), S ) :-
  42.   at(agent,City, S),
  43.   not((visited(City, S) )).
  44.  
  45.  
  46.  
  47.  
  48.  
  49. % --- Successor state axioms ------------------------------------------
  50. % describe the value of fluent based on the previous situation and the
  51. % action chosen for the plan.
  52.  
  53. % fluent(..., result(A,S)) :- positive; previous-state, not(negative)
  54.  
  55. at(agent,Where, result(A, S)) :-
  56.   (A = fly(_, Where); A = drive(_, _, Where);A = bus(_, Where) );
  57.   at(agent,Where, S) , not(( A = fly(Where, _) ; A = drive(_, Where, _) ; A = bus(Where, _)  )).
  58.  
  59. at(car,Where, result(A, S)) :-
  60.     (A = drive(car, _, Where));
  61.   at(car, Where, S) , not(( A = drive(car, Where, _) )).
  62.  
  63.  
  64. visited(Place, result(A,S)) :-
  65.    A = visit(Place);
  66.    visited(Place, S), not(A=visit(Place)).
  67.  
  68.  
  69.  
  70. money(X, result(A, S)) :-
  71.   A = fly(_,_), money(N,S), X is N -10;
  72.   A = drive(_,_,_), money(N,S), X is N -1;
  73.   A = bus(_,_), money(N,S), X is N -5 ;
  74.   money(X,S),
  75.   not((A =fly(_,_) ; A =drive(_,_,_) ; A =bus(_,_)))  .
  76.  
  77.  
  78.  
  79. % ---------------------------------------------------------------------
  80. % ---------------------------------------------------------------------