Lindo解线性规划问题实例
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
标题:LINDO 软件包介绍;
副标题:Lindo 解线性规划问题实例
导语:LINDO 软件包首先由Linus Schrage 开发,现在,美国的LINDO 系统公司(LINDO System Inc.)拥有版权,是一种专门求解数学规划(优化问题)的软件包。
它能求解线性规划、(0,1)规划、整数规划、二次规划等优化问题,并能同时给出灵敏度分析、影子价格以及最优解的松弛分析,非常方便实用。
1.注意事项
(1) 低版本的LINDO 要求变量一律用大写字母表示;
(2) 求解一个问题,送入的程序必须以MIN 或MAX 开头,以END 结
束;然后按Ctrl + S (或按工具栏中的执行快捷键)进行求解;
(3) 目标函数与约束条件之间要用SUBJECT TO (或ST )分开,其
中字母全部大写;
(4) LINDO 已假定所有变量非负,若某变量,例如X5有可能取负值,
可在END 命令下面一行用FREE X5命令取消X5的非负限制;
LINDO 要求将取整数值的变量放在前面(即下标取小值),在
END 下面一行用命令INTEGER K ,表示前K 个变量是(0,1)
变量;在END 下面一行用命令GIN H 表示前H 个变量是整数变
量;
(5) 在LINDO 中,“<”等价于“≤” ,“>”等价于“≥” ;
(6) 在LINDO 的输出结果中有STATUS (状态栏),它的表出状态有:
OPTIMAL (说明软件包求得的结果是最优解)、FEASIBLE (说
明软件包求得的结果只是可行解)、INFEASIBLE (说明软件包
求得的结果是不可行解)。
(7) 在LINDO 命令中,约束条件的右边只能是常数,不能有变量;
(8) 变量名不能超过8个字符;
(9) LINDO 对目标函数的要求,每项都要有变量,例如,LINDO 不
认识MIN 2000-X+Y ,要改为MIN –X+Y ;
(10)LINDO 不认识400(X+Y )要改为400X+400Y 。
2.求解线性规划问题
例6-1 求解下列线性规划问题:
⎪⎩
⎪⎨⎧≥≤+≤++=0,12
531034..32max y x y x y x t s y
x f 在LINDO 中输入下列命令:
MAX 2X+3Y
SUBJECT TO
4X+3Y<10
3X+5Y<12
END
LINDO输出下列结果:STATUS OPTIMAL
LP OPTIMUM FOUND AT STEP 1
OBJECTIVE FUNCTION V ALUE
1) 7.454545
V ARIABLE V ALUE REDUCED COST
X 1.272727 0.000000
Y 1.636364 0.000000
ROW SLACK OR SURPLUS DUAL PRICES
2) 0.000000 0.090909
3) 0.000000 0.545455
NO. ITERATIONS= 1
RANGES IN WHICH THE BASIS IS UNCHANGED:
OBJ COEFFICIENT RANGES V ARIABLE CURRENT ALLOWABLE
ALLOWABLE
COEF INCREASE DECREASE
X 2.000000 2.000000 0.200000
Y 3.000000 0.333333 1.500000
RIGHTHAND SIDE RANGES
ROW CURRENT ALLOWABLE ALLOWABLE
RHS INCREASE DECREASE
2 10.000000 6.000000 2.800000
3 12.000000 4.666667 4.500000
这个结果说明:LINDO求解此线性规划问题(LP)只用一步迭代就得到最优解fmax = 7.454545,x = 1.272727, y = 1.636364。
两个松弛变量取0值,即,这个最优解使得约束条件都取等号;其对偶问题的最优解(影子价格)DUAL PRICES为Y1=0.090909,Y2=0.545455。
同时灵敏度分析告诉我们:在目标函数
中,X 的系数是2,允许下降0.2,允许增加2,即,X 的系数在区间[1.8,4]中任意变化,最优基不变;在目标函数中,Y 的系数是3,允许下降1.5,允许增加0.333333,即,Y 的系数在区间[1.5,3.333333]中任意变化,最优基不变;约束条件右边第一个常数是10,允许下降2.8,允许增加6,即在区间[7.2,16]中任意变化,最优基不变;约束条件右边第二个常数是12,允许下降4.5,允许增加4.666667,即在区间[7.5,16.666667]中任意变化,最优基不变。
例6-2求解下列线性规划问题:
⎪⎩⎪⎨⎧>≤-≤++=yFREE
x y x y x t s y
x f ,01149
32..min
在LINDO 中输入以下命令:
MIN X+Y
ST
2X+3Y 〈9
X-4Y 〈11
END
FREE Y
LINDO 运算后输出以下结果:STATUS OPTIMAL
LP OPTIMUM FOUND AT STEP 1
OBJECTIVE FUNCTION V ALUE
1) -2.750000
V ARIABLE V ALUE REDUCED COST
X 0.000000 1.250000
Y -2.750000 0.000000
ROW SLACK OR SURPLUS DUAL PRICES
2) 17.250000 0.000000
3) 0.000000 0.250000
NO. ITERATIONS= 1
RANGES IN WHICH THE BASIS IS UNCHANGED:
OBJ COEFFICIENT RANGES
V ARIABLE CURRENT
ALLOWABLE
ALLOWABLE
COEF INCREASE DECREASE X 1.000000 INFINITY 1.250000
Y 1.000000 INFINITY 1.000000
RIGHTHAND SIDE RANGES
ROW CURRENT ALLOWABLE ALLOWABLE
RHS INCREASE DECREASE
2 9.000000 INFINITY 17.250000
3 11.000000 INFINITY 23.000000
这个结果说明:LINDO求解此线性规划问题(LP)只用一步迭代就得到最优解fmin = -2.75,x = 0, y = -2.75。
第一个松弛变量取值17.25,第二个松弛变量取0值,即,这个最优解使得第二个约束条件取等号;其对偶问题的最优解(影子价格)DUAL PRICES为Y1=0,Y2=0.25。
同时灵敏度分析告诉我们:在目标函数中,X的系数是1,允许下降1.25,允许增加∞,即,X的系数在区间[-0.25,∞]中任意变化,最优基不变;在目标函数中,Y的系数是1,允许下降1,允许增加∞,即,Y的系数在区间[0,∞]中任意变化,最优基不变;约束条件右边第一个常数是9,允许下降17.25,允许增加∞,即在区间[-8.25,∞]中任意变化,最优基不变;约束条件右边第二个常数是11,允许下降23,允许增加∞,即在区间[-12,∞]中任意变化,最优基不变。
例6-3求解下列线性规划问题(参见第5章例18):
MAX 360X1+220X2+240X3+360X4+220X5+240X6
ST
X1+X2+X3<300
X4+X5+X6<1200
X1+X4<6000
X2+X5<500
X3+X6<1000
X1-4X4>0
9X2-X5>0
END
得到结果如下:
LP OPTIMUM FOUND AT STEP 3
OBJECTIVE FUNCTION V ALUE
1) 400000.0
V ARIABLE V ALUE REDUCED COST
X1 285.714294 0.000000
X2 14.285714 0.000000
X3 0.000000 200.000000
X4 71.428574 0.000000
X5 128.571426 0.000000
X6 1000.000000 0.000000
ROW SLACK OR SURPLUS DUAL PRICES
2) 0.000000 400.000000
3) 0.000000 200.000000
4) 5642.856934 0.000000
5) 357.142853 0.000000
6) 0.000000 40.000000
7) 0.000000 -40.000000
8) 0.000000 -20.000000
NO. ITERATIONS= 3
RANGES IN WHICH THE BASIS IS UNCHANGED:
OBJ COEFFICIENT RANGES
V ARIABLE CURRENT ALLOWABLE ALLOWABLE
COEF INCREASE DECREASE X1 360.000000 1750.000000 174.999985
X2 220.000000 175.000000 1750.000000
X3 240.000000 200.000000 INFINITY
X4 360.000000 7000.000000 155.555542
X5 220.000000 38.888885 194.444427
X6 240.000000 INFINITY 40.000000
RIGHTHAND SIDE RANGES
ROW CURRENT ALLOWABLE ALLOWABLE
RHS INCREASE DECREASE
2 300.000000 499.999969 277.777771
3 1200.000000 312.499969 124.999992
4 6000.000000 INFINITY 5642.856934
5 500.000000 INFINITY 357.142853
6 1000.000000 124.999992 312.499969
7 0.000000 277.777771 499.999969
8 0.000000 2499.999756 125.000000
3.求解整数线性规划问题
例6-4求解下列(0,1)线性规划问题:
⎪⎪⎪⎪⎩
⎪⎪⎪⎪⎨⎧=≤≤=≤≤=+++++++++++++++++++=∑∑==1,05
1,14
1,1..45104410435424413510349334323312510247233222211571451321211max 4
1
5
1
ij i ij j ij x j x i x t s x x x x x x x x x x x x x x x x x x x x f 在LINDO 中输入下列命令:
MAX X11+X12+2X13+5X14+7X15+X21+2X22+3X23+7X24+10X25
+X31+3X32+4X33+9X34+10X35+X41+4X42+5X43+10X44+10X45
ST
X11+X12+X13+X14+X15=1
X21+X22+X23+X24+X25=1
X31+X32+X33+X34+X35=1
X41+X42+X43+X44+X45=1
X11+X21+X31+X41=1
X12+X22+X32+X42=1
X13+X23+X33+X43=1
X14+X24+X34+X44=1
X15+X25+X35+X45=1
END
INT 20
LINDO 运算后输出下列结果:STATUS INFEASIBLE (求不出最优解)。
若将问题变为5×5的问题,就能求出解来。
⎪⎪⎪⎪⎩
⎪⎪⎪⎪⎨⎧=≤≤=≤≤=+++++++++++++++++++=∑∑==1,05
1,14
1,1..45104410435424413510349334323312510247233222211571451321211max 5
1
5
1
ij i ij j ij x j x i x t s x x x x x x x x x x x x x x x x x x x x f 在LINDO 中输入下列命令:
MAX X11+X12+2X13+5X14+7X15+X21+2X22+3X23+7X24+10X25
+X31+3X32+4X33+9X34+10X35+X41+4X42+5X43+10X44+10X45
ST
X11+X12+X13+X14+X15=1
X21+X22+X23+X24+X25=1
X31+X32+X33+X34+X35=1
X41+X42+X43+X44+X45=1
X51+X52+X53+X54+X55=1
X11+X21+X31+X41+X51=1
X12+X22+X32+X42+X52=1
X13+X23+X33+X43+X53=1
X14+X24+X34+X44+X54=1
X15+X25+X35+X45+X55=1
END
INT 25
LINDO运算后输出下列结果:STATUS OPTIMAL
LP OPTIMUM FOUND AT STEP 15
OBJECTIVE V ALUE = 25.0000000
FIX ALL V ARS.( 11) WITH RC > 1.00000
NEW INTEGER SOLUTION OF 25.0000000 AT BRANCH 0 PIVOT 15
BOUND ON OPTIMUM: 25.00000
ENUMERATION COMPLETE. BRANCHES= 0 PIVOTS= 15 LAST INTEGER SOLUTION IS THE BEST FOUND
RE-INSTALLING BEST SOLUTION...
OBJECTIVE FUNCTION V ALUE
1) 25.00000
V ARIABLE V ALUE REDUCED COST
X11 0.000000 -1.000000
X12 0.000000 -1.000000
X13 1.000000 -2.000000
X14 0.000000 -5.000000
X15 0.000000 -7.000000
X21 0.000000 -1.000000
X22 0.000000 -2.000000
X23 0.000000 -3.000000
X24 0.000000 -7.000000
X25 1.000000 -10.000000
X31 0.000000 -1.000000
X32 0.000000 -3.000000
X33 0.000000 -4.000000
X34 1.000000 -9.000000
X35 0.000000 -10.000000
X41 0.000000 -1.000000
X42 1.000000 -4.000000
X43 0.000000 -5.000000
X44 0.000000 -10.000000
X45 0.000000 -10.000000
X51 1.000000 0.000000
X52 0.000000 0.000000
X53 0.000000 0.000000
X54 0.000000 0.000000
X55 0.000000 0.000000
ROW SLACK OR SURPLUS DUAL PRICES
2) 0.000000 0.000000
3) 0.000000 0.000000
4) 0.000000 0.000000
5) 0.000000 0.000000
6) 0.000000 0.000000
7) 0.000000 0.000000
8) 0.000000 0.000000
9) 0.000000 0.000000
10) 0.000000 0.000000
11) 0.000000 0.000000
NO. ITERATIONS= 15
BRANCHES= 0 DETERM.= 1.000E 0
这个结果说明:LINDO求解此(0,1)整数线性规划问题(LP)只15步迭代得到最优解fmax = 25,x13 = x25 = x34 = x42 = x51 =1,其它xij = 0。
松弛变量都取0值,即,这个最优解使得约束条件都取等号;其对偶问题的最优解(影子价格)DUAL PRICES都为0。
例6-5求解下列整数线性规划问题(参见第5章例6):
⎪⎪⎪⎪⎩⎪⎪⎪⎪⎨⎧≥+≤++≤++≤++=+=+=++=+++=egers
y x y x y x y x y
x y x y x y y y x x x t s y x f j i int ,0,20
*1530*2531532520
*2030*3022023020*1030*201101203
1532522023011012020
321,
30321..1
10120max
在LINDO 环境下,输入下列命令:
MAX 20X1+10Y1
ST
X1+X2+X3=30
Y1+Y2+Y3=20
20X1+10Y1=30X2+20Y2
30X2+20Y2=25X3+15Y3
20X1+10Y1<800
30X2+20Y2<1300
25X3+15Y3<1050
END
GIN 6
LINDO 运行后,输出以下结果:STATUS :OPTIMAL
LP OPTIMUM FOUND AT STEP 5
OBJECTIVE V ALUE = 350.000000
FIX ALL V ARS.( 2) WITH RC > 0.000000E+00
DELETE Y2 AT LEVEL 1
RELEASE FIXED V ARIABLES
FIX ALL V ARS.( 1) WITH RC > 0.000000E+00
DELETE Y2 AT LEVEL 1
RELEASE FIXED V ARIABLES
FIX ALL V ARS.( 1) WITH RC > 0.000000E+00
SET X3 TO <= 11 AT 1, BND=
348.7 TWIN=-0.1000E+31 17
SET X2 TO >= 2 AT 2, BND=
348.3 TWIN=-0.1000E+31 18
SET Y2 TO <= 14 AT 3, BND=
348.1 TWIN=-0.1000E+31 19
SET X2 TO >= 3 AT 4, BND=
347.5 TWIN=-0.1000E+31 20
SET X3 TO <= 9 AT 5, BND=
347.0
TWIN=-0.1000E+31 22
SET X2 TO >= 4 AT 6, BND= 346.7 TWIN=-0.1000E+31 23
SET Y2 TO <= 11 AT 7, BND= 346.5 TWIN=-0.1000E+31 25
SET X2 TO >= 5 AT 8, BND= 345.8 TWIN=-0.1000E+31 26
SET X3 TO <= 7 AT 9, BND= 345.2 TWIN=-0.1000E+31 28
SET X2 TO >= 6 AT 10, BND= 345.0 TWIN=-0.1000E+31 29
SET Y2 TO <= 8 AT 11, BND= 344.9 TWIN=-0.1000E+31 31
SET X3 TO <= 6 AT 12, BND= 344.3 TWIN=-0.1000E+31 33
SET X2 TO >= 7 AT 13, BND= 344.2 TWIN=-0.1000E+31 34
SET Y2 TO <= 6 AT 14, BND= 343.8 TWIN=-0.1000E+31 36
SET X2 TO >= 8 AT 15, BND= 343.3 TWIN=-0.1000E+31 37
SET Y2 TO <= 5 AT 16, BND= 343.2 TWIN=-0.1000E+31 39
SET X2 TO >= 9 AT 17, BND= 342.5 TWIN=-0.1000E+31 40
SET Y2 TO <= 3 AT 18, BND= 342.2 TWIN=-0.1000E+31 42
SET X2 TO >= 10 AT 19, BND= 341.7 TWIN=-0.1000E+31 43
SET Y2 TO <= 2 AT 20, BND= 341.6 TWIN=-0.1000E+31 45
SET X2 TO >= 11 AT 21, BND= 340.8 TWIN=-0.1000E+31 46
SET Y2 TO <= 0 AT 22, BND= 340.5 TWIN=-0.1000E+31 47
DELETE X2 AT LEVEL 23
DELETE Y2 AT LEVEL 22
DELETE X2 AT LEVEL 21
DELETE Y2 AT LEVEL 20
DELETE X2 AT LEVEL 19
DELETE Y2 AT LEVEL 18
DELETE X2 AT LEVEL 17
DELETE Y2 AT LEVEL 16
DELETE X2 AT LEVEL 15
DELETE Y2 AT LEVEL 14
DELETE X2 AT LEVEL 13
DELETE X3 AT LEVEL 12
DELETE Y2 AT LEVEL 11
DELETE X2 AT LEVEL 10
DELETE X3 AT LEVEL 9
DELETE X2 AT LEVEL 8
DELETE Y2 AT LEVEL 7
DELETE X2 AT LEVEL 6
DELETE X3 AT LEVEL 5
DELETE X2 AT LEVEL 4
DELETE Y2 AT LEVEL 3
DELETE X2 AT LEVEL 2
DELETE X3 AT LEVEL 1
RELEASE FIXED V ARIABLES
SET Y2 TO <= 15 AT 1, BND= 347.8 TWIN=-0.1000E+31 59
SET X2 TO >= 2 AT 2, BND= 347.5 TWIN=-0.1000E+31 62
SET Y2 TO <= 14 AT 3, BND= 347.3 TWIN=-0.1000E+31 64
SET X2 TO >= 3 AT 4, BND= 346.7 TWIN=-0.1000E+31 66
SET Y2 TO <= 12 AT 5, BND= 346.2 TWIN=-0.1000E+31 70
SET X2 TO >= 4 AT 6, BND= 345.8 TWIN=-0.1000E+31 72
SET Y2 TO <= 11 AT 7, BND= 345.7 TWIN=-0.1000E+31 75
SET X2 TO <= 4 AT 8, BND= 340.0 TWIN= 345.0 77
NEW INTEGER SOLUTION OF 340.000000 AT BRANCH 33 PIVOT 77
BOUND ON OPTIMUM: 349.1667
DELETE X2 AT LEVEL 8
DELETE Y2 AT LEVEL 7
DELETE X2 AT LEVEL 6
DELETE Y2 AT LEVEL 5
DELETE X2 AT LEVEL 4
DELETE Y2 AT LEVEL 3
DELETE X2 AT LEVEL 2
DELETE Y2 AT LEVEL 1
ENUMERATION COMPLETE. BRANCHES= 33 PIVOTS= 77
LAST INTEGER SOLUTION IS THE BEST FOUND
RE-INSTALLING BEST SOLUTION...
OBJECTIVE FUNCTION V ALUE
1) 340.0000
V ARIABLE V ALUE REDUCED COST
X1 13.000000 -20.000000
Y1 8.000000 -10.000000
X2 4.000000 0.000000
X3 13.000000 0.000000
Y2 11.000000 0.000000
Y3 1.000000 0.000000
ROW SLACK OR SURPLUS DUAL PRICES
2) 0.000000 0.000000
3) 0.000000 0.000000
4) 0.000000 0.000000
5) 0.000000 0.000000
6) 460.000000 0.000000
7) 960.000000 0.000000
8) 710.000000 0.000000
NO. ITERATIONS= 77
BRANCHES= 33 DETERM.= 1.000E 0
这个结果说明:LINDO 求解此线性规划问题(LP )共用77步迭代得到最优解 fmax = 340,x1 = 13,x2 = 4,x3 = 13,y 1= 8, y2 = 11,y3 = 1 。
前4个松弛变量取0值,即,这个最优解使得前4个约束条件取等号;其对偶问题的最优解(影子价格)DUAL PRICES 都为0。
例6-6求解下列整数线性规划问题(参见第5章例8):
⎪⎩⎪⎨⎧≥≥+++++≥++++++++++=egers x x x x x x x x x x x x x t s x x x x x x f j
int ,020000
6*0542332516100006554433221*0..6
54321min 在LINDO 中输入下列命令:
MIN X1+X2+X3+X4+X5+X6
ST
X2+2X3+3X4+4X5+5X6>10000
6X1+5X2+3X3+2X4+X5>20000
END
GIN 6
LINDO运行后输出以下结果:STATUS:OPTIMAL
LP OPTIMUM FOUND AT STEP 3
OBJECTIVE V ALUE = 5200.00000
FIX ALL V ARS.( 4) WITH RC > 0.400000E-01
NEW INTEGER SOLUTION OF 5200.00000 AT BRANCH 0 PIVOT 3
BOUND ON OPTIMUM: 5200.000
ENUMERATION COMPLETE. BRANCHES= 0 PIVOTS= 3 LAST INTEGER SOLUTION IS THE BEST FOUND
RE-INSTALLING BEST SOLUTION...
OBJECTIVE FUNCTION V ALUE
1) 5200.000
V ARIABLE V ALUE REDUCED COST
X1 0.000000 1.000000
X2 4000.000000 1.000000
X3 0.000000 1.000000
X4 0.000000 1.000000
X5 0.000000 1.000000
X6 1200.000000 1.000000
ROW SLACK OR SURPLUS DUAL PRICES
2) 0.000000 0.000000
3) 0.000000 0.000000
NO. ITERATIONS= 3
BRANCHES= 0 DETERM.= 1.000E 0
这个结果说明:LINDO求解此线性规划问题(LP)共用3步迭代得到最优解fmin = 5200,x2 = 4000,
x6 = 1200,其它xj = 0。
松弛变量都取0值,即,这个最优解使得约束条件都取等号;其对偶问题的最优解(影子价格)DUAL PRICES都为0。