资源描述:
《MATLAB分支定界法求解例题.doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、MATLAB分支定界法求解例题题目:min(4*x1+4*x2);约束条件:2*x1+5*x2<=15,2*x1-2*x2<=5,x1,x2>=0,且都为整数.把以下程序存为ILP.m,%============================function[x,y]=ILp(f,G,h,Geq,heq,lb,ub,x,id,options)%整数线性规划分支定界法,可求解纯整数规划和混合整数规划。%y=minf’*xs.t.G*x<=hGeq*x=heqx为全整数或混合整数列向量%用法%[x,y]=I
2、Lp(f,G,h,Geq,heq,lb,ub,x,id,options)%参数说明%lb:解的下界列向量(Default:-int)%ub:解的上界列向量(Default:int)%x:迭代初值列向量%id:整数变量指标列向量,1-整数,0-实数(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;%下面是子函数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)结果:xn=00yn=0Optimizationterminated.x=1.0e-013*0.2990040786747590.503948216933779fval=3.211809182434153e-013exitflag=1