当前位置:文档之家› 整数线性规划word版

整数线性规划word版

第三章 整数线性规划本章, 我们介绍三种解决整数线性规划问题的软件:第一种: MATLAB 中的optimization toolbox 中的若干程序;第二种: LINDO 软件;第二种: LINGO 软件.1. MATLAB 程序说明程序名: intprogram, L01p_e, L01p_ie, transdetobi, biprogramintprogram 是利用分支定界法解决整数规划问题, 是全部的整数规划问题;L01p_e 是利用枚举法解决0-1规划问题, 变量要求全部为0或者1;L01p_ie 是利用隐枚举法解决0-1规划问题, 变量要求全部为0或者1;Transdetobi 是枚举法和隐枚举法中利用到的将十进制数转化为二进制数的函数;Biprogram 是MATLAB6.5以上版本中有的求解0-1规划的函数的程序.intprogram 执行实例1:12121212max 2010s.t.54242513,0, f x x x x x x x x =++≤+≤≥ 且为整数在命令窗口的程序执行过程和结果如下:>> c=[-20,-10]; %将最大转化为最小;>> a=[5,4;2,5];>> b=[24;13];>> [x,f]=intprogram(c,a,b,[0;0],[inf;inf],[],0,0.0001) % c,a,b 之后[0;0] is the value of low bound;[inf;inf] is the value of up bound;[] is the initialization;0 is the number of the equation constraints; 0.0001 is the concise rate. x =4.00001.0000f =-90intprogram 执行实例2: 书中例题3.3.1在命令窗口的程序执行过程和结果如下:>> c=[-1,-1];>> a=[-4,2;4,2;0,-2];>> b=[-1;11;-1];>> [x,f]=intprogram(c,a,b,[0;0],[inf;inf],[],0,0.0001)x =2 21 1f =-3L01p_e 和L01p_ie 执行实例:1231231231223123max 325s.t.2244346,,01f x x x x x x x x x x x x x x x x =-++-≤++≤+≤+≤= - 或在命令窗口的程序执行过程和结果如下:>> c=[3,-2,5]; %将最大转化为最小;>> a=[1,2,-1;1,4,1;1,1,0;0,4,1];>> b=[2;4;3;6];>> x1=L01p_e(c,a,b);x2=L01p_ie(c,a,b); %x1表示利用枚举法解决0-1规划问题,x2表示用隐% 枚举法解决问题, 结果是一样的>> x1x1 =1>> x2x2 =1biprogram 执行实例: 12341234341324min ()9564s.t.635291f x x x x x x x x x x x x x x x =---+++≤+≤+≤-+≤ - -在命令窗口的程序执行过程和结果如下:the program is with the binary linear programmingPlease input the constraints number of the programming m=4m =4Please input the variant number of the programming n=4n =4Please input cost array of the objective function c(n)_T=[-9,-5,-6,-4]'c =-9-5-6-4Please input the coefficient matrix of the constraints A(m,n)=[6,3,5,2;0,0,1,1; -1,0,1,0;0,-1,0,1]A =6 3 5 20 0 1 1-1 0 1 00 -1 0 1Please input the resource array of the program b(m)_T=[9,1,0,0]'b =91Optimization terminated successfully.x =11程序的相关知识:Solve binary integer programming problems of the formwhere f, b, and beq are vectors, A and Aeq are matrices, and the solution x is required to be a binary integer vector -- that is, its entries can only take on the values 0 or 1.语法如下:x = bintprog(f)x = bintprog(f, A, b)x = bintprog(f, A, b, Aeq, beq)x = bintprog(f, A, b, Aeq, beq, x0)x = bintprog(f, A, b, Aeq, beq, x0, options)[x, fval] = bintprog(...)[x,fval, exitflag] = bintprog(...)[x, fval, exitflag, output] = bintprog(...)解释:x = bintprog(f) solves the binary integer programming problemx = bintprog(f, A, b) solves the binary integer programming problemx = bintprog(f, A, b, Aeq, beq) solves the preceding problem with the additional equality constraint.x = bintprog(f, A, b, Aeq, beq, x0) sets the starting point for the algorithm to x0. If x0 is not in the feasible region, bintprog uses the default initial point.x = bintprog(f, A, b, Aeq, Beq, x0, options) minimizes with the default optimization options replaced by values in the structure options, which you can create using the function optimset.[x, fval] = bintprog(...) returns fval, the value of the objective function at x.[x,fval, exitflag] = bintprog(...) returns exitflag that describes the exit condition of bintprog. See Output Arguments.[x, fval, exitflag, output] = bintprog(...) returns a structure output that contains information about the optimization. See Output Arguments.2.LINDO 程序说明LINDO 也提供了解决全整数规划、混合整数规划以及0-1规划的方法.2.1 解决全整数规划问题程序名: intlpallintlpall 执行实例:min 1110s.t.21231 ,0, x yx y x y x y ++<->> 且为整数在命令窗口键入以下内容:max 11x+10yst2x+y<12x-3y>1endgin x ! the general integer statement – GIN 将变量约束为整数gin y ! the general integer statement – GIN 将变量约束为整数按solve 键在reports window 出现:LP OPTIMUM FOUND AT STEP 7OBJECTIVE VALUE = 72.4285736NEW INTEGER SOLUTION OF 66.0000000 AT BRANCH 0 PIVOT 12 BOUND ON OPTIMUM: 66.00000ENUMERATION COMPLETE. BRANCHES= 0 PIVOTS= 12LAST INTEGER SOLUTION IS THE BEST FOUNDRE-INSTALLING BEST SOLUTION...OBJECTIVE FUNCTION VALUE1) 66.00000VARIABLE VALUE REDUCED COSTX 6.000000 -11.000000Y 0.000000 -10.000000ROW SLACK OR SURPLUS DUAL PRICES2) 0.000000 0.0000003) 5.000000 0.000000NO. ITERATIONS= 12BRANCHES= 0 DETERM.= 1.000E 0]2.2 解决混合整数规划问题:程序名:intlpsecintlpsec 执行实例:min 1110s.t.21231,0, x yx y x y x y x ++<->> 且为整数在命令窗口键入以下内容:max 11x+10yst2x+y<12x-3y>1endgin x !only the general integer statement – GIN 只将变量x 约束为整数按solve 键在reports windows 中出现以下内容:LP OPTIMUM FOUND AT STEP 2OBJECTIVE VALUE = 72.4285736SET X TO >= 6 AT 1, BND= 66.00 TWIN= 68.33 16NEW INTEGER SOLUTION OF 66.0000000 AT BRANCH 1 PIVOT 16 BOUND ON OPTIMUM: 68.33334FLIP X TO <= 5 AT 1 WITH BND= 68.333336NEW INTEGER SOLUTION OF 68.3333359 AT BRANCH 1 PIVOT 16 BOUND ON OPTIMUM: 68.33334DELETE X AT LEVEL 1ENUMERATION COMPLETE. BRANCHES= 1 PIVOTS= 16LAST INTEGER SOLUTION IS THE BEST FOUNDRE-INSTALLING BEST SOLUTION...OBJECTIVE FUNCTION VALUE1) 68.33334VARIABLE VALUE REDUCED COSTX 5.000000 -14.333333Y 1.333333 0.000000ROW SLACK OR SURPLUS DUAL PRICES2) 0.666667 0.0000003) 0.000000 -3.333333NO. ITERATIONS= 17BRANCHES= 1 DETERM.= 1.000E 02.3 解决0-1整数规划问题:程序名:intlp01intlp01执行实例:max 1002012s.t.100117 ,001x y zy x y z z y z x -++-<+<<>= 或在命令窗口键入以下内容:max -100x+20y+12zsty-10x<0y+z<11z<7endint x !约束x 为0-1变量按solve 键在reports windows 中出现以下内容:LP OPTIMUM FOUND AT STEP 3OBJECTIVE VALUE = 124.000000SET X TO >= 1 AT 1, BND= 112.0 TWIN= 84.00 9NEW INTEGER SOLUTION OF 112.000000 AT BRANCH 1 PIVOT 9 BOUND ON OPTIMUM: 112.0000DELETE X AT LEVEL 1ENUMERATION COMPLETE. BRANCHES= 1 PIVOTS= 9LAST INTEGER SOLUTION IS THE BEST FOUNDRE-INSTALLING BEST SOLUTION...OBJECTIVE FUNCTION VALUE1) 112.0000VARIABLE VALUE REDUCED COSTX 1.000000 20.000000Y 10.000000 0.000000Z 1.000000 0.000000ROW SLACK OR SURPLUS DUAL PRICES2) 0.000000 8.0000003) 0.000000 12.0000004) 6.000000 0.000000NO. ITERATIONS= 10BRANCHES= 1 DETERM.= 1.000E 03. LINGO 程序说明除了特别说明, LINGO 默认变量是非负的以及连续的, 但是可用以下命令使得变量满足要求: @GIN restricts a variable to being an integer value,@BIN makes a variable binary (i.e., 0 or 1),@FREE allows a variable to assume any real value, positive or negative@BND limits a variable to fall within a finite range 等.程序名: intlp (该程序主要是解决整数线性规划问题的, 用上述命令赋予变量属性.) intlp 执行实例:max 100150s.t.2160100120,0, x yx y x y x y ++<≤≤> 且为整数在模型命令窗口键入以下内容:max =100*x+150*y;x<=100;y<=120;x+2*y<=160;@gin (x);@gin (y);!若要只限制x,只要限制x 即可.按运行按钮在solution report 窗口得到以下结果:Global optimal solution found at iteration: 2 Objective value: 14500.00Variable Value Reduced Cost X 100.0000 -100.0000 Y 30.00000 -150.0000Row Slack or Surplus Dual Price 1 14500.00 1.000000 2 0.000000 0.000000 3 90.00000 0.000000 4 0.000000 0.000000程序名: bilpbilp 的执行实例:1231231231223123max 325..2244346,,01f x x x s t x x x x x x x x x x x x x or =-+-+-≤++≤+≤+≤= 在模型命令窗口键入以下内容:max =-3*x1+2*x2+5*x3;x1+2*x2-x3<=2;x1+4*x2+x3<=4;x1+x2<=3;4*x2+x3<=6;@bin (x1);@bin (x2);@bin (x3);按运行按钮在solution report 窗口得到以下结果:Global optimal solution found at iteration: 0 Objective value: 5.000000Variable Value Reduced Cost X1 0.000000 3.000000 X2 0.000000 -2.000000 X3 1.000000 -5.000000Row Slack or Surplus Dual Price 1 5.000000 1.000000 2 3.000000 0.0000003 3.000000 0.0000004 3.000000 0.0000005 5.000000 0.000000。

相关主题