楼主: qaz143109
2161 0

[新手尝试] Matlab 非负整数线性规划 [推广有奖]

  • 0关注
  • 0粉丝

学前班

80%

还不是VIP/贵宾

-

威望
0
论坛币
10 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
80 点
帖子
2
精华
0
在线时间
0 小时
注册时间
2016-7-4
最后登录
2016-7-4

楼主
qaz143109 发表于 2016-7-4 15:59:54 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
  1. function [x,y]=IntLp(f,G,h,Geq,heq,lb,ub,x,id,options)
  2.     %整数线性规划分枝定界法,可求解全整数线性或混合整数线性规划。
  3.     % y = min f'*x subject to: G*x <= h Geq*x=heq x为全整数或混合整% 数列向量
  4.     %用法
  5.     % [x,y]=IntLp(f,G,h)
  6.     % [x,y]=IntLp(f,G,h,Geq,heq)
  7.     % [x,y]=IntLp(f,G,h,Geq,heq,lb,ub)
  8.     % [x,y]=IntLp(f,G,h,Geq,heq,lb,ub,x)
  9.     % [x,y]=IntLp(f,G,h,Geq,heq,lb,ub,x,id)
  10.     % [x,y]=IntLp(f,G,h,Geq,heq,lb,ub,x,id,options)
  11.     %参数说明
  12.     % x:最优解列向量; y:目标函数最小值;f:目标函数系数列向量
  13.     % G:约束不等式条件系数矩阵;h:约束不等式条件右端列向量
  14.     % Geq:约束等式条件系数矩阵;heq:约束等式条件右端列向量
  15.     % lb:解的下界列向量(Default: -inf);ub:解的上界列向量(Default: inf)
  16.     % x:迭代初值列向量;
  17.     % id:整数变量指标列向量,1-整数,0-实数(Default: 1)
  18.     % options的设置请参见optimset或lingprog
  19.     %例 min Z=x1+4x2
  20.     % s.t. 2x1+x2<=8
  21.     % x1+2x2>=6
  22.     % x1, x2>=0且为整数
  23.     %先将x1+2x2>=6化为 - x1 - 2x2<= -6
  24.     %[x,y]=IntLp([1;4],[2 1;-1 -2],[8;-6],[],[],[0;0])

  25.     %胡良剑,孙晓君, Matlab数学实验,高等教育出版社, 2006

  26.     global upper opt c x0 A b Aeq beq ID options;
  27.     if nargin<10, options=optimset({});options.Display='off';end
  28.     %options.LargeScale='off';
  29.     if nargin<9, id=ones(size(f));end
  30.     if nargin<8, x=[];end
  31.     if nargin<7|isempty(ub), ub=inf*ones(size(f));end
  32.     if nargin<6|isempty(lb), lb=zeros(size(f));end
  33.     if nargin<5, heq=[];end
  34.     if nargin<4, Geq=[];end
  35.     upper=inf;c=f;x0=x;A=G;b=h;Aeq=Geq;beq=heq;ID=id;
  36.     ftemp=ILP(lb(:),ub(:));
  37.     x=opt;y=upper;


  38. %以下子函数
  39. function ftemp=ILP(vlb,vub)
  40.     global upper opt c x0 A b Aeq beq ID options;
  41.     [x,ftemp,how]=linprog(c,A,b,Aeq,beq,vlb,vub,x0,options);
  42.     if how<=0
  43.         return;
  44.     end;
  45.     if ftemp-upper>0.00005 %in order to avoid error
  46.         return;
  47.     end;
  48.     if max(abs(x.*ID-round(x.*ID)))<0.00005
  49.         if upper-ftemp>0.00005 %in order to avoid error
  50.             opt=x';upper=ftemp;
  51.             return;
  52.         else
  53.             opt=[opt;x'];
  54.             return;
  55.         end;
  56.     end;
  57.     notintx=find(abs(x-round(x))>=0.00005); %in order to avoid error
  58.     intx=fix(x);tempvlb=vlb;tempvub=vub;
  59.     if vub(notintx(1,1),1)>=intx(notintx(1,1),1)+1
  60.         tempvlb(notintx(1,1),1)=intx(notintx(1,1),1)+1;
  61.         ftemp=ILP(tempvlb,vub);
  62.     end;
  63.     if vlb(notintx(1,1),1)<=intx(notintx(1,1),1)
  64.         tempvub(notintx(1,1),1)=intx(notintx(1,1),1);
  65.         ftemp=ILP(vlb,tempvub);
  66.     end;
复制代码


二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:MATLAB matla atlab 线性规划 Lab function

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

本版微信群
jg-xs1
拉您进交流群
GMT+8, 2025-12-31 08:35