2016-11-14 18:36:01 +01:00
|
|
|
% Convert a plan (possibly with parallel actions), given by atoms over occurs/2,
|
|
|
|
% to a sequential plan, expressed by atoms over sequence/2
|
|
|
|
|
|
|
|
time(T) :- occurs(A,T).
|
|
|
|
time :- time(T).
|
|
|
|
|
|
|
|
:- goal(X,V), not initialState(X,V), not time.
|
|
|
|
|
2016-11-15 09:07:36 +01:00
|
|
|
last(T2) :- time, T2 = #max{T1 : time(T1)}.
|
2016-11-14 18:36:01 +01:00
|
|
|
|
2016-11-15 09:07:36 +01:00
|
|
|
offset(T2,M) :- time(T2), M = #count{A,T1 : occurs(A,T1), T1 < T2}.
|
|
|
|
finish(T,M+N) :- offset(T,M), N = #count{A : occurs(A,T)}.
|
|
|
|
index(T,M+1..N) :- offset(T,M), finish(T,N).
|
2016-11-14 18:36:01 +01:00
|
|
|
|
|
|
|
postcondition(A,X,V) :- postcondition(A,E,X,V), occurs(A,T).
|
|
|
|
postcondition(A,X) :- postcondition(A,X,V).
|
|
|
|
|
|
|
|
before(A1,A2,T) :- occurs(A1,T), occurs(A2,T), A1 != A2,
|
2016-11-15 09:07:36 +01:00
|
|
|
precondition(A1,X,V), postcondition(A2,X), not postcondition(A2,X,V).
|
2016-11-14 18:36:01 +01:00
|
|
|
|
|
|
|
order(A1,A2,T) :- occurs(A1,T), occurs(A2,T), A1 < A2, A <= A1 : occurs(A,T), A < A2.
|
|
|
|
first(A2,T) :- occurs(A2,T), #false : order(A1,A2,T).
|
|
|
|
|
|
|
|
undone(A,T,M) :- occurs(A,T), offset(T,M).
|
|
|
|
undone(A,T,N) :- undone(A,T,N-1), select(A1,T,N), A != A1, index(T,N+1).
|
|
|
|
|
|
|
|
done(A,T,N) :- select(A,T,N).
|
|
|
|
done(A,T,N) :- done(A,T,N-1), index(T,N).
|
|
|
|
|
2016-11-15 09:07:36 +01:00
|
|
|
:- finish(T,N), occurs(A,T), not done(A,T,N).
|
2016-11-14 18:36:01 +01:00
|
|
|
|
2016-11-15 09:07:36 +01:00
|
|
|
hold(X,V,0) :- initialState(X,V).
|
|
|
|
hold(X,V,N) :- select(A,T,N), postcondition(A,X,V).
|
|
|
|
hold(X,V,N) :- select(A,T,N), hold(X,V,N-1), not postcondition(A,X).
|
2016-11-14 18:36:01 +01:00
|
|
|
|
2016-11-15 09:07:36 +01:00
|
|
|
:- last(T), finish(T,N), goal(X,V), not hold(X,V,N).
|
2016-11-14 18:36:01 +01:00
|
|
|
|
2016-11-15 09:07:36 +01:00
|
|
|
hold(X,N) :- hold(X,V,N).
|
2016-11-14 18:36:01 +01:00
|
|
|
|
2016-11-15 09:07:36 +01:00
|
|
|
:- hold(X,N), #count{V : hold(X,V,N)} > 1.
|
2016-11-14 18:36:01 +01:00
|
|
|
|
2016-11-15 09:07:36 +01:00
|
|
|
preconditions(A,T,N) :- undone(A,T,N), hold(X,V,N) : precondition(A,X,V).
|
2016-11-14 18:36:01 +01:00
|
|
|
applicable(A,T,N) :- preconditions(A,T,N), done(A1,T,N) : before(A1,A,T).
|
|
|
|
|
|
|
|
inapplicable(A,T,N) :- done(A,T,N), index(T,N+1).
|
2016-11-15 09:07:36 +01:00
|
|
|
inapplicable(A,T,N) :- undone(A,T,N), precondition(A,X,V1), hold(X,V2,N), V1 != V2.
|
2016-11-14 18:36:01 +01:00
|
|
|
inapplicable(A,T,N) :- undone(A1,T,N), before(A1,A,T).
|
|
|
|
|
|
|
|
continue(A2,T,N) :- order(A1,A2,T), inapplicable(A1,T,N), first(A1,T).
|
|
|
|
continue(A2,T,N) :- order(A1,A2,T), inapplicable(A1,T,N), continue(A1,T,N).
|
|
|
|
|
|
|
|
select(A,T,N+1) :- applicable(A,T,N), first(A,T).
|
|
|
|
select(A,T,N+1) :- applicable(A,T,N), continue(A,T,N).
|
|
|
|
|
|
|
|
% DISPLAY PART
|
|
|
|
|
2016-11-15 09:07:36 +01:00
|
|
|
#show.
|
|
|
|
#show sequence(A,N) : select(A,T,N).
|