%% ignite.lp -- translation of system description from Section 9.2.2 %% (Code from Appendix D.1) %% Last Modified: 2/3/14 %% A burner is connected to a gas tank through a pipeline. The gas tank is on %% the left-most end of the pipeline and the burner is on the right-most end. %% The pipeline is made up of sections connected with each other by valves. The %% pipe sections can be either pressurized by the tank or unpressurized. Opening %% a valve causes the section on its right side to be pressurized if the section %% to its left is pressurized. Moreover, for safety reasons, a valve can be %% opened only if the next valve in the line is closed. Closing a valve causes %% the pipe section on its right side to be unpressurized. %% ---------------------------------------------------- %% ignite.lp %% ---------------------------------------------------- section(s1). section(s2). section(s3). valve(v1). valve(v2). connected_to_tank(s1). connected(s1,v1,s2). connected(s2,v2,s3). connected_to_burner(s3). fluent(inertial, burner_on). fluent(inertial, opened(V)) :- valve(V). fluent(defined, pressurized(S)) :- section(S). action(open(V)) :- valve(V). action(close(V)) :- valve(V). action(ignite). #const n = 4. step(0..n). %% ---------------------- %% AL System Description: %% ---------------------- %% pressurized(S) if connected_to_tank(S). holds(pressurized(S),I) :- step(I), connected_to_tank(S). %% pressurized(S2) if connected(S1,V,S2), %% opened(V), %% pressurized(S1). holds(pressurized(S2), I) :- connected(S1,V,S2), holds(opened(V), I), holds(pressurized(S1), I). %% -burner_on if connected_to_burner(S), %% -pressurized(S). -holds(burner_on, I) :- connected_to_burner(S), -holds(pressurized(S),I). %% open(V) causes opened(V). holds(opened(V), I+1) :- occurs(open(V),I), I < n. %% impossible open(V) if opened(V). -occurs(open(V),I) :- holds(opened(V),I). %% impossible open(V1) if connected(S1,V1,S2), %% connected(S2,V2,S3), %% opened(V2). -occurs(open(V1),I) :- connected(S1,V1,S2), connected(S2,V2,S3), holds(opened(V2),I). %% close(V) causes -opened(V). -holds(opened(V), I+1) :- occurs(close(V), I), I < n. %% impossible close(V) if -opened(V). -occurs(close(V), I) :- -holds(opened(V), I). %% ignite causes burner_on. holds(burner_on, I+1) :- occurs(ignite, I), I < n. %% impossible ignite if connected_to_burner(S), %% -pressurized(S). -occurs(ignite, I) :- connected_to_burner(S), -holds(pressurized(S), I). %% CWA for Defined Fluents: -holds(F,I) :- fluent(defined,F), step(I), not holds(F,I). %% General Inertia Axiom holds(F,I+1) :- fluent(inertial,F), holds(F,I), not -holds(F,I+1), I < n. -holds(F,I+1) :- fluent(inertial,F), -holds(F,I), not holds(F,I+1), I < n. %% CWA for Actions -occurs(A,I) :- action(A), step(I), not occurs(A,I). %% ----------------------- %% Simple Planning Module: %% ----------------------- success :- goal(I), I <= n. :- not success. 1{occurs(Action,I): action(Action)}1 :- step(I), not goal(I), I < n. %% ------------------ %% Initial Situation: %% ------------------ -holds(burner_on, 0). -holds(opened(v1),0). holds(opened(v2),0). %% ----- %% Goal: %% ----- goal(I) :- holds(burner_on,I). %% ------------------ %% Output formatting: %% ------------------ #show occurs/2.