Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Ant Colony Optimization ACOUCP.m
Replies: 1   Last Post: Dec 20, 2013 1:01 PM

 Messages: [ Previous | Next ]
 Ahmed Hakim Posts: 22 Registered: 1/22/09
Ant Colony Optimization ACOUCP.m
Posted: Mar 11, 2013 9:50 AM

Hello Guys,

I was searching the google about Ant Colony Optimization Matlab Code and I found this nice code.

I was unlucky to find it in chinese language, It was my first problem.
I tried to translate it as I can.

Now I am working to understand its concept but I have some problems, if anyone here could help me about ant colony optimization I will be grateful.

I will paste the code here (in its language) and then I will type my questions:

____________________________________________________________________________
function [BESTX,BESTY,ALLX,ALLY]=ACOUCP(K,N,Rho,Q,Lambda,LB,UB,Num,Den,Delay,ts,StepNum,SigType,PIDLB,PIDUB)
%% ?????????????????PID?????
%% ??????
% K ????
% N ????
% Rho ??????????0?1???????0.7?0.95
% Q ??????????0?????1??
% Lambda ?????????0?1???????0.1?0.5
% LB ????????M×1???
% UB ????????M×1???
% Num ????????????????
% Den ????????????????
% Delay ????
% ts ??????
% StepNum ?????
% SigType ?????1??????2??????3??????
% PIDLB PID???????????
% PIDUB PID???????????
%% ??????
% BESTX K×1???????????M×1?????????????
% BESTY K×1???????????????????
% ALLX K×1???????????M×N?????????????
% ALLY K×N????????????????

%% ???????
M=length(LB);%???????
%???????
X=zeros(M,N);
for i=1:M
x=unifrnd(LB(i),UB(i),1,N);%%X?3*10????????????????10?????
X(i,:)=x;
end
%???????
ALLX=cell(K,1);%???????????M×N???????????
ALLY=zeros(K,N);%K×N?????????????
BESTX=cell(K,1);%???????????M×1?????????????
BESTY=zeros(K,1);%K×1???????????????????
k=1;%????????
Tau=ones(1,N);%??????
Y=zeros(1,N);%??????
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%?????
NN=5;
Rho_min=0.1;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% ????????
while k<=K
YY=zeros(1,N);
for n=1:N
x=X(:,n);
[J,u,yout,error]=PIDOBJ(x(1),x(2),x(3),Num,Den,Delay,ts,StepNum,SigType,PIDLB,PIDUB);
YY(n)=J;
end
maxYY=max(YY);
temppos=find(YY==maxYY);
POS=temppos(1);
%??????
for n=1:N
if n~=POS
x=X(:,n);
[J,u,yout,error]=PIDOBJ(x(1),x(2),x(3),Num,Den,Delay,ts,StepNum,SigType,PIDLB,PIDUB);
Fx=J;
mx=GaussMutation(x,LB,UB);
[J,u,yout,error]=PIDOBJ(mx(1),mx(2),mx(3),Num,Den,Delay,ts,StepNum,SigType,PIDLB,PIDUB);
Fmx=J;
if Fmx<Fx
X(:,n)=mx;
Y(n)=Fmx;
elseif rand>1-(1/(sqrt(k)))%%????????????????????????????
X(:,n)=mx;
Y(n)=Fmx;
else
X(:,n)=x;
Y(n)=Fx;
end
end
end
for n=1:N
if n~=POS
x=X(:,n);
[J,u,yout,error]=PIDOBJ(x(1),x(2),x(3),Num,Den,Delay,ts,StepNum,SigType,PIDLB,PIDUB);
Fx=J;
mx=GaussMutation(x,LB,UB);
[J,u,yout,error]=PIDOBJ(mx(1),mx(2),mx(3),Num,Den,Delay,ts,StepNum,SigType,PIDLB,PIDUB);
Fmx=J;
if Fmx<Fx
X(:,n)=mx;
Y(n)=Fmx;
elseif rand>1-(1/(sqrt(k)))%%???????????????????????????????
X(:,n)=mx;
Y(n)=Fmx;
else
X(:,n)=x;
Y(n)=Fx;
end
end
end

%???????????
for n=1:N
if n~=POS
x=X(:,n);
r=(K+k)/(K+K);
p=randperm(N);%%?1?N??????
t=ceil(r*N);%?????????????r*N?????
pos=p(1:t);%%?p??t???????
TempTau=Tau(pos);
maxTempTau=max(TempTau);
pos2=find(TempTau==maxTempTau);
pos3=pos(pos2(1));
x2=X(:,pos3(1));%%%?????????????????
x3=(1-Lambda)*x+Lambda*x2;%%
[J,u,yout,error]=PIDOBJ(x(1),x(2),x(3),Num,Den,Delay,ts,StepNum,SigType,PIDLB,PIDUB);
Fx=J;
[J,u,yout,error]=PIDOBJ(x(1),x(2),x(3),Num,Den,Delay,ts,StepNum,SigType,PIDLB,PIDUB);%%%????????????x(1),x(2),x(3)??x3(1),x3(2),x3(3)
Fx3=J;
if Fx3<Fx
X(:,n)=x3;
Y(n)=Fx3;
elseif rand>1-(1/(sqrt(k)))
X(:,n)=x3;
Y(n)=Fx3;
else
X(:,n)=x;
Y(n)=Fx;
end
end
end
%????????
Tau=Tau*(1-Rho);
maxY=max(Y);
minY=min(Y);
DeltaTau=(maxY-Y)/(maxY-minY);
Tau=Tau+Q*DeltaTau;
ALLX{k}=X;
ALLY(k,:)=Y;
minY=min(Y);
pos4=find(Y==minY);
BESTX{k}=X(:,pos4(1));
BESTY(k)=minY;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%??????????
if k>NN
if BESTY(k)>=BESTY(k-NN)
if 0.95*Rho>=Rho_min
Rho=0.95*Rho
else
Rho=Rho_min;
end
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
disp(k);
k=k+1;
end

___________________________________________________________________________

I concluded from this code that it is an improved Ant colony algorith that uses Mutation (guass mutation) to be having the genetics characteristics.

in the following portion of code:
I can not define how the ant can find its next path pheromone (largest) where is the equation that is known as random probalistic used always ???

_________________________________________________________________________
%???????????
for n=1:N
if n~=POS
x=X(:,n);
r=(K+k)/(K+K);
p=randperm(N);%%?1?N??????
t=ceil(r*N);%?????????????r*N?????
pos=p(1:t);%%?p??t???????
TempTau=Tau(pos);
maxTempTau=max(TempTau);
pos2=find(TempTau==maxTempTau);
pos3=pos(pos2(1));
x2=X(:,pos3(1));%%%?????????????????
x3=(1-Lambda)*x+Lambda*x2;%%
__________________________________________________________________________

what is the use of Lamda ???

what kind of equation you use to update the DeltaTau in the following
_________________________________________________________________________
%????????
Tau=Tau*(1-Rho);
maxY=max(Y);
minY=min(Y);
DeltaTau=(maxY-Y)/(maxY-minY);
Tau=Tau+Q*DeltaTau;
ALLX{k}=X;
ALLY(k,:)=Y;
minY=min(Y);
pos4=find(Y==minY);
BESTX{k}=X(:,pos4(1));
BESTY(k)=minY;
___________________________________________________________________

I hope to find a paper in english having this algorithm