function varargout = Dynamic(varargin)
% MATPLANWDM Application M-file for matplanwdm.fig
% FIG = matplanwdm2 launch matplanwdm2 GUI.
% matplanwdm('callback_name', ...) invoke the named callback.
% Last Modified by GUIDE v2.5 14-Jul-2006 18:15:26
if nargin == 0 % LAUNCH GUI
close all
clear all
clc
fig = openfig(mfilename,'new');
% Generate a structure of handles to pass to callbacks, and store it.
handles = guihandles(fig);
guidata(fig, handles);
if nargout > 0
varargout{1} = fig;
end
gui_ini(handles)
elseif ischar(varargin{1}) % INVOKE NAMED SUBFUNCTION OR CALLBACK
try
if (nargout)
[varargout{1:nargout}] = feval(varargin{:}); % FEVAL switchyard
else
feval(varargin{:}); % FEVAL switchyard
end
catch
%disp(lasterr);
end
end
%set(fig,'Color',get(0,'DefaultUicontrolBackgroundColor'));
%| ABOUT CALLBACKS:
%| GUIDE automatically appends subfunction prototypes to this file, and
%| sets objects' callback properties to call them through the FEVAL
%| switchyard above. This comment describes that mechanism.
%|
%| Each callback subfunction declaration has the following form:
%| <SUBFUNCTION_NAME>(H, EVENTDATA, HANDLES, VARARGIN)
%|
%| The subfunction name is composed using the object's Tag and the
%| callback type separated by '_', e.g. 'slider2_Callback',
%| 'figure1_CloseRequestFcn', 'axis1_ButtondownFcn'.
%|
%| H is the callback object's handle (obtained using GCBO).
%|
%| EVENTDATA is empty, but reserved for future use.
%|
%| HANDLES is a structure containing handles of components in GUI using
%| tags as fieldnames, e.g. handles.figure1, handles.slider2. This
%| structure is created at GUI startup using GUIHANDLES and stored in
%| the figure's application data using GUIDATA. A copy of the structure
%| is passed to each callback. You can store additional information in
%| this structure at GUI startup, and you can change the structure
%| during callbacks. Call guidata(h, handles) after changing your
%| copy to replace the stored original so that subsequent callbacks see
%| the updates. Type "help guihandles" and "help guidata" for more
%| information.
%|
%| VARARGIN contains any extra arguments you have passed to the
%| callback. Specify the extra arguments by editing the callback
%| property in the inspector. By default, GUIDE sets the property to:
%| <MFILENAME>('<SUBFUNCTION_NAME>', gcbo, [], guidata(gcbo))
%| Add any extra arguments after the last argument, before the final
%| closing parenthesis.
%
%set(fig,'Color',get(0,'DefaultUicontrolBackgroundColor'));
% --------------------------------------------------------------------
% --------------------------------------------------------------------
% INITIALIZATION FUNCTION
% --------------------------------------------------------------------
% --------------------------------------------------------------------
function gui_ini(handles)
load_global_Dynamic;
imageUPCT=imread('upct_logo.jpg','jpg');
axes(handles.axes6);
image(imageUPCT);
axis off
%%%%%%%%%%%%%%%%%%%%%%%HEURISTICS MENU BUILDING%%%%%%%%%%%%%%%%%%%%%%%%%%%
h = dir(fullfile(pwd, 'algorithms/dynamicPlanning/*.m'));
priv_h = dir(fullfile(pwd, 'algorithms/private/dynamicPlanning/*.m'));
numberOfPublicHeuristicAlgorithms = length(h);
numberOfPrivateHeuristicAlgorithms = length(priv_h);
heuristicAlgorithms=cell(numberOfPublicHeuristicAlgorithms+numberOfPrivateHeuristicAlgorithms,1);
heuristicAlgorithms(1:numberOfPublicHeuristicAlgorithms) = {h.name}';
heuristicAlgorithms(numberOfPublicHeuristicAlgorithms+1:end) = {priv_h.name}';
numberOfHeuristicAlgorithms=length(heuristicAlgorithms);
methodsString=cell(numberOfHeuristicAlgorithms+1,1);
methodsString(1)={['Select desired']};
methodsString(2:length(methodsString))=heuristicAlgorithms;
set(handles.popupmenu3,'String',methodsString);
%%%%%%%%%%%%%%%%%%%%%%%TRAFFIC PATTERN MENU BUILDING%%%%%%%%%%%%%%%%%%%%%%%
h = dir(fullfile(pwd, 'algorithms/dynamicTrafficGenerators/*.m'));
priv_h = dir(fullfile(pwd, 'algorithms/private/dynamicTrafficGenerators/*.m'));
numberOfPublicTrafficPattern = length(h);
numberOfPrivateTrafficPattern = length(priv_h);
trafficPatterns=cell(numberOfPublicTrafficPattern+numberOfPrivateTrafficPattern,1);
trafficPatterns(1:numberOfPublicTrafficPattern) = {h.name}';
trafficPatterns(numberOfPublicTrafficPattern+1:end) = {priv_h.name}';
numberOftrafficPattern=length(trafficPatterns);
trafficString=cell(numberOftrafficPattern+1,1);
trafficString(1)={['Select desired']};
trafficString(2:length(trafficString))=trafficPatterns;
set(handles.popupmenu2,'String',trafficString);
%%%%%%%%%%%%%%%%%%%%%PHYSICAL TOPOLOGY MENU BUILDING%%%%%%%%%%%%%%%%%%%%%%%%%%%
s=pwd;
s=[s '\data\physicalTopologies\*.xml'];
c=dir(s);
physicalTopologys = struct2cell(c);
numberOfphysicalTopologys=length(physicalTopologys(1,:));
physicalTopologysString=cell(numberOfphysicalTopologys+1,1);
physicalTopologysString(1)={['Select desired']};
physicalTopologysString(2:length(physicalTopologysString))=physicalTopologys(1,:);
set(handles.popupmenu1,'String',physicalTopologysString);
% --------------------------------------------------------------------
% --------------------------------------------------------------------
% MENU 1 File
% --------------------------------------------------------------------
% --------------------------------------------------------------------
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Quit
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function varargout = Quit_Callback(h, eventdata, handles, varargin)
close
% *********************************************************************
% *********************************************************************
% MENU 2 - MODE
% *********************************************************************
% *********************************************************************
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%mode1 - DESIGN LIGHTPATH LOGICAL NETWORK
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function varargout = mode1_Callback(h, eventdata, handles, varargin)
set(handles.men1,'Checked','on');
set(handles.men2,'Checked','off');
set(handles.men3,'Checked','off');
set(handles.men4,'Checked','off');
clear all
close
matplanwdm
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%mode2 - WHAT IF ANALYSIS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function varargout = modeWhatIf_Callback(h, eventdata, handles, varargin)
set(handles.men1,'Checked','off');
set(handles.men2,'Checked','on');
set(handles.men3,'Checked','off');
set(handles.men4,'Checked','off');
clear all
close
WhatIfAnalysis
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%mode3 - MULTIHOUR ANALYSIS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function varargout = modeMultiHour_Callback(h, eventdata, handles, varargin)
set(handles.men1,'Checked','off');
set(handles.men2,'Checked','off');
set(handles.men3,'Checked','on');
set(handles.men4,'Checked','off');
clear all
close
MultiHourAnalysis
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%mode4 - DYNAMIC ANALYSIS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function varargout = modeDynamic_Callback(h, eventdata, handles, varargin)
set(handles.men1,'Checked','off');
set(handles.men2,'Checked','off');
set(handles.men3,'Checked','off');
set(handles.men4,'Checked','on');
clear all
close
Dynamic
% *********************************************************************
% *********************************************************************
% MENU 3 - TOOLS
% *********************************************************************
% *********************************************************************
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Traffic Generation
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function varargout = trafficGen_Callback(h, eventdata, handles, varargin)
% load_global_Multihour;%Global variables are loaded
trafficGenerationFigure=openfig('trafficGeneration.fig','reuse');
dataTrafficGenerationFigure=guihandles(trafficGenerationFigure);
guidata(trafficGenerationFigure,dataTrafficGenerationFigure);
numberOfNodes=0;
% *********************************************************************
% *********************************************************************
% MENU 4 - HELP
% *********************************************************************
% *********************************************************************
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%MatplanWDM HELP
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function varargout = matplanwdmHelp_Callback(h, eventdata, handles, varargin)
HelpPath =[pwd '\help\matplanwdmHelp.html'];
web(HelpPath, '-helpbrowser')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%About
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function varargout = about_Callback(h, eventdata, handles, varargin)
openfig('about.fig','new')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%popupmenu12 - LIGHTPATH MENU
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function varargout = popupmenu12_Callback(h, eventdata, handles, varargin)
load_global_Dynamic;
%When a lightpath is chosen, its physical route is drawn
lightpathID=get(handles.popupmenu12,'Value');
axes(handles.axes8);
lightpathTitle='';
hold off
if lightpathID~=1
plotLightpath (phys.nodesPlaceMatrix, phys.linkTable, lightpathID-1, ...
netState.lightpathRoutingMatrix, lightpathTitle)
else
topologyTitle='';
plotTopology (phys.nodesPlaceMatrix, phys.linkTable, 0, topologyTitle, 0)
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%popupmenu11 - FLOW MENU
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function varargout = popupmenu11_Callback(h, eventdata, handles, varargin)
%%Partial flows are drawn
load_global_Dynamic;
% %When a flow is chosen, its logical route is drawn
flowNumber=get(handles.popupmenu11,'Value');
axes(handles.axes2);
topologyTitle='';
hold off
if flowNumber~=1
plotTrafficFlow (phys.nodesPlaceMatrix, netState.lightpathTable(:,2:3), ...
flowNumber-1, netState.flowTable, netState.flowRoutingMatrix, topologyTitle)
else
plotTopology (phys.nodesPlaceMatrix, netState.lightpathTable(:,2:3), 1, topologyTitle, 0)
end
% --------------------------------------------------------------------
% --------------------------------------------------------------------
% EXECUTION CONTROLS
% --------------------------------------------------------------------
% --------------------------------------------------------------------
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%pushbutton5 - RUN
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function varargout = pushbutton5_Callback(h, eventdata, handles, varargin)
load_global_Dynamic;%Global variables are loaded
set(handles.pushbutton7,'UserData',0); %Simulation State =continue
set(handles.popupmenu11,'Enable','off');
set(handles.popupmenu12,'Enable','off');
set(handles.popupmenu1,'Enable','off');
set(handles.popupmenu2,'Enable','off');
set(handles.popupmenu3,'Enable','off');
set(handles.edit11,'Enable','off');
set(handles.edit12,'Enable','off');
set(handles.edit13,'Enable','off');
set(handles.edit17,'Enable','off');
transitoryTime=str2num(get(handles.edit17,'String'));
if transitoryTime <= 0
error('The transitory time have to be more than 0')
end
maxSimulationTime=str2num(get(handles.edit13,'String'));
if maxSimulationTime <= 0
error('The simulation time have to be more than 0')
end
if isempty(maxSimulationTime)
maxSimulationTime = 100000;
end
if isempty(transitoryTime)
transitoryTime = maxSimulationTime/100;
end
generatorParameters=get(handles.edit11,'String');
algorithmParameters=get(handles.edit12,'String');
algorithmSelection=get(handles.popupmenu3,'Value');
if(algorithmSelection~=1)
[pathstr,algorithmMethod,ext,versn]=fileparts(heuristicAlgorithms{algorithmSelection-1});
end
trafficPattern=get(handles.popupmenu2,'Value');
%GENERATOR SELECTION
if(trafficPattern~=1)
[pathstr,generator,ext,versn]=fileparts(trafficPatterns{trafficPattern-1});
end
%Read the .phys file and get the variables
s=pwd;
s=[s '\data\physicalTopologies\*.xml'];
c=dir(s);
physicalTopologys = struct2cell(c);
numberOfphysicalTopologys=length(physicalTopologys(1,:));
physicalTopologysString=cell(numberOfphysicalTopologys+1,1);
physicalTopologysString(1)={['Select desired']};
physicalTopologysString(2:length(physicalTopologysString))=physicalTopologys(1,:);
net=get(handles.popupmenu1,'Value');
physName=physicalTopologysString(net);
physName=char(physName);
fullpathname=[pwd '\data\physicalTopologies\' physName];
try
[metadata, phys] = io_readXML(fullpathname);
checkPhys(phys)
catch
lastErrorMsg=lasterr;
errordlg(lastErrorMsg,'Unexpected Error On Reading/Checking Physical Topology from the XML File!!!','modal');
return
end
axes(handles.axes8);
topologyTitle='';
plotTopology (phys.nodesPlaceMatrix, phys.linkTable, 0, topologyTitle, 1)
axis('off');
% %We show the loaded file in the edit
physTextReport = physXMLfileTextReport(metadata , phys);
topologyReport=vertcat(get(handles.edit6,'String'), {[' ']},{['######### PHYSICAL TOPOLOGY FILE "',physName,'" LOADED ##########']},{[' ']}, physTextReport);
set(handles.edit6,'String', topologyReport);
batchSimulationFlag=0;
eventDispatcherMainLoop(maxSimulationTime , transitoryTime , physName,...
batchSimulationFlag,handles);
set(handles.popupmenu1,'Enable','on');
set(handles.popupmenu2,'Enable','on');
set(handles.popupmenu3,'Enable','on');
set(handles.edit11,'Enable','on');
set(handles.edit12,'Enable','on');
set(handles.edit13,'Enable','on');
set(handles.edit17,'Enable','on');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%CHECKBOX1 - WITH REFRESH
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function varargout = checkbox1_Callback(h, eventdata, handles,varargin)
load_global_Dynamic;
if (get(h,'Value') == get(h,'Max'))
% then checkbox is checked-take approriate action
withRefreshFlag=1;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%pushbutton14 - CONTINUE
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function varargout = pushbutton14_Callback(h, eventdata, handles, varargin)
load_global_Dynamic;%Global variables are loaded
set(handles.pushbutton7,'UserData',0); %simulationState=0
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%pushbutton7 - STOP
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function varargout = pushbutton7_Callback(h, eventdata, handles, varargin)
load_global_Dynamic;%Global variables are loaded
set(handles.pushbutton7,'UserData',2);% simulationState=2;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%pushbutton8 - STEP
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function varargout = pushbutton8_Callback(h, eventdata, handles, varargin)
load_global_Dynamic;%Global variables are loaded
set(handles.pushbutton7,'UserData',3);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%pushbutton9 - ENDSIMULATION
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function varargout = pushbutton9_Callback(h, eventdata, handles, varargin)
global dynStatistics;
set(handles.pushbutton7,'UserData',4);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%pushbutton10 - SHOW STAT
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function varargout = pushbutton10_Callback(h, eventdata, handles, varargin)
global dynStatistics;
%SHOW RESULTS
GUIShowStat;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%pushbutton20 - SHOW STAT
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function varargout = pushbutton20_Callback(h, eventdata, handles, varargin)
global netState;
%SHOW RESULTS
GUIShowState;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%pushbutton11 - CLEAR
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function varargout = pushbutton11_Callback(h, eventdata, handles, varargin)
load_global_Dynamic;%Global variables are loaded
textReport=[''];
set(handles.edit6,'String',textReport);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%pushbutton12 - SAVE
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function varargout = pushbutton12_Callback(h, eventdata, handles, varargin)
load_global_Dynamic;%Global variables are loaded
textReport=get(handles.edit6,'String');
[filename, pathname] = uiputfile({'*.dynResults',...
'Dynamic Results File (*.dynResults)'},'Save Dynamic Results File as');
fid = fopen(filename, 'w');
text=['// Information File \n \n'];
fprintf(fid, text);
fprintf(fid, textReport);
fclose(fid);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%pushbuttonSaveXML -
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function varargout = pushbutton16_Callback(h, eventdata, handles, varargin)
load_global_Dynamic;
metadataFigure=openfig('metadataFigureDynamic.fig','reuse');
dataMetadataFigure=guihandles(metadataFigure);
guidata(metadataFigure,dataMetadataFigure);