function [requests,times] = LEM_gen_requests_cells(t_min,t_max,cells,...
    num_requests,launch_interval,speeds,min_alt,max_alt)
% LEM_gen_requests_cells - generate a set of flight requests for cells
% On input:
%     t_min (float): earliest start time for flight
%     t_max (float): latest start time for flight
%     cells (cells struct): cells info
%     num_requests (int): number of requested flights
%     launch_interval (float): time spread for posisble launch
%     speeds (1x2 vector): [min_speed, max_speed]
%     min_alt (float): minimum altitude for flight
%     max_alt (float): max altitude for flight
% On output:
%     requests (requests struct): request info
%      (k).request_time (float): time request is submitted
%      (k).launch_interval (1x2 vector): [earliest time, latest time]
%      (k).speed (float): desired average speed (uniform from speeds)
%      (k).path (nx6 array): endpts of flight path line segments
%      (k).launch_index (int): index in airways.launch_lane_vertexes
%      (k).land_index (int): index in airways.land_lane_vertexes
% Call:
%     req = LEM_gen_requests_cells(0,10,cells,10,4,[20,30],467,530);
% Author:
%     T. Henderson
%     UU
%     Fall 2020
%

time_spread = t_max - t_min;
alt_spread = max_alt - min_alt;
arrival_times = sort(t_min + rand(num_requests,1)*time_spread);
min_speed = min(speeds);
speed_spread = max(speeds) - min_speed;
num_requests = length(arrival_times);
times = zeros(num_requests,1);
launch_sites = cells.launch_sites;
num_launch_sites = length(launch_sites);
land_sites = cells.land_sites;
num_land_sites = length(land_sites);

for r = 1:num_requests
    requests(r).request_time = arrival_times(r);
    t1 = requests(r).request_time;
    times(r) = t1;
    t2 = t1 + launch_interval;
    requests(r).launch_interval = [t1,t2];
    requests(r).speed = min_speed + rand*speed_spread;
    launch_index = randi(num_launch_sites);
    land_index = randi(num_land_sites);
    alt = min_alt + rand*alt_spread;
    path = zeros(3,6);
    pt1 = [launch_sites(launch_index,:),0];
    pt2 = [pt1(1:2),alt];
    pt4 = [land_sites(land_index,:),0];
    pt3 = [pt4(1:2),alt];
    path = [pt1 pt2; pt2 pt3; pt3 pt4];
    requests(r).path = path;
    requests(r).launch_index = launch_index;
    requests(r).land_index = land_index;
end

tch = 0;
