|
第二章 线性规划 本章, 我们介绍三种解决线性规划问题的软件: 第一种: MATLAB软件中的optimization toolbox中的若干程序; 第二种: LINDO软件; 第三种: LINGO软件. 1. MATLAB程序说明程序名: lprogram执行实例:file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtml1/01/clip_image002.gif 在命令窗口的程序执行过程和结果如下:the program is with the linear programming Please input the constraints number of the linear programming m=7 m =7 Please input the variant number of the linear programming n=4 n =4 Please input cost array of the objective function c(n)_T=[-2,-1,3,-5]' c =
- K+ Q% V+ |# `- Y-2 6 H$ E/ u* e+ z" D. Q
-1 ' u, ]# o! X: N; d% Y# m
3
" f9 ]: U8 T3 B9 ]3 l) M-5
Please input the coefficient matrix of the constraints A(m,n)=[1,2,4,-1;2,3,-1,1; 1,0,1,1;-1,0,0,0;0,-1,0,0;0,0,-1,0;0,0,0,-1] A =
6 x7 K. L- h0 S) v1( C+ o( R' Y3 Y: {: `5 v
2
$ p& Y2 l: j0 n4- _5 Y6 L5 R3 g/ W3 n9 }- b/ i% R
-1
/ @. B; T: q8 m8 |6 M2
6 ~1 j; t3 `; W! V3
: S$ I- k- w& m-1
. ^0 S0 z6 b5 D! |7 b" p1
, M4 x; l" M1 s N& i I: k
1
5 q4 U3 A" U' v: g7 K/ L0/ l' O, t. f: P6 v2 L
17 O7 m. J1 W% \# g* e4 b3 b, Z
1
- J& q6 P5 F/ Y-14 E- B9 G; M/ J0 s0 U. K
0! q, G2 L- C6 {: h- A" s( Z% D5 x
02 ]& T9 h% B9 ]
0
, ]' }* {5 W$ o. }- K, X4 f
0
8 c8 ~4 u5 {1 k1 O& X-1
' x3 z( y+ {" T! c$ X( t$ b04 Q$ o+ R u7 f4 f" Q+ v
0
2 I( }- Q6 K& O6 R0 Y0 y; n9 K0
! Z$ B( ?3 E% t6 Y: U0
6 e1 b! C( U% A3 Q- ]5 r-16 {; E) V. o5 {) I! H5 q
0
. d$ a {; u. U# s+ N2 z2 Y/ e) X" i0 o9 ?; R; ^3 }, r8 t3 L* O
0) x7 k9 G4 {% j3 k" f6 Y/ P8 j' B( _
0
" @% h; F( S/ W4 L-1
Please input the resource array of the program b(m)_T=[6,12,4,0,0,0,0]' b =
9 L' R* S! l3 V7 |6
" h2 k% A! ]: M: I+ ]- D! l12
) |! s7 T% [/ k: [7 {% z& T4
' M$ a6 V$ E6 z5 A, @0
2 k! x2 U" a8 B c3 T
0 : x, ]$ ]5 I! j8 [9 ]. h N+ r3 b
0
% X' c8 g1 m+ _+ K( R( }0
Optimization terminated successfully. The optimization solution of the programming is: x = Q/ ~* @; ~0 e9 D4 b
0.0000
' b* ]) ]1 m+ R/ Y6 u2.6667
: d4 A$ z w4 I-0.0000
& y4 O! h0 v; t) y0 B4.0000
The optimization value of the programming is: opt_value = -22.6667 注: 红色字表示计算机的输出结果. 程序的相关知识:Solve a linear programming problem file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtml1/01/clip_image003.gif where f, x, b, beq, lb, and ub are vectors and A and Aeq are matrices. 相关的语法:x = linprog(f,A,b,Aeq,beq) x = linprog(f,A,b,Aeq,beq,lb,ub) x = linprog(f,A,b,Aeq,beq,lb,ub,x0) x = linprog(f,A,b,Aeq,beq,lb,ub,x0,options) [x,fval] = linprog(...) [x,fval,exitflag] = linprog(...) [x,fval,exitflag,output] = linprog(...) [x,fval,exitflag,output,lambda] = linprog(...) 解释:linprog solves linear programming problems. x = linprog(f,A,b) solves min f'*x such that A*x <= b. x = linprog(f,A,b,Aeq,beq) solves the problem above while additionally satisfying the equality constraints Aeq*x = beq. Set A=[] and b=[] if no inequalities exist. x = linprog(f,A,b,Aeq,beq,lb,ub) defines a set of lower and upper bounds on the design variables, x, so that the solution is always in the range lb <= x <= ub. Set Aeq=[] and beq=[] if no equalities exist. x = linprog(f,A,b,Aeq,beq,lb,ub,x0) sets the starting point to x0. This option is only available with the medium-scale algorithm (the LargeScale option is set to 'off' using optimset). The default large-scale algorithm and the **x algorithm ignore any starting point. x = linprog(f,A,b,Aeq,beq,lb,ub,x0,options) minimizes with the optimization options specified in the structure options. Use optimset to set these options. [x,fval] = linprog(...) returns the value of the objective function fun at the solution x: fval = f'*x. [x,lambda,exitflag] = linprog(...) returns a value exitflag that describes the exit condition. [x,lambda,exitflag,output] = linprog(...) returns a structure output that contains information about the optimization. [x,fval,exitflag,output,lambda] = linprog(...) returns a structure lambda whose fields contain the Lagrange multipliers at the solution x. 2.LINDO 程序说明程序名:linear执行实例:file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtml1/01/clip_image005.gif 在命令窗口键入以下内容:max 10x+15y !也可以直接解决min问题 subject to x<10 y<12 x+2y<16 end
# F' O% j' R& x. y* a4 @5 g: b9 V!注释符号; 系统默认为自变量>0, 若不要求用free命令. ( x3 q1 g& J( f) D
!在出来report windows之前可选择显示对此规划进行灵敏度分析等 按solve键, 在reports window中出现以下内容:LP OPTIMUM FOUND AT STEP" M! F2 k; }9 O7 b" c, d
2
$ K8 @8 J1 {6 t6 J, O# }* U( QOBJECTIVE FUNCTION VALUE
8 j5 q- Z( A8 u1)+ _7 g, I- [+ D1 a# Y
145.0000
# w, I2 f/ H' gVARIABLE
0 O2 l* |, s, Z1 C* V8 D Z. xVALUE
9 F$ c, z. @# lREDUCED COST
# ~" k' h5 H4 z- PX. f$ l4 J6 F1 X2 \
10.0000005 W5 D$ W; U$ q9 m2 p" O
0.000000
@' K+ p- z# iY
0 Y2 f9 O e" ?' y4 l) L3 n3 ~( [3.000000% w2 Q, M( W- q2 c1 i) f! D
0.000000
3 F% g/ \: M- X& K$ b4 A; W
ROW7 [) W1 B; R2 U
SLACK OR SURPLUS/ L7 D! X) m3 o6 J2 G; F- T
DUAL PRICES
6 q" P/ ~6 N# u2)( ~7 p! O4 e. a, ?: I8 l
0.000000& K z9 N V5 m' M+ b6 s O6 U0 L7 C
2.500000
, B" Z' a/ H3 y, u5 y; `7 ~3)
4 H6 L9 q' V+ W3 A# c9.0000002 O9 y. E) R7 _; ^* K2 e% P% k: x+ q
0.000000
! f& f( K$ U; m* a& B' l, g4)
& E3 c/ _6 ^# T0 h0.000000
/ [4 {7 E, J2 Z7.500000
9 Y% g9 B, u0 v8 c: p
NO. ITERATIONS=$ V; F4 t: n( Y# F
2
" h" d/ r9 Q* E6 ~RANGES IN WHICH THE BASIS IS UNCHANGED:
+ C+ @0 z# }& d# yOBJ COEFFICIENT RANGES
; O) w, @/ x' ^; V: y" Z6 eVARIABLE
+ Q" F# R& d" }1 J: u' f; pCURRENT
+ m6 [/ i! p0 b6 u7 p5 ?2 RALLOWABLE1 Q; E5 Z/ {% _3 ]* t' X0 d
ALLOWABLE
4 |+ ?$ T5 Q' M) r
COEF; ]; H8 B" {* {
INCREASE/ S; o6 |; |# `; X2 f% g
DECREASE 0 P2 ~! ^9 ?8 X* X
X
' \& Z+ S1 `- J) k& Q0 ^1 H10.000000
! f, x6 @1 c- d/ @8 P3 jINFINITY* y( P$ j# o* p& s! j* r& \' \
2.500000
; H0 K' U1 k# n6 s' \Y
4 G( @! C( s! q2 v15.000000$ p( y1 p+ x2 Z2 }6 {+ u0 u! ~! r/ \- [
5.000000
" n6 S2 t V8 Z% a( n15.000000
. ^* B" f# ^5 Z( W4 \& l' J rRIGHTHAND SIDE RANGES
: T) T, N2 W' s0 {0 t
ROW: S- B5 G8 n! n, ^. a ^
CURRENT2 q- ~& m1 c$ G8 B
ALLOWABLE
$ E6 s, r! L7 n: l7 F: ]ALLOWABLE
& J" m' r% X+ I6 LRHS
. ?! m, s |4 h: ^; I) VINCREASE# }* p3 i1 Y6 [7 |
DECREASE
: z: n4 E! }7 u) s
: \( F$ A8 |3 a) L% [2
- i+ J' J" w* L. Z" Q- N10.000000* z0 ^2 L" t; o3 V+ e0 W
6.000000
8 N: C$ L, Z! ^- j10.000000
0 p2 y# R8 x% V37 k3 t! }+ A* U8 O
12.000000
" c% i# L$ c' s3 oINFINITY
% G! S: V. p9 s3 {! F) r* J& ^9.000000
0 a* U2 v9 y0 R
4
0 P; Q$ c4 i5 k5 v" t f W16.000000
2 o7 u* Y( b8 I18.000000
' h4 L9 h+ s( V9 b7 F: i9 e" t* A' f6.000000 3.LINGO 程序说明3.1 程序名: linearp1(求极小问题)linearp1运行实例:file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtml1/01/clip_image007.gif 在model window中输入以下语句:min=5*x1+21*x3; x1-x2+6*x3-x4=2; x1+x2+2*x3-x5=1; 按运行按钮在solution" C# R2 W2 A/ W- ^0 ~
report 窗口得到以下结果: # p8 y4 Y% g1 M+ Z/ i8 [& O
Global optimal solution found at iteration:
1 e2 m p0 C# q. y- t9 S [' Z2 $ s' n2 Y$ N0 g" y
Objective value:
, H$ y% F/ i4 C: R$ G7.750000 9 H( i2 j; k" ?- Q3 g* g& ?
Variable
- @; A( E; D* M, x& r" D( K" }Value: [* U) B0 L! d: P4 |; ~- h8 d
Reduced Cost 9 s3 O5 a' p% c& E& t: h- b
X1
- e' _+ Q+ v0 p7 B1 b* O0.5000000
8 [1 r/ Q% f* n8 Y+ |* g4 \: t0.000000 4 a' l0 Z5 c) D3 A
X3# M9 G+ p; d5 P& X& }3 q
0.2500000
2 r# o `' ]- P0.000000
- {" _$ b& o1 B" Q
& ?7 o/ n9 s, n" a5 `1 d8 JX29 F4 Q$ `9 U% ?2 N" {5 F
0.000000' B) A6 v. M7 s( s4 D3 E- Q; U
0.5000000
) c0 `" {' R) g( p |3 cX4
1 x; Z; n, U& t0.000000
; _( M8 G& b4 B2 e& C& s2.750000
# R# T7 E. A) O$ e6 ?
X5
# l7 y6 n7 p8 f4 L! F+ e0.000000
3 [: B+ ?: a/ H0 [; c4 C2.250000 ! O- B$ x2 S$ a5 O9 W
Row# j. U0 F3 {/ D6 \2 J8 e5 ]: `
Slack or Surplus
9 Q: v$ t! v& bDual Price
4 d6 w, z+ d5 c1 ]* t! B" h' }1
; b+ h. A s! @) p7.750000
8 r0 s$ N- _" G P O ~-1.000000
. \6 ~, M& P' A" v/ v
2( O7 G/ d! \4 O1 j2 u# g/ L# a
0.000000 Z- v9 a- a6 \ U# W* }
-2.750000
% Z1 d) S) s% ]7 N- B3
8 L' S: z5 L4 f7 b0.000000
3 H2 { [; ?2 ^# f( J o! D-2.250000
3.2 程序名: linearp2(求极大问题)linearp2运行实例:file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtml1/01/clip_image009.gif 在model window中输入以下语句:max=100*x+150*y;
1 i8 g/ J/ j: s# d* a+ {! this is a commnent; x<=100; y<=120; x+2*y<=160; 按运行按钮在solution report 窗口得到以下结果: Global optimal solution found at iteration:9 o7 Q: O) d9 k4 B( m
2 9 j: {3 s% o# a n
Objective value:
( }% n0 l1 P. ?. C* L2 W. I0 M9 \
) m: W& C1 g: g: Z" T! A B: ^14500.00 / O1 C2 G6 G% g' z/ B" u) h, X, g
Variable
: O5 A; O2 D" b2 O) Q1 dValue ^# E3 @% d/ V: q5 I
Reduced Cost
6 J" |- t. {0 o8 pX' u+ j3 g3 ~7 ~, k0 V' h& `9 \
100.0000$ x6 h5 j7 q7 U
0.000000
8 s6 w8 O* N5 f: Y2 ^8 c. K
Y7 f) |$ d! U3 O- z4 `- |; L
30.00000
+ l+ x0 b+ ?9 u0.000000 ' x1 Y- H4 e) d1 p" L$ y5 s
Row- {- h5 q4 t; I( W8 y3 T" t
Slack or Surplus8 b' X% ~# @& Q3 f2 X) s
Dual Price
( a ]1 I; m2 P, Z) z* B10 [# j( l9 b0 b& b# N
14500.00
1 R$ n3 ~( z1 T1.000000
% y) N% o& J, Z! U$ r: N, P2
! W1 T& N9 D: d" X5 k/ E$ x0.000000
8 P" m( B4 o- A# Q3 x& E" b25.00000
8 t! X+ G8 J; {1 o3
( s0 P/ ^. M) D90.00000, \9 P1 F9 R: r, F& J* c* Z
0.000000
43 [- w8 b: t: R$ w
0.000000- m5 A+ q* U! k/ F# b7 M/ {
1 q$ h/ R* [& @' d75.00000 |