数学建模--整数规划

规划中的变量(部分或全部)限制为整数时,成为整数规划(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';end
if nargin<9, id=ones(size(f));end
if nargin<8, x=[];end
if nargin<7|isempty(ub), ub=inf*ones(size(f));end
if nargin<6|isempty(lb), lb=zeros(size(f));end
if nargin<5, heq=[];end
if nargin<4, Geq=[];end
upper=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 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=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;
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

_relax

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值