资源描述:
《遗传算法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
2、,400,1000,120,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;
3、 maxgen=500; pc=0.8; pm=0.04; forkem=1:popsizepopulation(kem,:)=randperm(hromlength); endpopulation;%评价目标函数值foruim=1:popsize vector=pop
4、ulation(uim,:); obj(uim)=hanshu(hromlength,vector,phen);end%obj%min(obj)clearuim;objmin=min(obj);forsequ=1:popsize ifobj(sequ)==objminWORD完美格式下载可编辑专业资料 opti=population(sequ,:); endendclearsequ;fmax=22000;%==forgen=1:maxgen%选择操作%将求最小值的函数转化为适应度函数fori
5、ndivi=1:popsize obj1(indivi)=1/obj(indivi);endclearindivi;%适应度函数累加总合total=0;forindivi=1:popsize total=total+obj1(indivi);endclearindivi;%每条染色体被选中的几率forindivi=1:popsize fitness1(indivi)=obj1(indivi)/total;WORD完美格式下载可编辑专业资料endclearindivi;%各条染色体被选中的范围forind
6、ivi=1:popsize fitness(indivi)=0; forj=1:indivi fitness(indivi)=fitness(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(r
9、anseti,:)=population(1,:); else forfet=2:popsizeWORD完美格式下载可编辑专业资料 if(ran>fitness(fet-1))&&(ran<=fitness(fet)) newpopulation(ranseti,:)=population(fet,:); end end endendclearran;newpopulation;%交叉forint=1:2:popsi
10、ze-1 popmoth=newpopulation(int,:); popfath=newpopulation(int+1,:); popcross(int,:)=popmoth; popcross(int+1,:)=popfath; randnum=rand;