資源描述:
《遺傳算法解決非線性規(guī)劃問題的matlab程序》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫。
1、非線性整數(shù)規(guī)劃的遺傳算法Matlab程序(附圖)通常,非線性整數(shù)規(guī)劃是一個(gè)具有指數(shù)復(fù)雜度的NP問題,如果約束較為復(fù)雜,Matlab優(yōu)化工具箱和一些優(yōu)化軟件比如lingo等,常常無法應(yīng)用,即使能應(yīng)用也不能給出一個(gè)較為令人滿意的解。這時(shí)就需要針對(duì)問題設(shè)計(jì)專門的優(yōu)化算法。下面舉一個(gè)遺傳算法應(yīng)用于非線性整數(shù)規(guī)劃的編程實(shí)例,供大家參考!模型的形式和適應(yīng)度函數(shù)定義如下:這是一個(gè)具有200個(gè)01決策變量的多目標(biāo)非線性整數(shù)規(guī)劃,編寫優(yōu)化的目標(biāo)函數(shù)如下,其中將多目標(biāo)轉(zhuǎn)化為單目標(biāo)采用簡單的加權(quán)處理。functionFitness=FITNESS(x,FARM,e,q,w)%%適應(yīng)度
2、函數(shù)%?輸入?yún)?shù)列表%?x???????決策變量構(gòu)成的4×50的0-1矩陣%?FARM????細(xì)胞結(jié)構(gòu)存儲(chǔ)的當(dāng)前種群,它包含了個(gè)體x%?e???????4×50的系數(shù)矩陣%?q???????4×50的系數(shù)矩陣%?w???????1×50的系數(shù)矩陣%%gamma=0.98;N=length(FARM);%種群規(guī)模F1=zeros(1,N);F2=zeros(1,N);fori=1:N???xx=FARM{i};???ppp=(1-xx)+(1-q).*xx;???F1(i)=sum(w.*prod(ppp));???F2(i)=sum(sum(e.*xx));en
3、dppp=(1-x)+(1-q).*x;f1=sum(w.*prod(ppp));f2=sum(sum(e.*x));Fitness=gamma*sum(min([sign(f1-F1);zeros(1,N)]))+(1-gamma)*sum(min([sign(f2-F2);zeros(1,N)]));?針對(duì)問題設(shè)計(jì)的遺傳算法如下,其中對(duì)模型約束的處理是重點(diǎn)考慮的地方function[Xp,LC1,LC2,LC3,LC4]=MYGA(M,N,Pm)%%求解01整數(shù)規(guī)劃的遺傳算法%%輸入?yún)?shù)列表%?M????遺傳進(jìn)化迭代次數(shù)%?N????種群規(guī)模%?Pm???變
4、異概率%%輸出參數(shù)列表%?Xp???最優(yōu)個(gè)體%?LC1??子目標(biāo)1的收斂曲線%?LC2??子目標(biāo)2的收斂曲線%?LC3??平均適應(yīng)度函數(shù)的收斂曲線%?LC4??最優(yōu)適應(yīng)度函數(shù)的收斂曲線%%參考調(diào)用格式[Xp,LC1,LC2,LC3,LC4]=MYGA(50,40,0.3)%%第一步:載入數(shù)據(jù)和變量初始化loadeqw;%載入三個(gè)系數(shù)矩陣e,q,w%輸出變量初始化Xp=zeros(4,50);LC1=zeros(1,M);LC2=zeros(1,M);LC3=zeros(1,M);LC4=zeros(1,M);Best=inf;%%第二步:隨機(jī)產(chǎn)生初始種群farm
5、=cell(1,N);%用于存儲(chǔ)種群的細(xì)胞結(jié)構(gòu)k=0;whilek???%以下是一個(gè)合法個(gè)體的產(chǎn)生過程???x=zeros(4,50);%x每一列的1的個(gè)數(shù)隨機(jī)決定???fori=1:50???????R=rand;???????Col=zeros(4,1);???????ifR<0.7???????????RP=randperm(4);%1的位置也是隨機(jī)的???????????Col(RP(1))=1;???????elseifR>0.9???????????RP=randperm(4);???????????Col(RP(1:2))=1;???????els
6、e???????????RP=randperm(4);???????????Col(RP(1:3))=1;???????end???????x(:,i)=Col;???end???%下面是檢查行和是否滿足約束的過程,對(duì)于不滿足約束的予以拋棄???Temp1=sum(x,2);???Temp2=find(Temp1>20);???iflength(Temp2)==0???????k=k+1;???????farm{k}=x;???endend???%%以下是進(jìn)化迭代過程counter=0;%設(shè)置迭代計(jì)數(shù)器whilecounter???%%第三步:交叉???%交叉采
7、用雙親雙子單點(diǎn)交叉???newfarm=cell(1,2*N);%用于存儲(chǔ)子代的細(xì)胞結(jié)構(gòu)???Ser=randperm(N);%兩兩隨機(jī)配對(duì)的配對(duì)表???A=farm{Ser(1)};%取出父代A???B=farm{Ser(2)};%取出父代B???P0=unidrnd(49);%隨機(jī)選擇交叉點(diǎn)???a=[A(:,1:P0),B(:,(P0+1):end)];%產(chǎn)生子代a???b=[B(:,1:P0),A(:,(P0+1):end)];%產(chǎn)生子代b???newfarm{2*N-1}=a;%加入子代種群???newfarm{2*N}=b;???%以下循環(huán)是重復(fù)上述
8、過程???fori=1: