预览加载中,请您耐心等待几秒...
1/10
2/10
3/10
4/10
5/10
6/10
7/10
8/10
9/10
10/10

亲,该文档总共11页,到这已经超出免费预览范围,如果喜欢就直接下载吧~

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

functionyouhuafun D=code;N=50;%Tunablemaxgen=50;%Tunablecrossrate=0.5;%Tunablemuterate=0.08;%Tunablegeneration=1;num=length(D);fatherrand=randint(num,N,3);score=zeros(maxgen,N);whilegeneration<=maxgenind=randperm(N-2)+2;%随机配对交叉A=fatherrand(:,ind(1:(N-2)/2));B=fatherrand(:,ind((N-2)/2+1:end));%多点交叉rnd=rand(num,(N-2)/2);ind=rndtmp=A(ind);A(ind)=B(ind);B(ind)=tmp; %%两点交叉%forkk=1:(N-2)/2%rndtmp=randint(1,1,num)+1;%tmp=A(1:rndtmp,kk);%A(1:rndtmp,kk)=B(1:rndtmp,kk);%B(1:rndtmp,kk)=tmp;%endfatherrand=[fatherrand(:,1:2),A,B];%变异rnd=rand(num,N);ind=rnd[m,n]=size(ind);tmp=randint(m,n,2)+1;tmp(:,1:2)=0;fatherrand=tmp+fatherrand;fatherrand=mod(fatherrand,3);%fatherrand(ind)=tmp;%评价、选择scoreN=scorefun(fatherrand,D);%求得N个个体的评价函数score(generation,:)=scoreN;[scoreSort,scoreind]=sort(scoreN);sumscore=cumsum(scoreSort);sumscore=sumscore./sumscore(end);childind(1:2)=scoreind(end-1:end);fork=3:Ntmprnd=rand;tmpind=tmprnddifind=[0,diff(tmpind)];if~any(difind)difind(1)=1;endchildind(k)=scoreind(logical(difind));endfatherrand=fatherrand(:,childind);generation=generation+1;end%scoremaxV=max(score,[],2);minV=11*300-maxV;plot(minV,'*');title('各代的目标函数值');F4=D(:,4);FF4=F4-fatherrand(:,1);FF4=max(FF4,1);D(:,5)=FF4;saveDDataD functionD=codeloadyouhua.mat%propertiesF2andF3F1=A(:,1);F2=A(:,2);F3=A(:,3);if(max(F2)>1450)||(min(F2)<=900)error('DATApropertyF2exceedit''srange(900,1450]')end%getgrouppropertyF1ofdata,accordingtoF2valueF4=zeros(size(F1));forite=11:-1:1index=find(F2<=900+ite*50);F4(index)=ite;endD=[F1,F2,F3,F4]; functionScoreN=scorefun(fatherrand,D)F3=D(:,3);F4=D(:,4);N=size(fatherrand,2);FF4=F4*ones(1,N);FF4rnd=FF4-fatherrand;FF4rnd=max(FF4rnd,1);ScoreN=ones(1,N)*300*11;%这里有待优化fork=1:NFF4k=FF4rnd(:,k);forite=1:11F0index=find(FF4k==ite);if~isempty(F0index)tmpMat=F3(F0index);tmpSco=sum(tmpMat);ScoreBin(ite)=mod(tmpSco,300);endendScorek(k)=sum(ScoreBin);endScoreN=ScoreN-Scorek; 遗传算法实例: %下面举例说明遗传算法% %求下列函数的最大值% %f(x)=10*sin(5x)+7*cos(4x)x∈[0,10]% %将x的值用一个10位的二值形式表示为二值问题,一个10位的二值数提供的分辨率是每为(10-