2016-11-14 16:56:51 +01:00
|
|
|
% Constant '_parallel' to enable parallel actions
|
|
|
|
% - value '1': "forall" parallel actions that can be arranged in any sequence
|
|
|
|
% - value '2': "exists" parallel actions that can be arranged in some sequence
|
2017-01-16 17:15:19 +01:00
|
|
|
% - value '3': "exists" parallel actions omitting achievement of preconditions
|
|
|
|
% - value '4': "exists" parallel actions like '3' implemented by acyclicity
|
2016-11-14 16:56:51 +01:00
|
|
|
% - otherwise: sequential actions
|
2016-11-14 12:00:14 +01:00
|
|
|
|
|
|
|
#const _parallel = 0.
|
|
|
|
|
2017-01-17 17:15:21 +01:00
|
|
|
% Constant 'planner_on' to enable encoding support for ASP-based planner
|
|
|
|
% - value '0': no compatibility to ASP-based planner (no idle steps permitted)
|
|
|
|
% - otherwise: compatibility to ASP-based planner (idle steps permitted)
|
|
|
|
|
|
|
|
#const planner_on = 0.
|
2016-11-14 16:56:51 +01:00
|
|
|
|
2016-11-14 12:00:14 +01:00
|
|
|
% BASE PROGRAM
|
|
|
|
|
2016-11-14 16:56:51 +01:00
|
|
|
% Define auxiliary predicates for actions w.r.t. parallel mode
|
2016-11-14 12:00:14 +01:00
|
|
|
|
2017-01-17 17:15:21 +01:00
|
|
|
selfdefeat(A,X) :- active(A), precondition(A,X,V), _parallel = 1,
|
|
|
|
has_condition(A,X,1), not postcondition(A,X,V).
|
2017-01-17 13:31:34 +01:00
|
|
|
|
2017-01-17 17:15:21 +01:00
|
|
|
diverge(A1,A2,X) :- active(A1), active(A2), postcondition(A1,X,V),
|
2016-11-14 12:00:14 +01:00
|
|
|
has_condition(A2,X,1), not postcondition(A2,X,V),
|
2017-01-16 17:15:19 +01:00
|
|
|
0 < _parallel, _parallel < 5.
|
2016-11-14 16:56:51 +01:00
|
|
|
diverge(A1,A2) :- diverge(A1,A2,X).
|
2016-11-14 12:00:14 +01:00
|
|
|
|
2017-01-17 17:15:21 +01:00
|
|
|
exclude(A1,A2) :- active(A1), active(A2), precondition(A1,X,V),
|
|
|
|
has_condition(A2,X,0), not precondition(A2,X,V),
|
|
|
|
0 < _parallel, _parallel < 5, _parallel != 2.
|
2016-11-14 12:00:14 +01:00
|
|
|
|
2016-11-14 16:56:51 +01:00
|
|
|
disable(A1,A2) :- active(A1), active(A2), A1 != A2, postcondition(A1,X,V),
|
|
|
|
has_condition(A2,X,0), not precondition(A2,X,V),
|
2017-01-17 17:15:21 +01:00
|
|
|
not diverge(A1,A2), not exclude(A1,A2),
|
2017-01-16 17:15:19 +01:00
|
|
|
1 < _parallel, _parallel < 5.
|
|
|
|
|
2017-01-17 19:52:12 +01:00
|
|
|
disable :- _parallel = 4, #sum{1,A1 : disable(A1,A2); -1,A2 : disable(A1,A2)} > 0.
|
2016-11-14 16:56:51 +01:00
|
|
|
|
|
|
|
scope(X,V) :- active(A), precondition(A,X,V), _parallel = 2.
|
|
|
|
|
|
|
|
% Define relevant fluents w.r.t. parallel mode
|
|
|
|
|
2016-11-14 12:00:14 +01:00
|
|
|
fluent(X,V) :- produce(X,V).
|
|
|
|
fluent(X,V) :- persist(X,V).
|
|
|
|
fluent(X,V) :- initialState(X,V), fluent(X).
|
|
|
|
fluent(X,V) :- active(A), postcondition(A,X,V), fluent(X).
|
|
|
|
fluent(X) :- fluent(X,V).
|
|
|
|
fluent(X) :- diverge(A1,A2,X), not exclude(A1,A2).
|
|
|
|
|
|
|
|
% Define unsubsumed mutexes
|
|
|
|
|
2016-11-14 16:56:51 +01:00
|
|
|
mutex(G,X) :- mutexGroup(G), contains(G,X,V), fluent(X,V).
|
|
|
|
mutex(G) :- mutexGroup(G), #count{X : mutex(G,X)} > 1.
|
2016-11-14 12:00:14 +01:00
|
|
|
|
|
|
|
% Define initial state
|
|
|
|
|
|
|
|
holds(X,V,0) :- initialState(X,V), fluent(X).
|
|
|
|
|
2016-11-14 16:56:51 +01:00
|
|
|
:- fluent(X), #count{V : holds(X,V,0)} > 1.
|
|
|
|
:- mutex(G), #count{X,V : holds(X,V,0), contains(G,X,V)} > 1.
|
2016-11-14 12:00:14 +01:00
|
|
|
|
|
|
|
% STEP PROGRAM
|
|
|
|
|
|
|
|
#program step(t).
|
|
|
|
|
|
|
|
% Generate successor state
|
|
|
|
|
|
|
|
1 {holds(X,V,t) : fluent(X,V)} 1 :- fluent(X).
|
|
|
|
|
2016-11-14 16:56:51 +01:00
|
|
|
:- mutex(G), #count{X,V : holds(X,V,t), contains(G,X,V)} > 1.
|
2016-11-14 12:00:14 +01:00
|
|
|
|
2016-11-14 16:56:51 +01:00
|
|
|
change(X,t) :- holds(X,V,t-1), not holds(X,V,t).
|
2016-11-14 12:00:14 +01:00
|
|
|
|
|
|
|
% Generate actions
|
|
|
|
|
2017-01-18 15:45:12 +01:00
|
|
|
{occurs(A,t)} :- active(A).
|
2017-01-16 17:15:19 +01:00
|
|
|
|
2017-01-17 17:15:21 +01:00
|
|
|
:- planner_on = 0, not occurs(A,t) : active(A).
|
2016-11-14 12:00:14 +01:00
|
|
|
|
|
|
|
:- occurs(A,t), postcondition(A,X,V), fluent(X), not holds(X,V,t).
|
|
|
|
|
|
|
|
effect(X,t) :- occurs(A,t), postcondition(A,X,V), fluent(X), not precondition(A,X,V).
|
|
|
|
|
|
|
|
:- change(X,t), not effect(X,t).
|
|
|
|
|
2016-11-14 16:56:51 +01:00
|
|
|
% Checks w.r.t. parallel mode
|
2016-11-14 12:00:14 +01:00
|
|
|
|
2017-01-16 17:15:19 +01:00
|
|
|
:- _parallel != 1, _parallel != 2, _parallel != 3, _parallel != 4, #count{A : occurs(A,t)} > 1.
|
2016-11-14 12:00:14 +01:00
|
|
|
|
|
|
|
:- _parallel != 2, occurs(A,t), precondition(A,X,V), not holds(X,V,t-1).
|
|
|
|
|
2016-11-14 16:56:51 +01:00
|
|
|
:- _parallel = 1, occurs(A,t), precondition(A,X,V), not has_condition(A,X,1), not holds(X,V,t).
|
|
|
|
|
2017-01-17 13:31:34 +01:00
|
|
|
single(X,t) :- occurs(A,t), selfdefeat(A,X).
|
2016-11-14 16:56:51 +01:00
|
|
|
|
|
|
|
:- single(X,t), #count{A : occurs(A,t), postcondition(A,X,V), not precondition(A,X,V)} > 1.
|
2016-11-14 12:00:14 +01:00
|
|
|
|
2016-11-14 16:56:51 +01:00
|
|
|
proceed(X,V,t) :- holds(X,V,t-1), scope(X,V).
|
2017-01-17 19:52:12 +01:00
|
|
|
proceed(X,V,t) :- perform(A,t), scope(X,V), postcondition(A,X,V), not precondition(A,X,V),
|
|
|
|
occurs(A,t).
|
2016-11-14 12:00:14 +01:00
|
|
|
|
2017-01-17 19:52:12 +01:00
|
|
|
perform(A,t) :- active(A), 1 < _parallel, _parallel < 4,
|
|
|
|
proceed(X,V,t) : precondition(A,X,V), _parallel = 2;
|
|
|
|
alright(A1,t) : disable(A,A1).
|
2017-01-16 17:15:19 +01:00
|
|
|
|
2017-01-17 19:52:12 +01:00
|
|
|
alright(A,t) :- active(A), 1 < _parallel, _parallel < 4, not occurs(A,t).
|
|
|
|
alright(A,t) :- perform(A,t).
|
|
|
|
|
|
|
|
:- 1 < _parallel, _parallel < 4, active(A), not alright(A,t).
|
2016-11-14 12:00:14 +01:00
|
|
|
|
2017-01-17 10:12:37 +01:00
|
|
|
#edge((A1,t),(A2,t)) : disable(A1,A2), occurs(A1,t), _parallel = 4, not disable.
|
|
|
|
#edge((A1,t),(A2,t)) : disable(A1,A2), occurs(A2,t), disable.
|
2016-11-14 12:00:14 +01:00
|
|
|
|
|
|
|
% CHECK PROGRAM
|
|
|
|
|
|
|
|
#program check(t).
|
|
|
|
|
|
|
|
% Check goal conditions
|
|
|
|
|
|
|
|
:- query(t), goal(X,V), not holds(X,V,t).
|
|
|
|
|
|
|
|
% DISPLAY PART
|
|
|
|
|
|
|
|
#show occurs/2.
|