|
第二章 线性规划 本章, 我们介绍三种解决线性规划问题的软件: 第一种: 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 =
0 L7 c6 d- k4 w/ _, r) ^-2 0 e+ j- T" b" n/ Y; `
-1
$ d [) }: V2 C) m; H, m3
; O' E1 @% ?& {
-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 =& N/ z& L3 Z4 ?* }; k
1
, i4 S; t" l! h8 x* j2
7 A4 r+ I( U& W# ]4- @7 F4 w8 z, _- i' c* @
-1
6 g* [+ n, ]# E9 w1 J, f7 Q7 |2
# T" i9 L f) `: W' i! R2 d39 h7 `2 x3 o6 ]
-1; D3 a& g9 e0 `# ?9 P
1
& l7 Z; w* _6 l/ ]% } _
1
9 r. i$ W& {( D; ]- k5 G% _8 T0
9 T z) [2 F0 W3 M5 x8 v1
# a, b4 r% i1 B; t1 1 Y1 J, b# z9 T4 k' C; W
-1
4 _ ~: a, |# L6 _+ t, {1 L0# U+ w: _9 P! B4 U7 R0 V# T
0% z# m: x' D; W3 ^0 l. q9 P
0
; R# {2 ^ a# g0$ h) M* d: C6 H3 j( P& u* Q
-14 F9 [* y6 V0 A; l
0
4 O9 m" d7 R( Q3 Q6 M# \0
9 [' p' d4 l% N% |0
6 h. X! [8 i8 h- Z( x6 p0
; [& e1 Y, r6 c+ y-1
/ X9 l, o. j. F0
2 w; ]6 s, Q- Z( O- p09 Q9 t; B4 _; l3 w4 L1 j9 f2 y2 L
0# Q7 [) o" G2 L$ B! {
0
% A" [5 ^$ x0 |; c-1
Please input the resource array of the program b(m)_T=[6,12,4,0,0,0,0]' b =" b. l1 v$ n _: S8 S
6
1 o( i1 o0 x d12
) }0 m, e$ C( d% O5 {- f: W4
' ^" |' k' p6 H7 I0
: E1 B. a9 Q) ?
0
$ s+ a+ b8 E) E3 k0
& Q' c, e8 E6 s% @/ @
0 Optimization terminated successfully. The optimization solution of the programming is: x =
) A5 |/ k- D: O. L: [0.0000 6 g% Z) d/ u$ F6 d9 ~
2.6667
c2 b& g, ` b% X/ j, r# ^) X# O1 P-0.0000
9 u9 l! t$ x& {4 }& W5 j' Y% l4.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" V1 h3 K1 Y- w- [; {% m
!注释符号; 系统默认为自变量>0, 若不要求用free命令. L! y' D0 l2 F- F4 s' s# r7 I
!在出来report windows之前可选择显示对此规划进行灵敏度分析等 按solve键, 在reports window中出现以下内容:LP OPTIMUM FOUND AT STEP
4 w7 ^ L" P& V) \8 {* y0 S( {2 4 U, I- o' P% n$ e) o: V
OBJECTIVE FUNCTION VALUE # Y" H% Y7 H9 ^* i9 m$ @- Y$ y8 N
1)' j$ T- x, p2 `: } E( Y5 G7 [ ^
145.0000 " k+ J5 @* d$ R( C8 t, _$ a- p
VARIABLE. W0 x; U0 q) C7 Y* G
VALUE
* j+ M( L5 w `* FREDUCED COST ) b4 C7 C. {: D) \' R$ G% k) g
X7 W. S7 j6 x2 W4 |& r5 X
10.000000% S& e5 U# Z, B2 F% V
0.000000
7 P. e) e1 M: X* o: ~" @5 e! E" BY
# d7 _5 I+ `/ F- X7 \3.0000007 w8 A. ?' v! f2 p0 M
0.000000
. K+ p* k& w* r- n0 d Z$ }ROW
) G9 J; u$ s. }SLACK OR SURPLUS# W- Z% l. G) r( E+ t, [/ Z, ?
DUAL PRICES
6 F+ K, _3 W8 L9 |6 u5 K2)6 \8 W* m/ }* Z6 u) P9 |, P- `
0.000000
3 k. T6 U( w7 J0 t; r2.500000
( M/ b2 ~% }/ L. i0 I/ {; p0 y3)" a5 C, e; W3 M0 c$ x( P+ M7 C# v
9.000000* O, i- J9 ~4 a. ^1 C' j
0.000000
6 S4 P/ y- V* Z. _. Z: O4)
" s) n: k x" r& @* U# }+ F0.000000( ]" j: f1 l0 ?
7.500000
9 S5 {' }& W/ s8 F5 N: ENO. ITERATIONS=, R1 ?+ I0 V9 _; u; n
2
, H* S% N0 u/ K7 p+ rRANGES IN WHICH THE BASIS IS UNCHANGED:
6 X& {0 S9 v' WOBJ COEFFICIENT RANGES
9 J/ X5 L5 R8 o. ~; Q7 I
VARIABLE
: A' Y+ _ Z; t' q. M$ wCURRENT! H! S R6 K$ V; f' U- X+ |1 f
ALLOWABLE/ c- k8 r2 X, L# Q+ S2 {# |
ALLOWABLE
- y6 Q- x9 n) z2 Y0 l5 E/ U6 H; q( k$ W# CCOEF
% P+ p0 @( c( M! f6 IINCREASE
9 W0 c9 ~. @% {& ]DECREASE
" J5 O" C7 `$ M4 J0 MX
% P2 @$ p1 V. o% M10.000000! c4 \, Y5 F! L7 i: |+ u
INFINITY8 ^: I: P. `7 }# M+ ~
2.500000
3 Q! s, r. J% N( w) ? k1 h" U0 ~" TY
! H4 ~+ }# V: }. k" R15.000000& g' Y3 P) i2 w H7 J# @. _
5.000000
4 {* Z3 t1 }8 y% l* _# d15.000000
_" q4 ^' ]4 N! n1 QRIGHTHAND SIDE RANGES
+ {/ Q. R, P: N: D0 O
ROW
; g9 |9 _+ q! a4 G& {5 JCURRENT
) x+ E. n1 K' V/ ]6 q7 fALLOWABLE, j' F' P6 _! i1 J0 ?+ {0 v
ALLOWABLE
2 R4 T: S; x; q" jRHS. C; l7 s) u+ `( y* m( \; l
INCREASE) S* L' V& `% }. h/ C
DECREASE
; ~8 Z" g* Y% P" h8 n7 @% Q' q: k( I* ~! r8 @2 T) `; v# u) A
2
- I- v/ j2 n- A, q% Z2 n5 f10.000000
; w$ T2 l; C8 F' _6.000000! F" R/ V0 Y& P. n6 T8 W- G
10.000000
2 Q' z, U; T4 h- o# ]# t3 ^3$ _# \4 f& G& ~& l& Z. R
12.000000' Z( `! j1 ^+ m
INFINITY
2 J6 O- I4 {- i V9 p6 {8 T9.000000
2 Q2 a+ a3 ]4 L; u7 w4 _$ }43 ~( Z* h- S5 R1 y% [5 a. q6 o
16.0000005 S2 c' Q6 ?) v
18.000000
4 Z6 Z3 y* z3 B8 S% G$ X6.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; 按运行按钮在solution1 a& a) B0 o% Y& V. x
report 窗口得到以下结果:
0 N$ R- {9 s0 g4 j( bGlobal optimal solution found at iteration:& q+ T0 f, D- c9 ?
2
5 T2 L. a6 S: }& u6 yObjective value:
* u+ U) X7 Q6 z' m/ `2 H( M7.750000
! L$ [) Q6 ?) a' EVariable3 Y$ v9 g7 P9 ~, j: r! Y/ F' P$ T
Value8 O l* ]( V6 p' I& f
Reduced Cost
' |. y: K& E7 e x% UX15 g/ F- O/ }, t" [' A
0.5000000$ X( Z; @; T' }" u
0.000000
' W0 v8 I' r3 a! uX36 p4 C* r- U7 Z. A, C
0.2500000/ y# z% J$ \" f5 I6 M
0.000000
! `% i* u- ~, u/ A" Y/ r0 f& z% m6 J+ F8 r- ]; g( A( c2 Q H- p
X2
) m+ L: V5 H8 j/ H! Z7 Q$ t0.000000
+ @2 Z/ `4 C, o. X& g0.5000000
5 b- v0 y7 g `3 w i
X4+ n; a/ U! s8 j
0.000000
6 x& m, f% M# m4 x; b7 t/ \2.750000 1 g9 Q0 l! [+ Z; W! S/ [
X5. D( |# U+ Z$ L6 ?: U4 p
0.000000
# T- W: k7 Q) S9 S: q5 o: f2.250000
2 Q- ^& u1 w& w' l% C$ NRow
9 O" a% D! P; O+ X. z" B* oSlack or Surplus
; J% o8 W+ @! QDual Price
# ^" C/ \2 C! s; E! o8 c* h4 P+ D1 s7 k/ o' X3 t7 ?2 D' n* ?
7.750000
! o0 J& ^3 l8 E-1.000000
& }' S1 }. j+ r
2& c* B& ?- ~5 {! e6 Y. K
0.000000
- ^2 c, }/ G# Y' W$ D# P8 ]-2.750000 0 M: _/ ~3 Z) k; z3 i; W- h8 y! W! T* E
3: F# q$ Q/ k6 J! `' p
0.0000002 J+ ?+ v) a' h$ ^
-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;2 h: ^ T% J7 J, v7 f
! this is a commnent; x<=100; y<=120; x+2*y<=160; 按运行按钮在solution report 窗口得到以下结果: Global optimal solution found at iteration:' `$ \4 Z" x2 i8 i7 @
2 2 P6 p: i7 c; l6 R" I4 K) C
Objective value:
7 k+ V' D7 U& y5 u% m4 ~! @4 ^& x% v
14500.00
5 K6 {. q4 d6 ~Variable
8 V& j1 u) x& Q! pValue% U1 X$ F8 W2 D* ]( q: P; P% z: ^
Reduced Cost
1 A" w @6 W; S( g* \! i
X
3 w0 I# O" P- }: E100.0000; N" c: {% |! `( Z: m
0.000000
9 p4 d6 Q B* }3 wY4 h+ I2 c0 E/ \& }1 `0 k0 ~
30.00000 ^* ?4 C* [ t( ~' h0 H, z
0.000000
6 y1 C: |, Y M8 a7 t2 [! R
Row3 N2 D6 v4 u/ Z# l3 b# m
Slack or Surplus6 r% K) k% P3 n9 t0 ?7 J& h/ I+ c
Dual Price
) D1 A- z& x. G6 @! }: }) p" ]1
- U" {; T/ j3 B) }* k5 A7 U; E14500.00, `" `/ c/ M; B+ [
1.000000
' ]3 S, L# }0 U! N- Q
2- p& ]' R5 s- D+ W
0.000000
6 i$ F6 I. z9 G& y: c25.00000
( O5 u" q" Y. g5 k2 @3
0 F" b: Q9 U& o2 N0 z9 D90.00000 r8 @( k; s0 [4 |6 }3 `
0.000000
4
( w- Y; e' y. k" s3 M; I1 _0.000000
% O* O1 r5 ~: y8 q% y* O/ \8 v" b% y1 P6 A* G7 A
75.00000 |