Skip to content

Instantly share code, notes, and snippets.

@d4hines
Created November 20, 2019 03:12
Show Gist options
  • Save d4hines/8f0647de932131fc0da24c1abd558b13 to your computer and use it in GitHub Desktop.
Save d4hines/8f0647de932131fc0da24c1abd558b13 to your computer and use it in GitHub Desktop.
Attempt a translation of Dr. Gelfond's system description of windows.
% fluent win(W), where W is a window name, e.g "w".
% fluent position(W, P), where W is a window, and P is a possible position, e.g "p1"
% Note: position is really a total function: every window has one and only one position. position is not injective, i.e windows can occupy the same position.
% add(W, P) causes window(W).
window(W, T + 1) :- occurs(add(W, P), T).
% add(W, P) causes position(W, P).
position(W, T + 1) :- occurs(add(W, P), T).
% remove(W) causes -window(W).
-window(W, T + 1) :- occurs(remove(W), T).
% impossible add(W, P) if window(W).
:- occurs(add(W, P), T), window(W, T).
% impossible remove(W, P) if -window(W).
:- occurs(remove(W), T), -window(W, T).
% move(W, P) causes position(W, P).
position(W, P, T + 1) :- occurs(move(W, P), T).
% impossible move(W, P) if -window(W).
:- occurs(move(W, P), T), -window(W, T).
% Functional constraint: every window may have one and only one position.
% -position(W, P) if window(W, P), position(W, P2), P1 != P2.
-position(W, P1, T) :- window(W, T), position(W, P2), P1 != P2.
% Inertial laws
% Window is a total fluent, i.e, defined on every proper input.
window(W, T + 1) :- window(W, T), step(T).
% position, by contrast, is a partial fluent with a dynamic domain (i.e, domain depending on a time step).
position(W, P, T + 1) :- position(W, P, T), window(W, T + 1), not -position(W, P, T + 1), step(T).
% Instance
step(0..4).
% initial state.
-window(w, 0).
% example history.
occurs(add(w, p1), 0).
occurs(move(w, p2), 1).
occurs(remove(w), 2).
@d4hines
Copy link
Author

d4hines commented Nov 20, 2019

This program produces the following error in Clingo:

gelfond-window-test.lp:24:1-64: error: unsafe variables in:
  (-position(W,P1,T)):-[#inc_base];position(W,P2);window(W,T);P1!=P2.
gelfond-window-test.lp:24:14-16: note: 'P1' is unsafe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment