|
第二章 线性规划 本章, 我们介绍三种解决线性规划问题的软件: 第一种: 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 =7 V% x( x0 J6 E' l2 Q
-2
8 L9 D9 B; f5 W! `-1
1 Q& L9 E# o7 O; d4 R% p; Y
3
3 B5 O* `/ u7 y# f6 x-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 =
c' g3 X$ _) K7 x f* [12 j: v/ m! k2 ` X$ }: f- n) k
27 w, j. |$ i! z; M
48 d/ a5 V$ i( x4 U
-1
" \( [: |# O! h0 j1 n2
9 S0 A& |5 }. s3. ~ A9 j7 V% D3 J
-1) V; r4 u+ `3 l4 S) @* H3 i
1
2 l, @- `9 K; K" h/ Y! Y' a# [" O1# t/ H( C* k/ x# h& U/ b
0$ @. w2 Z4 P& m7 S
10 w' a1 y. d( o; _
1
9 z C) l: R Z/ K% A( |-1
; A% {3 m4 _% L# t08 G: n7 ~. @ }! W/ [3 D( }
09 W% e( H2 J0 M$ G
0
6 v% [1 j0 I) n `7 O* Q06 c8 B [7 Q3 j2 O' d3 }
-1
/ q3 t6 K3 c0 a* R! ]0
3 R* l( I6 ]7 x$ N9 j! C0
2 ?4 }1 `6 U ~1 I9 M; p' s5 F! S; P
0
! t% [! I! s9 B0
2 I: v* m0 i8 X; \* l! S-1% e& z0 S* C/ {4 F5 Q% H6 o
0 $ y8 J8 ~4 z1 B. F
0
3 @! p& W( U7 w# g! D1 t' @9 t0
, t& u- ]* I0 G0
6 [6 r( ^6 S9 O$ r8 q" d-1 Please input the resource array of the program b(m)_T=[6,12,4,0,0,0,0]' b =
5 L, G; P) o% X' A2 u0 `0 R6
; o# A% N K6 ]& f12
/ L) v. }" `& m/ ]" Y4
1 H. c8 T2 `+ ]0
' H! N# e+ w! Z
0
B0 R @# e# c, L l0
7 R: f) }$ c, L3 Q& F0
Optimization terminated successfully. The optimization solution of the programming is: x =1 ]* f! i }+ c( Z
0.0000
7 n; R ?# b! f) Y2.6667
2 \3 ^9 Q6 Q& X5 ^/ b7 z m4 H1 Z-0.0000
" R* D8 n) Y! B) 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
* s: o1 ^" w0 J% a, |2 y) W+ F!注释符号; 系统默认为自变量>0, 若不要求用free命令.
$ ~* s D$ K. q/ I) Z$ W2 `!在出来report windows之前可选择显示对此规划进行灵敏度分析等
按solve键, 在reports window中出现以下内容:LP OPTIMUM FOUND AT STEP3 M) m$ k# A2 v# }2 h' }9 g8 ]6 Q: }
2
8 i5 L' J# M2 d/ Z4 r# R4 |+ u. SOBJECTIVE FUNCTION VALUE
4 s: L7 T1 o9 Q) V1)( {/ k; Z3 Q& t( \
145.0000
9 U+ z# G% k# n! m! gVARIABLE
7 y5 f0 X# k2 @3 h- s; V2 h7 fVALUE, S: [( K; ^' E& T+ c
REDUCED COST
# g' {1 K; G& J, d, _0 |5 yX
* S4 a! ^" r" J! s10.000000
1 b5 ]4 T% ~3 e6 D# Y$ X0.000000
$ k: X9 Y8 `4 W% h0 `
Y9 K3 T1 |1 c5 ]6 ^( Z
3.000000
* c6 a# i3 H2 c* k0.000000
+ |% c% f$ d+ s; I. r1 A# gROW
2 j8 m: b5 t, nSLACK OR SURPLUS7 R; _5 x$ [ Y; q$ |
DUAL PRICES
2 f0 w* l6 p6 b2)
7 `1 r3 n- F4 S3 `* f3 g- u0.000000
" C# w: Z* [7 E- r1 v2.500000
8 X# o# v5 a: K* K* ?+ @- J& F3)
* }; K# Q# D3 W& A2 p( X3 {9 ^2 Z9.000000
+ y- Q! C+ X( {/ c1 v- {% g0.000000
( T; q X% @1 g7 T9 R1 `: r, Q4)
( v5 B5 Y9 e" w" X0 A _0.000000" b; V; w a( ?/ w
7.500000
, U1 X2 c, W6 T: @) V& |NO. ITERATIONS=
; ~- v S% s2 w$ ~2
+ F2 c, G3 f" u' G+ z- i" ]. h4 PRANGES IN WHICH THE BASIS IS UNCHANGED:
* o; ]0 z6 T! Y$ u8 ?
OBJ COEFFICIENT RANGES ( _6 P9 r9 Z, I# Z: a
VARIABLE8 z* `- ?4 E9 Q
CURRENT, y& T* W3 \; i. ]3 [( p/ t7 ?9 m
ALLOWABLE6 v% N: z; I% ]+ T0 d% R
ALLOWABLE
+ b7 j6 x6 A3 g5 k. n* rCOEF! V- h9 i3 s6 p7 y
INCREASE
! P: m$ u3 E9 Z7 MDECREASE
" R& c9 U/ m; M# P' ^" I ?( X9 bX
9 U, O2 x5 ~; X10.000000
3 b z/ B( y/ qINFINITY) b0 k% i. y# Z- U: \, V* D& V
2.500000
" m$ L' T4 a$ S9 [2 u# U. k9 KY
! M. N( X7 L7 \6 c6 n$ D15.000000
4 H0 j: u0 A0 d3 V S5.000000' G) E% u: {6 {8 [
15.000000
0 e0 x, S2 L( E3 j
RIGHTHAND SIDE RANGES
% |% c1 {# w7 jROW3 g2 S* i% W& l4 k, ~
CURRENT
% j+ W" |5 `: n5 LALLOWABLE+ }0 v! J5 |( m- [4 a& _
ALLOWABLE
0 q9 s. m2 A3 T4 O* H" z" S( ?$ i/ HRHS
+ T2 h: r) x8 T2 t+ GINCREASE) E! l* w( G# r4 G( f4 g
DECREASE
) O5 S+ p- B- T
9 K, l4 ?6 \7 M1 u" T: [" \23 i; D. p% m) q: r( ?
10.000000
6 B2 ~& P( n) u6.000000
* M3 i& @' ]+ j) X. _10.000000
/ o* N. i3 Z% K0 S- @" B38 M V: k3 j: r9 J, ]( t% B( A( s
12.000000& [% a% ~+ s+ W3 L5 ~
INFINITY
2 {5 W; G8 E5 x8 N9.000000
4 r1 K$ i: m! R+ m% j. l4
' z9 w/ g% P6 V1 R16.000000
' l" ]" k, {$ P8 n: _18.000000
) K' Y5 Q+ \- N5 J$ l- s6.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/ K) z: F" K+ F4 v
report 窗口得到以下结果: ! z0 f6 m$ n2 Z1 w B
Global optimal solution found at iteration:
# i9 k( B% Q, H2 M2
3 c3 M/ l3 _# h( T/ s8 G7 Y0 xObjective value:- O [& C$ W) a
7.750000
2 s3 I" D; w8 n5 \+ c! y3 Q& r4 }4 p3 LVariable; Q4 j$ P: n3 K2 _0 D& a% e
Value
% b# ]$ v" f7 \+ r* SReduced Cost
& ]$ B+ s' H; v& ?0 _1 c8 v
X1
" s" d7 p' f z" g# P9 J0.5000000 }) M" ?5 [" z6 [2 ?- n0 U
0.000000 ( n d1 ?0 M1 o$ B
X3. Q$ A8 A0 Q- n& ~
0.25000006 u# O' P! _( @( G( ^
0.000000
. M \; T' s- D4 _
- N( ]( B: {% x2 j' mX27 u E9 k7 E* B
0.000000
' A8 o$ u0 Q. Q9 A) N& s0.5000000
/ d \- @9 Y3 b" ~2 xX4& a' c: t5 S9 {( T& T
0.000000
7 o" O! E7 S) R4 U* }: y2.750000
7 H9 V7 f2 R! D$ T0 zX5
/ @: f7 F$ H8 a6 X0.000000
! z8 {2 `; u/ I2.250000
# I2 ~9 I0 L8 J# Q0 URow8 T3 Y8 ]4 ]% _- R( a+ j
Slack or Surplus
/ U" G3 j" }- S1 R( x$ [1 Z. w5 |8 pDual Price
8 B' O3 @, W2 |9 Y14 o @+ a/ F) E' c2 b) F+ ` {* l1 h
7.750000$ ^) ?- a" J1 s# d
-1.000000
0 g# \, Q# r- s
2' G. h2 F! g# Y$ o
0.000000
, ^2 T, b. Z4 H& Q. K-2.750000
0 L- D! K! r- u' l' G5 S3
! M- b* P9 f# f0.000000
; C. G# S8 T" y# o$ P, m& c) v-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;, [# a# h" L' @8 |" k, L3 O: M% n( S
! this is a commnent; x<=100; y<=120; x+2*y<=160; 按运行按钮在solution report 窗口得到以下结果: Global optimal solution found at iteration:$ b1 I5 y2 i. ]) K: V
2 8 ^7 E$ B2 Y( O; @
Objective value:5 ?; u9 {% p( l$ p2 _9 S
, }; y, h- R7 G' N" n7 E e
14500.00 6 S, z. e7 ]7 V1 {# O# `* u
Variable
9 T( x/ n) o2 l$ h- e0 WValue
% {/ Y( Y7 K, m4 PReduced Cost
- w+ m) \$ D8 |/ u& k; IX
7 ]* T" v3 Y3 G" _100.0000( s$ l+ e4 O5 S% L3 \; E9 S0 _ \2 @
0.000000
4 z' Z# b }" j/ t+ R) i' SY
0 N0 @: N4 g" o' {) o30.00000
3 H, F- T2 `3 O4 I$ Y4 c* q' J8 b9 ]0.000000
: W" E7 G$ p( k8 k! a$ i
Row7 {9 U$ o' s# R4 Y2 g
Slack or Surplus
; _$ c9 n) S0 ]2 R1 hDual Price 2 M' B( k {0 C
15 t4 w; r$ k: V |4 }+ V' ]* ]
14500.00
! s+ B* R% F) m3 P' C- d1 d/ E1.000000
7 l+ F- T' b1 {$ O" a R2* \& t' g- s" d0 [6 c
0.000000
! y7 M: I. d6 J5 A25.00000
7 @0 a/ Y7 j: r1 I' [9 \- i
3
) O0 @0 @ ]" d/ Z/ Z3 @: `1 t" s90.00000
& o' o$ S. s1 x; P. j* O; L$ e: m0.000000 48 R/ k$ o$ O+ Q* f# H- u5 ~9 [
0.000000
( X M! r) Y' T9 Z$ ]
9 p+ c U5 `7 [' O75.00000 |