function clrs = get_color_grade(densities, flows, celldata, a)
% GET_COLOR_GRADE - returns array of colors that corresponds to the array of
% densities: green means free flow, red means congested.
%
% Call:
% clrs = get_color_grade(densities, flows, celldata)
% clrs = get_color_grade(densities, flows, celldata, a)
%
% Parameters:
% densities - vector of density values;
% flows - vector of flows, must be the same size as 'densities';
% celldata - array of freeway cell structures, whose length must be
% the same as size of 'densities' and 'flows';
% a - fraction of maximum flow used to determine
% yellow and orange colors (this parameter is optional,
% default value is 0.95).
%
% Returns: clrs - vertical array of colors.
%
% Last modified: 07/30/2006.
%
% Alex Kurzhanskiy <akurzhan@eecs.berkeley.edu>
%
G = [0 1 0]; % green
Y = [1 1 0]; % yellow
O = [1 0.4 0.07]; % orange
R = [0.8 0 0]; % red
if nargin < 4
c = [0.95 0.95]; % default: 95% of maximum flow
else
c = [a a];
end
m = size(densities, 1);
n = size(celldata, 2);
if m ~= n
error('GET_COLOR_GRADE: number of densities does not match number of cells.');
end
clrs = [];
for i = 1:n
if densities(i, 1) <= celldata(i).FDrhocrit
if flows(i, 1) <= (c(1) * celldata(i).FDfmax)
clrs = [clrs; G]; % free flow
else
clrs = [clrs; Y]; % free flow, but reaching more than 95% maximum capacity
end
else
if flows(i, 1) <= (c(2) * celldata(i).FDfmax)
clrs = [clrs; R]; % congested
else
clrs = [clrs; O]; % congested, but reaching more than 95% maximum capacity
end
end
end
return;