from
Cross Entropy TSP Solver
by Sebastien PARIS
Solve TSP problem with a CE method.
|
| distmat(V);
|
function L = distmat(V);
%
% Returns the Distance Matrix (n x n) given coordinates V (n x 2).
%
% L = distmat(V);
%
%
% Author : Sbastien PARIS
%
[n , d] = size(V);
if( (d ~=2) || (n < 2) )
error('Cities coordinates must be (n x 2)');
end
n2 = n*n;
On = ones(n , 1);
ind_x = (1 : n);
ind_y = ind_x';
L = reshape(sqrt(sum((V(reshape(ind_x(On , :) , n2 , 1) , :) - V(reshape(ind_y(: , On) , n2 , 1) , :)).^2 , 2)) , n , n); % Distance Matrix (n x n)
|
|
Contact us at files@mathworks.com