%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% The gas-diffusion problem: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%A building contains a number of rooms. %%%Each room is connected to (some) other rooms via gates. %%%Initially, all gates are closed and some of the %%%rooms contain certain amounts of gas %%%(the other rooms are assumed to be empty). %%%Each gate can be opened or closed. %%%When a gate between two rooms is opened %%%the gas contained in these rooms flows through the gate. %%%The gas diffusion continue until the pressure reaches an equilibrium. %%%The only condition to be always satisfied is that a gate in a room can be %%%opened only if all other gates are closed. %%%The goal is to move a desired quantity of gas in one specified room. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% Coded by DFP, July 2008 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% For the current instance, call :-sicsplan(7). %% The 11 rooms of our instances: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% 10 9 %% 11 8 %% 1 -7- 6 %% 2 5 %% 3 4 %%%% TOPOLOGY description room(N) :- interval(N,1,11). gate(1,2). gate(1,7). gate(1,11). gate(2,3). gate(3,4). gate(4,5). gate(5,6). gate(6,7). gate(6,8). gate(8,9). gate(9,10). gate(10,11). %%%% FLUENTS fluent(contains(N),0,255) :- room(N). fluent(is_open(X,Y),0,1) :- gate(X,Y). %%%% ACTIONS action(open(X,Y)) :- gate(X,Y). action(close(X,Y)) :- gate(X,Y). %%%% EXECUTABILITY %executable(open(X,Y),L) :- % action(open(X,Y)), % findall((is_open(X,Z) eq 0), gate(X,Z),L1), % findall((is_open(Z,X) eq 0), gate(Z,X),L2), % findall((is_open(Y,Z) eq 0), (gate(Y,Z),neq(Z,X)),L3), % findall((is_open(Z,Y) eq 0), (gate(Z,Y),neq(Z,X)),L4), % append(L1,L2,La),append(L3,L4,Lb),append(La,Lb,L). executable(open(X,Y),L) :- action(open(X,Y)), findall((is_open(X,Z) eq 0), gate(X,Z),L1), findall((is_open(Z,X) eq 0), gate(Z,X),L2,L1), findall((is_open(Y,Z) eq 0), (gate(Y,Z),neq(Z,X)),L3,L2), findall((is_open(Z,Y) eq 0), (gate(Z,Y),neq(Z,X)),L,L3). executable(close(X,Y),[is_open(X,Y) eq 1]) :- action(close(X,Y)). causes(open(X,Y), contains(Y) eq (contains(X)^(-1)+contains(Y)^(-1))/2, []) :- action(open(X,Y)). causes(open(X,Y), contains(X) eq (contains(X)^(-1)+contains(Y)^(-1))/2, []) :- action(open(X,Y)). causes(open(X,Y), is_open(X,Y) eq 1,[]) :- action(open(X,Y)). causes(close(X,Y), is_open(X,Y) eq 0,[]) :- action(close(X,Y)). %%%% Initial and final states initially(is_open(X,Y) eq 0) :- gate(X,Y). initially(contains(10) eq 128). initially(contains(3) eq 128). initially(contains(A) eq 0) :- room(A), diff(A,3,10). goal(contains(1) gt 32). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%