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

assign_pm(celldata, pmstart, direction)
function new_cd = assign_pm(celldata, pmstart, direction)
% ASSIGN_PM - assign post miles to cells.
%
% Call:   new_cd = assign_pm(celldata, pmstart, direction)
%
% Parameters:
%             celldata  - array of freeway cell structures;
%             pmstart   - starting post mile;
%             direction - 1 specifies left to right, -1 - right to left.
%
% Returns:   new_cd - updated array of freeway cells.
%
% Last modified:   11/17/2006.

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

N      = size(celldata, 2);  % number of cells
pms    = pmstart;
new_cd = celldata;

for i = 1:N
  l                 = abs(new_cd(i).PMend - new_cd(i).PMstart);
  new_cd(i).PMstart = pms;
  new_cd(i).PMend   = new_cd(i).PMstart  +  (direction * l);
  pms               = new_cd(i).PMend;
end

return;

Contact us at files@mathworks.com