2016-11-20 23:52:55 +01:00
|
|
|
#const horizon=1.
|
|
|
|
|
2017-06-28 16:41:31 +02:00
|
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
2016-11-20 23:52:55 +01:00
|
|
|
% Horizon, must be defined externally
|
2017-06-28 16:41:31 +02:00
|
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
|
|
|
2016-11-20 23:52:55 +01:00
|
|
|
time(0..horizon).
|
|
|
|
|
2017-06-28 16:41:31 +02:00
|
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
2016-11-20 23:52:55 +01:00
|
|
|
% Establish initial state
|
2017-06-28 16:41:31 +02:00
|
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
|
|
|
2016-11-20 23:52:55 +01:00
|
|
|
holds(Variable, Value, 0) :- initialState(Variable, Value).
|
|
|
|
|
2017-06-28 16:41:31 +02:00
|
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
|
|
% Compute derived predicates
|
|
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
|
|
|
|
|
|
% conjunctive preconditions
|
2017-11-17 17:32:05 +01:00
|
|
|
satisfied(DerivedPredicate, type(and), T) :- derivedPredicate(DerivedPredicate, type(and)), holds(Variable, Value, T) : precondition(DerivedPredicate, type(and), Variable, Value); time(T).
|
2017-06-28 16:41:31 +02:00
|
|
|
|
|
|
|
% disjunctive preconditions
|
2017-11-17 17:32:05 +01:00
|
|
|
satisfied(DerivedPredicate, type(or), T) :- precondition(DerivedPredicate, type(or), Variable, Value), holds(Variable, Value, T), time(T).
|
2017-06-28 16:41:31 +02:00
|
|
|
|
|
|
|
holds(DerivedVariable, Value, T) :- satisfied(DerivedPredicate, Type, T), postcondition(DerivedPredicate, Type, effect(unconditional), DerivedVariable, Value).
|
|
|
|
|
2017-11-17 17:32:05 +01:00
|
|
|
holds(derivedVariable(DerivedVariable), value(DerivedVariable, false), T) :- derivedVariable(DerivedVariable), not holds(derivedVariable(DerivedVariable), value(DerivedVariable, true), T), time(T).
|
2017-06-28 16:41:31 +02:00
|
|
|
|
|
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
2016-11-20 23:52:55 +01:00
|
|
|
% Perform actions
|
2017-06-28 16:41:31 +02:00
|
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
|
|
|
2016-11-20 23:52:55 +01:00
|
|
|
1 {occurs(Action, T) : action(Action)} 1 :- time(T), T > 0.
|
|
|
|
|
|
|
|
% Check preconditions
|
2017-06-28 16:41:31 +02:00
|
|
|
:- occurs(Action, T), precondition(Action, Variable, Value), not holds(Variable, Value, T - 1).
|
2016-11-20 23:52:55 +01:00
|
|
|
|
|
|
|
% Apply effects
|
2017-06-28 16:41:31 +02:00
|
|
|
caused(Variable, Value, T) :-
|
|
|
|
occurs(Action, T),
|
|
|
|
postcondition(Action, Effect, Variable, Value),
|
|
|
|
holds(VariablePre, ValuePre, T - 1) : precondition(Effect, VariablePre, ValuePre).
|
|
|
|
|
|
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
|
|
% Inertia rules
|
|
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
|
|
|
2017-11-17 17:34:16 +01:00
|
|
|
modified(Variable, T) :- caused(Variable, Value, T).
|
2016-11-20 23:52:55 +01:00
|
|
|
|
2017-06-28 16:41:31 +02:00
|
|
|
holds(Variable, Value, T) :- caused(Variable, Value, T).
|
2017-11-17 17:43:44 +01:00
|
|
|
holds(variable(V), Value, T) :- holds(variable(V), Value, T - 1), not modified(variable(V), T), time(T).
|
2017-06-28 16:41:31 +02:00
|
|
|
|
|
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
|
|
% Variables and mutex groups
|
|
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
2016-11-20 23:52:55 +01:00
|
|
|
|
|
|
|
% Check that variables have unique values
|
|
|
|
:- variable(Variable), not 1 {holds(Variable, Value, T) : contains(Variable, Value)} 1, time(T).
|
|
|
|
|
|
|
|
% Check mutexes
|
|
|
|
:- mutexGroup(MutexGroup), not {holds(Variable, Value, T) : contains(MutexGroup, Variable, Value)} 1, time(T).
|
|
|
|
|
2017-06-28 16:41:31 +02:00
|
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
2016-11-20 23:52:55 +01:00
|
|
|
% Verify that goal is met
|
2017-06-28 16:41:31 +02:00
|
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
|
|
|
2016-11-20 23:52:55 +01:00
|
|
|
:- goal(Variable, Value), not holds(Variable, Value, horizon).
|
|
|
|
|
2017-06-28 16:41:31 +02:00
|
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
|
|
|
2016-11-20 23:52:55 +01:00
|
|
|
#show occurs/2.
|