资源描述:
《智能优化算法程序代码集锦》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、人工蚂蚁算法%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%function[x,y,minvalue]=AA(func)%Example[x,y,minvalue]=AA('Foxhole')clc;tic;subplot(2,2,1);%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%plot1draw(func);title([func,'Function']);%初始化各参数Ant=1
2、00;%蚂蚁规模ECHO=200;%迭代次数step=0.01*rand(1);%局部搜索时的步长temp=[0,0];%各子区间长度start1=-100;end1=100;start2=-100;end2=100;Len1=(end1-start1)/Ant;Len2=(end2-start2)/Ant;%P=0.2;%初始化蚂蚁位置fori=1:AntX(i,1)=(start1+(end1-start1)*rand(1));X(i,2)=(start2+(end2-start2)*rand(1));%func=AA_Foxhole_Func(X(i,1),X(i,2))
3、;val=feval(func,[X(i,1),X(i,2)]);T0(i)=exp(-val);%初始信息素,随函数值大,信息素浓度小,反之亦然%%%%%*********************************************************************end;%至此初始化完成forEcho=1:ECHO%开始寻优%P0函数定义,P0为全局转移选择因子a1=0.9;b1=(1/ECHO)*2*log(1/2);f1=a1*exp(b1*Echo);a2=0.225;b2=(1/ECHO)*2*log(2);f2=a2*exp(b2*Ech
4、o);ifEcho<=(ECHO/2)P0=f1;elseP0=f2;end;%P函数定义,P为信息素蒸发系数a3=0.1;b3=(1/ECHO).*log(9);P=a3*exp(b3*Echo);lamda=0.10+(0.14-0.1)*rand(1);%全局转移步长参数Wmax=1.0+(1.4-1.0)*rand(1);%步长更新参数上限Wmin=0.2+(0.8-0.2)*rand(1);%步长更新参数下限%寻找初始最优值T_Best=T0(1);forj=1:AntifT0(j)>=T_BestT_Best=T0(j);BestIndex=j;end;end;W=
5、Wmax-(Wmax-Wmin)*(Echo/ECHO);%局部搜索步长更新参数forj_g=1:Ant%全局转移概率求取,当该蚂蚁随在位置不是bestindex时ifj_g~=BestIndexr=T0(BestIndex)-T0(j_g);Prob(j_g)=exp(r)/exp(T0(BestIndex));else%当j_g=BestIndex的时候进行局部搜索ifrand(1)<0.5temp(1,1)=X(BestIndex,1)+W*step;temp(1,2)=X(BestIndex,2)+W*step;elsetemp(1,1)=X(BestIndex,1)-
6、W*step;temp(1,2)=X(BestIndex,2)-W*step;end;Prob(j_g)=0;%bestindex的蚂蚁不进行全局转移end;X1_T=temp(1,1);X2_T=temp(1,2);X1_B=X(BestIndex,1);X2_B=X(BestIndex,2);%func1=AA_Foxhole_Func(X1_T,X2_T);%%%%%%%%%%%***************************************************%F1_T=func1;F1_T=feval(func,[X(i,1),X(i,2)]);F1
7、_B=feval(func,[X1_B,X2_B]);%F1_T=(X1_T-1).^2+(X2_T-2.2).^2+1;%func2=AA_Foxhole_Func(X1_B,X2_B);%%%%%%%%%%%%%***************************************************%F1_B=func2;%F1_B=(X1_B-1).^2+(X2_B-2.2).^2+1;ifexp(-F1_T)>exp(-F1_B)X(BestIndex,1)=temp(