|
第二章 线性规划 本章, 我们介绍三种解决线性规划问题的软件: 第一种: 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 Z6 L( l; k2 Z S- ?9 E
-2
4 c. ^' y+ L: M. i-1
) g+ [: v6 n n3
! _$ A9 r: A" @5 }3 G-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 =
1 ~0 f7 q# l D k/ p5 u' C4 O( S1. @. l: W& b0 `6 |. y7 o3 Y
2' a- x5 _3 U3 S/ Q+ i4 v+ ]
4; i& J0 k7 R# z0 x* j! ]! f1 N/ A
-1
( V- x v8 m7 V- @: W, Y25 d$ [- b0 A' y$ {7 a; S
3
5 v! J' k4 l9 S y b) ?-1
) N- D. S6 w6 `8 S$ `1
, p2 S1 R9 h6 `; N4 O
1
- |0 {$ J# c' A- s$ a" I/ u0" t; c+ J2 D I# p
1
" U5 w, ]7 r, M/ [1 # A' B& b" @* m) z$ {, L
-1
' j3 b6 u" z( r% |0# [6 E6 {8 D/ |& Q
0* `& A; t7 B6 D
0
; Y% F; t7 m9 D3 _* i8 m, I) _& E06 ]8 O" Y7 [( a; J
-13 d! B2 o7 ^" R
0 r+ i! o; M! ?* W( s8 A
0
- R! P. {6 h" u4 u( ]
0
. k" m3 A* G7 P% s+ {; b07 s" o B7 d- o' X: v
-1
6 h% r0 r% T6 z8 b$ A0
+ S3 o [( T- n, k2 [4 C0
: R" r4 Y4 H5 l9 z3 r4 n( i02 X1 z- }2 c( d- {( b. l. H
09 U7 q5 a4 W; a. N R- c/ Z% H
-1
Please input the resource array of the program b(m)_T=[6,12,4,0,0,0,0]' b =
C+ D' Q5 @; ~1 d! K6 g6
5 D1 y( G3 _, Q3 h12
- d, X+ Z8 p) J) H2 r4
" m* p! C* [: c* x$ _0
/ c {& Q6 Q5 f+ p- @- y
0 " b: r$ S' d6 ?: X2 x7 F; G# C
0
" D! ? T; n- o- j4 J' f6 y d7 r0
Optimization terminated successfully. The optimization solution of the programming is: x =5 p% N6 G! ^& N7 {0 }+ F
0.0000 3 Z' ^" ~- }& P6 w
2.6667 ; N8 R2 y# g1 R: N$ L
-0.0000 ( Q6 l. T0 m0 n* z: F6 l" I
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/ B6 K; {, E, k R; V
!注释符号; 系统默认为自变量>0, 若不要求用free命令. 0 f6 n9 M, J! ~
!在出来report windows之前可选择显示对此规划进行灵敏度分析等 按solve键, 在reports window中出现以下内容:LP OPTIMUM FOUND AT STEP
' h" A, {' o n/ ?+ N7 ?7 r7 {2
h- q$ n* T$ x6 k! i* d4 yOBJECTIVE FUNCTION VALUE
% _% i1 W& }# T* t$ K1 D4 m- }! Q1 x
1)
7 I* z6 \3 i3 ^% X" W145.0000 $ X( g. Y6 S; @+ W5 ?) U, B9 ~) V
VARIABLE- Y; [1 @1 H3 Z# G- Y2 J/ Y% d
VALUE
# m; e0 T6 q0 `! |5 @. LREDUCED COST ( X# q; D- H9 ]7 i# S; e8 p
X- S. g" Z; [/ I: G& \- l" i
10.000000
6 [* K% K( @5 s l0.000000
7 N. l9 S% b1 kY
8 G4 l, k6 N1 B. n3.000000
9 b5 o& w/ m7 |- l0.000000
/ K2 d( R! y* WROW
% D5 \- G( @+ ]SLACK OR SURPLUS
2 Q% n& [. ^% L+ u8 e6 PDUAL PRICES
1 d& a% n+ l- j6 a+ ?$ [2)
& t# C1 t0 F, j( b% ?! O0.000000
) S5 A* I/ |* T0 L0 ^3 V6 N; T2.500000
& p' \' E5 J' `" `" C0 K( P/ i
3)
4 I: _# |& b, y7 c/ |+ e+ [" n9.000000) V" x3 _) t$ `$ b5 n7 M- X
0.000000
, `! E3 k2 g& O4 @- X: d. B" d4)/ z; p. O. k1 w$ T" [! U( `
0.0000009 ^! {' ]2 l5 t5 O; t
7.500000
1 v( Y6 {/ s" M1 @) i: l
NO. ITERATIONS=
+ o$ {* t, M+ `2 6 V7 k4 d: b, B0 @" Q! d* v2 Z; _
RANGES IN WHICH THE BASIS IS UNCHANGED: i0 E' }1 F0 r: b+ G8 f
OBJ COEFFICIENT RANGES
: e+ a% i- P, ]- dVARIABLE
" L r- ]8 x! m6 a* d- I d6 S3 k! VCURRENT; j) B% @" D9 H* M5 D; H0 m
ALLOWABLE
2 E3 Z0 ]- c$ g2 t6 ?ALLOWABLE
9 e F' u; e; X
COEF
) M3 ]( s4 Q6 m/ Z; R4 }INCREASE
. ]. C" q3 }6 TDECREASE
& r, }" y: b' Q# {0 xX4 s$ U+ r. ?7 g( t! w/ L
10.000000- I" @5 g( M* D$ a; u& _* A: ~
INFINITY
& F2 M$ B; m+ |) W! U- X2.500000
* \- q) A' h5 N/ w; H
Y; j9 a, z/ P5 l# K
15.000000* w$ G' ]+ @$ A# t% [
5.000000
$ P4 C" H* B% @/ m _* i' H15.000000 & l; v' |8 L9 D$ q
RIGHTHAND SIDE RANGES
7 l1 C5 k o% {% C) o' [ Q. T9 i+ g& RROW
% F/ `5 M; w% d# Y% ^CURRENT
- y) A s1 D) B8 A8 a* QALLOWABLE
9 A6 `, a' }4 lALLOWABLE
% ] c* Z& N8 F( q; j0 ]RHS
& v7 w; Y: }8 H* X1 l# J0 j7 l3 HINCREASE
! d( {5 G6 t5 o6 wDECREASE
8 F o# V3 f! O3 P s# x$ Y( }
5 Y6 U' H# w( b1 ^3 E- c
2
" b- F3 v1 B, _, @10.000000
) e8 c9 ]' n) P/ x4 w6.000000
3 C+ M2 s$ j. n" C4 I3 E3 W5 l5 \+ K) H10.000000 - i! G; Z4 @5 n3 D7 Y
3
% v8 V* x0 W4 h- M+ E9 H12.000000
$ e4 I0 {6 F/ y! Z# n6 N1 z3 BINFINITY
0 n5 I& P3 I. r" p6 v3 Q% {9.000000 9 l/ G0 [( s k
4* g7 Y) r0 A8 L9 @; O2 _" E# T; q
16.000000" I( h, ]* j5 i1 g( x5 ?
18.000000. g) D/ E3 A$ P) s) ?5 Z
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; ^) F# N3 F3 W$ K
report 窗口得到以下结果:
; h9 C& i4 C$ v- M' B6 R- O8 `* hGlobal optimal solution found at iteration:1 `! K0 M5 G. k+ k- w! x
2
; I* A7 P: w3 v- P8 D1 x- LObjective value:6 d* a9 `/ N, |" T& m8 v
7.750000
# R p( O) r/ o( H4 l
Variable
Z1 o7 u4 f6 U0 }/ r/ m6 RValue Q U/ k6 y1 D
Reduced Cost
) j4 m4 L6 T1 EX1! W3 B+ k- l1 ?1 ~2 {
0.5000000- Z+ _0 E: Y4 p# e
0.000000
* r* V9 t9 a, e$ s
X3
% @0 y, I* O: @$ z1 w0.2500000
9 h* n8 Z y( m% [0.000000
; d5 f9 n- X1 X0 C
& u! e% n. e. n7 p6 p$ Y/ Z5 CX2
) g0 m+ v! I- {! z! ?- t4 P0.000000
) ~2 c# t/ T% q7 h% |+ y0.5000000
, [+ C/ R- E1 e/ z: xX47 A% \$ k& w: k0 q( b1 G
0.000000& x& o- K9 V! d& M8 Q' H9 L& {
2.750000
6 S3 Z9 `* m, p% n8 \: ~X5; \ b) S! Y+ z
0.000000
! b& X. Q9 v2 X2.250000
' e, R, Z. ^( K# ^3 z. r
Row
9 r: F" p6 H# DSlack or Surplus8 [8 N- y6 v U, `' `
Dual Price
1 j8 u, u: k6 O! _1
6 `0 N+ x' f9 J8 o7.750000
, z: ]& C* w" T' C/ G* ?-1.000000
) P( e7 C6 S9 _. v( Z6 m0 {& O
2
3 m- i0 C4 f2 |1 a2 `; O0.000000
* P% B% X! O7 X# D* v% ?; y- _-2.750000
( F3 Y, y8 K5 ]; f6 I# ~37 s- G+ W! H% v7 O+ b6 j }3 y
0.000000
, b8 O5 P2 w! t% U- |-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;
X' J9 L3 E$ e! |% ^! this is a commnent; x<=100; y<=120; x+2*y<=160; 按运行按钮在solution report 窗口得到以下结果: Global optimal solution found at iteration:) o+ V6 Y( Z' c8 K" E( G- N
2
8 G4 m, H! e- h; D+ }; TObjective value:) O5 _) [, R. ^$ k
# W2 h" o7 O2 L, L) {8 g( v14500.00
. ]' `0 M: U) ?, M4 Z6 @8 B
Variable6 d+ E- B! }9 |# c
Value
+ m* {" }, Y4 k- |3 {Reduced Cost
1 F; y+ P0 n, D; g: \X
* W% h6 f, Z5 d100.0000
* ^ L% ?3 f) x( _6 g) W% t0.000000
- {0 R4 e3 }2 j+ y. RY: f6 g* C- |, R0 D' R
30.00000
" x3 G1 P, B8 e Y/ E: t/ J# J0.000000
# i# Y" ?1 J- B( Z- h0 d
Row+ x8 g0 m0 |. x3 G3 H( P# \ S
Slack or Surplus
$ \) Y9 V5 }, P$ MDual Price , C& z' ?# u. S# m, W4 w) ?
1/ c6 d V) P1 p+ ^
14500.006 R a7 w/ P- k8 l9 M ]' { G
1.000000
5 r, N. W, Z8 v: z27 @: n1 a5 H8 {5 @8 Z" }: ?: l' ^
0.000000! F3 U* k3 X9 { O: j
25.00000
. @- Z7 ~- O! ]+ `( Z4 O/ I$ r( f, B3
8 \9 F& {: B3 Z4 A/ f- w' Z5 z# b/ K90.00000" ^, @' C6 i. ^8 q; [# C
0.000000
4
) j# x) y$ q+ L- R- i7 a& U0.000000& U; ?* v8 q% b5 i$ M
: J4 {* h0 R2 ?+ m75.00000 |