数学建模--整数规划

来源:互联网 发布:循序渐进学java 编辑:程序博客网 时间:2024/05/20 02:30

规划中的变量(部分或全部)限制为整数时,成为整数规划(Integer Linear Programming)。若在线性规划模型中,变量限制为整数,则称为整数线性规划。目前所流行的求解整数规划的方法往往只是用于整数线性规划。
在一般的规划中,增加限定:决策变量是整数,记为整数规划问题。标准形式如下:
minf=CTxst.Ax=bxj
其中,x_j是整数。
算法:
求解这类线性规划问题时,如果可行域时有界的,可以使用穷举法求解,变量太多时,则这种算法实行起来就很困难了。分支定界法是由Land、Diog等人提出的用于线性规划问题的。
基本实现代码如下:

function [x,y]=IntLp(f,G,h,Geq,heq,lb,ub,x,id,options)%整数线性规划分枝定界法,可求解全整数线性或混合整数线性规划。% y = min f'*x subject to: G*x <= h Geq*x=heq x为全整数或混合整% 数列向量%用法% [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)%参数说明% x:最优解列向量; y:目标函数最小值;f:目标函数系数列向量 % G:约束不等式条件系数矩阵;h:约束不等式条件右端列向量% Geq:约束等式条件系数矩阵;heq:约束等式条件右端列向量% lb:解的下界列向量(Default: -inf);ub:解的上界列向量(Default: inf)% x:迭代初值列向量;% id:整数变量指标列向量,1-整数,0-实数(Default: 1)% options的设置请参见optimset或lingprog%例 min Z=x1+4x2% s.t. 2x1+x2<=8% x1+2x2>=6% x1, x2>=0且为整数%先将x1+2x2>=6化为 - x1 - 2x2<= -6%[x,y]=IntLp([1;4],[2 1;-1 -2],[8;-6],[],[],[0;0])%胡良剑,孙晓君, Matlab数学实验,高等教育出版社, 2006%利用迭代求解global upper opt c x0 A b Aeq beq ID options;if nargin<10, options=optimset({});options.Display='off';options.LargeScale='off';endif nargin<9, id=ones(size(f));endif nargin<8, x=[];endif nargin<7|isempty(ub), ub=inf*ones(size(f));endif nargin<6|isempty(lb), lb=zeros(size(f));endif nargin<5, heq=[];endif nargin<4, Geq=[];endupper=inf;c=f;x0=x;A=G;b=h;Aeq=Geq;beq=heq;ID=id;ftemp=ILP(lb(:),ub(:));x=opt;y=upper;%以下子函数function ftemp=ILP(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 how<=0    return;end;if ftemp-upper>0.00005 %in order to avoid error    return;end;if max(abs(x.*ID-round(x.*ID)))<0.00005    if upper-ftemp>0.00005 %in order to avoid error        opt=x';upper=ftemp;        return;    else         opt=[opt;x'];        return;    end;end;notintx=find(abs(x-round(x))>=0.00005); %in order to avoid errorintx=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=ILP(tempvlb,vub);end;    if vlb(notintx(1,1),1)<=intx(notintx(1,1),1)    tempvub(notintx(1,1),1)=intx(notintx(1,1),1);    ftemp=ILP(vlb,tempvub);end;