资源描述:
《遗传算法matlab实现源程序》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、专业技术资料分享clc;clear;%各份订单基本数据phen=[1234567891011121314 41,52,-23,-46,-143,-74,-56,101,73,74,95,86,-35,32 65,23,-76,104,34,38,4,-23,55,-49,39,89,-86,52 7716,9887,12188,8819,4002,6119,3284,4607,5600,4587,9821,13024,6547,2684 500,400,1000,120,
2、0,235,654,241,0,361,120,254,300,150 1,4,2,2,4,4,3,3,3,1,4,5,1,3 WORD文档下载可编辑专业技术资料分享2.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;
3、 pc=0.8; pm=0.04; forkem=1:popsizepopulation(kem,:)=randperm(hromlength); endpopulation;%评价目标函数值foruim=1:popsize vector=population(uim,:); obj(uim)=hanshu(hromlength,vec
4、tor,phen);end%obj%min(obj)clearuim;objmin=min(obj);forsequ=1:popsize ifobj(sequ)==objminWORD文档下载可编辑专业技术资料分享 opti=population(sequ,:); endendclearsequ;fmax=22000;%==forgen=1:maxgen%选择操作%将求最小值的函数转化为适应度函数forindivi=1:popsize obj1(indivi)=1/obj(indivi);endclearindivi;%适应度
5、函数累加总合total=0;forindivi=1:popsize total=total+obj1(indivi);endclearindivi;%每条染色体被选中的几率forindivi=1:popsize fitness1(indivi)=obj1(indivi)/total;WORD文档下载可编辑专业技术资料分享endclearindivi;%各条染色体被选中的范围forindivi=1:popsize fitness(indivi)=0; forj=1:indivi fitness(indivi)=fitness
6、(indivi)+fitness1(j); endendclearj;fitness;%选择适应度高的个体forranseti=1:popsize ran=rand; while(ran>1
7、
8、ran<0) ran=rand; end ran; ifran<=fitness(1) newpopulation(ranseti,:)=population(1,:); else forfet=2:popsizeWORD文档下载可编辑专业技术资料分享 if(ran>fitne
9、ss(fet-1))&&(ran<=fitness(fet)) newpopulation(ranseti,:)=population(fet,:); end end endendclearran;newpopulation;%交叉forint=1:2:popsize-1 popmoth=newpopulation(int,:); popfath=newpopulation(int+1,:); pop
10、cross(int,:)=popmoth; popcross(int+1,:)=popfath; r