整数线性规划word版
- 格式:doc
- 大小:97.00 KB
- 文档页数:10
第三章 整数线性规划本章, 我们介绍三种解决整数线性规划问题的软件:第一种: 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.6352910f 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 12BOUND 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 9BOUND 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: 0Objective 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.000000 3 3.000000 0.000000 4 3.000000 0.0000005 5.000000 0.000000注:范本无法思考和涵盖全面,最好仔细浏览后下载使用,感谢您的关注!。
§3.1 整数线性规划整数线性规划( Integer Linear Programming ,简记为 ILP )⎪⎪⎩⎪⎪⎨⎧⊂∈∈≥=},,2,1{,0..min n J i I x x b Ax t s x c i T Λ (3.1.1)其中,},2,1,0{Λ=I<1>若 },,2,1{},1,0{n J I Λ==,则称(3.1.1)为0-1规划问题;<2>若 J 是 },,2,1{n Λ的非空真子集,则称(3.1.1)是混合整数线性规划问题;<3>若 },,2,1{n J Λ=,则称(3.1.1)是纯整数线性规划问题。
1、整数线性规划问题举例例 3.1.1 某部门在今后五年中有 B 万元的资金可以用于投资,有 )2(≥n n 个可以考虑的投资项目。
假定每个项目最多投资一次,其中第 j 个项目需投资金额为 j b 万元,将会获得的利润为 j c 万元,问应如何选择项目,才能使获得的总利润最大?解:设投资决策变量为n j j j x j ,,1,0,1Λ=⎩⎨⎧=个项目,决定不投资第个项目,决定投资第,设获得的总利润为 z ,则⎪⎪⎪⎪⎩⎪⎪⎪⎪⎨⎧==≤<=∑∑==n j x Bx b t s x c z j n j j j n j jj ...,2,1;010..max 11或 (3.1.2) 问题(3.1.2)是一个0-1规划。
01或=j x 这个约束可以用一个等价非线性约束0)1(=-j j x x来代替它。
因而变量限制为整数本质上是一个非线性约束。
例 3.1.2 某建筑公司承包两种类型宿舍。
甲种宿舍每幢占地面积为 31025.0⨯平方米;乙种宿舍每幢占地面积为 3104.0⨯平方米。
该公司已购进 3103⨯平方米的建筑用地。
计划要求建甲种宿舍不超过8幢,乙种宿舍不超过4幢。
建甲种宿舍每幢可获利10万元,建乙种宿舍每幢可获利20万元。
第八章整數線性規劃本章內容:8.1 各類型的整數線性規劃模式8.2 全整數規劃問題的圖解法及電腦解8.3 包含0-1變數應用8.4 0-1變數賦予的建模彈性1⏹8.1 各類型的整數線性規劃模式●一線性規劃中,所有變數都限定為整數,稱為“全整數線性規劃(all integer linear program)”。
下列為一全整數線規劃摸式:Max 2X1+3X2s.t. 3X1+3X2≦121X2+1X2≦41X1+2X2≦6X1,X2≧0且為整數2●刪除整數線性規劃決策變數的「整數」限定後線性規劃問題,稱為“整數線性規劃的LP寬鬆式(LP Relaxation)”。
●一線性規劃中,僅有部份變數被限定為整數稱為混合整數線性規劃(mixed integer linear programming MILP)下列為一混合整數線性規劃模式:Max 3X1+4X2s.t. -1X1+2X2≦81X2+2X2≦122X1+1X2≦16X1,X2≧0且X2為整數3此例中將“X2為整數”的要求刪去後之線性規劃稱為“混合整數線性規劃的LP寬鬆式”。
●在全整數或混合整數線性規劃中,整數值的變數為離散變數(discrete variable),其他變數稱為連續變數(continuous variable)。
●一整數規劃中,整數變數只允許0或1稱為0-1或二元(binary)整數規劃。
48.2 全整數規劃問題的圖解法及電腦解例:東生不動產公司目前有2,000,000元可用來投資出租房屋計劃。
公司將投資方案限於在住宅區的別墅及公寓,別墅每棟282,000元,而目前只有五戶別墅可買得到,每棟公寓售價400,000元,公寓的數量則很多。
公司管理人員每月有140小時間來管理這些投資的不動產。
每棟別墅需4小時管理,每棟公寓需40小時。
每月利潤,別墅每棟為10,000元,公寓每棟為15,000元,公司要如何分配資金投資到別墅及公寓,以使總利潤最高。
第三章 整数线性规划本章, 我们介绍三种解决整数线性规划问题的软件:第一种: 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。