from
MatPlanWDM v0.5
by Pablo Pavon MariƱo Educational network planning tool for the RWA problem in WDM networks (MILP and heuristic based)
calculateDistanceMatrix.m
% calculateDistanceMatrix
%
% Usage: [distanceMatrix]=calculateDistanceMatrix(nodesPlaceMatrix)
%
% Abstract: this function calculates the euclidean distance in KM between any
% pair of nodes based on the positions of the nodes.
%
% Arguments:
% o In:
% nodesPlaceMatrix(Nx2): XY coordinates of nodes, where N is the number of
% nodes. They are contained in the first and second column respectively.
%
% o Out:
% distanceMatrix (NxN): Matrix of distances. As entry (x,y) is the distance
% in kilometers between the node 'x' and the node 'y'.
%
%
function [distanceMatrix]=calculateDistanceMatrix(nodesPlaceMatrix)
numberOfNodes=length(nodesPlaceMatrix);
distanceMatrix=zeros(numberOfNodes);
k=1;
for i=k:numberOfNodes-1,
for j=k+1:numberOfNodes,
sourcePosition=nodesPlaceMatrix(i,:);
destinationPosition=nodesPlaceMatrix(j,:);
distanceMatrix(i,j)=sqrt((sourcePosition(1)-destinationPosition(1))^2+(sourcePosition(2)-destinationPosition(2))^2);
distanceMatrix(j,i)=distanceMatrix(i,j);
end
k=k+1;
end