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

orpGUI(varargin)
function varargout = orpGUI(varargin)
% ORPGUI M-file for orpGUI.fig
%      ORPGUI, by itself, creates a new ORPGUI or raises the existing
%      singleton*.
%
%      H = ORPGUI returns the handle to a new ORPGUI or the handle to
%      the existing singleton*.
%
%      ORPGUI('Property','Value',...) creates a new ORPGUI using the
%      given property value pairs. Unrecognized properties are passed via
%      varargin to orpGUI_OpeningFcn.  This calling syntax produces a
%      warning when there is an existing singleton*.
%
%      ORPGUI('CALLBACK') and ORPGUI('CALLBACK',hObject,...) call the
%      local function named CALLBACK in ORPGUI.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 orpGUI

% Last Modified by GUIDE v2.5 07-Oct-2006 17:02:00

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @orpGUI_OpeningFcn, ...
                   'gui_OutputFcn',  @orpGUI_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 orpGUI is made visible.
function orpGUI_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 orpGUI
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes orpGUI 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 'orpGUI' is initiated from 'ctmGUI'
global g_orpGUI;

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

g_orpGUI.cellIndex  = 1;

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

g_orpGUI.OK = 0;

NC          = size(g_orpGUI.cellData, 2);
orlst       = get_ramp_lists(g_orpGUI.cellData);
orlst       = orlst(2:(NC+1), :);  % remove in- and out- flow entries

set(handles.cellList, 'String', orlst);
set(handles.header, 'String', [g_orpGUI.freeway ' on-ramp parameters']);

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

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

if isempty(g_orpGUI.cellData(1).ORname)
  str = 'Cell 1: no on-ramp';
  set(handles.gammaTxt, 'String', '');
  set(handles.xiTxt, 'String', '');
  set(handles.fmaxTxt, 'String', '');
  set(handles.qmaxTxt, 'String', '');
  set(handles.orknobTxt, 'String', '');
  set(handles.gammaTxt, 'Enable', 'off');
  set(handles.xiTxt, 'Enable', 'off');
  set(handles.fmaxTxt, 'Enable', 'off');
  set(handles.qmaxTxt, 'Enable', 'off');
  set(handles.orknobTxt, 'Enable', 'off');
else
  if g_orpGUI.cellData(1).ORlanes > 1
    str = sprintf('%s: %d lanes', g_orpGUI.cellData(1).ORname, g_orpGUI.cellData(1).ORlanes);
  else
    str = sprintf('%s: 1 lane', g_orpGUI.cellData(1).ORname);
  end
  set(handles.gammaTxt, 'String', num2str(g_orpGUI.cellData(1).ORgamma));
  set(handles.xiTxt, 'String', num2str(g_orpGUI.cellData(1).ORxi));
  set(handles.fmaxTxt, 'String', num2str(g_orpGUI.cellData(1).ORfmax));
  set(handles.qmaxTxt, 'String', num2str(g_orpGUI.cellData(1).ORqsize));
  set(handles.orknobTxt, 'String', num2str(g_orpGUI.cellData(1).ORknob));
  set(handles.gammaTxt, 'Enable', 'on');
  set(handles.xiTxt, 'Enable', 'on');
  set(handles.fmaxTxt, 'Enable', 'on');
  set(handles.qmaxTxt, 'Enable', 'on');
  set(handles.orknobTxt, 'Enable', 'on');
end

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

return;





% --- Outputs from this function are returned to the command line.
function varargout = orpGUI_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_orpGUI;

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

if isempty(g_orpGUI.cellData(idx).ORname)
  str = sprintf('Cell %d: no on-ramp', idx);
  set(handles.gammaTxt, 'String', '');
  set(handles.xiTxt, 'String', '');
  set(handles.fmaxTxt, 'String', '');
  set(handles.qmaxTxt, 'String', '');
  set(handles.orknobTxt, 'String', '');
  set(handles.gammaTxt, 'Enable', 'off');
  set(handles.xiTxt, 'Enable', 'off');
  set(handles.fmaxTxt, 'Enable', 'off');
  set(handles.qmaxTxt, 'Enable', 'off');
  set(handles.orknobTxt, 'Enable', 'off');
else
  if g_orpGUI.cellData(idx).ORlanes > 1
    str = sprintf('%s: %d lanes', g_orpGUI.cellData(idx).ORname, g_orpGUI.cellData(idx).ORlanes);
  else
    str = sprintf('%s: 1 lane', g_orpGUI.cellData(idx).ORname);
  end
  set(handles.gammaTxt, 'String', num2str(g_orpGUI.cellData(idx).ORgamma));
  set(handles.xiTxt, 'String', num2str(g_orpGUI.cellData(idx).ORxi));
  set(handles.fmaxTxt, 'String', num2str(g_orpGUI.cellData(idx).ORfmax));
  set(handles.qmaxTxt, 'String', num2str(g_orpGUI.cellData(idx).ORqsize));
  set(handles.orknobTxt, 'String', num2str(g_orpGUI.cellData(idx).ORknob));
  set(handles.gammaTxt, 'Enable', 'on');
  set(handles.xiTxt, 'Enable', 'on');
  set(handles.fmaxTxt, 'Enable', 'on');
  set(handles.qmaxTxt, 'Enable', 'on');
  set(handles.orknobTxt, 'Enable', 'on');
end

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

g_orpGUI.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_orpGUI;

save_orparams(g_orpGUI.cellData, g_orpGUI.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)

orpGUIclose;

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_orpGUI;

g_orpGUI.OK = 1;

orpGUIclose;

return;





% --- Executes during object creation, after setting all properties.
function gammaTxt_CreateFcn(hObject, eventdata, handles)
% hObject    handle to gammaTxt (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 gammaTxt_Callback(hObject, eventdata, handles)
% hObject    handle to gammaTxt (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 gammaTxt as text
%        str2double(get(hObject,'String')) returns contents of gammaTxt as a double

global g_orpGUI;

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

if (v >= 0) & (v <= 1)
  g_orpGUI.cellData(g_orpGUI.cellIndex).ORgamma = v;
else
  set(hObject, 'String', num2str(g_orpGUI.cellData(g_orpGUI.cellIndex).ORgamma));
end

return;



% --- Executes during object creation, after setting all properties.
function xiTxt_CreateFcn(hObject, eventdata, handles)
% hObject    handle to xiTxt (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 xiTxt_Callback(hObject, eventdata, handles)
% hObject    handle to xiTxt (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 xiTxt as text
%        str2double(get(hObject,'String')) returns contents of xiTxt as a double

global g_orpGUI;

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

if (v >= 0) & (v <= 1)
  g_orpGUI.cellData(g_orpGUI.cellIndex).ORxi = v;
else
  set(hObject, 'String', num2str(g_orpGUI.cellData(g_orpGUI.cellIndex).ORxi));
end

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_orpGUI;

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

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

return;


% --- Executes during object creation, after setting all properties.
function qmaxTxt_CreateFcn(hObject, eventdata, handles)
% hObject    handle to qmaxTxt (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 qmaxTxt_Callback(hObject, eventdata, handles)
% hObject    handle to qmaxTxt (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 qmaxTxt as text
%        str2double(get(hObject,'String')) returns contents of qmaxTxt as a double

global g_orpGUI;

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

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

return;


% --- Executes during object creation, after setting all properties.
function orknobTxt_CreateFcn(hObject, eventdata, handles)
% hObject    handle to orknobTxt (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 orknobTxt_Callback(hObject, eventdata, handles)
% hObject    handle to orknobTxt (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 orknobTxt as text
%        str2double(get(hObject,'String')) returns contents of orknobTxt as a double

global g_orpGUI;

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

if v >= 0
  g_orpGUI.cellData(g_orpGUI.cellIndex).ORknob = v;
else
  set(hObject, 'String', num2str(g_orpGUI.cellData(g_orpGUI.cellIndex).ORknob));
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_orpGUI;

fm = g_orpGUI.cellData(g_orpGUI.cellIndex).ORfmax;
qs = g_orpGUI.cellData(g_orpGUI.cellIndex).ORqsize;
dc = g_orpGUI.cellData(g_orpGUI.cellIndex).ORknob;
g  = g_orpGUI.cellData(g_orpGUI.cellIndex).ORgamma;
xi = g_orpGUI.cellData(g_orpGUI.cellIndex).ORxi;

N  = size(g_orpGUI.cellData, 2);

for i = 1:N
  if ~isempty(g_orpGUI.cellData(i).ORname)
    g_orpGUI.cellData(i).ORfmax  = fm;
    g_orpGUI.cellData(i).ORqsize = qs;
    g_orpGUI.cellData(i).ORknob  = dc;
    g_orpGUI.cellData(i).ORgamma = g;
    g_orpGUI.cellData(i).ORxi    = xi;
  end
end

return;

Contact us at files@mathworks.com