資源描述:
《遺傳算法matlab實(shí)現(xiàn)源程序》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在行業(yè)資料-天天文庫。
1、word資料下載可編輯附頁:一.遺傳算法源程序:clc;clear;population;%評(píng)價(jià)目標(biāo)函數(shù)值foruim=1:popsize???vector=population(uim,:);???obj(uim)=hanshu(hromlength,vector,phen);end%obj%min(obj)專業(yè)技術(shù)資料word資料下載可編輯clearuim;objmin=min(obj);forsequ=1:popsize???ifobj(sequ)==objmin???????opti=population(sequ,:);???en
2、dendclearsequ;fmax=22000;%==forgen=1:maxgen%選擇操作%將求最小值的函數(shù)轉(zhuǎn)化為適應(yīng)度函數(shù)forindivi=1:popsize???obj1(indivi)=1/obj(indivi);endclearindivi;%適應(yīng)度函數(shù)累加總合total=0;forindivi=1:popsize???total=total+obj1(indivi);endclearindivi;%每條染色體被選中的幾率專業(yè)技術(shù)資料word資料下載可編輯forindivi=1:popsize???fitness1(indi
3、vi)=obj1(indivi)/total;endclearindivi;%各條染色體被選中的范圍forindivi=1:popsize???fitness(indivi)=0;???forj=1:indivi???????fitness(indivi)=fitness(indivi)+fitness1(j);???endendclearj;fitness;%選擇適應(yīng)度高的個(gè)體forranseti=1:popsize???ran=rand;???while(ran>1
4、
5、ran<0)???????ran=rand;???end???ran
6、;???ifran<=fitness(1)???????newpopulation(ranseti,:)=population(1,:);???else???????forfet=2:popsize???????????if(ran>fitness(fet-1))&&(ran<=fitness(fet))專業(yè)技術(shù)資料word資料下載可編輯???????????????newpopulation(ranseti,:)=population(fet,:);???????????end???????end???endendclearran;new
7、population;%交叉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(rand*hromlength);?????????
8、???????cpoint2=round(rand*hromlength);??????????????????while(cpoint2==cpoint1)????????????????????????????cpoint2=round(rand*hromlength);???????end???????ifcpoint1>cpoint2????????????????????????????????tem=cpoint1;???????????cpoint1=cpoint2;???????????cpoint2=tem;專業(yè)技術(shù)資料w
9、ord資料下載可編輯???????end???????cpoint1;???????cpoint2;???????forterm=cpoint1+1:cpoint2??????????????????????????????forss=1:hromlength???????????????ifpopcross(int,ss)==popfath(term)???????????????????tem1=popcross(int,ss);???????????????????popcross(int,ss)=popcross(int,term)
10、;???????????????????popcross(int,term)=tem1;???????????????end???????????end???????????cl