Untitled
By: a guest | Mar 22nd, 2010 | Syntax:
Prolog | Size: 2.48 KB | Hits: 61 | Expires: Never
:- multifile at/3, at_car/3, visited/2, money/2, rented/2, returned/3.
% --- Primitive control actions ---------------------------------------
% this section defines the name and the number of parameters of the
% actions available to the planner
%
% primitive_action( dosomething(_,_) ). % underscore means `anything'
primitive_action( drive(_,_,_) ).
primitive_action( fly(_,_) ).
primitive_action( visit(_) ).
primitive_action( rent(_,_) ).
primitive_action( return(_,_) ).
% --- Precondition for primitive actions ------------------------------
% describe when an action can be carried out, in a generic situation S
%
% poss( doSomething(...), S ) :- preconditions(..., S).
poss(drive(Car,From,To), S) :-
at(agent,From,S),
at_car(Car,From,S),
rented(Car,S),
road(From,To),
money(X, S), X >= 1.
poss( fly(From, To), S ) :-
at(agent,From, S),
flight(From, To),
money(X, S), X >= 10.
poss(visit(City), S ) :-
at(agent,City, S),
not((visited(City, S) )).
poss(rent(Car,X), S) :-
(at(agent,X,S), agencyAt(Car,X), not(rented(Car,S)), money(M,S), M >= 2);
(at(agent,X,S), agencyAt(Car,X), returned(Car,X,S), money(M,S), M >= 2).
poss(return(O,X), S) :- at(agent,X,S), rented(O,S), at_car(O,X,S), agencyAt(_,X).
% --- Successor state axioms ------------------------------------------
% describe the value of fluent based on the previous situation and the
% action chosen for the plan.
%
% fluent(..., result(A,S)) :- positive; previous-state, not(negative)
at(agent,Where, result(A, S)) :-
(A = fly(_, Where); A = drive(_, _, Where);A = bus(_, Where) );
at(agent,Where, S) , not(( A = fly(Where, _) ; A = drive(_, Where, _) )).
at_car(Car,City,result(A,S)) :-
A = drive(Car,_,City);
at_car(Car,City,S),
not(A = drive(car,City,_)).
visited(Place, result(A,S)) :-
A = visit(Place);
visited(Place, S), not(A=visit(Place)).
money(X, result(A, S)) :-
A = fly(_,_), money(N,S), X is N -10;
A = drive(_,_,_), money(N,S), X is N -1;
A = rent(_,_), money(N,S), X is N -2 ;
money(X,S),
not((A =fly(_,_) ; A =drive(_,_,_) ; A =rent(_,_))) .
rented(Car,result(A,S)) :-
A = rent(Car,_);
rented(Car,S),
not(A = return(Car,_)).
returned(Car,X,result(A,S)) :-
A = return(Car,X);
returned(Car,X,S),
not(A = rent(Car,_)).
% ---------------------------------------------------------------------
% ---------------------------------------------------------------------