資源描述:
《MATLAB分支定界法求解例題.doc》由會員上傳分享,免費在線閱讀,更多相關(guān)內(nèi)容在行業(yè)資料-天天文庫。
1、MATLAB分支定界法求解例題題目:min(4*x1+4*x2);約束條件:2*x1+5*x2<=15,2*x1-2*x2<=5,x1,x2>=0,且都為整數(shù).把以下程序存為ILP.m,%============================function[x,y]=ILp(f,G,h,Geq,heq,lb,ub,x,id,options)%整數(shù)線性規(guī)劃分支定界法,可求解純整數(shù)規(guī)劃和混合整數(shù)規(guī)劃。%y=minf’*xs.t.G*x<=hGeq*x=heqx為全整數(shù)或混合整數(shù)列向量%用法%[x,y]=I
2、Lp(f,G,h,Geq,heq,lb,ub,x,id,options)%參數(shù)說明%lb:解的下界列向量(Default:-int)%ub:解的上界列向量(Default:int)%x:迭代初值列向量%id:整數(shù)變量指標(biāo)列向量,1-整數(shù),0-實數(shù)(Default:1)globalupperoptcx0AbAeqbeqIDoptions;ifnargin<10,options=optimset({});options.Display='off';options.LargeScale='off';endifn
3、argin<9,id=ones(size(f));endifnargin<8,x=[];endifnargin<7
4、isempty(ub),ub=inf*ones(size(f));endifnargin<6
5、isempty(lb),lb=zeros(size(f));endifnargin<5,heq=[];endifnargin<4,Geq=[];endupper=inf;c=f;x0=x;A=G;b=h;Aeq=Geq;beq=heq;ID=id;ftemp=ILP(lb(:),ub(:));x=o
6、pt;y=upper;%下面是子函數(shù)functionftemp=ILP(vlb,vub)globalupperoptcx0AbAeqbeqIDoptions;[x,ftemp,how]=linprog(c,A,b,Aeq,beq,vlb,vub,x0,options);ifhow<=0return;end;ifftemp-upper>0.00005%inordertoavoiderrorreturn;end;ifmax(abs(x.*ID-round(x.*ID)))<0.00005ifupper-fte
7、mp>0.00005%inordertoavoiderroropt=x';upper=ftemp;return;elseopt=[opt;x'];return;end;end;notintx=find(abs(x-round(x))>=0.00005);%inordertoavoiderrorintx=fix(x);tempvlb=vlb;tempvub=vub;ifvub(notintx(1,1),1)>=intx(notintx(1,1),1)+1;tempvlb(notintx(1,1),1)=in
8、tx(notintx(1,1),1)+1;ftemp=IntLP(tempvlb,vub);end;ifvlb(notintx(1,1),1)<=intx(notintx(1,1),1)tempvub(notintx(1,1),1)=intx(notintx(1,1),1);ftemp=IntLP(vlb,tempvub);end;%====================================然后:clc;clearf=[44]A=[25;2-2]b=[15;5]Aeq=[];beq=[];L
9、B=[00];UB=[];[xn,yn]=ILp(f,A,b,Aeq,beq,LB,UB,[11],1,[])[x,fval,exitflag]=linprog(f,A,b,Aeq,beq,LB,UB)結(jié)果:xn=00yn=0Optimizationterminated.x=1.0e-013*0.2990040786747590.503948216933779fval=3.211809182434153e-013exitflag=1