电脑桌面
添加小米粒文库到电脑桌面
安装后可以在桌面快捷访问

遗传算法matlab实现源程序VIP免费

遗传算法matlab实现源程序_第1页
1/11
遗传算法matlab实现源程序_第2页
2/11
遗传算法matlab实现源程序_第3页
3/11
clc;clear;%各份订单基本数据phen=[123456789101112131441,52,-23,-46,-143,-74,-56,101,73,74,95,86,-35,3265,23,-76,104,34,38,4,-23,55,-49,39,89,-86,527716,9887,12188,8819,4002,6119,3284,4607,5600,4587,9821,13024,6547,2684500,400,1000,120,0,235,654,241,0,361,120,254,300,1501,4,2,2,4,4,3,3,3,1,4,5,1,32.7,1.8,4,2.5,1.6,1,3.6,5,4.2,1.9,6.4,2.8,1.4,8];hromlength=14;popsize=30;maxgen=500;pc=0.8;pm=0.04;forkem=1:popsizepopulation(kem,:)=randperm(hromlength);endpopulation;%评价目标函数值foruim=1: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

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;endendclearterm;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;endendclearpopulation;clearobjmin;clearobjmean;%遗传操作结束population=newpop;forium=1:popsizevector2=population(ium,:);obj(ium)=object(hromlength,vector2,phen);endobjmin=min(obj);objmean=mean(obj);clearopti;forsequ1=1:popsizeifobj(sequ1)==objminopti=population(sequ1,:);endendsolution=objmin;final(gen)=objmin;final1(gen)=objmean;endoptisolutionplot(final);holdon;plot(final1,'--')holdoff%目标函数值子函数function[cost]=hanshu(hromlength,vector,phen)wmax=20000;ct=1.2;ch=0.5;fornum=1:hromlengthline=vector(num);s(:,num)=phen(:,line);endm=1;cshort=0;chold=0;ctrans=0;whilem<=hromlengthj=m;weight=s(4,j);day=s(6,j);dis=sqrt(s(2,j)^2+s(3,j)^2);while((j

weight=weight+s(4,j+1);if(s(6,j+1)

cshort=(s(5,j+1))*(s(7,j+1))*0.1+cshort;chold=(s(4,j+1))*ch+chold;enddis=sqrt((s(2,j)-s(2,j+1))^2+(s(3,j)-s(3,j+1))^2);j=j+1;enddis=dis+sqrt(s(2,j)^2+s(3,j)^2);ctrans=ctrans+dis*weight*ct;m=j+1;endcost=cshort+chold+ctrans;

1、当您付费下载文档后,您只拥有了使用权限,并不意味着购买了版权,文档只能用于自身使用,不得用于其他商业用途(如 [转卖]进行直接盈利或[编辑后售卖]进行间接盈利)。
2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。
3、如文档内容存在违规,或者侵犯商业秘密、侵犯著作权等,请点击“违规举报”。

碎片内容

遗传算法matlab实现源程序

确认删除?
VIP
微信客服
  • 扫码咨询
会员Q群
  • 会员专属群点击这里加入QQ群
客服邮箱
回到顶部