function res = LEM_sim1_FAA_NASA
% LEM_sim1_FAA_NASA - basic small-scale simulation of FAA-NASA method
% On input:
%     N/A
% On output:
%     sim1_FAA_NASA (mp4 file): visualization of flights
%     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_LBSD;
% 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);
min_altitude = 467;
max_altitude = 524;
del_x = 1;
del_y = 1;
del_t = 0.5;
hd = 1;

num_flights = 100;
requests = LEM_gen_requests_LBSD(0,100,airways,num_flights,120,[10,10]);

[cells,requests_cells] = LEM_requests_LBSD2cells(requests,airways,...
    min_altitude,max_altitude,del_x,del_y,hd);
flights_cells = LEM_requests2cells(requests_cells,cells,hd,del_t);
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

LEM_run_flights(airways,flights_cells,-1,1,'sim1_FAA_NASA');

P = LEM_performance(flights_cells);

res.roads = roads;
res.airways = airways;
res.requests = requests;
res.reservations = [];
res.flights = [];
failures_LBSD = [];
res.failures_LBSD = failures_LBSD;
res.mp4 = 'sim1_FAA_NASA.mp4';
res.P_cells = P;
res.P_LBSD = [];
res.flights_cells = flights_cells;
res.cells = cells;
res.requests_cells = requests_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;
