为什么混合蛙跳算法 无法达到预期的收敛效果(,0.001)? 附代码
%%%%%%%%%%%混合跬跳算法优化%%%%%%%%%%%%
clc;clear all; m=20 %种群分组数 n=10; %每组青蛙包含的个数 Ne=15; %组内迭代数 smax = 5; %最大步长
MAXGEN=500; %种群总进化代数 d=20; %优化问题维数 max=d-1;
pmax =5; %d维最大值 pmin = -5;%d维最小值 %
%%产生初始青娃 F=m*n; tic; for i1=1:F
p(i1,:)=pmax*rands(1,d); end
%%全局迭代寻优
yy=zeros(1,MAXGEN); for ii=1:MAXGEN for i2=1:F
fitness(i2)=fun(p(i2,:),max); end
%排序,找最好的,并分组 [fitsort,index]=sort(fitness); for i3=1:F
x(i3,:)=p(index(i3),:); end
gx=x(1,:);%种群内最好的青娃 yy(ii)=fitsort(1); for i4=1:m
local = p(i4:m:end,:);
for j=1:Ne %每组青蛙迭代次数 pb=local(1,:);%组内最优 pw=local(n,:);%组内最差
s1=rand.*(pb-pw);%采用组内最优更新 s1(find(s1>smax))=smax; temp(1,:)= pw+s1;
temp(find(temp>pmax))=pmax; temp(find(temp
temp(find(temp>pmax))=pmax; temp(find(temp if fun1(temp,max)>fun1(pw,max) % s1=pmax*rands(1,d);%随机更新 % s1(find(s1>smax))=smax; % temp(1,:)= pw+s1; temp=pmax*rands(1,d); temp(find(temp>pmax))=pmax; temp(find(temp local(n,:) = temp; for loc=1:n fitlocal(loc)=fun1(local(loc,:),max); end [localsort,indexlocal]=sort(fitlocal); for loc=1:n localnew(loc,:) = local(indexlocal(loc),:); end local=localnew; end %结束Ne p(i4:m:end,:) =local; end %结束m %最好的青娃适配值 end %结束MAXGEN toc %结果分析 plot(yy) title('混合跬跳算法优化'); xlabel('总进化代数');ylabel('函数最优解'); yy(MAXGEN) function y = fun(x,max) %第1个函数 % max=3; % y=x(1)*x(1); % for i=2:max % y=x(i)*x(i)+y; % end %第2个函数Rosenbrock function y=100*(x(2)-x(1)*x(1))^2+(x(1)-1)^2; for i=2:max y=100*(x(i+1)-x(i)*x(i))^2+(x(i)-1)^2+y; end