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

compute_speeds(densities, flows, frflows, celldata, outflow, ts)
function speeds = compute_speeds(densities, flows, frflows, celldata, outflow, ts)
% COMPUTE_SPEEDS - compute speeds from densities and flows.
%
% Call:   speeds = compute_speeds(densities, flows, frflows, celldata, outflow, ts)
%
% Parameters:
%             densities - vector of densities;
%             flows     - vector of flows, must have the same size as 'densities';
%             frflows   - vector of off-ramp flows, must have the same size as 'densities';
%             celldata  - array of cell data structures,
%                         whose length must be the same as size of 'densities';
%             outflow   - how much can be allowed through the right boundary;
%             ts        - sampling period.
%
% Returns:   speeds - vector of speeds.
%
% Last modified:   10/06/2006.

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

K = size(densities, 1);
L = size(flows, 1);
M = size(frflows, 1);
N = size(celldata, 2);  % row vector

if K ~= L
  error('COMPUTE_SPEEDS: number of densities does not match number of flows.');
end

if K ~= M
  error('COMPUTE_SPEEDS: number of densities does not match number of off-ramp flows.');
end

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

speeds = [];

for i = 1:N
  if densities(i, 1) <= 1e-7
    v = celldata(i).FDfmax / celldata(i).FDrhocrit;
  else
    if i == N
      v = get_rbflow(densities(N, 1), flows(N, 1), celldata(N), outflow, ts) / densities(i, 1);
    else
      v = (flows(i+1, 1) + frflows(i, 1)) / densities(i, 1);
    end
  end

  v = min([v (celldata(i).FDfmax / celldata(i).FDrhocrit)]);

  speeds = [speeds; v];
end

return;

Contact us at files@mathworks.com