|
第二章 线性规划 本章, 我们介绍三种解决线性规划问题的软件: 第一种: 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 =& H7 n$ E1 P& _8 B0 {
-2
& @+ {' ?8 V- l+ O3 q7 _8 y5 p/ d& E r-1
: K8 Q0 u$ ?7 O' P
3 * k7 G0 X# U+ A7 X" B' H7 G* y
-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 =. I8 o: J! A, [ P" E* E& z
1
) l1 Q* N$ j9 A1 |; U2
9 ^9 f7 x x: _$ j7 z" ?- ~4
* d# a) P3 P: k) R1 W3 b H-1 # J% q% K/ F8 z2 I% K" j
2
1 v E& v8 A# r* Y( K3 C* f0 O$ X8 R3
7 x8 Y2 I7 Q, ?5 X-1
0 P8 x$ I1 e4 r9 M9 N" ~1 $ ]+ s# s p% y! {" K2 J& ]
1) y, F% M" Y. a6 _7 E
0; t' Z8 d$ S+ F L, X
1
' E6 j" V9 z d1
r3 Z) m" u5 }" y$ _2 i# P* `-1
0 u2 b4 { I+ T06 J, D9 g; `7 G7 {0 ^' @* J
02 Y1 j s1 {! F
0
4 B4 r4 f; {7 ]+ u2 a0. I2 A" R& g' d4 {& S/ c& p
-1
3 b" K) F& @8 M; a- X' u% `0
! |5 x+ u3 B6 e0
$ _6 K7 k, d7 c+ i0/ ?$ f- P v, x/ l
0
' b8 V9 @/ ~1 I5 y& ~-1
" m8 U) ]* s% |: c0
6 v2 m0 @6 V& I2 q% d% M0
5 \% j, X$ V+ m' b& J! U0
$ c+ q3 ~" L' I" |5 w4 }0
: J( m3 t2 _/ m-1
Please input the resource array of the program b(m)_T=[6,12,4,0,0,0,0]' b =9 H6 k$ a0 _' Z# H7 t3 ?: z
6
4 M7 V3 P5 k# F12
: s& |" o' S V6 g4
4 F- Z& p4 ]: P. T. q: g+ [) A& A
0 - n. {- p& p. x( ^
0 " w; }/ O4 F2 Q5 y
0
$ G# U* Q W( i0
Optimization terminated successfully. The optimization solution of the programming is: x =1 Y0 _* d6 t% u! {
0.0000 4 W# {% X. b1 t* k" C& o( [
2.6667 . X9 H6 k8 |( s* B8 ?& g
-0.0000 3 Y8 J0 }- y+ V- y2 r% n7 n( v# c' b2 r, n
4.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$ V% H# H( Q: \" z. ]0 p
!注释符号; 系统默认为自变量>0, 若不要求用free命令. $ c0 `! q' l: `4 m
!在出来report windows之前可选择显示对此规划进行灵敏度分析等 按solve键, 在reports window中出现以下内容:LP OPTIMUM FOUND AT STEP
- M) q9 s' G: a; L! F2 7 `. G, E7 P( z+ M: C( w
OBJECTIVE FUNCTION VALUE 7 y& j0 s i" B# d% }' d
1)
: G# b# O2 q( f0 c: o5 s/ Q145.0000 " ^" C& i7 L) x
VARIABLE- a% y! M8 k, L' t
VALUE; d: Y1 u: S# F: f
REDUCED COST
9 P2 a5 z R- O2 o9 s9 Q. IX3 n- ] ~8 ^3 Q" G
10.000000( I% S' l$ _+ q- q- S2 n5 X
0.000000
3 i+ Y9 W- p1 gY
# [7 @, C, ?0 y: ]+ D V0 o' T3.000000% z6 V* `7 R$ s- \
0.000000
" e6 H# }9 A7 ^; t, d2 b
ROW% k+ U" {5 m: W' z& s
SLACK OR SURPLUS4 U5 t/ m ?0 p
DUAL PRICES 7 P- l; {# ]& }) ?, B& q
2)" m4 C. ]' z- T- l
0.000000: J0 _ l- y% ?; y: S/ T
2.500000
t9 }6 ^' ~/ V L% Z3)+ I" L0 e( d6 ~: Y: @
9.000000
# O3 [) d8 J5 T8 a+ k% z7 {0.000000
$ w$ M7 `6 G5 f) O, h7 L5 `% p j4)
1 ?& t" o; W8 D& u0.000000$ R7 s9 ^" o r( G2 n
7.500000
9 h: }: x+ \1 {4 O0 W5 ]3 o
NO. ITERATIONS=
; J& F0 ]2 W( ?3 K+ [# C% l2 * W1 i! o+ Z# x) L: |. s, g( x* O
RANGES IN WHICH THE BASIS IS UNCHANGED: $ E* P( I1 t1 y& K+ m$ C
OBJ COEFFICIENT RANGES
: i' d. g3 w' B3 ]VARIABLE
- G1 f& E( _3 r. z% ICURRENT" y$ Z" _; s' P" W" u
ALLOWABLE
, R/ d( L3 v$ c+ w* q/ IALLOWABLE
" g0 Z3 m" i4 B% R% S1 m/ K
COEF5 S( C# a0 `( r
INCREASE
6 O& s8 |! q5 r% SDECREASE ' ?( w% {& D/ i1 R0 P6 U" z7 x' u
X
3 w0 c7 Z8 ^' @3 V7 s10.000000! y* S' n6 \ @' j
INFINITY
4 o/ X1 W- X4 z2 N" w- D( l! w2 o2.500000
q: O M. p3 \" Z+ L$ ?! Y" O7 t4 RY- N- W+ P4 E. E! z6 q. Z
15.000000
' c, D! A2 U/ t- y' b# J5.000000) J7 ]# u) M% B; b' C$ e. E
15.000000
( d. Q9 ~$ q! ? g* c. z9 h
RIGHTHAND SIDE RANGES
( [( a' R' I; W9 p5 l4 jROW Z7 V% l4 C4 n
CURRENT
& I' O2 I8 f' G2 }- t8 _5 O4 \ALLOWABLE
1 `% h$ v3 o) s! L% K0 IALLOWABLE
i+ n& e. p b9 a3 P' J
RHS/ n+ q/ }0 L5 k3 Y7 v
INCREASE
* R( u/ j! U0 G; G! ZDECREASE
+ ~" F9 a+ a) h U4 c2 B0 ]
% B" Q: T0 S5 S; Q/ |; K2 j$ |3 m2
0 q# S& o8 }' _* x10.000000
% o! z% x" R. _# Z6.000000
# d7 }5 E8 t6 j9 A10.000000
# o' h+ d" a* ^9 ]& a7 t9 j: b3
: U6 H4 z4 h' z( [+ A! w8 o12.0000003 H6 ^5 V. d, [1 S6 |: b1 {: G5 [/ ~
INFINITY
( P. ^# N% K9 }4 E6 ~- Q9.000000
! k+ s/ I0 v7 @+ C9 [
4
3 T1 U. `! _2 R16.000000
8 C7 n$ Z2 u. R: q% p6 w18.000000. k0 Y' J* M ?9 K9 t. K y
6.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; 按运行按钮在solution5 L6 [. |1 |1 D2 |- H$ D
report 窗口得到以下结果:
/ _* w* ?2 t" }7 p, eGlobal optimal solution found at iteration:: g( b; d+ Y' U+ n1 f. T2 A3 X- h+ T
2
& n* t, k0 J: T- eObjective value:; Q7 K+ a5 b! B7 i4 F! K, |
7.750000
% I5 `, d1 Y( i- Z
Variable- Y& s+ L' S; _3 b/ ~( }9 w
Value
* \" D, g2 N8 a: U! {Reduced Cost , W# [! L& [) K; \0 F6 |
X1
& v' F/ c2 m. p! Z5 T0.5000000
# t) Q3 _( L' {- f: s) T0.000000
! }0 j" x. j* [! S& D( XX3
+ s/ o w# ]2 m8 C# n6 j6 ~0.2500000" N% K. V X$ ?& g3 J8 B
0.000000
, w# K7 K2 d3 _. E' c
* L! b( u5 ]" h1 S/ |8 bX2
$ ?7 U* Y1 S6 r9 E2 z& H- r0.0000006 C8 ~* }* E- y# a7 r, X" l
0.5000000
1 Z9 @: C9 G- o: c' s: J& GX4
, m( z8 X' q# `$ p0.000000
" r& J6 a- ~3 s3 S( W/ n2.750000
+ _ c* k O$ V% S3 j3 G
X50 p5 _7 e$ g) u3 `4 w
0.000000
7 g$ O8 c# H- j! d9 w. \2.250000
5 ?3 e/ F! @8 `3 N R' JRow0 \5 P3 p' R/ B% U: G
Slack or Surplus( F \6 ^; F2 b5 E' _& _9 F
Dual Price
% r) y# h8 m& H
12 @* F0 P- A6 Q3 R6 {" z1 ~: ?
7.7500002 U, o7 i$ H! E; o# o1 p
-1.000000
) {( x: }0 S( Q* m" r$ G2
9 c% s0 n8 f( I: Z& Z8 R0.000000. V" U/ Q* r+ k- s. {8 l: ]0 D0 G
-2.750000
" z& k5 I' T, e. J
3
/ E1 l0 h" e) y: O& h% H9 @0.000000
- `3 u3 C. `, x1 z; K& n-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;
, U9 F4 b2 v8 {3 r# ~- V Y/ B# h! this is a commnent; x<=100; y<=120; x+2*y<=160; 按运行按钮在solution report 窗口得到以下结果: Global optimal solution found at iteration:
3 p0 t! ]( M5 D& m- O5 ?2
8 n @) q+ ~ J) e. d5 k2 U6 MObjective value:
, z. R2 }( q1 O. L8 l$ D" y( f: {. {4 _& w. m9 `
14500.00
- m3 C1 C* X9 l7 h
Variable
; M0 t# x3 M! T5 R4 o4 u( ^Value% [& f8 m! n3 D8 b7 E
Reduced Cost 8 w* o. P0 U( _( M- m. B9 M
X J i2 L7 h) v
100.0000
6 @# B5 i r) |6 r* K% c! J0.000000
/ h6 m* j) _5 n( q0 ?9 W% jY
" g3 O- a" k1 R5 q5 I9 _& J ?$ D30.00000
9 I& D" E% X$ R; o0.000000
# G: m4 b% T" f, _. T& T1 D
Row
" Z1 m8 ^% z" @2 D7 LSlack or Surplus6 z; r! x+ w7 J& R& Q7 c
Dual Price 7 U# q3 F+ S8 n3 ~0 z* G) S
1( J& @8 r' Y3 W2 a' B% V. h! X
14500.005 {, Z0 m, j- n% D/ w
1.000000 , h& m" r5 q# `7 r, F' f% s
2
0 u3 J4 s$ ^7 H7 A- P0.000000! g' j) f' E& W
25.00000 4 c7 V9 D! m: c y$ `) z$ [$ g4 A
3
" i( K. d0 \( O3 i$ x S90.00000
: ?* @. X4 R$ {3 E+ Y9 b6 ?0.000000 4
4 \5 ]5 \ C# s) `0.000000
( y- p4 W, ?7 W5 P
; O' a2 u+ y% F( d& H75.00000 |