                The Credit Card Problem

Date: Sun, 27 Jun 99
From: Michael Gelfond and Monica Nogueira
To: TAG


We want to discuss the following interesting example which is a variation 
of the Jack's trip problem presented by Michael at the Workshop on 
Logic-Based AI (we will refer to it as the "credit card problem"). 
We will use this example to address two different points.
 
The story goes as follows: 
Mike wants to buy an airline ticket, which can only be purchased at the 
airport. He can drive to the airport, get money (if needed), and buy the 
ticket using a credit card or money. An exogenous action of loosing some 
of his possessions can interfer with Mike's plans. He knows that the loss 
of his credit card should be reported to the credit card company as soon 
as it is discovered. In his plans, he attempts to fulfill this obligation. 

Initially, Mike is at home, has a credit card but no money. 
This is represented by axioms H0

 	1. holds(mike_at(home),0).
 	2. holds(has(creditCard),0).
 	3. holds(nhas(money),0).  
 
Mike plans to go to the airport and buy the ticket. When at the airport 
he discovers that he has no credit card. He infers that the card was lost 
and creates a new plan which includes reporting the loss.

We want to model this behaviour.


The first point that is interesting to us is the following: the agent 
(Mike) performs the first action of driving to the airport at moment of 
time T=0
 	4. occurs(drives(airport),0).
but encounters an unexpected observation 
 	5. holds(nhas(creditCard),1). 

His new collection of axioms, H1, consists of 1-5.
He explains observation by the occurrence of an exogenous action
 	occurs(loses(creditCard),0).
and replans to achieve his goal of buying a ticket.

 
To do that two things are necessary:
 
1. The agent assumes that any exogenous action can occur in the past. 
Since the only exogenous action is "loses" and the current time is 1 
we can express it by the rule:

   occurs(loses(O),T) v occurs(nloses(O),T) :- time(T), T < 1, object(O).

Note that disjunctive rules are translated into non-disjunctive rules 
as usual when computing stable models using Smodels. 
 

Adding the above axiom is however not enough. We also have to change 
the inertia axioms.
 
 
2. Instead of writing inertia laws using normal defaults, we write 
inertia in the semi-normal defaults format using abnormalities, as
 
 	holds(F,T1) :- next(T,T1), holds(F,T), not ab(F,T).

Now D + H1 entails occurs(loses(creditCard),0).


We found this example interesting because it presents a case where 
semi-normal defaults in the inertia seem to work when normal defaults 
inertia does not. (Similar situation appears when we reason with 
incomplete info)
 

We use the same example to make a second point.
 
 
We decided to have another look on the monkey-trainer problem. The 
trainer's obligation to come to the monkey is, to some extent, modeled 
here by the requirement that if the credit card is lost, a call should 
be made to report the loss to the credit card company.  In this example 
it is treated differently (and we believe better) than in the 
monkey-trainer problem since here we do not use defaults and preserve 
the diontic character of the agreement. Mike ought to call and trainer 
ought to come to the monkey but they may not. We would like our 
representation to allow for such possibility.

To do that we just say
 
 occurs(callsCompany,T1) :- time(T), time(T1), T < T1, 
                             occurs(loses(creditCard),T), 
                             not holds(lossReported,T1),
			     not noccurs(callsCompany,T1).
 
meaning that if credit card was lost at some time T previous to T1, 
the loss has not yet been reported at time T1, and there is no 
reason to believe a call to the credit card company has not been made 
at time T1, then action callsCompany is executed at time T1.
 
This rule is part of the control module which describes the space of plans.
 
 
Notice that any plan to get a ticket developed in situation 1 
(with axioms H1) will contain an immediate call to the credit card 
company. However, the set H2 of axioms consisting of (1)-(5)
and
	noccurs(callsCompany,2).

is consistent.

Please find the program as an attachment below. Notice that we have 
function symbols in the domain description since the new version of 
lparse (lparse-0.99.17) can handle them. lparse is the parser which 
generates the ground logic programs to be used as input to Smodels.  
However, this version is not stable yet.

----------------------------------------------------------------------------



%---------------------------------------------------------------------------
%  Credit Card problem
%
%  Mike wants to buy an airline ticket, which can only be purchased at the 
%  airport. He can drive to the airport, get money (if needed), and buy the 
%  ticket using a credit card or money.
%  An exogeneous action of loosing some of his possessions can interfer with
%  Mike's plans. He knows that the loss of his credit card should be reported
%  to the credit card company as soon as it is discovered. In his plans, he 
%  attempts to fulfill this obligation. 
%  Initially, Mike is at home, has a credit card but no money. 
%  Mike plans to go to the airport and buy the ticket. When at the airport he 
%  discovers that he has no credit card. He infers that the card was lost and 
%  creates a new plan which includes reporting the loss.
%  
%  We want to model this behaviour.
%
%  Last modification: 6/25/99
%---------------------------------------------------------------------------

%---------------------------------------------------------------------------
%  Facts
%---------------------------------------------------------------------------

object(creditCard).
object(ticket).
object(money).

location(home).
location(airport).


%---------------------------------------------------------------------------
%  Fluents 
%---------------------------------------------------------------------------

% fluent(mike_at(L),T) :- time(T), location(L).

% fluent(has(O),T) :- time(T), object(O).

% fluent(at(O),T) :- time(T), object(O).

% fluent(lossReported,T) :- time(T).


%---------------------------------------------------------------------------
%  Actions 
%---------------------------------------------------------------------------

% action(drives(L),T) :- time(T), location(L).

% action(buys(ticket),T) :- time(T).

% action(gets(money),T) :- time(T).

% action(loses(O),T) :- time(T), object(O).

% action(callsCompany,T) :- time(T).



%---------------------------------------------------------------------------
%  Dynamic Causal Laws             
%---------------------------------------------------------------------------

holds(mike_at(L),T1) :- next(T,T1), location(L), occurs(drives(L),T).

ab(nmike_at(L),T) :- time(T), location(L), occurs(drives(L),T).


holds(has(ticket),T1) :- next(T,T1), occurs(buys(ticket),T).

ab(nhas(ticket),T) :- time(T), occurs(buys(ticket),T).


holds(has(money),T1) :- next(T,T1), occurs(gets(money),T).

ab(nhas(money),T) :- time(T), occurs(gets(money),T).


holds(nhas(O),T1) :- next(T,T1), object(O), occurs(loses(O),T).

ab(has(O),T) :- time(T), object(O), occurs(loses(O),T).


holds(lossReported,T1) :- next(T,T1), occurs(callsCompany,T).

ab(nlossReported,T) :- time(T), occurs(callsCompany,T).



%----------------------------------------------------------------------------
%  Static Causal Laws
%----------------------------------------------------------------------------

holds(nmike_at(L2),T) :- time(T),location(L1),location(L2),neq(L1,L2),holds(mike_at(L1),T).

ab(mike_at(L2),T) :- next(T,T1),location(L1),location(L2),neq(L1,L2),holds(mike_at(L1),T1).


holds(at(O,L),T) :- time(T),location(L),object(O),holds(mike_at(L),T),holds(has(O),T).

ab(nat(O,L),T) :- next(T,T1),object(O),location(L),holds(mike_at(L),T1),holds(has(O),T1).


holds(nat(O,L2),T) :- time(T),object(O),location(L1),location(L2),neq(L1,L2),holds(at(O,L1),T).

ab(at(O,L2),T) :- next(T,T1),object(O),location(L1),location(L2),neq(L1,L2),holds(at(O,L1),T1).




%----------------------------------------------------------------------------
%  Inertia Laws
%----------------------------------------------------------------------------

holds(mike_at(L),T1)  :- next(T,T1),location(L),holds(mike_at(L),T),not ab(mike_at(L),T).

holds(nmike_at(L),T1) :- next(T,T1),location(L),holds(nmike_at(L),T),not ab(nmike_at(L),T).


holds(has(O),T1)  :- next(T,T1),object(O),holds(has(O),T),not ab(has(O),T).

holds(nhas(O),T1) :- next(T,T1),object(O),holds(nhas(O),T),not ab(nhas(O),T).


holds(at(O,L),T1)  :- next(T,T1),location(L),object(O),holds(at(O,L),T),not ab(at(O,L),T).

holds(nat(O,L),T1) :- next(T,T1),location(L),object(O),holds(nat(O,L),T),not ab(nat(O,L),T).


holds(lossReported,T1) :- next(T,T1),holds(lossReported,T),not ab(lossReported,T).

holds(nlossReported,T1) :- next(T,T1),holds(nlossReported,T),not ab(nlossReported,T).



%-------------------------------------------------------------------------------
%  Defining Negation for Fluents
%-------------------------------------------------------------------------------
:- time(T),location(L), holds(mike_at(L),T), holds(nmike_at(L),T).

:- time(T),location(L),object(O), holds(at(O,L),T), holds(nat(O,L),T).

:- time(T),object(O), holds(has(O),T), holds(nhas(O),T).  

:- time(T),holds(lossReported,T), holds(nlossReported,T).



%-------------------------------------------------------------------------------
%  Executability Conditions
%-------------------------------------------------------------------------------
:- time(T), location(L), holds(mike_at(L),T), occurs(drives(L),T).

:- time(T), holds(has(ticket),T), occurs(buys(ticket),T).

:- time(T), holds(nmike_at(airport),T), occurs(buys(ticket),T).

:- time(T), holds(nhas(creditCard),T), holds(nhas(money),T), occurs(buys(ticket),T).

:- time(T), object(O), holds(nhas(O),T), occurs(loses(O),T).

:- time(T), holds(has(money),T), occurs(gets(money),T).



% Actions that can NOT be executed in parallel

:- time(T), object(O), occurs(loses(O),T), occurs(buys(ticket),T).
:- time(T), occurs(callsCompany,T), occurs(buys(ticket),T).



%-------------------------------------------------------------------------------
%  Control Module
%-------------------------------------------------------------------------------

occurs(drives(airport),T) :- time(T), not goal(T), not occurs(gets(money),T), 
not occurs(buys(ticket),T), not occurs(drives(home),T).

occurs(drives(home),T) :- time(T), not goal(T), not occurs(buys(ticket),T), 
not occurs(drives(airport),T), not occurs(gets(money),T).

occurs(buys(ticket),T) :- time(T), not goal(T), not occurs(gets(money),T), 
not occurs(drives(airport),T), not occurs(drives(home),T).

occurs(gets(money),T) :- time(T), not goal(T), not occurs(drives(airport),T), 
not occurs(drives(home),T), not occurs(buys(ticket),T), not holds(has(creditCard),T).



% Diontic Actions (ought to do)

occurs(callsCompany,T1) :- time(T), time(T1), T < T1, occurs(loses(creditCard),T), 
not holds(lossReported,T1), not noccurs(callsCompany,T1).



% Exogeneous Actions (can only happen in the past)

occurs(loses(O),T) :- time(T), T < 1, object(O), not occurs(nloses(O),T).

occurs(nloses(O),T) :- time(T), T < 1, object(O), not occurs(loses(O),T).		      



%---------------------------------------------------------------------------
%  H I S T O R Y
%---------------------------------------------------------------------------
%  Initial Conditions
%---------------------------------------------------------------------------
holds(mike_at(home),0).

holds(has(creditCard),0).

holds(nhas(money),0).

holds(nhas(ticket),0).

holds(nlossReported,0).


%---------------------------------------------------------------------------
% Occurrence of actions and observations
%---------------------------------------------------------------------------
occurs(drives(airport),0).

holds(nhas(creditCard),1).



%---------------------------------------------------------------------------
%  Goal
%---------------------------------------------------------------------------
goal(T) :- time(T), holds(has(ticket),T).


%---------------------------------------------------------------------------
%  Query
%---------------------------------------------------------------------------
:- not goal(5).



%---------------------------------------------------------------------------
%  Auxiliary Predicates 
%---------------------------------------------------------------------------
time(0..5).
next(T,T1) :- time(T), time(T1), T1=T+1.

hide goal(X).
hide holds(X,Y).
hide ab(X,Y).
hide time(X).
hide next(X,Y).
hide location(X).
hide object(X).

%--------------------------------------------------------------------------


