- 1、本文档共5页,可阅读全部内容。
- 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
F(x1 , x2)=100*(x1^2-x2)^2+(1-x1)^2;遗传算法求解函数的最大值 (MATLAB)%Generic Algorithm for function f(x1,x2) optimum clear all;close all;(最大值)%Parameters Size=80; G=100;CodeL=10;umax=2.048;umin=-2.048;
F(x1 , x2)=100*(x1^2-x2)^2+(1-x1)^2;
遗传算法求解函数
的最大值 (MATLAB)
%Generic Algorithm for function f(x1,x2) optimum clear all;
close all;
(最大值)
%Parameters Size=80; G=100;
CodeL=10;
umax=2.048;
umin=-2.048;
E=round(rand(Size,2*CodeL));
%Initial Code
%Main Program for k=1:1:G
time(k)=k;
for s=1:1:Size m=E(s,:);
y1=0;y2=0;
%Uncoding m1=m(1:1:CodeL); for i=1:1:CodeL
y1=y1+m1(i)*2^(i-1); end
x1=(umax-umin)*y1/1023+umin; m2=m(CodeL+1:1:2*CodeL); for i=1:1:CodeL
y2=y2+m2(i)*2^(i-1); end
x2=(umax-umin)*y2/1023+umin;
F(s)=100*(x1^2-x2)^2+(1-x1)^2;
end
Ji=1./(F+1);
%****** Step 1 : Evaluate BestJ ******BestJ(k)=min(Ji);fi=F; [Oderfi,Indexfi]=sort(fi); Bestfi=Oderfi(Size); BestS=E(Indexfi(Size),:); max(fi)bfi(k)=Bestfi;%Fitness Function%Arranging fi small to bigger%Let Bestfi=max(fi)%Let BestS=E(m), m is the Indexfi belong to%****** Step 2 : Select and Reproduct Operation****** fi_sum=sum(fi);fi_Size=(Oderfi/fi_sum)*Size;fi_S=floor(fi_Size);%Selecting Bigger fi value (取整)kk=1;for i=1:1:Sizefor j=1:1:fi_S(i)
%****** Step 1 : Evaluate BestJ ******
BestJ(k)=min(Ji);
fi=F; [Oderfi,Indexfi]=sort(fi); Bestfi=Oderfi(Size); BestS=E(Indexfi(Size),:); max(fi)
bfi(k)=Bestfi;
%Fitness Function
%Arranging fi small to bigger
%Let Bestfi=max(fi)
%Let BestS=E(m), m is the Indexfi belong to
%****** Step 2 : Select and Reproduct Operation****** fi_sum=sum(fi);
fi_Size=(Oderfi/fi_sum)*Size;
fi_S=floor(fi_Size);
%Selecting Bigger fi value (取整)
kk=1;
for i=1:1:Size
for j=1:1:fi_S(i)
%Select and Reproduce
TempE(kk,:)=E(Indexfi(i),:); kk=kk+1;
end
end
%kk is used to reproduce
%************ Step 3 : Crossover Operation ************ pc=0.60;
n=ceil(20*rand); for i=1:2:(Size-1)
temp=rand;
if pctemp for j=n:1:20
TempE(i,j)=E(i+1,j);
TempE(i+1,j)=E(i,j);
end end
%Crossover Condition
end
TempE(Size,:)=BestS; E=TempE;
%*****
文档评论(0)