
#const n=4.      

%%%%%%%%%%%%%%%%%%%%  SCENARIO 7  %%%%%%%%%%%%%%%%
%                                                %
%  John is in Paris. On Dec 1st he packs his     %
%  laptop in the carry-on luggage and takes a    %
%  plane to Baghdad.                             %
%  Where is his laptop on Dec 2nd?               %
%                                                %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% This differs from scenario 6 only by the query.
% We are asking to find out what fluents of a given
% class are true on a given day. 

%           THE TRANSLATION

% John is in Paris. 

    h(at(john,paris),0).

% On Dec 1st he packs his laptop in the carry-on luggage.

    o(pack(john,laptop(john),carry_on(john)),0).

    time(0,d,1).           % Step 0 corresponds to day 1.

% John goes to Baghdad:

    h(trip_by(j(paris,baghdad),plane),1).
    o(go_on(john,j(paris,baghdad)),1).
    time(1,d,1).

% Query: 
% We need to find C such that true_on(at(laptop(john), C),2).
% The query differ from that in scenario6 by 
% an extra variable, C, of q. 
% In general we will have q(V1,...Vn), where V1,...,Vn
% are the variables whose values the query
% is requesting.

answer_true(q(C)) :-
		true_on(at(laptop(john),C),2).

% type of query
type_query(q(C),find).   

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% To run the program we use

ans(Q) :-
       type_query(Q,find),
       answer_true(Q).

hide.

show ans(A),time(A,B,C).

% 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).

% The new relation true_on(Fl,Day) states that fluent Fl was true 
% sometime during the day Day. Similarly for false_on(Fl,Day).

true_on(Fl,Day) :- 
      time(T,d,Day),
      h(Fl,T).

false_on(Fl,Day) :- 
      time(T,d,Day),
      -h(Fl,T).

% We will use the same defaults as in scenario6:

true_on(at(O,C),Day+1) :- 
   h(at(O,C),n),
   time(n,d,Day).

false_on(at(O,C),Day+1) :- 
      -h(at(O,C),n),
      time(n,d,Day).

% In both answer sets the answer is Baghdad
