problem in using grTravSale function

5 次查看(过去 30 天)
I am facing the difficulty is implementing the TSP problem in the following code
xm=50;
ym=50;
n = 5 % number of nodes
% random deployment of nodes in 2-D grid
for i=1:1:n
node(i).x = round(rand(1,1)*xm);
node(i).y = round(rand(1,1)*ym);
fprintf('Plotting (%d, %d)\n', node(i).x, node(i).y);
plot(node(i).x,node(i).y,'x');
text(node(i).x,node(i).y,int2str(i),'FontSize',10);
grid on;
end
% calculating distances between each node with every other node
index = 5;
for l = 1 : index
for m = 1 : index
if l ~= m
% tem(l,m)= tovisit(l), tovisit(m);
distances(l,m) = round(sqrt((node(l).x - node(m).x)^2 + (node(l).y - node(m).y)^2));
else
distances(l,m) = 0;
end
end
end
close;
for l = 1 : index
for m = 1 : index
fprintf('%d, ', distances(l,m));
end
fprintf('\n');
end
index
a = size (distances);
% using grTravSale to compute the sequence to visit
ou(a,b) =grTravSale(distances(index, index));
Upon the execution of code I am facing the following error
??? Error using ==> grTravSale at 40 Must be not less than 3 cities!
Error in ==> temp at 36 ou(a,b) =grTravSale(distances(index, index));
Although the number of nodes are 5, Please help me in this regards. Thank you

回答(0 个)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by