/***************************************************************** 
  FILE: cond.pl 
*****************************************************************/

all_preconditions_satisfied(Process, Instance) :- 

   writeln('--- calling all_preconditions_satisfied '), 

   dyn(agenda(process(Instance, Process/_PID, _Status, _Priority, 
               _Begin_time/_End_time, _Time_cost, 
               _Header, 
               _P_Trigger, Precond, _Action, _Postcond))), 

   test_all_cond(Precond).

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

all_postconditions_satisfied(Process, Instance) :- 

   writeln('--- calling all_postconditions_satisfied '), 

   dyn(agenda(process(Instance, Process/_PID, _Status, _Priority, 
               _Begin_time/_End_time, _Time_cost, 
               _Header, 
               _P_Trigger, _Precond, _Action, Postcond))), 

   test_all_cond(Postcond).

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
test_all_cond([]). 

test_all_cond([X| Rest]) :-

   writeln('--- calling test_all_cond '),
   writeln(X), 

   test_cond(X),

   writeln('--- condition succeed'), 

   test_all_cond(Rest). 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

test_cond(true). 

test_cond(X) :- 
   math_formula(List), 
   member(X, List), 
   X. 

test_cond(exist(X)) :-
   dyn(X). 

test_cond(not_exist(X)) :-
   \+ dyn(X). 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


