|
第二章 线性规划 本章, 我们介绍三种解决线性规划问题的软件: 第一种: 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 =
3 b8 P# l. }' S7 j$ o2 W# s-2 m: ?- w2 A* S' ?
-1 + E' i" r. s5 N" m
3 # K4 w% x/ i* l) A" S6 l7 M$ 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 =8 Y9 B$ p0 I3 E Y& g4 \& D8 y D, U
17 T+ L7 U" @. l
2
! T5 Q9 e3 c( w, M. J; r3 T0 Q4
) v! J. l8 `4 A7 h6 D. X. ^ G- u-1
( [7 G$ `3 P3 Y5 S }5 o1 |20 R' O+ a) g% _
3: U+ C( A' E; b( I
-12 A m W3 O8 m3 s4 w2 Q
1
8 |: D! j$ F9 {0 N1
& h6 y% R, O4 w' W7 y/ g$ M0* `# }. b8 G8 e9 W
1
' s7 \! p8 G7 w4 [. M9 ` D6 T1
t4 v4 ?/ B6 t+ _( v0 u4 X* @-1
) C$ _/ Z/ E3 w0
1 ~* Y9 w: _1 q# m n0
( a# Q" I1 B0 X+ v l& n0
0 E. ^1 @8 G! ]& |0 |0" f; s8 C) x9 Z* H: K4 p
-1
) x, q: y0 Z! F) E& h0
$ F% U+ Z) }% h8 _5 q6 T0
A# n1 N7 \9 M# T8 z
0
. r a' }9 @- o- L0: D, c% a+ z* h" {
-1, \: C. E4 U8 G8 @
0 - g$ Z. Y* d; k1 O" l) Q4 i) r8 q
0
6 l6 |( a0 f7 U, ]5 P) i& n( t" H0
+ D5 E; k8 D+ Z2 V V0 M0
4 c! i& y. t5 z) t-1 Please input the resource array of the program b(m)_T=[6,12,4,0,0,0,0]' b =
, q& H) W! A8 p1 B6 ; _$ Q) e# y0 {0 j, G& k9 L
12
( |9 u3 E$ z4 U9 X4
) r2 k& z% e% I9 z2 f2 W# ]! _0
$ a6 A+ f4 q6 |. m0
8 R! p. s4 K4 o; n4 d
0
3 a+ Y a& o2 K# e- }6 K0
Optimization terminated successfully. The optimization solution of the programming is: x =
8 C6 N* C d1 a4 `" K6 B& D0.0000 3 s. F4 |- A) M( i+ E3 A+ n
2.6667 / {& a$ G" F! U& u8 `) X
-0.0000
4 v0 W+ ^1 N( G) _! F- T4 O8 a& a4.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
" B) S5 I3 I2 W, Z5 W5 c S!注释符号; 系统默认为自变量>0, 若不要求用free命令.
0 A, C3 }- b9 e( Y+ L$ I" u; `!在出来report windows之前可选择显示对此规划进行灵敏度分析等
按solve键, 在reports window中出现以下内容:LP OPTIMUM FOUND AT STEP$ F0 `6 g& D5 g, e* i6 Q8 l
2 $ _: |( O6 Y# L3 B7 `
OBJECTIVE FUNCTION VALUE / [- u. n6 y9 M
1)6 [% E# W w$ b$ S( N p) T% p
145.0000 0 u! {8 ]. l: m; y; m; X7 `
VARIABLE8 O* W, A5 Q5 W' C9 K
VALUE
\: }) T& z6 B% tREDUCED COST " D/ b1 m' \5 X0 \0 S0 T; @' L' F
X
: V h8 ~7 I/ m9 V( |: @) S10.000000
\0 @3 D" {! g; K0.000000
3 N# B& M" ^9 NY5 E* C5 ^4 Z: z; x H
3.0000002 I8 d. H/ o, i/ ?; V
0.000000
- s' K. a2 |3 o
ROW
7 ~/ Q( F; ` z% B2 `2 X1 v9 XSLACK OR SURPLUS
7 r( B% O+ O3 |DUAL PRICES 2 S# g0 L* q/ y5 t. Y9 d
2)
5 g+ p$ V9 A# \6 i9 K/ }7 f0.000000/ d' o5 Z) T" w% m% B& K
2.500000 - R0 p. {9 @$ \; Y
3)
' n+ R" G! ?( E+ m' j9.000000
, ?1 _7 @ _! z: T6 a0.000000 8 \1 u* _4 j1 P
4)
( }& p3 d" |$ c% p, R4 J0.000000
! K- j( I+ g# B2 M( {, s& Z6 O$ ]5 v& o7.500000 i* C) E \) C# Q
NO. ITERATIONS=/ W( Q. w3 ?6 ? Q: o
2
. o6 Z# q7 H$ a3 g! e qRANGES IN WHICH THE BASIS IS UNCHANGED:
3 V j3 E3 _% LOBJ COEFFICIENT RANGES
* j/ g! h5 {* H T3 k2 a% ^$ eVARIABLE
6 u8 O; I& V1 b! x _ RCURRENT
! e0 q) M/ {: x1 {ALLOWABLE
; ] i7 ?* R! W+ N3 _ALLOWABLE
8 q; f9 x6 t S8 Y% P; n
COEF+ ^# ]0 u6 l0 b8 |( Q. m& @# P
INCREASE
- {, c5 ]' `, [$ H, F C5 CDECREASE 5 r Q s( ~5 W+ ?1 \' @
X
' N/ B8 |1 C. b5 |10.000000/ f2 n( ~( S6 y& U" @
INFINITY1 u$ k/ W X3 P2 Z$ v% n- v4 [: R5 [
2.500000
$ h Q8 e, C/ H' L/ ZY
" l1 I! C; {" Z' _15.000000/ E& A- R3 K" {, z6 T0 b: \
5.000000
* p+ U. _$ s$ o. g7 V6 O/ ]15.000000
' A& k$ Q+ W. n2 r/ ZRIGHTHAND SIDE RANGES
: @$ S# ^$ R' Y" ~4 ^7 e, ?& iROW
! k$ ~1 x4 [, R# `/ gCURRENT# q+ |% m+ X, w% ]2 D
ALLOWABLE6 h Y) U# m3 z0 o8 n* x7 i# P
ALLOWABLE
$ l* d u2 T# K3 mRHS
* S6 ?1 M$ a! ^INCREASE
+ q1 E Y( k. R$ x$ Z, bDECREASE
8 s! M) L; Q% s; G
; w+ S. I, P- I% q, x% f2
: c: I2 B6 ^, }' F- i, e6 Z) Q( _10.000000+ O$ O2 p# |+ }: u0 v
6.000000
& A. |& I0 P U! w1 y& X# c: W( r10.000000
+ p' o3 P; r1 \8 j3
4 e: o% Q% h Q( t' U o: v: P12.000000/ \5 N; p% D! Y* w7 {! x a# F
INFINITY
5 {; Y3 s5 U+ R( B& [9.000000
& P% F, o2 U2 c+ t4 F
4, B- K E1 i, k7 f
16.000000% F! z! [% i8 b
18.000000, H; c1 D% i" _1 F
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; 按运行按钮在solution* m3 J( n/ G3 p) A. }* e
report 窗口得到以下结果:
& C! `3 K# j+ {, M7 BGlobal optimal solution found at iteration:
$ }/ q* a) K0 S& a9 x2
* H' ?. E% k7 y5 S$ d9 M, oObjective value:2 p% K( k6 i( k1 i/ `
7.750000
$ l* h. L8 F0 ]+ wVariable8 ?9 V7 O# c8 M' K$ a
Value
/ c. Y6 K {! ~8 aReduced Cost
, ], z& ?6 n- ?# g/ ?
X1 W6 @) ?$ u+ t- R8 i o7 |
0.50000002 i% c/ {. Y+ P: k) l/ Z: k
0.000000 ! M: o8 t) U) w0 t
X3
. a; F4 ~" {. U9 F# f0.25000006 P; l! F# v/ |- a
0.000000
/ _( D0 \5 I; l. i8 |- `5 h5 Q, A
* X, ]7 v6 d9 O* V# a) T9 y' qX2, K I# m( h6 ~( _$ t3 a7 j% i
0.000000
* x* ~) q. i0 B3 k* R0.5000000
6 T8 T! P) g$ |" t& q' x; ~2 J- S$ ?X44 ?+ H8 Q4 g* ]7 U
0.000000
) m S' }. D+ @* ^( l& p9 L2.750000
9 ~( j! E- X5 @$ S! q
X5
" ]6 m$ |- v+ e' P0.000000
! ^9 J O# ~) U/ G" M2.250000 ; \- u* w/ c# D
Row
8 @$ @4 i* e3 A/ q$ QSlack or Surplus
+ t* d. G0 S) d8 VDual Price
. _5 `: I3 s, B# t t1- n2 p& ]2 B5 J" m& N6 l
7.750000/ r3 u6 q" Q5 R3 S
-1.000000
6 ]: A6 k' f6 g0 W9 ^2 G) m
25 Z8 X5 f% B" S5 s
0.000000
. Y4 u$ f F# S5 i-2.750000
. \( O+ d) N5 _6 }" H4 }9 m3
X: d3 j' C7 j t$ ^+ r* E n. U0.000000) V) O3 s& w1 ]& U/ B
-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;6 {3 H! h0 o* Y
! this is a commnent; x<=100; y<=120; x+2*y<=160; 按运行按钮在solution report 窗口得到以下结果: Global optimal solution found at iteration:# U* j1 r; B6 \( P/ Y1 B/ i
2
5 b, d/ k0 |# b; ZObjective value:
$ {: ]% ^+ o; n: Q# G0 W$ l9 ^0 R
14500.00
* `2 }3 [* t" ~; E. a: oVariable% d5 Q% P2 J+ J: Q: U9 ^
Value3 q3 |+ Q* A0 K4 c' |3 a
Reduced Cost
" K: H/ b4 Q4 r6 y5 i" c K6 q
X
7 V5 i" W& X- _+ J4 M0 M100.0000$ s& c6 Q3 Q+ h8 |! }
0.000000
; `* H6 V2 i3 j+ `1 R( `Y% g5 M, [) P# x& G* z( j4 \
30.00000( u- R0 D2 N9 _
0.000000
, U3 O8 n% H' a) I& [Row- v* g7 R9 A8 R) c' J2 L
Slack or Surplus# H' u3 h6 j5 x' f9 V, G2 e
Dual Price
5 e! t: b: q( M/ k2 |0 e7 q! v1
8 J; k- i& L% v; s( t# P9 }14500.00
0 t1 _4 D, |. l4 t1.000000
4 T. W |4 j v1 S1 I. x% \
2
# k4 T1 s& T7 L- b, K) o2 l0.000000( g$ N$ Q$ B0 b& I3 x
25.00000
& \! Y$ b$ D$ m, X9 n1 F- Y36 L" H" S- e3 R. h/ |* O) H. M; Y
90.00000
$ n4 J! y3 p+ k9 c0.000000
4
8 V- C4 J: ] x X0.0000005 q( q* I6 ? s: p0 N
+ M/ E( d, m! m4 R6 B* m
75.00000 |