Code covered by the BSD License  

Highlights from
CTMSIM - an interactive freeway traffic macrosimulator

image thumbnail
from CTMSIM - an interactive freeway traffic macrosimulator by Alex Kurzhanskiy
Freeway traffic simulation based on Asymmetric Cell Transmission Model

adjust_or_flows(densities, orflows, celldata, ts)
function flows = adjust_or_flows(densities, orflows, celldata, ts)
% ADJUST_OR_FLOWS - make sure on-ramp flows do not exceed allowed limits.
%
% Call:   flows = adjust_or_flows(densities, orflows, celldata, ts)
%
% Parameters:
%             densities - vector of densities;
%             orflows   - vector of on-ramp flows, same size as 'densities';
%             celldata  - array of freeway cell structures whose length must be
%                         the same as size of 'densities';
%             ts        - sampling period.
%
% Returns:   flows - vector of adjusted on-ramp flows;
%
% Last modified:   09/29/2006.

%
% Alex Kurzhanskiy   <akurzhan@eecs.berkeley.edu>
%

L = size(densities, 1);
M = size(orflows, 1);
N = size(celldata, 2);

if L ~= N
  error('ADJUST_OR_FLOWS: number of densities does not match number of cells.');
end

if M ~= N
  error('ADJUST_OR_FLOWS: number of on-ramp flows does not match number of cells.');
end

flows = [];

for i = 1:N
  % cell length
  l     = abs(celldata(i).PMend - celldata(i).PMstart);
  % available main line capacity
  dn    = celldata(i).ORxi * (celldata(i).FDrhojam - densities(i, 1)) * (l/ts);

  flows = [flows; min([dn celldata(i).ORfmax orflows(i, 1)])];
end

return;

Contact us at files@mathworks.com