整數(shù)規(guī)劃_分支定界法_MATLAB程序_第1頁
整數(shù)規(guī)劃_分支定界法_MATLAB程序_第2頁
整數(shù)規(guī)劃_分支定界法_MATLAB程序_第3頁
整數(shù)規(guī)劃_分支定界法_MATLAB程序_第4頁
免費預(yù)覽已結(jié)束,剩余1頁可下載查看

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

1、整數(shù)規(guī)劃分支定界法 MATLAB 程序1. 這種方法絕對能都解出答案,而且答案正確 function x,val=fzdj(n,f,a,b,aeq,beq,lb,ub) x=zeros(n,1);x1=zeros(n,1);m1=2;m2=1;x1,val1=linprog(f,a,b,aeq,beq,lb,ub);if (x1=0) x=x1;val=val1;elseif (round(x1)=x1) x=x1;val=val1;else e1=0,a,b,aeq,beq,lb,ub,x1,val1; e(1,1)=e1;zl=0; zu=-val1;while (zu=zl)for c=

2、1:1:m2if (m1=2)if (cell2mat(em1-1,c(1)=1) e1=1,0; e(m1,c*2-1)=e1;e(m1,c*2)=e1; continue;end;end; x1=cell2mat(em1-1,c(8); x2=zeros(n,1);s=0;s1=1;s2=1; lb1=cell2mat(em1-1,c(6); ub1=cell2mat(em1-1,c(7); lb2=cell2mat(em1-1,c(6); ub2=cell2mat(em1-1,c(7);for d=1:1:nif (abs(round(x1(d)-x1(d)0.0001)&(s=0) s

3、=1;lb1(d)=fix(x1(d)+1;if (a*lb1=b)s1=0;end;ub2(d)=fix(x1(d);if (a*lb2=b)s2=0;end;end;end;e1=s1,a,b,aeq,beq,lb1,ub1,0;e2=s2,a,b,aeq,beq,lb2,ub2,0;e(m1,c*2-1)=e1;e(m1,c*2)=e2;end;m1=m1+1;m2=m2*2;for c=1:1:m2if (cell2mat(em1-1,c(1)=0)x1,val1=linprog(f,cell2mat(em1-1,c( 2),cell2mat(em1-1,c(3),cell2mat(e

4、m1-1,c(4),cell2 mat(em1-1,c(5),cell2mat(em1-1,c(6),cell2mat(em1-1,c(7);e1=cell2mat(em1-1,c(1),cell2mat(em1-1,c(2),cell2mat(em1-1,c(3),cell2mat(em1-1,c( 4),cell2mat(em1-1,c(5),cell2mat(em1-1,c(6),cell2mat(em1-1,c(7),x1,val1; e(m1-1,c)=e1;end;z=val1;if (-z)(-zl)e1=1,0;e(m1-1,c)=e1;elseif (abs(round(x1

5、)-x1)(-zu)zu=cell2mat(em1-1,c(9);end;end;end;for c=1:1:m2if (cell2mat(em1-1,c(1)=0)&(cell2mat(em1-1,c(9)=zu) x=cell2mat(em1-1,c(8);end;end;val=zu;end;2. 這種方法是課本上的程序,但是不能解題,希望高手能將它改進(jìn)function x,y=IntLp(f,G ,h,Geq,heq,lb,ub,x,id,options)%整數(shù)線性規(guī)劃分支定界法,可求解全整數(shù)線性或混合整數(shù)線性規(guī)劃 %y=min f*x subject to:G*x=h Geq*x=h

6、eq x 為全整數(shù) %數(shù)或混合整數(shù)列向量%用法%x,y=IntLp(f,G ,h)%x,y=IntLp(f,G ,h,Geq,heq)x,y=IntLp(f,G ,h,Geq,heq,lb,ub)x,y=IntLp(f,G ,h,Geq,heq,lb,ub,x)%x,y=IntLp(f,G ,h,Geq,heq,lb,ub,x,id)%x,y=IntLp(f,G ,h,Geq,heq,lb,ub,x,id,options) %參數(shù)說明%x:最優(yōu)解列向量;y:目標(biāo)函數(shù)最小值;f:目標(biāo)函數(shù)系數(shù)列向量%G :約束不等式條件系數(shù)矩陣;h :約束不等式條件右端列向量% Gep:約束等式條件系數(shù)矩陣;he

7、q:約束等式條件右端列向量%lb:解的下界列向量(Default:nf)%ub:解得上界列向量(Default:inf)%x:迭代初值列向量;%id:整數(shù)變量指標(biāo)列向量,1整數(shù),0 實數(shù)(default)%options 的設(shè)置請參見optimset 或linprog%例 min z=x1+4x2%s.t.2x1+x2=6%x1,x2=0 且為整數(shù)%先將 x1+x2=6 化為 -x1-2x2=-6 %x,y=IntLp(1;4,2 1;-1 -2,8;-6,0;0)global upper opt c x0 A b Aeq beq ID options;if nargin10,options=

8、optimset();options.Display=off;options.LargeScale=off;endif nargin9,id=ones(size(f);endif nargin8,x=;endif nargin7|isempty(ub),ub=inf*ones(size(f);endif nargin6|isempty(lb),lb=zeros(size(f);endif nargin5,heq=;endif nargin4,Geq=;end upper=inf;c=f;x0=x;A=G;b=h;Aeq=Geq;beq=heq;ID=id; ftemp=IntLp(lb(:),

9、ub(:); x=opt;y=upper;%以下為子函數(shù) function ftemp=IntLp(vlb,vub) global upper opt c x0 A b Aeq beq ID options;x,ftemp,how=linprog(c,A,b,Aeq,beq,vlb,vub,x0,options); if how0.00005%in order to avoid error return;end;if max(abs(x.*ID-round(x.*ID)0.00005%in order to avoid error opt=x;upper=ftemp;return;else o

10、pt=opt;x; return;end;end; notintx=find(abs(x-round(x)0.00005);%in order to avoid error intx=fix(x);tempvlb=vlb;tempvub=vub;if vub(notintx(1,1),1)=intx(notintx(1,1),1)+1 tempvlb(notintx(1,1),1)=intx(notintx(1,1),1)+1; ftemp=IntLp(tempvlb,vub);end;if vlb(notintx(1,1),1)= UB)if isempty(FN)=1flag=1;else

11、k=FN(1);A=AAk;b=BBk;endelsefor i=1:NLif abs(x(i)-round(x(i)1e-7 kk=FN(end); FN=FN,kk+1,kk+2; temp_A=zeros(1,NL); temp_A(i)=1; temp_A1=A;temp_A; AA(kk+1)=temp_A1; b1=b;fix(x(i); BB(kk+1)=b1; temp_A2=A;-temp_A; AA(kk+2)=temp_A2; b2=b;-(fix(x(i)+1); BB(kk+2)=b2; FN(1)=; k=FN(1); A=AAk; b=BBk; break;endendif (i=NL) & (abs(x(i)-round(x(i)=1e-7)UB=fval;y=x;FN(1)=

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論