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

frpGUI(varargin)
function varargout = frpGUI(varargin)
% FRPGUI M-file for frpGUI.fig
%      FRPGUI, by itself, creates a new FRPGUI or raises the existing
%      singleton*.
%
%      H = FRPGUI returns the handle to a new FRPGUI or the handle to
%      the existing singleton*.
%
%      FRPGUI('Property','Value',...) creates a new FRPGUI using the
%      given property value pairs. Unrecognized properties are passed via
%      varargin to frpGUI_OpeningFcn.  This calling syntax produces a
%      warning when there is an existing singleton*.
%
%      FRPGUI('CALLBACK') and FRPGUI('CALLBACK',hObject,...) call the
%      local function named CALLBACK in FRPGUI.M with the given input
%      arguments.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help frpGUI

% Last Modified by GUIDE v2.5 07-Oct-2006 17:03:44

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @frpGUI_OpeningFcn, ...
                   'gui_OutputFcn',  @frpGUI_OutputFcn, ...
                   'gui_LayoutFcn',  [], ...
                   'gui_Callback',   []);
if nargin & isstr(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before frpGUI is made visible.
function frpGUI_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   unrecognized PropertyName/PropertyValue pairs from the
%            command line (see VARARGIN)

% Choose default command line output for frpGUI
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes frpGUI wait for user response (see UIRESUME)
% uiwait(handles.figure1);

% First, we shall copy all necessary data from the global 'g_ctmGUI' structure

global g_ctmGUI;  % MUST (!) exist - the call to 'frpGUI' is initiated from 'ctmGUI'
global g_frpGUI;

g_frpGUI.configFile = g_ctmGUI.configFile;
g_frpGUI.cellData   = g_ctmGUI.cellData;
g_frpGUI.pmData     = g_ctmGUI.pmData;
g_frpGUI.freeway    = g_ctmGUI.freeway;

g_frpGUI.cellIndex  = 1;

xmin = g_frpGUI.cellData(1).PMstart;
xmax = g_frpGUI.cellData(end).PMend;
if xmin <= xmax
  g_frpGUI.xLims = [xmin xmax];
else
  g_frpGUI.xLims = [xmax xmin];
end

g_frpGUI.OK = 0;

NC          = size(g_frpGUI.cellData, 2);
[orl, frl]  = get_ramp_lists(g_frpGUI.cellData);

set(handles.cellList, 'String', frl);
set(handles.header, 'String', [g_frpGUI.freeway ' off-ramp parameters']);

axes(handles.direction);
if g_frpGUI.cellData(1).PMstart <= g_frpGUI.cellData(1).PMend
  image(imread('lr.jpg'));
else
  image(imread('rl.jpg'));
end
axis off;

axes(handles.freeway);
plotbar(g_frpGUI.pmData, 0.5*ones(1, NC), 'w');
hold on;
plotbar([g_frpGUI.pmData(1) g_frpGUI.pmData(2)], 0.5, 'k');
plot(g_frpGUI.pmData(2), 0.75, 'c^', 'MarkerFaceColor', 'c');
axis([g_frpGUI.xLims 0 1]);
xlabel('Post mile');
set(handles.freeway, 'YTick', []);
hold off

if isempty(g_frpGUI.cellData(1).FRname)
  str = 'Cell 1: no off-ramp';
  set(handles.fmaxTxt, 'String', '');
  set(handles.fmaxTxt, 'Enable', 'off');
  set(handles.frknobTxt, 'String', '');
  set(handles.frknobTxt, 'Enable', 'off');
else
  if g_frpGUI.cellData(1).FRlanes > 1
    str = sprintf('%s: %d lanes', g_frpGUI.cellData(1).FRname, g_frpGUI.cellData(1).FRlanes);
  else
    str = sprintf('%s: 1 lane', g_frpGUI.cellData(1).FRname);
  end
  set(handles.fmaxTxt, 'Enable', 'on');
  set(handles.fmaxTxt, 'String', num2str(g_frpGUI.cellData(1).FRfmax));
  set(handles.frknobTxt, 'Enable', 'on');
  set(handles.frknobTxt, 'String', num2str(g_frpGUI.cellData(1).FRknob));
end

set(handles.cellTxt, 'String', str);

return;





% --- Outputs from this function are returned to the command line.
function varargout = frpGUI_OutputFcn(hObject, eventdata, handles)
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;





% --- Executes during object creation, after setting all properties.
function cellList_CreateFcn(hObject, eventdata, handles)
% hObject    handle to cellList (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called
% Hint: listbox controls usually have a white background on Windows.
%       See ISPC and COMPUTER.

% --- Executes on selection change in cellList.
function cellList_Callback(hObject, eventdata, handles)
% hObject    handle to cellList (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% Hints: contents = get(hObject,'String') returns cellList contents as cell array
%        contents{get(hObject,'Value')} returns selected item from cellList

global g_frpGUI;

axes(handles.freeway);
plotbar(g_frpGUI.pmData, 0.5*ones(1, size(g_frpGUI.cellData, 2)), 'w');
hold on;
idx = get(hObject, 'Value');
plotbar([g_frpGUI.pmData(idx) g_frpGUI.pmData(idx+1)], 0.5, 'k');
plot(g_frpGUI.pmData(idx + 1), 0.75, 'c^', 'MarkerFaceColor', 'c');
axis([g_frpGUI.xLims 0 1]);
xlabel('Post mile');
set(handles.freeway, 'YTick', []);
hold off;

if isempty(g_frpGUI.cellData(idx).FRname)
  str = sprintf('Cell %d: no off-ramp', idx);
  set(handles.fmaxTxt, 'String', '');
  set(handles.fmaxTxt, 'Enable', 'off');
  set(handles.frknobTxt, 'String', '');
  set(handles.frknobTxt, 'Enable', 'off');
else
  if g_frpGUI.cellData(idx).FRlanes > 1
    str = sprintf('%s: %d lanes', g_frpGUI.cellData(idx).FRname, g_frpGUI.cellData(idx).FRlanes);
  else
    str = sprintf('%s: 1 lane', g_frpGUI.cellData(idx).FRname);
  end
  set(handles.fmaxTxt, 'Enable', 'on');
  set(handles.fmaxTxt, 'String', num2str(g_frpGUI.cellData(idx).FRfmax));
  set(handles.frknobTxt, 'Enable', 'on');
  set(handles.frknobTxt, 'String', num2str(g_frpGUI.cellData(idx).FRknob));
end

set(handles.cellTxt, 'String', str);

g_frpGUI.cellIndex = idx;

return;





% --- Executes on button press in saveButton.
function saveButton_Callback(hObject, eventdata, handles)
% hObject    handle to saveButton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

global g_frpGUI;

save_frparams(g_frpGUI.cellData, g_frpGUI.configFile);

return;



% --- Executes on button press in cancelButton.
function cancelButton_Callback(hObject, eventdata, handles)
% hObject    handle to cancelButton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

frpGUIclose;

return;



% --- Executes on button press in okButton.
function okButton_Callback(hObject, eventdata, handles)
% hObject    handle to okButton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

global g_frpGUI;

g_frpGUI.OK = 1;

frpGUIclose;

return;



% --- Executes during object creation, after setting all properties.
function fmaxTxt_CreateFcn(hObject, eventdata, handles)
% hObject    handle to fmaxTxt (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.

function fmaxTxt_Callback(hObject, eventdata, handles)
% hObject    handle to fmaxTxt (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of fmaxTxt as text
%        str2double(get(hObject,'String')) returns contents of fmaxTxt as a double

global g_frpGUI;

v = str2double(get(hObject, 'String'));

if v >= 0
  g_frpGUI.cellData(g_frpGUI.cellIndex).FRfmax = v;
else
  set(hObject, 'String', num2str(g_frpGUI.cellData(g_frpGUI.cellIndex).FRfmax));
end

return;



% --- Executes during object creation, after setting all properties.
function frknobTxt_CreateFcn(hObject, eventdata, handles)
% hObject    handle to frknobTxt (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.

function frknobTxt_Callback(hObject, eventdata, handles)
% hObject    handle to frknobTxt (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of frknobTxt as text
%        str2double(get(hObject,'String')) returns contents of frknobTxt as a double

global g_frpGUI;

v = str2double(get(hObject, 'String'));

if v >= 0
  g_frpGUI.cellData(g_frpGUI.cellIndex).FRknob = v;
else
  set(hObject, 'String', num2str(g_frpGUI.cellData(g_frpGUI.cellIndex).FRknob));
end

return;





% --- Executes on button press in applytoallButton.
function applytoallButton_Callback(hObject, eventdata, handles)
% hObject    handle to applytoallButton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

global g_frpGUI;

fm = g_frpGUI.cellData(g_frpGUI.cellIndex).FRfmax;
fc = g_frpGUI.cellData(g_frpGUI.cellIndex).FRknob;

N  = size(g_frpGUI.cellData, 2);

for i = 1:N
  if ~isempty(g_frpGUI.cellData(i).FRname)
    g_frpGUI.cellData(i).FRfmax = fm;
    g_frpGUI.cellData(i).FRknob = fc;
  end
end

return;

Contact us at files@mathworks.com