No BSD License  

Highlights from
WDM Network Blocking Computation Toolbox

image thumbnail
from WDM Network Blocking Computation Toolbox by Przemyslaw Pawelczak
Blocking computation in WDM Networks for three different types of constraints.

varargout=create_load_uniform(varargin)
function varargout=create_load_uniform(varargin)
%CREATE_LOAD_UNIFORM Create uniform traffic matrix for specified network.
%   [TRAFFIC]=CREATE_LOAD_UNIFORM(METHOD,LOAD,NAME,NUMBER) is a script that
%   creates traffic matrix for a sprcified network saved in a *.MAT file in
%   MATLABROOT/networks/ directory. LOAD is the total offered load in the
%   network, NAME is the 'NAME.mat' file stored in string that holds
%   definition of the network, NUMBER is the structure number saved in the
%   file according to STRUCTURE{:,:,NUMBER} [2] (for precise fields
%   descriptionsee i.e. help CREATE_NETWORK).
%
%   METHOD is the method used to make traffic matrix. Choosing 1 makes
%   shortest paths (choosen randomly according to SHORTEST_PATH_DIJKSTRA
%   function) between all node pairs. Load on every path is (LOAD)/(Number
%   of paths). Method 2 uses algorithm described in [1] to choose shortest
%   paths. Briefly saying, algorithm chooses paths between all node pairs,
%   that have least adjacent links with other paths. Load on every path is
%   computed just like in method 1.
%
%   Result is saved in the NAME.mat file in the TRAFFIC field. If such
%   field does not exists then script makes such one. If not then new
%   traffic matrix is saved in the TRAFFIC field in NAME.mat file. Result
%   can be also loaded to workspace.
%
%   For example CREATE_LOAD_UNIFORM(1,13,'network',2) makes uniform load for
%   STRUCTURE{:,:,2} definition saved in NETWORK.mat file in
%   MATLABROOT/networks/ directory where total load in the network is 13
%   Erlangs.
%
%   See also CREATE_LOAD_MANUAL, CREATE_RAND_NETWORK, CREATE_NETWORK.
%
%   References: 
%       [1] Przemyslaw Pawelczak, "Traffic Engineering in all-optical
%       networks", M.Sc. thesis, Wroclaw University of Technology, Poland
%       [2]  T. E. Cormen et al., "Introduction to Algorithms", 
%       WNT, Warsaw 2000, page 527.

%   Copyright 2003-2004 Przemyslaw Pawelczak
%   E-mail: przemyslaw_pawelczak@idg.com.pl
%   Wroclaw University of Technology, Poland
%   $Revision: 1.0 $  $Date: 2004/02/20 12:40:16 $

%If no NUMBER specified then it will be first
if nargin==3
    varargin{4}=1;
end

%Exeption handling
message=nargchk(3,4,nargin);
testing_int=[varargin{1},varargin{2},varargin{4}];
if ~isempty(message)
    error('MATLAB:CREATE_LOAD_UNIFORM:NumberOfInputArguments',...
        message);
end
if find(isnan(testing_int))
    error('MATLAB:CREATE_LOAD_UNIFORM:ArgumentType',...
        'Arguments must be numbers.');
end
%Check if VARARGIN are positive integers
if sum([testing_int<0,...
            fix(varargin{1})~=varargin{1},...
            fix(varargin{4})~=varargin{4},...
            varargin{1}>2])~=0 %Only 2 choices
    error('MATLAB:CREATE_LOAD_UNIFORM:ArgumentType',...
        'Wrong type of argument.');
end
if ~isstr(varargin{3})
    error('MATLAB:CREATE_LOAD_UNIFORM:ArgumentType',...
        'Argument must be string.');
end

%Change string into number (for all number of arguments)
for k=[1,2,4]
    if isstr(varargin{k})==1
        varargin{k}=str2num(varargin{k});
    end
end

%List all '*.mat' files in current working directory
%Change directory to MATLABROOT\networks - catalog must exist
cd([matlabroot,['\work\networks']]);
directory=what;
directory=struct2cell(directory);
directory=cellstr(directory{3});

%Check if specified '*.mat' file already exist
if find(strcmp(directory,[varargin{3},'.mat'])==1)
    %Load *.MAT file
    load(varargin{3});
    fields_vector=[exist('description'),exist('structure')];
    if length(find(fields_vector))~=2
        error('MATLAB:CREATE_LOAD_UNIFORM:BadFieldNames',...
            'Bad field names.'); 
    end
    %Check if TRAFFIC definition already exists in this file
    %Initialize flag
    load_exists=0;
    varias=who;
    varias_dimension=cellfun('ndims',varias);
    varias_dimension=length(varias_dimension');
    %Check
    for k=1:varias_dimension
        if isequal(cell2mat(varias(k)),'traffic')
            load_exists=1;
        end
    end
    %If definition does exist - add another
    if load_exists==1
        %Find how many different LOAD definitions are in this '*.mat' file
        traffic_dimension=cellfun('ndims',traffic);
        traffic_dimension=length(traffic_dimension(1,1,:))+1;
        %Load MAKE_LOAD procedure
        traffic=make_load(varargin{3},varargin{2},structure,traffic,varargin{4},traffic_dimension,varargin{1});
        varargout{1}=save_network(description,structure,traffic,varargin{3});
        %If definition does not exist - make first one
    elseif load_exists==0;
        traffic{1,1,1}=[];
        %Load MAKE_LOAD procedure
        traffic=make_load(varargin{3},varargin{2},structure,traffic,varargin{4},1,varargin{1});
        varargout{1}=save_network(description,structure,traffic,varargin{3});
    end  
else
    error('MATLAB:CREATE_LOAD_UNIFORM:BadFiledName',...
        'Bad file name.'); 
end

function [traffic]=make_load(name,load,structure,traffic,structure_dimension,traffic_dimension,method)
%Data format: traffic{path number,path-1/load on path-2,number of dimensions (structures)};

%Check how many nodes are in the graph
struct_dim=cellfun('ndims',structure);
structure_length=length(struct_dim(:,1,1));
node_number=0;
for k=1:structure_length
    if ~isempty(structure{k,1,structure_dimension})
        node_number=node_number+1;
    end
end

%Initialization of temporary traffic structure
%Pair of nodes for one direction
for k=1:(node_number^2/2-node_number)
    %Pair of nodes for two directions
    %for k=1:(node_number^2-node_number)
    traffic_temp{k,1,1}=[];
    traffic_temp{k,2,1}=[];
end

%Making vector of coordinates for paths (begin node - x, end node - y)
x_vector=[];
y_vector=[];
remove=[];
for k=1:node_number
    x_vector=[x_vector,ones(1,node_number)+k-1];
    y_vector=[y_vector,1:node_number];
    %Pair of nodes for one direction
    remove=[remove,((k-1)*node_number+1):(k+(k-1)*node_number)];
    %Pair of nodes for two directions
    %remove=[remove,(k+(k-1)*node_number)];
end
x_vector(remove)=[];
y_vector(remove)=[];

%Choose method for designing load and paths
switch method
    case 1 %Random path, uniform load
        %Computing paths and assignment to structure
        for k=1:length(x_vector)
            %Only shortest paths
            traffic_temp{k,1,1}=shortest_path_dijkstra(x_vector(k),y_vector(k),name,structure_dimension);
            traffic_temp{k,2,1}=load/length(x_vector);
        end
        %Procedure for adding traffic_temp to traffic
        for k=1:length(x_vector)
            traffic{k,1,traffic_dimension}=traffic_temp{k,1,1};
            traffic{k,2,traffic_dimension}=traffic_temp{k,2,1};
        end
    case 2 %Optimal paths, uniform load
        %Name every link in the graph with its number
        link_matrix=ones(node_number,node_number);
        link_wages=zeros(node_number,node_number);
        link_positions=find(tril(link_matrix));
        link_numbers=find(link_positions);
        link_matrix(link_positions)=link_numbers;
        link_matrix=tril(link_matrix)+triu(link_matrix',1);
        %Assign wages to links
        for k=1:length(x_vector)
            %Only shortest paths - all shortest paths
            all_paths=shortest_path_dijkstra_all(x_vector(k),y_vector(k),name,structure_dimension);
            [row,column]=size(all_paths);
            for f=1:row
                for g=1:column-1
                    [sorted,sorted_positions]=sort([all_paths(f,g),all_paths(f,g+1)]);
                    link_wages(sorted(1),sorted(2))=link_wages(sorted(1),sorted(2))+1;
                end
            end
        end
        %Computing paths for the second time
        for k=1:length(x_vector)
            all_paths=shortest_path_dijkstra_all(x_vector(k),y_vector(k),name,structure_dimension);
            [row,column]=size(all_paths);
            wage_all_path(1:row)=0;
            for f=1:row
                for g=1:column-1
                    [sorted,sorted_positions]=sort([all_paths(f,g),all_paths(f,g+1)]);
                    wage_all_path(f)=wage_all_path(f)+link_wages(sorted(1),sorted(2));
                end
            end
            [minimal,minimal_position]=min(wage_all_path);
            traffic_temp{k,1,1}=all_paths(minimal_position,:);
            traffic_temp{k,2,1}=load/length(x_vector);
        end
        %Procedure for adding traffic_temp to traffic
        for k=1:length(x_vector)
            traffic{k,1,traffic_dimension}=traffic_temp{k,1,1};
            traffic{k,2,traffic_dimension}=traffic_temp{k,2,1};
        end
end

function display_gap
disp(sprintf('\n'));

function [net_out]=save_network(description,structure,traffic,name)
save(name,'description','structure','traffic');
%Cannot make structure with cells of different dimension (sic!) - it needs
%checking
net_out=struct('traffic',traffic);

Contact us at files@mathworks.com