No BSD License  

Highlights from
MatPlanWDM v0.5

image thumbnail
from MatPlanWDM v0.5 by Pablo Pavon MariƱo
Educational network planning tool for the RWA problem in WDM networks (MILP and heuristic based)

trafficGeneration(varargin)
function varargout = trafficGeneration(varargin)
% TRAFFICGENERATION M-file for trafficGeneration.fig
%      TRAFFICGENERATION, by itself, creates a new TRAFFICGENERATION or raises the existing
%      singleton*.
%
%      H = TRAFFICGENERATION returns the handle to a new TRAFFICGENERATION or the handle to
%      the existing singleton*.
%
%      TRAFFICGENERATION('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in TRAFFICGENERATION.M with the given input arguments.
%
%      TRAFFICGENERATION('Property','Value',...) creates a new TRAFFICGENERATION or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before trafficGeneration_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to trafficGeneration_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Copyright 2002-2003 The MathWorks, Inc.

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

% Last Modified by GUIDE v2.5 02-Dec-2007 19:28:02

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @trafficGeneration_OpeningFcn, ...
                   'gui_OutputFcn',  @trafficGeneration_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(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 trafficGeneration is made visible.
function trafficGeneration_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   command line arguments to trafficGeneration (see VARARGIN)

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

% Update handles structure
guidata(hObject, handles);

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


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


% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %NrNodes_edit - NUMBER OF NODES
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function NrNodes_edit_Callback(hObject, eventdata, handles)
% hObject    handle to NrNodes_edit (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 NrNodes_edit as text
%        str2double(get(hObject,'String')) returns contents of NrNodes_edit as a double

% --- Executes during object creation, after setting all properties.
function NrNodes_edit_CreateFcn(hObject, eventdata, handles)
% hObject    handle to NrNodes_edit (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.
if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end


% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ApplyReset_pushbutton - PUSHBUTTON TO ENTER THE NUMBER OF NODES AND RESET
% THE TRAFFIC MATRIX
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% --- Executes on button press in NrNodes_pushbutton.
function ApplyReset_pushbutton_Callback(hObject, eventdata, handles)
% hObject    handle to NrNodes_pushbutton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

load_global_traffGen;
auxNumberOfNodes=str2num(get(handles.NrNodes_edit,'String'));

if isempty(auxNumberOfNodes), 
    errordlg('The number of nodes must be a positive integer','Incorrect Value','modal');
elseif (abs(auxNumberOfNodes)-abs(fix(auxNumberOfNodes)) ~= 0),
    errordlg('The number of nodes must be a positive integer','Incorrect Value','modal')
elseif auxNumberOfNodes <=0,
     errordlg('The number of nodes must be a positive integer','Incorrect Value','modal')
else
    numberOfNodes=auxNumberOfNodes;
    
    set(handles.autoGeneration_popupmenu,'Enable','on');
    set(handles.Generation_pushbutton,'Enable','on');
    set(handles.Normalization_popupmenu,'Enable','on');
    set(handles.Normalization_pushbutton,'Enable','on');
    
    set(handles.Validate_pushbutton,'Enable','on');
    set(handles.Save_pushbutton,'Enable','on');
    set(handles.Cancel_pushbutton,'Enable','on');
    
    set(handles.autoGeneration_popupmenu,'Value',1);
    set(handles.Normalization_popupmenu,'Value',1);

    
    %We change the traffic matrix to fit them to the new value of number of nodes
    warndlg('If you modify the number of nodes, you will reset the traffic matrix','Warning!','modal')   
    provTrafficMatrix=zeros(numberOfNodes, numberOfNodes);
    
    %Preview the traff file
    [traffString] = IO_writeTraffString(provTrafficMatrix);
    set(handles.trafficFile_edit,'String', traffString)
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%openTraffFile_pushbutton - OPEN TRAFF FILE BUTTON
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function varargout = openTraffFile_pushbutton_Callback(h, eventdata, handles, varargin)

load_global;%Global variables are loaded

%We open the file to read our 'Traffic File (*.traff)'
[filename, pathname] = uigetfile({'*.traff','Traffic File (*.traff)'},'Open Traffic File','Data\Traffics\');
fullpathname=[pathname filename];
[provTrafficMatrix, errmsg, errorFlag] = IO_readTraffFile(fullpathname);
if errorFlag==-1,
    errordlg(errmsg,'Error On Reading Traff File!!!','modal');
    return
end
numberOfNodes=size(provTrafficMatrix,1); 

set(handles.autoGeneration_popupmenu,'Enable','on');
set(handles.Generation_pushbutton,'Enable','on');
set(handles.Normalization_popupmenu,'Enable','on');
set(handles.Normalization_pushbutton,'Enable','on');

set(handles.Validate_pushbutton,'Enable','on');
set(handles.Save_pushbutton,'Enable','on');
set(handles.Cancel_pushbutton,'Enable','on');

set(handles.autoGeneration_popupmenu,'Value',1);
set(handles.Normalization_popupmenu,'Value',1);

%We load a traff file
warndlg('Traffic matrix data modified: traff file loaded','Warning!','modal')

%Preview the traff file
[traffString] = IO_writeTraffString(provTrafficMatrix);
set(handles.trafficFile_edit,'String', traffString)

%We update the nr of nodes
set(handles.NrNodes_edit,'String',num2str(numberOfNodes));


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%autoGeneration_popupmenu - AUTOMATIC GENERATION POPUPMENU 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% --- Executes on selection change in autoGeneration_popupmenu.
function autoGeneration_popupmenu_Callback(hObject, eventdata, handles)
% hObject    handle to autoGeneration_popupmenu (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 autoGeneration_popupmenu contents as cell array
%        contents{get(hObject,'Value')} returns selected item from autoGeneration_popupmenu

load_global_traffGen;
trafficSelection=get(handles.autoGeneration_popupmenu,'Value');
switch trafficSelection
    case 1
   
    %% TRAFFIC PATTERN P1 - REALISTIC PATTERN DEPENDING ON POPULATION AND DISTANCE
    %% Traffics between the nodes depending on the population the distance and
    %% the design parameters
    case 2
        onPopDistTrafficFigure=openfig('onPopulationDistanceTraffic.fig','reuse');
        dataOnPopDistTrafficFigure=guihandles(onPopDistTrafficFigure);
        guidata(onPopDistTrafficFigure,dataOnPopDistTrafficFigure);
        
        
        %We will use the auxiliar variable only inside 'onPopulationDistanceTraffic.fig'        
%         auxTrafficMatrix=provTrafficMatrix;
%         auxRF=RF;
%         auxPopOffset=popOffset;
%         auxPopPower=popPower;
%         auxDistOffset=distOffset;
%         auxDistPower=distPower;
        set(dataOnPopDistTrafficFigure.RF_edit, 'String', RF);
        set(dataOnPopDistTrafficFigure.popOffset_edit, 'String', popOffset);
        set(dataOnPopDistTrafficFigure.popPower_edit, 'String', popPower);
        set(dataOnPopDistTrafficFigure.distOffset_edit, 'String', distOffset);
        set(dataOnPopDistTrafficFigure.distPower_edit, 'String', distPower);        

        
    %% TRAFFIC PATTERN P2 - UNIFORM
    %% All node pairs are allocated a random amount of traffic chosen from
    %% a uniform distribution in (0,10).        
    case 3
      
       
    %% TRAFFIC PATTERN P3 - UNIFORM
    %% All node pairs are allocated a random amount of traffic chosen from
    %% a uniform distribution in (0,100).
    case 4

    %% TRAFFIC PATTERN P4 - NON UNIFORM
    %% Traffic between 50% of randomly chosen node pairs is a uniformly distributed random number
    %% from 0 to 100. Traffic between the rest of the node pairs is a uniformly distributed random
    %% number between 0 and 10.    
    case 5
        
    %% TRAFFIC PATTERN P5 - NON UNIFORM
    %% Traffic between 25% of randomly chosen node pairs is a uniformly distributed random number
    %% from 0 to 100. Traffic between the rest of the node pairs is a uniformly distributed random
    %% number between 0 and 10.
    case 6

    otherwise
         error('??? Error using ==> trafficGeneration: Traffic Distribution Selection not valid.')
end



% --- Executes during object creation, after setting all properties.
function autoGeneration_popupmenu_CreateFcn(hObject, eventdata, handles)
% hObject    handle to autoGeneration_popupmenu (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Generation_pushbutton - PUSHBUTTON TO GENERATE AUTOMATICALLY THE TRAFFIC   
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

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


load_global_traffGen;

%We update the provTrafficMatrix with the info from the edit text
traffStringFromEdit=get(handles.trafficFile_edit,'String');
% 'traffStringFromEdit' has not the right format: a string readed from a edit
% box is matrix 'NrRows x NrCols' without formating, but a traffString must
% be formatted as a phys file: a vector row formatted with /n between the rows..
[traffString] = IO_formatEditString(traffStringFromEdit);
[editTrafficMatrix, errmsg, errorFlag] = IO_readTraffString(traffString);
%We check the read traff string
%if the traff string is not valid due to a Format Error and not to a Field
%Error
if errorFlag==-1 & strcmp(errmsg(1:12),'Field Error:')==0,
    errordlg(errmsg,'Traff File in edit text not valid!!!','modal') ;
    return;
else
    provTrafficMatrix=editTrafficMatrix;
    numberOfNodes=size(provTrafficMatrix,1);
end

trafficSelection=get(handles.autoGeneration_popupmenu,'Value');
switch trafficSelection
    case 1
   
    %% TRAFFIC PATTERN P1 - REALISTIC PATTERN DEPENDING ON POPULATION AND DISTANCE
    %% Traffics between the nodes depending on the population the distance and
    %% the design parameters
    case 2
        if isempty(auxPhys.nodePopulation) | isempty(distanceMatrix) | isempty(auxPhys.nodeLevel) | isempty(auxPhys.levelMatrix) | ...
                isempty(RF) | isempty(popOffset) | isempty(popPower) | isempty(distOffset) | isempty(distPower), 
            errordlg('Some parameter is incorrect or empty','Incorrect Values','modal')
            return
        end
        
        [provTrafficMatrix, pattern] = trafficGenerator(auxPhys.nodePopulation, distanceMatrix,...
            auxPhys.nodeLevel, auxPhys.levelMatrix, RF, popOffset, popPower, distOffset, distPower);     

        
    %% TRAFFIC PATTERN P2 - UNIFORM
    %% All node pairs are allocated a random amount of traffic chosen from
    %% a uniform distribution in (0,10).        
    case 3
        provTrafficMatrix=zeros(numberOfNodes);
        provTrafficMatrix(1:numberOfNodes^2)=rand(1,numberOfNodes^2)*10;%Traffic chosen from a uniform distribution in (0,10)
        provTrafficMatrix=provTrafficMatrix.*(diag(diag(ones(numberOfNodes)))==zeros(numberOfNodes));
      
       
    %% TRAFFIC PATTERN P3 - UNIFORM
    %% All node pairs are allocated a random amount of traffic chosen from
    %% a uniform distribution in (0,100).
    case 4
        provTrafficMatrix=zeros(numberOfNodes);
        provTrafficMatrix(1:numberOfNodes^2)=rand(1,numberOfNodes^2)*100;%Traffic chosen from a uniform distribution in (0,100)
        provTrafficMatrix=provTrafficMatrix.*(diag(diag(ones(numberOfNodes)))==zeros(numberOfNodes));

    %% TRAFFIC PATTERN P4 - NON UNIFORM
    %% Traffic between 50% of randomly chosen node pairs is a uniformly distributed random number
    %% from 0 to 100. Traffic between the rest of the node pairs is a uniformly distributed random
    %% number between 0 and 10.    
    case 5
        aux=randperm(numberOfNodes^2);
        randomIndexesHighTraffic=aux(1:ceil(numberOfNodes^2/2));
        provTrafficMatrix=zeros(numberOfNodes);
        provTrafficMatrix(randomIndexesHighTraffic)=rand(1,ceil(numberOfNodes^2/2))*100;%Traffic chosen from a uniform distribution in (0,100)
        randomIndexesLowTraffic=find(provTrafficMatrix==0);
        provTrafficMatrix(randomIndexesLowTraffic)=rand(1,length(randomIndexesLowTraffic))*10;%Traffic chosen from a uniform distribution in (0,10)
        provTrafficMatrix=provTrafficMatrix.*(diag(diag(ones(numberOfNodes)))==zeros(numberOfNodes));

    %% TRAFFIC PATTERN P5 - NON UNIFORM
    %% Traffic between 25% of randomly chosen node pairs is a uniformly distributed random number
    %% from 0 to 100. Traffic between the rest of the node pairs is a uniformly distributed random
    %% number between 0 and 10.
    case 6
        aux=randperm(numberOfNodes^2);
        randomIndexesHighTraffic=aux(1:ceil(numberOfNodes^2/4));
        provTrafficMatrix=zeros(numberOfNodes);
        provTrafficMatrix(randomIndexesHighTraffic)=rand(1,ceil(numberOfNodes^2/4))*100;%Traffic chosen from a uniform distribution in (0,100)
        randomIndexesLowTraffic=find(provTrafficMatrix==0);
        provTrafficMatrix(randomIndexesLowTraffic)=rand(1,length(randomIndexesLowTraffic))*10;%Traffic chosen from a uniform distribution in (0,10)
        provTrafficMatrix=provTrafficMatrix.*(diag(diag(ones(numberOfNodes)))==zeros(numberOfNodes));

    otherwise
        error('??? Error using ==> trafficGeneration: Traffic Distribution Selection not valid.')
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% load_global_traffGen;

% provTrafficMatrix=auxTrafficMatrix;

%Preview the traff file
[traffString] = IO_writeTraffString(provTrafficMatrix);
set(handles.trafficFile_edit,'String', traffString)

%We update the nr of nodes,
numberOfNodes=size(provTrafficMatrix,1);
set(handles.NrNodes_edit,'String', num2str(numberOfNodes))


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Normalization_popupmenu - NORMALIZATION POPUPMENU 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% --- Executes on selection change in Normalization_popupmenu.
function Normalization_popupmenu_Callback(hObject, eventdata, handles)
% hObject    handle to Normalization_popupmenu (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 Normalization_popupmenu contents as cell array
%        contents{get(hObject,'Value')} returns selected item from Normalization_popupmenu

load_global_traffGen;

%We update the provTrafficMatrix with the info from the edit text
traffStringFromEdit=get(handles.trafficFile_edit,'String');
% 'traffStringFromEdit' has not the right format: a string readed from a edit
% box is matrix 'NrRows x NrCols' without formating, but a traffString must
% be formatted as a phys file: a vector row formatted with /n between the rows..
[traffString] = IO_formatEditString(traffStringFromEdit);
[editTrafficMatrix, errmsg, errorFlag] = IO_readTraffString(traffString);
%We check the read traff string
%if the traff string is not valid due to a Format Error and not to a Field
%Error
if errorFlag==-1 & strcmp(errmsg(1:12),'Field Error:')==0,
    errordlg(errmsg,'Traff File in edit text not valid!!!','modal') ;
    return;
else
    provTrafficMatrix=editTrafficMatrix;
    numberOfNodes=size(provTrafficMatrix,1);
end

normalSelection=get(handles.Normalization_popupmenu,'Value');
switch normalSelection
    case 1   
        
    %% TOTAL NORMALIZATION - The total sum of the traffic matrix must be equal to the value of
    %% total offered traffic entered by the user
    case 2
        totalNormalFigure=openfig('totalNormalization.fig','reuse');
        dataTotalNormalFigure=guihandles(totalNormalFigure);
        guidata(totalNormalFigure,dataTotalNormalFigure);
                
        %We will use the auxiliar variable only inside 'totalNormalization.fig'        
%         auxTrafficMatrix=provTrafficMatrix;
%         auxTotalTraffic=totalTraffic;
        set(dataTotalNormalFigure.totalTraff_edit, 'String', num2str(totalTraffic));         
        
    %% ROWWISE NORMALIZATION - The sum of each row of the traffic matrix must be equal to the value of
    %% offered traffic for this row (outgoing traffic from the node) entered by the user
    case 3
        rowNormalFigure=openfig('rowNormalization.fig','reuse');
        dataRowNormalFigure=guihandles(rowNormalFigure);
        guidata(rowNormalFigure,dataRowNormalFigure);
        
        %We will use the auxiliar variable only inside 'rowNormalization.fig'        
%         auxTrafficMatrix=provTrafficMatrix;
%         auxOfferedTraffic=offeredTraffic;
        if size(offeredTraffic,1)==1, offeredTraffic=offeredTraffic';end
        set(dataRowNormalFigure.offeredTraffic_edit, 'String', num2str(offeredTraffic));         
 
    %% COLUMNWISE NORMALIZATION - The sum of each column of the traffic matrix must be equal to the value of
    %% offered traffic for this column (incoming traffic to the node) entered by the user   
    case 4
        columnNormalFigure=openfig('columnNormalization.fig','reuse');
        dataColumnNormalFigure=guihandles(columnNormalFigure);
        guidata(columnNormalFigure,dataColumnNormalFigure);
        
        %We will use the auxiliar variable only inside 'rowNormalization.fig'        
%         auxTrafficMatrix=provTrafficMatrix;
%         auxOfferedTraffic=offeredTraffic;
        if size(offeredTraffic,2)==1, offeredTraffic=offeredTraffic';end
        set(dataColumnNormalFigure.offeredTraffic_edit, 'String', num2str(offeredTraffic));         
        
    otherwise
         fprintf('\Nomalization Selection not valid');
end

% --- Executes during object creation, after setting all properties.
function Normalization_popupmenu_CreateFcn(hObject, eventdata, handles)
% hObject    handle to Normalization_popupmenu (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Normalization_pushbutton - PUSHBUTTON TO NORMALIZE THE TRAFFIC PATTERN   
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

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

load_global_traffGen;

%We update the provTrafficMatrix with the info from the edit text
traffStringFromEdit=get(handles.trafficFile_edit,'String');
% 'traffStringFromEdit' has not the right format: a string readed from a edit
% box is matrix 'NrRows x NrCols' without formating, but a traffString must
% be formatted as a phys file: a vector row formatted with /n between the rows..
[traffString] = IO_formatEditString(traffStringFromEdit);
[editTrafficMatrix, errmsg, errorFlag] = IO_readTraffString(traffString);
%We check the read traff string
%if the traff string is not valid due to a Format Error and not to a Field
%Error
if errorFlag==-1 & strcmp(errmsg(1:12),'Field Error:')==0,
    errordlg(errmsg,'Traff File in edit text not valid!!!','modal') ;
    return;
else
    provTrafficMatrix=editTrafficMatrix;
    numberOfNodes=size(provTrafficMatrix,1);
end

normalSelection=get(handles.Normalization_popupmenu,'Value');
switch normalSelection
    case 1   
        
    %% TOTAL NORMALIZATION - The total sum of the traffic matrix must be equal to the value of
    %% total offered traffic entered by the user
    case 2      
        provTrafficMatrix=(totalTraffic./sum(sum(provTrafficMatrix,2),1)).*provTrafficMatrix;
           
    %% ROWWISE NORMALIZATION - The sum of each row of the traffic matrix must be equal to the value of
    %% offered traffic for this row (outgoing traffic from the node) entered by the user
    case 3
        alpha=offeredTraffic./sum(provTrafficMatrix,2);
        provTrafficMatrix=diag(alpha)*provTrafficMatrix;
 
    %% COLUMNWISE NORMALIZATION - The sum of each column of the traffic matrix must be equal to the value of
    %% offered traffic for this column (incoming traffic to the node) entered by the user   
    case 4
        alpha=offeredTraffic./sum(provTrafficMatrix,1);
        provTrafficMatrix=provTrafficMatrix*diag(alpha); 
    otherwise
         fprintf('\Nomalization Selection not valid');
end


% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% load_global_traffGen;
% 
% provTrafficMatrix=auxTrafficMatrix;
% totalTraffic=auxTotalTraffic;
% offeredTraffic=auxOfferedTraffic;

%Preview the traff file
[traffString] = IO_writeTraffString(provTrafficMatrix);
set(handles.trafficFile_edit,'String', traffString)

%We update the nr of nodes,
numberOfNodes=size(provTrafficMatrix,1);
set(handles.NrNodes_edit,'String', num2str(numberOfNodes))


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%trafficFile_edit - TRAFFIC FILE
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function trafficFile_edit_Callback(hObject, eventdata, handles)
% hObject    handle to trafficFile_edit (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 trafficFile_edit as text
%        str2double(get(hObject,'String')) returns contents of trafficFile_edit as a double


% --- Executes during object creation, after setting all properties.
function trafficFile_edit_CreateFcn(hObject, eventdata, handles)
% hObject    handle to trafficFile_edit (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.
if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Validate_pushbutton - Pushbutton to validate the Traffic File 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

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

load_global_traffGen;

%We update the provTrafficMatrix with the info from the edit text
traffStringFromEdit=get(handles.trafficFile_edit,'String');
% 'traffStringFromEdit' has not the right format: a string readed from a edit
% box is matrix 'NrRows x NrCols' without formating, but a traffString must
% be formatted as a phys file: a vector row formatted with /n between the rows..
[traffString] = IO_formatEditString(traffStringFromEdit);
[editTrafficMatrix, errmsg, errorFlag] = IO_readTraffString(traffString);

if errorFlag==-1,%if the traff string is not valid
    errordlg(errmsg,'Traff File not valid!!!','modal') ;
else %if the traff string is valid
    msgbox('TRAFF FILE OK!!','Traff File valid!!!','modal');
    provTrafficMatrix=editTrafficMatrix;
     %We update the nr of nodes 
    set(handles.NrNodes_edit,'String',num2str(numberOfNodes));
end


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Save_pushbutton - Pushbutton to save the Traffic File 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

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

load_global_traffGen;

%We update the provTrafficMatrix with the info from the edit text
traffStringFromEdit=get(handles.trafficFile_edit,'String');
% 'traffStringFromEdit' has not the right format: a string readed from a edit
% box is matrix 'NrRows x NrCols' without formating, but a traffString must
% be formatted as a phys file: a vector row formatted with /n between the rows..
[traffString] = IO_formatEditString(traffStringFromEdit);
[editTrafficMatrix, errmsg, errorFlag] = IO_readTraffString(traffString);

if errorFlag==-1,%if the traff string is not valid
    errordlg(errmsg,'Traff File not valid!!!','modal') ;
else %if the traff string is valid
    provTrafficMatrix=editTrafficMatrix;
    traff_trafficMatrix=provTrafficMatrix;
   
    %We open the file to save our 'Traffic File (*.traff)'
    [filename, pathname] = uiputfile({'*.traff','Traffic File (*.traff)'},'Save Traffic File as','Data\Traffics\');
    fullpathname=[pathname filename];
    IO_writeTraffFile(traff_trafficMatrix, fullpathname) ;
    msgbox('TRAFF FILE SUCESSFULLY WRITTEN!!','Traff File Saved!!!','modal');
    %We update the nr of nodes 
    set(handles.NrNodes_edit,'String',num2str(numberOfNodes));
end

close;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Cancel_pushbutton - Pushbutton to cancel the Traffic File Generation
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

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

close;













Contact us at files@mathworks.com