\begin{verbatim} % block4-1.sm % % Here we treat clear(X) and handempty as defined fluents. % Thus they don't appear in effect axioms. % We also introduce qualification constraints and static causal % laws. That slightly simplifies executability conditions and % effect axioms too. % % Here we are dealing with block1-x.sm series. i.e., we donot % have conditional effects. % % block4-1.sm differs from block4-0.sm by not having clear(Y) as % an executability condition of stack(X,Y). We had to add % additional wekaer condition to make sure X is not stacked on a % non-existing block const length=7. time(1..length). block(a). block(b). block(c). block(d). block(e). %block(f). %block(g). %block(h). %block(i). %block(j). %block(k). % initially(handempty). % initially(clear(a)). % initially(clear(c)). % The above are removed because they are % defined fluents. initially(ontable(c)). initially(ontable(b)). initially(on(a,b)). finally(on(a,c)). finally(on(c,b)). not_goal(T):- time(T), literal(X), finally(X), not holds(X,T). goal(T) :- time(T), not not_goal(T). %goal(T):- % time(T), % holds(on(a,c),T), % holds(on(c,b),T). exists_plan :- goal(length). :- not exists_plan. %Defining what are fluents and %what are actions. fluent(on(X,Y)) :- block(X), block(Y). fluent(ontable(X)) :- block(X). def_fluent(clear(X)) :- block(X). fluent(holding(X)) :- block(X). def_fluent(handempty). action(pick_up(X)) :- block(X). action(put_down(X)) :- block(X). action(stack(X,Y)) :- block(X), block(Y). action(unstack(X,Y)) :- block(X), block(Y). %Definitions holds(neg(clear(X)),T) :- block(X), time(T), holds(holding(X),T). holds(neg(clear(X)),T) :- block(X), block(Y), time(T), holds(on(Y,X),T). holds(clear(X), T) :- block(X), time(T), holds(ontable(X), T), not holds(neg(clear(X)), T). holds(clear(X), T) :- block(X), block(Y), time(T), holds(on(X,Y), T), not holds(neg(clear(X)), T). holds(neg(handempty), T) :- block(X), time(T), holds(holding(X), T). holds(handempty, T) :- time(T), not holds(neg(handempty), T). %Qualification Constraint :- block(X), block(Y), block(Z), time(T), holds(on(X,Y), T), holds(on(Z,Y), T), neq(X,Z). %Static causal laws (cause ramifications) static_causes(on(X,Y), neg(holding(X))) :- block(X), block(Y). static_causes(holding(X), neg(on(X,Y)) ) :- block(X), block(Y). static_causes(ontable(X), neg(holding(X))) :- block(X). static_causes(holding(X), neg(ontable(X)) ) :- block(X). %Effects of actions and executability conditions. executable(pick_up(X), T) :- block(X), time(T), T < length, holds(clear(X), T), holds(ontable(X), T), holds(handempty, T). executable(put_down(X), T) :- block(X), time(T), T < length, holds(holding(X),T). executable(stack(X,Y),T) :- block(Y), block(X), block(Z), time(T), T < length, holds(holding(X),T), holds(on(Y,Z), T). % holds(clear(Y), T). % Removed because of the qualification constraint. % % Added holds(on(Y,Z), T) here and holds(ontable(Y), T) % in the next rule to make sure it does not stack X % on a non existent block. executable(stack(X,Y),T) :- block(Y), block(X), time(T), T < length, holds(holding(X),T), holds(ontable(Y),T). % holds(clear(Y), T). % Removed because of the qualification constraint. executable(unstack(X,Y),T) :- block(Y), block(X), time(T), T < length, holds(clear(X), T), holds(on(X,Y), T), holds(handempty, T). %causes(pick_up(X), neg(ontable(X))) :- % block(X). %causes(pick_up(X), neg(clear(X))) :- % block(X). causes(pick_up(X), holding(X)) :- block(X). %causes(pick_up(X), neg(handempty)) :- % block(X). causes(put_down(X), ontable(X)) :- block(X). %causes(put_down(X), clear(X)) :- % block(X). %causes(put_down(X), neg(holding(X))) :- % block(X). %causes(put_down(X), handempty) :- % block(X). %causes(stack(X,Y), neg(holding(X))) :- % block(X), % block(Y). %causes(stack(X,Y), neg(clear(Y))) :- % block(X), % block(Y). %causes(stack(X,Y), clear(X)) :- % block(X), % block(Y). %causes(stack(X,Y), handempty) :- % block(X), % block(Y). causes(stack(X,Y), on(X,Y)) :- block(X), block(Y). causes(unstack(X,Y), holding(X)) :- block(X), block(Y). %causes(unstack(X,Y), clear(Y)) :- % block(X), % block(Y). %causes(unstack(X,Y), neg(clear(X))) :- % block(X), % block(Y). %causes(unstack(X,Y), neg(handempty)) :- % block(X), % block(Y). %causes(unstack(X,Y), neg(on(X,Y))) :- % block(X), % block(Y). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% literal(G) :- fluent(G). literal(neg(G)) :- fluent(G). contrary(F, neg(F)) :- fluent(F). contrary(neg(F), F) :- fluent(F). def_literal(G) :- def_fluent(G). def_literal(neg(G)) :- def_fluent(G). contrary(F, neg(F)) :- def_fluent(F). contrary(neg(F), F) :- def_fluent(F). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% holds(F, 1) :- literal(F), initially(F). holds(F, T+1) :- literal(F), time(T), T < length, action(A), executable(A,T), occurs(A,T), causes(A,F). holds(F, T) :- literal(F), literal(G), time(T), T < length, holds(G, T), static_causes(G,F). holds(F, T+1) :- literal(F), literal(G), contrary(F,G), time(T), T < length, holds(F,T), not holds(G, T+1). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% possible(A,T) :- action(A), time(T), not goal(T). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% occurs(A,T) :- action(A), time(T), possible(A,T), not not_occurs(A,T). not_occurs(A,T) :- action(A), action(AA), time(T), occurs(AA,T), neq(A,AA). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% hide time(T). hide action(A). hide causes(A,F). hide initially(F). hide contrary(F,G). hide fluent(F). hide literal(L). hide executable(A,T). hide holds(F,T). hide not_occurs(A,T). hide possible(A,T). hide possible1(A,T). hide possible2(A,T). hide block(X). hide exists_plan. hide finally(X). hide goal(T). hide not_goal(T). hide static_causes(X,Y). hide def_fluent(X). hide def_literal(X). \end{verbatim}