下载此文档

遗传算法matlab实现源程序.docx


文档分类:IT计算机 | 页数:约12页 举报非法文档有奖
1/12
下载提示
  • 1.该资料是网友上传的,本站提供全文预览,预览什么样,下载就什么样。
  • 2.下载该文档所得收入归上传者、原创者。
  • 3.下载的文档,不会出现我们的网址水印。
1/12 下载此文档
文档列表 文档介绍
该【遗传算法matlab实现源程序 】是由【guoxiachuanyue014】上传分享,文档一共【12】页,该文档可以免费在线阅读,需要了解更多关于【遗传算法matlab实现源程序 】的内容,可以使用淘豆网的站内搜索功能,选择自己适合的文档,以下文字是截取该文章内的部分文字,如需要获得完整电子版,请下载此文档到您的设备,方便您编辑和打印。□2004006008001000**********(]10002000进化代数附页:.遗传算法源程序:遗传算法求解集运模型480046004血42004000■3800360034003200■3000clc;clear;population;%评价目标函数值foruim=l:popsizevector二population(uim,:);obj(uim)二hanshu(hromlength,vector,phen);end%obj%min(obj)clearuim;objmin=min(obj);forsequ=1:popsizeifobj(sequ)==objminopti=population(sequ,:);endendclearsequ;fmax=22000;%==forgen=1:maxgen%选择操作%将求最小值的函数转化为适应度函数forindivi=1:popsizeobj1(indivi)=1/obj(indivi);endclearindivi;%适应度函数累加总合total=0;forindivi=1:popsizetotal=total+obj1(indivi);endclearindivi;%每条染色体被选中的几率forindivi=1:popsizefitness1(indivi)=obj1(indivi)/total;endclearindivi;%各条染色体被选中的范围forindivi=1:popsizefitness(indivi)=0;forj=1:indivifitness(indivi)=fitness(indivi)+fitness1(j);endendclearj;fitness;%选择适应度高的个体forranseti=1:popsizeran=rand;while(ran>1||ran<0)ran=rand;endran;ifran<=fitness(1)newpopulation(ranseti,:)=population(1,:);elseforfet=2:popsizeif(ran>fitness(fet-1))&&(ran<=fitness(fet))newpopulation(ranseti,:)=population(fet,:);endendendendclearran;newpopulation;%交叉forint=1:2:popsize-1popmoth=newpopulation(int,:);popfath=newpopulation(int+1,:);popcross(int,:)=popmoth;popcross(int+1,:)=popfath;randnum=rand;if(randnum<P>cpoint1=round(rand*hromlength);cpoint2=round(rand*hromlength);while(cpoint2==cpoint1)cpoint2=round(rand*hromlength);endifcpoint1>cpoint2tem=cpoint1;cpoint1=cpoint2;cpoint2=tem;endcpoint1;cpoint2;forterm=cpoint1+1:cpoint2forss=1:hromlengthifpopcross(int,ss)==popfath(term)tem1=popcross(int,ss);popcross(int,ss)=popcross(int,term);popcross(int,term)=tem1;endendcleartem1;endforterm=cpoint1+1:cpoint2forss=1:hromlengthifpopcross(int+1,ss)==popmoth(term)tem1=popcross(int+1,ss);popcross(int+1,ss)=popcross(int+1,term);popcross(int+1,term)=tem1;endendcleartem1;endendendclearterm;endclearrandnum;popcross;%变异操作newpop=popcross;forint=1:popsizerandnum=rand;ifrandnumcpoint12=round(rand*hromlength);cpoint22=round(rand*hromlength);if(cpoint12==0)cpoint12=1;endif(cpoint22==0)cpoint22=1;endwhile(cpoint22==cpoint12)cpoint22=round(rand*hromlength);ifcpoint22==0;cpoint22=1;endendtemp=newpop(int,cpoint12);newpop(int,cpoint12)=newpop(int,cpoint22);newpop(int,cpoint22)=temp;endendnewpop;clearcpoint12;clearcpoint22;clearrandnum;clearint;forium=1:popsizevector1=newpop(ium,:);obj1(ium)=hanshu(hromlength,vector1,phen);endclearium;obj1max=max(obj1);forar=1:popsizeifobj1(ar)==obj1maxnewpop(ar,:)=opti;endend%:%初始格式化clearall;clc;formatlong;%给定初始化条件cl=;%学****因子1c2=;%学****因子2w=;%惯性权重MaxDT=100;%最大迭代次数D=2;%搜索空间维数(未知数个数)N=40;%初始化群体个体数目eps=10'(-6);%设置精度(在已知最小值时候用)%初始化种群的个体(可以在这里限定位置和速度的范围)fori=1:Nforj=1:Dx(i,j)二randn;%随机初始化位置v(i,j)二randn;%随机初始化速度endend%先计算各个粒子的适应度,并初始化Pi和Pgfori=1:Np(i)=fitness(x(i,:),D);y(i,:)=x(i,:);endpg=x(1,:);%Pg为全局最优fori=2:Niffitness(x(i,:),D)<FITNESS(pg,D)pg=x(i,:);end

遗传算法matlab实现源程序 来自淘豆网www.taodocs.com转载请标明出处.

相关文档 更多>>
非法内容举报中心
文档信息