%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Example: Visit a Dentist % Ram is at his office and he has a dentist appointment in one hour. For the % appointment, he needs to take his insurance card which is at home and some % cash to pay the doctor's fees. He can get cash from the nearby ATM. The % minimum time taken (in minutes) to travel between locations: Dentist (D), % Home (H), Office (O) and Atm (A) are tabulated as follows: % D H O A % D 0 20 30 40 % H 20 0 15 15 % O 30 15 0 20 % A 40 15 20 0 % % (a). Find a plan which takes Ram to the doctor on time and ready to pay. % (b). Find a plan which takes Ram to the doctor and he is early by 15 minutes % % (c). If Ram takes a cab for all his trips and the cab rate is 2.45$ per minute. % If the doctor's fees is $130 then how much amount should Ram withdraw % from the atm to pay all his expenses. % % (d). If Ram's expenses are more than the amount in his bank account then he % needs to borrow. If Ram has 160$ in his account then does he need to % borrow money to cover his expenses? % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Objects % % person and items person(ram). item(icard). item(cash). #domain person(P). #domain item(I). % locations loc(dentist). loc(office). loc(home). loc(atm). % step step(0..4). #domain step(S). #domain loc(L;L1;L2). % Fluents % fluent(at_loc(P,L)) :- person(P), loc(L). fluent(at_loc(I,L)) :- item(I), loc(L). fluent(has(P,I)) :- person(P), item(I). #domain fluent(F). % Actions % action(go_to(P,L)) :- person(P), loc(L). % Effects of action go_to % If a person goes to loc L then he is at L in the next moment of time. h(at_loc(P,L),S1) :- person(P), loc(L), next(S0,S1), o(go_to(P,L),S0). % If Ram is at loc L and item I is at loc L then he has item I h(has(P,I),S) :- step(S), h(at_loc(P,L),S), h(at_loc(I,L),S). % If a person has an item then it is at same loc as the person h(at_loc(I,L),S) :- h(has(P,I),S), h(at_loc(P,L),S). % A person cannot go to a loc he is already in :- step(S), person(P), loc(L), h(at_loc(P,L),S), o(go_to(P,L),S). % A person cannot be at two locations at the same time :- step(S), person(P), loc(L1), loc(L2), L1 != L2, h(at_loc(P,L1),S), h(at_loc(P,L2),S). %%%% next next(S,S+1) :- step(S+1). %% Inertia h(F,S1) :- next(S0,S1), h(F,S0), not -h(F,S1). -h(at_loc(P,L),S) :- h(at_loc(P,L1),S), neq(L,L1). -h(at_loc(I,L),S) :- h(at_loc(I,L1),S), neq(L,L1). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Timing Constraints % #const max_time = 1440. #csort time(0..max_time). %#domain time(T;T1;T2). % relation at_time(S,T) #mixed at_time(step,time). % Assign times increasingly. <~ next(S1, S2), at_time(S1,T1), at_time(S2,T2), gt(T1 - T2, 0). % Time taken to travel between dentist and home is atleast 20 minutes <~ h(at_loc(P, home), S1), o(go_to(P, dentist),S1), next(S1,S2), at_time(S1,T1), at_time(S2,T2), gt(T1-T2, -20). % Time taken to travel between home and dentist is atleast 20 minutes <~ h(at_loc(P, dentist), S1), o(go_to(P, home),S1), next(S1,S2), at_time(S1,T1), at_time(S2,T2), gt( T1 - T2, -20). % Time taken to travel between dentist and office is atleast 30 minutes <~ h(at_loc(P, office), S1), o(go_to(P, dentist),S1), next(S1,S2), at_time(S1,T1), at_time(S2,T2), gt( T1 - T2, -30). % Time taken between to travel between office and dentist is atleast 30 minutes <~ h(at_loc(P, dentist), S1), o(go_to(P, office),S1), next(S1,S2), at_time(S1,T1), at_time(S2,T2), gt( T1 - T2, -30). % Time taken between to travel between dentist and atm is atleast 40 minutes <~ h(at_loc(P, atm), S1), o(go_to(P, dentist),S1), next(S1,S2), at_time(S1,T1), at_time(S2,T2), gt( T1 - T2, -40). % Time taken between to travel between atm and dentist is atleast 40 minutes <~ h(at_loc(P, dentist), S1), o(go_to(P, atm),S1), next(S1,S2), at_time(S1,T1), at_time(S2,T2), gt( T1 - T2, -40). % Time taken between to travel between home and office is atleast 15 minutes <~ h(at_loc(P, home), S1), o(go_to(P, office),S1), next(S1,S2), at_time(S1,T1), at_time(S2,T2), T1 - T2 > -15. % Time taken between to travel between office and home is atleast 15 minutes <~ h(at_loc(P, office), S1), o(go_to(P, home),S1), next(S1,S2), at_time(S1,T1), at_time(S2,T2), T1 - T2 > -15. % Time taken between to travel between home and atm is atleast 15 minutes <~ h(at_loc(P, home), S1), o(go_to(P, atm),S1), next(S1,S2), at_time(S1,T1), at_time(S2,T2), T1 - T2 > -15. % Time taken between to travel between atm and home is atleast 15 minutes <~ h(at_loc(P, atm), S1), o(go_to(P, home),S1), next(S1,S2), at_time(S1,T1), at_time(S2,T2), T1 - T2 > -15. % Time taken between to travel between office and atm is atleast 20 minutes <~ h(at_loc(P, office), S1), o(go_to(P, atm),S1), next(S1,S2), at_time(S1,T1), at_time(S2,T2), T1 - T2 > -20. % Time taken between to travel between atm and office is atleast 20 minutes <~ h(at_loc(P, atm), S1), o(go_to(P, office),S1), next(S1,S2), at_time(S1,T1), at_time(S2,T2), T1 - T2 > -20. %% Planning Module 1 { o(go_to(Px,Lx),S) : person(Px) : loc(Lx) } 1 :- step(S), not goal(S). goal(S) :- h(at_loc(ram,dentist),S), h(has(ram,icard),S), h(has(ram,cash),S). plan :- goal(S). :- not plan. % (a). He should be at the dentist in 60 minutes <~ goal(S), at_time(0,T1), at_time(S,T2), gt(T2 - T1, 55). % (b). He should be at the dentist in 45 minutes %<~ goal(S), at_time(0,T1), at_time(S,T2), gt( T2 - T1, 45). % (c). If the cab rate is $2.45 per minute and the doctor's fees is 130$, then % how much should Ram withdraw from the bank to pay his expenses. doctor_expense(130). #csort money(0..2000). bank(atm). % relation get_amount(bank,money) #mixed need_amt(bank,money). reached_goal(S) :- goal(S), not ngoal(S). ngoal(S) :- step(S1), S1 X. <~ at_time(0,T), T != 0. %% Initial Situation h(at_loc(ram,office),0). h(at_loc(icard,home),0). h(at_loc(cash,atm),0). #hide. #show o(A,S). #show goal(S). #show at_time(S,T). %#show h(at_loc(P,L),S). #show enough_money. %#show reached_goal(S). #show borrow. % To run the example use command: acsolver dentist_clp % acsolver version 1.56 % ASPC % Number of Rules: 642 % Number of Atoms: 300 % Answer: 1 % Stable Model: goal(3) goal(4) o(go_to(ram,atm),0) o(go_to(ram,home),1) % o(go_to(ram,dentist),2) enough_money borrow #at_time(0,V0) #at_time(1,V1) % #at_time(2,V2) #at_time(3,V3) #at_time(4,V4) #need_amt(atm,V5) % Constraints: V0=0 V1=20 V2=35 V3=55 V4=55 V5=264.75 % True % Duration: 0.510 % Ground+Load Time: 0.113 % % Since there was only one solution, the constraints directly assign value to variables.