打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
分支定界法

  function [x,y]=ILp(f,G,h,Geq,heq,lb,ub,x,id,options)

         %整数线性规划分支定界法,可求解纯整数规划和混合整数规划。

         %y=minf’*x  s.t.  G*x<=h  Geq*x=heq  x为全整数或混合整数列向量

         %用法

         %[x,y]=ILp(f,G,h,Geq,heq,lb,ub,x,id,options)

         %参数说明

         %lb:解的下界列向量(Default:-int

         %ub:解的上界列向量(Default:int

         %x:迭代初值列向量

         %id:整数变量指标列向量,1-整数,0-实数(Default:1

        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=IntLP(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=IntLP(vlb,tempvub);

         end;

%====================================

然后:

 

 

clc;clear

f=[4 4]

A=[2 5;2 -2]

b=[15;5]

Aeq=[];beq=[];

LB=[0 0];UB=[];

[xn,yn]=ILp(f,A,b,Aeq,beq,LB,UB,[1 1],1,[])

[x,fval,exitflag]=linprog(f,A,b,Aeq,beq,LB,UB)

 

结果:

xn =

 

     0     0

 

 

yn =

 

     0

 

Optimization terminated.

 

x =

 

  1.0e-013 *

 

   0.299004078674759

   0.503948216933779

 

 

fval =

 

    3.211809182434153e-013

 

 

exitflag =

 

     1 

 

matlab的整数规划功能不行,还不如EXCELsolver

 8

回答

 

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
运筹学——线性规划Matlab求解 - 6DAN - 博客园
数学规划模型的matlab求解
[转载]Matlab——多元约束优化fmincon函数
新型钢承板优化设计与分析
Matlab求解0-1整数线性规划 - Matlab - 无
用MATLAB优化工具箱解线性规划
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服