資源簡介
蛙跳算法 MATLAB程序 用MATLAB編寫的基本蛙跳算法

代碼片段和文件信息
clc;clear?all;
m=50?%種群分組數
n=35;?%t每組青蛙包含的個數
Ne=25;?%組內迭代數
smax?=?100;??%最大步長
MAXGEN=100;??%種群總進化代數
d=25;?%優化問題維數
pmax?=1024;?%d維最大值
pmin?=?-1024;%d維最小值
%%產生初始青娃
F=m*n;
tic;
for?i1=1:F
????p(i1:)=pmax*rands(1d);
end
%%全局迭代尋優
yy=zeros(1MAXGEN);
for?ii=1:MAXGEN????
????for?i2=1:F
????????fitness(i2)=fun(p(i2:));
????end
????%排序,找最好的,并分組
????[fitsortindex]=sort(fitness);
????for?i3=1:F
????????x(i3:)=p(index(i3):);
????end
????gx=x(1:);%種群內最好的青娃
????yy(ii)=fitsort(1);
????%?yy(ii)=fun(x(1:));
??%???local=zeros(nd);
????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=?pw+s1;
??????????temp(find(temp>pmax))=pmax;
???????????temp(find(temp ???????????if?fun(temp)?>?fun(pw)
???????????????s1=rand.*(gx-pw);%采用全局最優更新
????????????????s1(find(s1>smax))=smax;
???????????????temp=pw+s1;
?????????????????temp(find(temp>pmax))=pmax;
??????????temp(find(temp ???????????end
???????????if?fun(temp)>fun(pw)
????????????s1=pmax*rands(1d);%隨機更新
?????????????s1(find(s1>smax))=smax;
?????????????temp=pw+s1;
?????????????temp(find(temp>pmax))=pmax;
????????????temp(find(temp ????????????end
?????????????local(n:)?=?temp;
?????????????for?loc=1:n
?????????????fitlocal(loc)=fun(local(loc:));
?????????????end
?????????????[localsortindexlocal]=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(‘函數最優解‘);
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????2031??2010-01-06?12:57??蛙跳程序\FSFLA.m
?????文件????????232??2010-01-06?12:57??蛙跳程序\fun.m
?????目錄??????????0??2011-01-07?13:40??蛙跳程序
-----------?---------??----------?-----??----
?????????????????2263????????????????????3
評論
共有 條評論