设为首页收藏本站

EPS数据狗论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 1687|回复: 0

(BranchBound)- 线性整数规划

[复制链接]

8

主题

79

金钱

125

积分

入门用户

发表于 2018-9-26 10:36:10 | 显示全部楼层 |阅读模式
  1. function [x,y]=lpint(f,G,h,lb,ub,x,n,id)
  2. %整数线性规划分枝定界法,可求解线性全整数或线性混合整数规划。
  3. %         y = min f'x    subject to:   Gx <= h  x为整
  4. %              x
  5. %用法
  6. %    [x,y]=lpint(f,G,h)
  7. %    [x,y]=lpint(f,G,h,lb,ub)
  8. %    [x,y]=lpint(f,G,h,lb,ub,x)
  9. %    [x,y]=lpint(f,G,h,lb,ub,x,n)
  10. %    [x,y]=lpint(f,G,h,lb,ub,x,n,id)
  11. %参数说明
  12. %    x: 最优解列向量
  13. %    y: 目标函数最小值
  14. %    f: 目标函数系数列向量
  15. %    G: 约束条件系数矩阵
  16. %    h: 约束条件右端列向量
  17. %    lb: 解的的下界列向量(Default: -inf)
  18. %    ub: 解的的上界列向量(Default: inf)
  19. %    x: 迭代初值列向量
  20. %    n: 等式约束数(Default: 0)
  21. %    id: 整数变量指标列向量。1-整数,0-实数(Default: 1)
  22. %例: min Z=x1+4x2
  23. % s.t.  2x1+x2<=8
  24. %      x1+2x2>=6
  25. %      x1, x2>=0且为整数
  26. %先将x1+2x2>=6化为 - x1 - 2x2<= -6
  27. %[x,y]=lpint([1;4],[2 1;-1 -2],[8;-6],[0;0])

  28. % Y. MA & L.J. HU 1999

  29. global upper opt c N x0 A b ID;
  30. if nargin<8, id=ones(size(f));end
  31. if nargin<7|isempty(n), n=0;end
  32. if nargin<6, x=[];end
  33. if nargin<5|isempty(ub), ub=inf*ones(size(f));end
  34. if nargin<4|isempty(lb), lb=zeros(size(f));end

  35. upper=inf;
  36. c=f;N=n;x0=x;A=G;b=h;ID=id;
  37. temp=ILP(lb(:),ub(:));
  38. x=opt;y=upper;

  39. %以下子函数
  40. function y=ILP(vlb,vub)
  41. global upper opt c N x0 A b ID;
  42.   warning off;
  43.   [x,temp,how]=lp(c,A,b,vlb,vub,x0,N,-1);
  44.   if strcmp(how,'ok')~=1
  45.      return;
  46.   end;
  47.   if c'*x-upper>0.00005  %in order to avoid error
  48.      return;
  49.   end;
  50.    
  51.   if max(abs(x.*ID-round(x.*ID)))<0.00005
  52.     if upper-c'*x>0.00005 %in order to avoid error
  53.       opt=x';
  54.       upper=c'*x;
  55.       return;
  56.    else
  57.       opt=[opt;x'];
  58.       return;
  59.     end;
  60.   end;
  61.   notintx=find(abs(x-round(x))>=0.00005); %in order to avoid error
  62.   intx=fix(x);
  63.   tempvlb=vlb;
  64.   tempvub=vub;
  65.   if vub(notintx(1,1),1)>=intx(notintx(1,1),1)+1
  66.      tempvlb(notintx(1,1),1)=intx(notintx(1,1),1)+1;
  67.      temp=ILP(tempvlb,vub);
  68.   end;
  69.   if vlb(notintx(1,1),1)<=intx(notintx(1,1),1)
  70.     tempvub(notintx(1,1),1)=intx(notintx(1,1),1);
  71.      temp=ILP(vlb,tempvub);
  72.   end;
复制代码


您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

站长推荐上一条 /1 下一条

客服中心
关闭
在线时间:
周一~周五
8:30-17:30
QQ群:
653541906
联系电话:
010-85786021-8017
在线咨询
客服中心

意见反馈|网站地图|手机版|小黑屋|EPS数据狗论坛 ( 京ICP备09019565号-3 )   

Powered by BFIT! X3.4

© 2008-2028 BFIT Inc.

快速回复 返回顶部 返回列表