Guest
Public paste!

Untitled

By: a guest | Mar 22nd, 2010 | Syntax: Prolog | Size: 2.48 KB | Hits: 61 | Expires: Never
Copy text to clipboard
  1.  
  2. :- multifile at/3, at_car/3, visited/2, money/2, rented/2, returned/3.
  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. primitive_action( drive(_,_,_) ).
  12. primitive_action( fly(_,_)     ).
  13. primitive_action( visit(_)     ).
  14. primitive_action( rent(_,_)    ).
  15. primitive_action( return(_,_)  ).
  16.  
  17.  
  18. % --- Precondition for primitive actions ------------------------------
  19. % describe when an action can be carried out, in a generic situation S
  20. %
  21. % poss( doSomething(...), S ) :- preconditions(..., S).
  22.  
  23. poss(drive(Car,From,To), S) :-
  24. at(agent,From,S),
  25. at_car(Car,From,S),
  26. rented(Car,S),
  27. road(From,To),
  28. money(X, S), X >= 1.
  29.  
  30.  
  31. poss( fly(From, To), S ) :-
  32.   at(agent,From, S),
  33.   flight(From, To),
  34.   money(X, S), X >= 10.
  35.  
  36.  
  37. poss(visit(City), S ) :-
  38.   at(agent,City, S),
  39.   not((visited(City, S) )).
  40.  
  41.  
  42.  
  43. poss(rent(Car,X), S) :-
  44.     (at(agent,X,S), agencyAt(Car,X), not(rented(Car,S)), money(M,S), M >= 2);
  45.     (at(agent,X,S), agencyAt(Car,X), returned(Car,X,S), money(M,S), M >= 2).
  46.  
  47. poss(return(O,X), S) :- at(agent,X,S), rented(O,S), at_car(O,X,S), agencyAt(_,X).
  48.  
  49.  
  50. % --- Successor state axioms ------------------------------------------
  51. % describe the value of fluent based on the previous situation and the
  52. % action chosen for the plan.
  53. %
  54. % fluent(..., result(A,S)) :- positive; previous-state, not(negative)
  55.  
  56. at(agent,Where, result(A, S)) :-
  57.   (A = fly(_, Where); A = drive(_, _, Where);A = bus(_, Where) );
  58.   at(agent,Where, S) , not(( A = fly(Where, _) ; A = drive(_, Where, _) )).
  59.  
  60.  
  61. at_car(Car,City,result(A,S)) :-
  62.   A = drive(Car,_,City);
  63.   at_car(Car,City,S),
  64.   not(A = drive(car,City,_)).
  65.  
  66.  
  67. visited(Place, result(A,S)) :-
  68.    A = visit(Place);
  69.    visited(Place, S), not(A=visit(Place)).
  70.  
  71.  
  72.  
  73. money(X, result(A, S)) :-
  74.   A = fly(_,_), money(N,S), X is N -10;
  75.   A = drive(_,_,_), money(N,S), X is N -1;
  76.   A = rent(_,_), money(N,S), X is N -2 ;
  77.   money(X,S),
  78.   not((A =fly(_,_) ; A =drive(_,_,_) ; A =rent(_,_)))  .
  79.  
  80.  
  81.  
  82.  
  83. rented(Car,result(A,S)) :-
  84.   A = rent(Car,_);
  85.   rented(Car,S),
  86.   not(A = return(Car,_)).
  87.  
  88. returned(Car,X,result(A,S)) :-
  89.   A = return(Car,X);
  90.   returned(Car,X,S),
  91.   not(A = rent(Car,_)).
  92.  
  93.  
  94. % ---------------------------------------------------------------------
  95. % ---------------------------------------------------------------------