回覆列表
  • 1 # 滴逃逃

    function [x fx string]=fun_SuiJiSuanFa2(N,genLenth,Pc,Pm,downbound,upbound,generation) %[x fx string]=fun_SuiJiSuanFa2(6,16,0.7,0.01,-3,3,100) %f 表示函式 %N表示染色體種群大小 %genLenth表示染色體長度 %Pc表示交叉機率 %Pm表示突變機率 %downbound %upbound %generation迴圈代數 %進位制編碼,此處編寫為二進位制 num=2; initdata=randi([0 num-1],N,genLenth); %二進位制編碼的權值 weight=(num).^(genLenth/2-1:-1:0); weights=repmat(weight,N,1); %儲存每代的最好值和平均值, meanally=zeros(1,generation); maxally=zeros(1,generation); Nowx=zeros(generation,genLenth); for k=1:generation %解碼後的整數 allx1=sum(initdata(:,1:genLenth/2).*weights,2); allx2=sum(initdata(:,genLenth/2+1:end).*weights,2); %對映到取值範圍 delt=(upbound-downbound)/(num^(genLenth/2)-1); allx1=allx1.*delt+downbound; allx2=allx2.*delt+downbound; %染色體的適應性 ally=f(allx1,allx2); %平均值,最大值 meanally(k)=mean(ally); maxally(k)=max(ally); %找下標function [x fx string]=fun_SuiJiSuanFa2(N,genLenth,Pc,Pm,downbound,upbound,generation) %[x fx string]=fun_SuiJiSuanFa2(6,16,0.7,0.01,-3,3,100) %f 表示函式 %N表示染色體種群大小 %genLenth表示染色體長度 %Pc表示交叉機率 %Pm表示突變機率 %downbound %upbound %generation迴圈代數 %進位制編碼,此處編寫為二進位制 num=2; initdata=randi([0 num-1],N,genLenth); %二進位制編碼的權值 weight=(num).^(genLenth/2-1:-1:0); weights=repmat(weight,N,1); %儲存每代的最好值和平均值, meanally=zeros(1,generation); maxally=zeros(1,generation); Nowx=zeros(generation,genLenth); for k=1:generation %解碼後的整數 allx1=sum(initdata(:,1:genLenth/2).*weights,2); allx2=sum(initdata(:,genLenth/2+1:end).*weights,2); %對映到取值範圍 delt=(upbound-downbound)/(num^(genLenth/2)-1); allx1=allx1.*delt+downbound; allx2=allx2.*delt+downbound; %染色體的適應性 ally=f(allx1,allx2); %平均值,最大值 meanally(k)=mean(ally); maxally(k)=max(ally); %找下標

  • 中秋節和大豐收的關聯?
  • 米粉等小米Mix4,還是現在買小米9?