function constraint_lanes = LEM_constraint_lanes(lanes)
% LEM_constraint_lanes - lanes into and out of lane entry and exit points
% On input:
%     lanes (nx6 array): lane endpoints
% On output:
%     constraint_lanes (constrint sturct): constraint info
%       (k).c_lanes (mx1 vector): lanes connected to lane k
% Call:
%     cl = LEM_constraint_lanes(airways.lanes);
% Author:
%     T. Henderson
%     UU
%     Spring 2023
%

[num_lanes,~] = size(lanes);

for k = 1:num_lanes
    p1 = lanes(k,1:3);
    p2 = lanes(k,4:6);
    in_p1 = find(lanes(:,4)==p1(1)&lanes(:,5)==p1(2)&lanes(:,6)==p1(3));
    out_p1 = find(lanes(:,1)==p1(1)&lanes(:,2)==p1(2)&lanes(:,3)==p1(3));
    in_p2 = find(lanes(:,4)==p2(1)&lanes(:,5)==p2(2)&lanes(:,6)==p2(3));
    out_p2 = find(lanes(:,1)==p2(1)&lanes(:,2)==p2(2)&lanes(:,3)==p2(3));
    c_lanes = unique([in_p1;out_p1;in_p2;out_p2]');
    constraint_lanes(k).c_lanes = c_lanes;
end

tch = 0;
