function
[R_best,L_best,L_ave,Shortest_Route,Shortest_Length]=ACATSP(C,NC_max,m,Alpha,Beta,Rho,Q)
%%=========================================================================
%% ACATSP.m
%% Ant Colony Algorithm for Traveling Salesman Problem
%%-------------------------------------------------------------------------
%%
%% C n , n× 2
%% NC_max
%% m
%% Alpha
%% Beta
%% Rho
%% Q
%% R_best
%% L_best
%%=========================================================================
C=[1,1.5;-8,8;-7.5,5;-18,1.5;-20,-2;-18.5,-12;
-12.5 -16;-0.5 -11;-6 -9.5;-9 -7;-5.5 -7;-1.5 -12;
4 -5;2.5 -3.5;-7 -5];
m=15;
Alpha=1;
Beta=5;
Rho=.1;
NC_max=13;
Q=100;
%%:
n=size(C,1);%*()
D=zeros(n,n);%D
for i=1:n
for j=1:n
if i~=j
D(i,j)=((C(i,1)-C(j,1))^2+(C(i,2)-C(j,2))^2)^0.5;
else
D(i,j)=eps;
end
D(j,i)=D(i,j);
end
end
Eta=1./D;%Eta ,
Tau=ones(n,n);%Tau
Tabu=zeros(m,n);%
NC=1;%
R_best=zeros(NC_max,n);%
L_best=inf.*ones(NC_max,1);%
L_ave=zeros(NC_max,1);%
while NC=rand);
to_visit=J(Select(1));
Tabu(i,j)=to_visit;
end
end
if NC>=2
Tabu(1,:)=R_best(NC-1,:);
end
%%:
L=zeros(m,1);
for i=1:m
R=Tabu(i,:);
for j=1:(n-1)
L(i)=L(i)+D(R(j),R(j+1));
end
L(i)=L(i)+D(R(1),R(n));
end
L_best(NC)=min(L);
pos=find(L==L_best(NC));
R_best(NC,:)=Tabu(pos(1),:);
L_ave(NC)=mean(L);
NC=NC+1
%%:
Delta_Tau=zeros(n,n);
for i=1:m
for j=1:(n-1)
Delta_Tau(Tabu(i,j),Tabu(i,j+1))=Delta_Tau(Tabu(i,j),Tabu(i,j+1))+Q /L(i);
end
Delta_Tau(Tabu(i,n),Tabu(i,1))=Delta_Tau(Tabu(i,n),Tabu(i,1))+Q /L(i);
end
Tau=(1-Rho).*Tau+Delta_Tau;
%%:
Tabu=zeros(m,n);
end
%%:
Pos=find(L_best==min(L_best));
Shortest_Route=R_best(Pos(1),:);
Shortest_Length=L_best(Pos(1));
subplot(1,2,1)
DrawRoute(C,Shortest_Route)
subplot(1,2,2)
plot(L_best)
hold on
plot(L_ave,'y')
title(' ')
function DrawRoute(C,R)
%%====================================================================
%% DrawRoute.m
%%
%%--------------------------------------------------------------------
%% C Coordinate , N× 2
%% R Route
%%====================================================================
N=length(R)
scatter(C(:,1),C(:,2))
hold on
plot([C(R(1),1),C(R(N),1)],[C(R(1),2),C(R(N),2)])
hold on
for ii=2:N
plot([C(R(ii-1),1),C(R(ii),1)],[C(R(ii-1),2),C(R(ii),2)])
hold on
end