完整可以运行的数值优化遗传算法源代码
i=1;
if opts(1)==1%浮点变异
maxfit=max(fit);
upfit=maxfit+0.05*abs(maxfit);
if opts(2)==1|opts(2)==3
while(i<=L)%自适应变异(自增或自减)
Point=unidrnd(n);
T=(1-fit(MutIn(i))/upfit)^2;
q=abs(1-rand^T);
%if q>1%按严格数学推理来说,这段程序是不能缺少的
% q=1
%end
p=OldPop(MutIn(i),Point)*(1-q);
if unidrnd(2)==1
NewPop(MutIn(i),Point)=p+q;
else
NewPop(MutIn(i),Point)=p;
end
i=i+1;
end
elseif opts(2)==2|opts(2)==4%AEA变异(任意变量的某一位变异)
while(i<=L)
Point=unidrnd(n);
T=(1-abs(upfit-fit(MutIn(i)))/upfit)^2;
v=1+unidrnd(1+ceil(10*T));
%v=1+unidrnd(5+ceil(10*eranum/MaxEranum));
q=mod(floor(OldPop(MutIn(i),Point)*10^v),10);
NewPop(MutIn(i),Point)=OldPop(MutIn(i),Point)-(q-unidrnd(9))/10^v;
i=i+1;
end
else
while(i<=L)
Point=unidrnd(n);
if round(rand)
NewPop(MutIn(i),Point)=OldPop(MutIn(i),Point)*(1-rand);
else
NewPop(MutIn(i),Point)=OldPop(MutIn(i),Point)+(1-OldPop(MutIn(i),Point))*rand; end
i=i+1;
end
end
elseif opts(1)==0%二进制串变异
if L>=1
while i<=L
k=unidrnd(n,1,VarNum); %设置变异点数(=变量数)
for j=1:length(k)
if NewPop(MutIn(i),k(j))==1
NewPop(MutIn(i),k(j))=0;
else
百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说教育文库遗传算法Matlab源代码(8)在线全文阅读。
相关推荐: