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_fr_flows(densities, frflows, celldata, ts)
function new_frflows = adjust_fr_flows(densities, frflows, celldata, ts)
% ADJUST_FR_FLOWS - adjust off-ramp flow values using off-ramp flow coefficients
%                   and make sure they do not exceed off-ramp capacities.
%
% Call:   new_frflows = adjust_fr_flows(densities, frflows, celldata, ts)
%
% Parameters:
%             densities - vector of densities;
%             frflows   - vector of off-ramp flows, same size as 'densities';
%             celldata  - array of freeway cell data structures, whose length
%                         must be the same as the size of 'densities' vector;
%             ts        - sampling period.
%
%
% Returns:   new_frflows - array of adjusted off-ramp flows.
%
% Last modified:   09/29/2006.

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

L = size(densities, 1);
M = size(frflows, 1);
N = size(celldata, 2);  % number of cells

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

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

new_frflows = [];

for i = 1:N
  l = abs(celldata(i).PMend - celldata(i).PMstart);  % cell length
  v = celldata(i).FDfmax / celldata(i).FDrhocrit;  % free-flow speed
  n = densities(i, 1) * l;  % number of vehicles
  r = celldata(i).ORgamma * celldata(i).ORflow * ts;  % number of vehicles from on-ramp
  if ~isempty(celldata(i).FRname)
    f = (v/l) * (n + r);
  else
    f = 0;
  end

  new_frflows = [new_frflows; min([celldata(i).FRfmax (celldata(i).FRknob*frflows(i, 1)) f])];
end

return;

Contact us at files@mathworks.com