#const n=3. %%%%%%%%%%%%%%%%%%%% SCENARIO 9 %%%%%%%%%%%%%%%%%%%% % % % John is in Boston on Dec 1. He has no passport. % % Can he go to Paris on Dec. 4? % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % The only difference here is the date of departure. % This means that the only change is the constant % in definnition of answer_true. % This time it is possible for John to go to Paris % on time (assuming of course that he'll receive % his passport quickly). Hence the answer to the query % should be YES. % THE TRANSLATION % translation of the first two sentences is straightforward. % John is in Boston on Dec 1. h(at(john,boston),0). time(0,d,1). % He has no passport. -h(has(john,passport(john)),0). % The query however is rather different from what we've seen % so far. It can be interpreted as asking if there is a plan % (a sequence of actions) which will allow John to go to % Paris on Dec 3. % (Recall that to go John needs a passport and that getting % one requires at least three days. So no such plan exists % and the answer to our query should be "NO"). % The query can be translated by a rule: answer_true(q) :- o(go_on(john,j(boston,paris)),T), time(T,d,4). % In general we may have % % answer_true(Q) :- h(F,T),...,o(a,T)... % time(T,U,V),... % % that is, the query may contain conditions % regarding several fluents, occurrences of actions, % and time atoms encoding dates and other time % measures. type_query(q,can). % The next fact states that the query % is about JOHN's ability to plan % his trip to Paris. planner(q,john). % To answer this query we need a planning module % described below: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % THE PLANNING MODULE % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % The module, used in conjunction with "scenario9" % and travel takes a non-negative integer n % as a parameter and finds a plan of maximum % length n which achieves the goal. If no % such plan exists the program has no model. yes :- type_query(Q,can), answer_true(Q). :- not yes. {o(Act,T) : action(Act) : actor(Act,P)}1 :- planner(Q,P), T < n-1. hide. show yes. % show time(A,B,C), do(A,B). % As before we need our "AboutTime" module: %%%%%%%% AboutTime 1{time(T,d,X) : day(X)}1 :- T < n. :- time(T1,d,Day1), time(T2,d,Day2), T1 < T2, Day2 < Day1. :- time(T,d,Day1), time(T,d,Day2), neq(Day1,Day2). % The following actions are performed % during a single day. time(T+1,d,Day) :- o(pack(P,PP,Container),T), time(T,d,Day). time(T+1,d,Day) :- o(embark(P,J),T), time(T,d,Day). time(T+1,d,Day) :- o(stop(J,C),T), time(T,d,Day). time(T+1,d,Day) :- o(disembark(P,J),T), time(T,d,Day).