function res = LEM_FAA1_driver(num_trials)
% LEM_FAA1_driver - produce earthquake scenario data for FAA emthod
% On input:
%     roads (roads struct): road info (loaded file)
%       .vertexes (nx3 aray): road interections or endpoints
%       .edges (kx2 aray): vertex index pairs for roads between vertexes
%     num_trials (int): number of trial runs to average
% On output:
%     res (4x12 array): results info
%       col  1: number of deliveries
%       col  2: number of depots
%       col  3: number of UAS
%       col  4: UAS speed
%       col  5: mean delay (seconds)
%       col  6: variance of delay
%       col  7: mean of max delay (seconds)
%       col  8: variance of max
%       col  9: mean deconfiction time
%       col 10: variance of deconfliction time
%       col 11: mean of max deconfliction times
%       col 12: variance of max deconfliction time
% Call:
%     res = LEM_FAA1_driver(10);
% Author:
%     T. Henderson
%     UU
%     Spring 2021
%

res = zeros(4,12);

load('roads_EQ_scenario.mat');

rng('default');
[num_vertexes,dummy] = size(roads.vertexes);
p = randperm(num_vertexes);
num_UAS = 500;
hd = 6;

res(:,1) = 6;
res(:,2) = 10;
res(3:4,2) = 50;
res(:,3) = 500;
res(1:2:4,4) = 30;
res(2:2:4,4) = 60;
params = [
    6,10,500,30;...
    6,10,500,60;...
    6,50,500,30;...
    6,50,500,60;...
    3,10,1000,30;...
    3,10,1000,60;...
    3,50,1000,30;...
    3,50,1000,60];

wb = waitbar(0,'FAA')
for count = 1:8
    waitbar(count/8);
    num_deliveries = params(count,1);
    num_depots = params(count,2);
    num_UAS = params(count,3);
    s = params(count,4);
    depots = p(1:num_depots);
    trial_data = zeros(num_trials,4);
    for t = 1:num_trials
        res_FAA = LEM_EQ_FAA1(roads.vertexes,depots,num_deliveries,...
            num_UAS,s,hd,0,count,t);
        P = LEM_performance(res_FAA.flights);
        trial_data(t,1) = mean(P(:,2));
        trial_data(t,2) = max(P(:,2));
        trial_data(t,3) = mean(P(:,4));
        trial_data(t,4) = max(P(:,4));
    end
    res(count,1) = num_deliveries;
    res(count,2) = num_depots;
    res(count,3) = num_UAS;
    res(count,4) = s;
    res(count,5) = mean(trial_data(:,1));
    res(count,6) = var(trial_data(:,1));
    res(count,7) = mean(trial_data(:,2));
    res(count,8) = var(trial_data(:,2));
    res(count,9) = mean(trial_data(:,3));
    res(count,10) = var(trial_data(:,3));
    res(count,11) = mean(trial_data(:,4));
    res(count,12) = var(trial_data(:,4));
end
close(wb);
tch = 0;
