%% Author: Juan Carlos Nieves %% The domain indepent part of program was taken from the book %% "Knowledge Representation Reasoning and Declarative Problem Solving", Page: 249-250. %% and the domain dependent part is part of the medical scenario presented in: %% "Reasoning about actions under uncertainty: A possibilistic approach", %% (CCIA), pp 300-309, 2007. %% For running this program you require SMODELS system: %% http://www.tcs.hut.fi/Software/smodels/ %%%%%%%%%%%%%%% Encoding the domain independent part %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% #const length = 2. time(1..length). not_goal(T) :- time(T), finally(X), not holds(X,T). goal(T) :- time(T), not not_goal(T). :- not goal(length). contrary(F,neg(F)) :- fluent(F). contrary(neg(F),F) :- fluent(F). not_executable(A,T) :- exec(A,F), not holds(F,T), time(T), action(A). executable(A,T) :- T < length, not not_executable(A,T), time(T), action(A). holds(F,1) :- initially(F). holds(F,TT) :- T < length, executable(A,T), occurs(A,T), cause(A,F,TT), TT = T + 1, time(T), time(TT), action(A), fluent(F). holds(F,TT) :- contrary(F,G), T < length, holds(F,T), not holds(G,TT), TT = T + 1, time(T), time(TT), fluent(F). occurs(A,T) :- action(A), time(T), not goal(T), not not_occurs(A,T). not_occurs(A,T) :- action(A), action(AA), time(T), occurs(AA,T), A!= AA, time(T). :- action(A), time(T), occurs(A,T), not executable(A,T). %%%%%%%%%%%%%%% Encoding the domain dependent part %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% patient_states(stable). patient_states(unstable). patient_states(cero_urgency). patient_states(dead). organ_status(terminal_insuff_function). organ_status(delayed_graft_function). organ_status(good_graft_function). organ_status(delayed_graft_function). organ_status(stopped_graft_function). organ_status(normal_graft_function). infection_status(present). infection_status(not_present). %%%%%%%%%%%%%%%%%%%%% Fluents %%%%%%%%%%%%%%%%%%%%%%%%% fluent(cs(X)) :- patient_states(X). fluent(o(X)) :- organ_status(X). fluent(inf(X)) :- infection_status(X). %%%%%%%%%%%%%%%%%%%% Actions %%%%%%%%%%%%%%%%%%%%%%%%%% action(transplant). action(wait). %action(post_transplant_treatment). %%%%%%%%%%%%%%%%% Effect propositions %%%%%%%%%%%%%%%% cause(wait, cs(unstable),TT) :- holds(cs(stable),T), holds(o(terminal_insuff_function),T), time(T),time(TT), TT = T + 1. cause(wait, cs(cero_urgency),TT) :- holds(cs(unstable),T), holds(o(terminal_insuff_function),T), time(T),time(TT), TT = T + 1. cause(wait, cs(dead),TT) :- holds(cs(cero_urgency),T), holds(o(terminal_insuff_function),T), time(T),time(TT), TT = T + 1. cause(transplant,o(good_graft_function), TT) :- holds(o(terminal_insuff_function),T), time(T),time(TT), TT = T + 1, not cause(transplant,o(delayed_graft_function),TT), not cause(transplant,o(terminal_insuff_function), TT). cause(transplant,o(delayed_graft_function), TT) :- holds(o(terminal_insuff_function),T), time(T),time(TT), TT = T + 1, not cause(transplant,o(good_graft_function),TT), not cause(transplant,o(terminal_insuff_function), TT). cause(transplant,o(terminal_insuff_function), TT) :- holds(o(terminal_insuff_function),T), time(T),time(TT), TT = T + 1, not cause(transplant,o(good_graft_function),TT), not cause(transplant,o(delayed_graft_function), TT). cause(transplant,cs(stable), T):- cause(transplant,o(good_graft_function), T), time(T). cause(transplant,cs(unstable), T) :- cause(transplant,o(delayed_graft_function), T), time(T). cause(transplant,cs(cero_urgency), T) :- holds(o(terminal_insuff_function),T), time(T). %cause(transplant,inf(present), _). %cause(transplant,inf(not_present), _). %%%%%%%%%%%%%%%%%%% Executability conditions %%%%%%%%%%%%%%%%%%%%%5 exec(transplant,neg(cs(dead))). %%%%%%%%%%%%%%%%% Causal qualification %%%%%%%%%%%%%%%%%%% holds(neg(cs(Y)),T) :- holds(cs(X),T), patient_states(X), patient_states(Y), time(T), not eq(X,Y). holds(neg(o(Y)),T) :- holds(o(X),T), organ_status(X), organ_status(Y), time(T), not eq(X,Y). holds(neg(inf(Y)),T) :- holds(inf(X),T), infection_status(X), infection_status(Y), time(T), not eq(X,Y). %%%%%%%%%%%%%%%%%%% Inicial states %%%%%%%%%%%%%%%%%%%% initially(cs(cero_urgency)). initially(inf(not_present)). initially(o(terminal_insuff_function)). %%%%%%%%%%%%%%%%%% Final states %%%%%%%%%%%%%%%%%%%%%% finally(cs(stable)). finally(o(good_graft_function)). %%%%%%%%%%%%%%%%% Extra code %%%%%%%%%%%%%%%%%%%%%%%% hide time(X). hide patient_states(X). hide initially(X). hide organ_status(X). hide infection_status(X). hide fluent(X). hide contrary(X,Y). hide action(X). hide not_occurs(A,T). hide not_goal(X). hide finally(X). hide exec(A,F). hide executable(X,Y).