遗传算法matlab实现源程序(共12页).doc

上传人:飞****2 文档编号:7254242 上传时间:2022-02-22 格式:DOC 页数:11 大小:60KB
返回 下载 相关 举报
遗传算法matlab实现源程序(共12页).doc_第1页
第1页 / 共11页
遗传算法matlab实现源程序(共12页).doc_第2页
第2页 / 共11页
点击查看更多>>
资源描述

《遗传算法matlab实现源程序(共12页).doc》由会员分享,可在线阅读,更多相关《遗传算法matlab实现源程序(共12页).doc(11页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。

1、精选优质文档-倾情为你奉上clc;clear;%各份订单基本数据phen=1 2 3 4 5 6 7 8 9 10 11 12 13 1441,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,

2、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;for kem=1:popsizepopulation(kem,:)=randperm(hromlength);endpopulation;%评价目标函数值for uim=1:popsize vector=population(uim,:); obj(uim)=hanshu(hromlength,vector,phen);end%obj%min(obj)clear uim

3、;objmin=min(obj);for sequ=1:popsize if obj(sequ)=objmin opti=population(sequ,:); endendclear sequ;fmax=22000;%=for gen=1:maxgen%选择操作%将求最小值的函数转化为适应度函数for indivi=1:popsize obj1(indivi)=1/obj(indivi);endclear indivi;%适应度函数累加总合total=0;for indivi=1:popsize total=total+obj1(indivi);endclear indivi;%每条染色体被

4、选中的几率for indivi=1:popsize fitness1(indivi)=obj1(indivi)/total;endclear indivi;%各条染色体被选中的范围for indivi=1:popsize fitness(indivi)=0; for j=1:indivi fitness(indivi)=fitness(indivi)+fitness1(j); endendclear j;fitness;%选择适应度高的个体for ranseti=1:popsize ran=rand; while (ran1|ran0) ran=rand; end ran; if ranfit

5、ness(fet-1)&(ran=fitness(fet) newpopulation(ranseti,:)=population(fet,:); end end endendclear ran;newpopulation;%交叉for int=1:2:popsize-1 popmoth=newpopulation(int,:); popfath=newpopulation(int+1,:); popcross(int,:)=popmoth; popcross(int+1,:)=popfath; randnum=rand; if(randnum cpoint1=round(rand*hroml

6、ength); cpoint2=round(rand*hromlength); while (cpoint2=cpoint1) cpoint2=round(rand*hromlength); end if cpoint1cpoint2 tem=cpoint1; cpoint1=cpoint2; cpoint2=tem; end cpoint1; cpoint2; for term=cpoint1+1:cpoint2 for ss=1:hromlength if popcross(int,ss)=popfath(term) tem1=popcross(int,ss); popcross(int,

7、ss)=popcross(int,term); popcross(int,term)=tem1; end end clear tem1; end for term=cpoint1+1:cpoint2 for ss=1:hromlength if popcross(int+1,ss)=popmoth(term) tem1=popcross(int+1,ss); popcross(int+1,ss)=popcross(int+1,term); popcross(int+1,term)=tem1; end end clear tem1; end end clear term;endclear ran

8、dnum;popcross;%变异操作newpop=popcross;for int=1:popsize randnum=rand; if randnum cpoint12=round(rand*hromlength); cpoint22=round(rand*hromlength); if (cpoint12=0) cpoint12=1; end if (cpoint22=0) cpoint22=1; end while (cpoint22=cpoint12) cpoint22=round(rand*hromlength); if cpoint22=0; cpoint22=1; end en

9、d temp=newpop(int,cpoint12); newpop(int,cpoint12)=newpop(int,cpoint22); newpop(int,cpoint22)=temp; endendnewpop;clear cpoint12;clear cpoint22;clear randnum;clear int;for ium=1:popsize vector1=newpop(ium,:); obj1(ium)=hanshu(hromlength,vector1,phen);endclear ium;obj1max=max(obj1);for ar=1:popsize if

10、obj1(ar)=obj1max newpop(ar,:)=opti; endendclear population;clear objmin;clear objmean;%遗传操作结束population=newpop;for ium=1:popsize vector2=population(ium,:); obj(ium)=object(hromlength,vector2,phen);endobjmin=min(obj);objmean=mean(obj);clear opti;for sequ1=1:popsize if obj(sequ1)=objmin opti=populatio

11、n(sequ1,:); endendsolution=objmin;final(gen)=objmin;final1(gen)=objmean;endoptisolutionplot(final);hold on;plot(final1,-)hold off%目标函数值子函数functioncost=hanshu(hromlength,vector,phen)wmax=20000;ct=1.2;ch=0.5;for num=1:hromlength line=vector(num); s(:,num)=phen(:,line);endm=1;cshort=0;chold=0;ctrans=0;

12、while m=hromlength j=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; end dis=sqrt(s(2,j)-s(2,j+1)2+(s(3,j)-s(3,j+1)2); j=j+1; end dis=dis+sqrt(s(2,j)2+s(3,j)2); ctrans=ctrans+dis*weight*ct; m=j+1;endcost=cshort+chold+ctrans;专心-专注-专业

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 应用文书 > 教育教学

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号© 2020-2023 www.taowenge.com 淘文阁