function res = LEM_sim1
% LEM_sim1 - basic small-scale simulation comparing LBSD vs FAA-NASA
% On input:
%     N/A
% On output:
%     res (results struct): results info
%       .roads (roads struct): roads info
%       .airways (airways struct): airways info
%       .requests (requests struct): LBSD requests
%       .reservations (reservations struct): reservations info
%       .flights (flights struct): flights info
%       .failures_LBSD (n by 1 vector): 0 if LBSD flight success; else 1
%       .flights_cells (flights struct): cells flight info
%       .cells (cells struct): FAA-NASA cells corresponding to LBSD layout
%       .requests_cells (requests_cells struct): FAA-NASA flight requests 
%       P_LBSD (nx5 array): performance info for LBSD
%         col 1 (float): 
%         col 2 (float): delay (actual_start - requested_min_start)
%         col 3 (float): 
%         col 4 (float): deconflict time
%         col 5 (float): 
%     P_cells (nx5 array): performance info for cells
%        cols: same as LBSD
%       .failures_cells (n by 1 vector): 0 if cells flight success; else 1
% Call:
%     res = LEM_sim1;
% Author:
%     T. Henderson
%     UU
%     Fall 2020
%

FAILED = 0;

res = [];

rng('default');
roads = LEM_gen_grid_roads(0,50,0,50,10,10);
launch_sites = [1:6];
land_sites = [31:36];
airways = LEM_gen_airways(roads,launch_sites,land_sites,2);

num_flights = 100;
requests = LEM_gen_requests_LBSD(0,100,airways,num_flights,120,[10,10]);
[reservations,flights] = LEM_requests2reservations(airways,requests,1);

del_t = 0.1;
for f = 1:num_flights
    f_out = LEM_gen_traj(flights(f),del_t);
    flights(f).traj = f_out.traj;
end

%M = LEM_run_flights(airways,flights,1,0.1);

res.roads = roads;
res.airways = airways;
res.requests = requests;
res.reservations = reservations;
res.flights = flights;
failures_LBSD = zeros(num_flights,1);
for f = 1:num_flights
    if flights(f).type==FAILED
        failures_LBSD(f) = 1;
    end
end
res.failures_LBSD = failures_LBSD;
return

%res.M = M;

% cells version
[cells,requests_cells] = LEM_requests_LBSD2cells(requests,airways,467,...
    534,1,1,1);
flights_cells = LEM_requests2cells(requests_cells,cells,1,0.5);
num_flights_cells = length(flights_cells);
del_t = 0.1;
for f = 1:num_flights_cells
    f_out = LEM_gen_traj(flights_cells(f),del_t);
    flights_cells(f).traj = f_out.traj;
end

%M = LEM_run_flights(airways,flights_cells,0,0.1);

P_LBSD = LEM_performance(flights);
P_cells = LEM_performance(flights_cells);
res.flights_cells = flights_cells;
res.cells = cells;
res.requests_cells = requests_cells;
res.P_LBSD = P_LBSD;
res.P_cells = P_cells;
failures_cells = zeros(num_flights,1);
for f = 1:num_flights
    if flights_cells(f).type==FAILED
        failures_cells(f) = 1;
    end
end
res.failures_cells = failures_cells;

tch = 0;
