%% Translation of theory.e (F2LP) into ASP encoding using f2lp-1.11
%% with an adaption by Joaquin Arias to run it using clingo 5.2.0:
%% - #domain is substituted by adding timestep/1 in each rule (to make them safe).
%% - #hide is substitute by #show


%% BEC1 - StoppedIn(t1,f,t2)
stoppedIn(T1,Fluent,T2) :- timestep(T1), timestep(T2), terminates(Event,Fluent,T),happens(Event,T),T1<T,T<T2.
stoppedIn(T1,Fluent,T2) :- timestep(T1), timestep(T2), releases(Event,Fluent,T),happens(Event,T),T1<T,T<T2.

%% BEC2 - StartedIn(t1,f,t2)
startedIn(T1,Fluent,T2) :- timestep(T1), timestep(T2), initiates(Event,Fluent,T),happens(Event,T),T1<T,T<T2.
startedIn(T1,Fluent,T2) :- timestep(T1), timestep(T2), releases(Event,Fluent,T),happens(Event,T),T1<T,T<T2.

%% BEC3 - HoldsAt(f,t)
holdsAt(Fluent2,T2) :- timestep(T1), happens(Event,T1),initiates(Event,Fluent1,T1),trajectory(Fluent1,T1,Fluent2,T2),not stoppedIn(T1,Fluent1,T2).

%% BEC4 - HoldsAt(f,t)
holdsAt(Fluent,T) :- timestep(T), initiallyP(Fluent),not stoppedIn(0,Fluent,T).

%% BEC5 - not HoldsAt(f,t)
:- timestep(T), {not holdsAt(Fluent,T)}0,initiallyN(Fluent),not startedIn(0,Fluent,T).

%% BEC6 - HoldsAt(f,t)
holdsAt(Fluent,T) :- timestep(T), happens(Event,T1),initiates(Event,Fluent,T1),T1<T,not stoppedIn(T1,Fluent,T).

%% BEC7 - not HoldsAt(f,t)
:- timestep(T), {not holdsAt(Fluent,T)}0,happens(Event,T1),terminates(Event,Fluent,T1),T1<T,not startedIn(T1,Fluent,T).
