资源描述:
《遗传算法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,0,235,654,2
2、41,0,361,120,254,300,150 1,4,2,2,4,4,3,3,3,1,4,5,1,3 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; pc=0.8;
3、 pm=0.04; forkem=1:popsizepopulation(kem,:)=randperm(hromlength); endpopulation;%评价目标函数值foruim=1:popsize vector=population(uim,:); obj(uim)=hanshu(hromlength,vector,phen);end%obj%min(obj)clearuim;o
4、bjmin=min(obj);forsequ=1:popsize ifobj(sequ)==objmin opti=population(sequ,:); endendclearsequ;fmax=22000;%==forgen=1:maxgen%选择操作%将求最小值的函数转化为适应度函数forindivi=1:popsize obj1(indivi)=1/obj(indivi);endclearindivi;%适应度函数累加总合total=0;forindivi=1:popsize total=total+obj1(indiv
5、i);endclearindivi;%每条染色体被选中的几率forindivi=1:popsize fitness1(indivi)=obj1(indivi)/total;endclearindivi;%各条染色体被选中的范围forindivi=1:popsize fitness(indivi)=0; forj=1:indivi fitness(indivi)=fitness(indivi)+fitness1(j); endendclearj;fitness;%选择适应度高的个体forranseti=1:popsize ra
6、n=rand; while(ran>1
7、
8、ran<0) ran=rand; end ran; ifran<=fitness(1) newpopulation(ranseti,:)=population(1,:); else forfet=2:popsize if(ran>fitness(fet-1))&&(ran<=fitness(fet)) newpopulation(ranseti,:)=population(fet,:); en
9、d end endendclearran;newpopulation;%交叉forint=1:2:popsize-1 popmoth=newpopulation(int,:); popfath=newpopulation(int+1,:); popcross(int,:)=popmoth; popcross(int+1,:)=popfath; randnum=rand; if(randnum
cpoint1=round(ra
10、nd*hromlength); cp