matlab 遗传算法 最值,完整版遗传算法求解函数最大值matlab

《完整版遗传算法求解函数最大值matlab》由会员分享,可在线阅读,更多相关《完整版遗传算法求解函数最大值matlab(7页珍藏版)》请在人人文库网上搜索。

1、遗传算法求解函数F(x1,x2)=100*(x12-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=。

2、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*(x12-x2)2+(1-x1)2; end Ji=1./(F+1); %* Step 1 : Evaluate BestJ * BestJ(k)=min(Ji); fi=F; %Fit。

3、ness Function Oderfi,Indexfi=sort(fi); %Arranging fi small to bigger Bestfi=Oderfi(Size); %Let Bestfi=max(fi) BestS=E(Indexfi(Size),:); %Let BestS=E(m), m is the Indexfi belong to max(fi) bfi(k)=Bestfi; %* Step 2 : Select and Reproduct Operation* fi_sum=sum(fi); fi_Size=(Oderfi/fi_sum)*Size; fi_S=fl。

4、oor(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; %kk is used to reproduce end end %* Step 3 : Crossover Operation * pc=0.60; n=ceil(20*rand); for i=1:2:(Size-1) temp=rand; if pctemp %Crossover Condition f。

5、or j=n:1:20 TempE(i,j)=E(i+1,j); TempE(i+1,j)=E(i,j); end end end TempE(Size,:)=BestS; E=TempE; %* Step 4: Mutation Operation * %pm=0.001; %pm=0.001-1:1:Size*(0.001)/Size; %Bigger fi, smaller Pm %pm=0.0; %No mutation %Big mutation pm=0.1; for i=1:1:Size for j=1:1:2*CodeL temp=rand; if pmtemp %Mutati。

6、on Condition if TempE(i,j)=0 TempE(i,j)=1; else TempE(i,j)=0; end end end end %Guarantee TempPop(30,:) is the code belong to the best individual(max(fi) TempE(Size,:)=BestS; E=TempE; end Max_Value=Bestfi BestS x1 x2 figure(1); plot(time,BestJ); xlabel(Times);ylabel(Best J); figure(2); plot(time,bfi); xlabel(times);ylabel(Best F); 轐行绒果? Map_Falue = 3.9059e+ 03 BestS = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 = ? -2&0480 x2 = -2.0080。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值