% Input:
% L: Matrix (row-wise direction vectors)
% psidelta: function handle (support function)
% delta: double (sampling time)
% A: Matrix (defining the flow equation)
% Omega0delta: function handle (over approximated support function of the initial set)
% N: Integer (number of sets to generate)

% Ouput:
% results: Matrix (containing the evaluation in directions L for each set)

% Description:
% Computes the evaluations of the flowpipe starting with the first set
% Omegadelta0 to N for the procedure from "SpaceEx: Scalale Verification of Hybrid Systems"

function [results] = evaluateSpaceEx(L,psidelta,delta,A,Omega0delta,N)

results = zeros(size(L,1),N);
eA = expm(delta*A);

parfor j=1:size(L,1)

    etA = 1;
    psi = 0;    
    l = L(j,:)';
    
    results(j,:) = parallelizationHelper(N,etA,eA,psi,psidelta,l,Omega0delta)
  
end;

% Description:
% Method to make the parallel evaluation of evaluateSpaceEx possible
function [res] = parallelizationHelper(N,etA,eA,psi,psidelta,l,Omega0delta)
res = zeros(1,N);
res(1) = Omega0delta(l);

for i = 2:1:N
        etA = etA * eA;
        psi = psi + psidelta( etA' * l); 
        res(i) = Omega0delta(etA' * l) + psi;
end;