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

plot_compare(pems, sim, ts)
function [vhth, vmth, delayh, plossh] = plot_compare(pems, sim, ts)
% PLOT_COMPARE - plots aggregate data - VHT, VMT, DELAY - comparing PEMS
%                values with values from CTMSIM.
%
% Call:
%       plot_compare(pems, sim, ts)
%       [vht, vmt, delay, ploss] = plot_compare(pems, sim, ts)
%
% Parameters:
%             pems - name of .mat file with PEMS data;
%             sim  - name of .mat file with saved CTMSIM simulation;
%             ts   - sampling time (in hours).
%
% Returns:
%          vht   - (optional) array of VHT values;
%          vmt   - (optional) array of VMT values;
%          delay - (optional) array of DELAY values.
%          ploss - (optional) array of PRODUCTIVITY LOSS values.
%             
% Last modified:   25/07/2007.

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

tt = 0:23;
C  = 1/ts;

load(pems);
load(sim);

s      = ctmGUI_data;

vht    = s.tvhData;
vmt    = s.tvmData;
delay  = s.cdelayData;
ploss  = s.cplossData;
vhth   = [];
vmth   = [];
delayh = [];
plossh = [];

for i = 0:23
  v1 = 0;
  v2 = 0;
  v3 = 0;
  v4 = 0;

  for j = 1:C
    v1 = v1 + vht(i*C + j);
    v2 = v2 + vmt(i*C + j);
    v3 = v3 + delay(i*C + j);
    v4 = v4 + ploss(i*C + j);
  end

  vhth   = [vhth v1];
  vmth   = [vmth v2];
  delayh = [delayh v3];
  plossh = [plossh v4];
end


if nargout > 3
  return;
elseif nargout > 2
  clear vmth delayh plossh;
  return;
elseif nargout > 1
  clear delayh plossh;
  return;
elseif nargout > 0
  clear plossh;
  return;
end


figure;
plot(tt, pemsH, '-b*'); hold on;
plot(tt, vhth, '-ro'); hold on;
legend('PEMS', 'CTMSIM');
xlabel('Time (hours)');
ylabel('VHT per hour');

figure;
plot(tt, pemsM, '-b*'); hold on;
plot(tt, vmth, '-ro'); hold on;
legend('PEMS', 'CTMSIM');
xlabel('Time (hours)');
ylabel('VMT per hour');

figure;
plot(tt, pemsD, '-b*'); hold on;
plot(tt, delayh, '-ro'); hold on;
legend('PEMS', 'CTMSIM');
xlabel('Time (hours)');
ylabel('Delay per hour');

figure;
plot(tt, pemsP, '-b*'); hold on;
plot(tt, plossh, '-ro'); hold on;
legend('PEMS', 'CTMSIM');
xlabel('Time (hours)');
ylabel('Productivity Loss per hour');

clear vhth vmth delayh plossh;


return;

Contact us at files@mathworks.com