|
第二章 线性规划 本章, 我们介绍三种解决线性规划问题的软件: 第一种: 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 =
. t6 t5 I0 V/ a-2 5 Z0 L+ X4 T; h: z$ f& r5 K
-1
& @( w+ d0 t( w3
4 N j% Z# ^+ X' c2 e! `5 \0 p
-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 =
9 ?8 z; ^8 G' V/ ?# h. [10 g Z: E( s3 L! G) Y$ l
2# E- c1 t8 H9 c# T' J
4% R* B3 p: A6 E" R( f
-1
) ^9 S$ l9 E" U" V2# H0 T4 n& @) z- v) J( C
3
. S7 I# z( r+ F+ ~2 N5 y-1! L: d* G) m# z4 u; C
1
+ \, O7 A! F% k8 p# _) _4 J
1
, e' b0 j# p* O0 }, T0
0 \- k0 o3 t" k' m& z8 f1 e1
6 E, W$ n! E. O$ Q( C- F4 w6 I9 m1 o1 / i6 [( R) r% _( ]
-1
+ A4 P- G( E/ J( O! r0
" s n: }! i% Y* W6 O- s0
$ L; a) t3 o5 g4 F: F# m, j4 k: ~# T; N: U0 1 ^: |7 G7 } \# h) c& T
02 `( G. j0 W& u. Z- ?9 b( B
-1! q+ @3 A" A. s) u. V) [1 x5 {
0- m4 c9 L: s" Q8 E. F' y
0 6 r4 ]& L4 C% T" b1 T: ?7 I
0+ l3 L0 _! t2 m/ H
0
$ a f7 z- U* Z/ x5 R [) p$ t6 m-15 t- a# Z Y7 Y
0
+ q; E2 [) k" P/ }; C0 {0) J+ y+ \# O$ n, L
0
/ R! i( r. G# M; s. @9 D0
) w) I7 U; |/ }' O1 y& u+ _-1
Please input the resource array of the program b(m)_T=[6,12,4,0,0,0,0]' b =
# Q* g( D# S2 \2 M6 , W0 F- D: J L: V; o
12 & P# ^6 j) [6 B! s# H# r
4
% b( o+ J. K: m! g: K0
, i" M% @3 Y- v2 W. [3 p* |
0
; s( k$ T- u0 O$ ?8 w5 j0
# t0 L& B! K( t8 U3 g q
0 Optimization terminated successfully. The optimization solution of the programming is: x =
* G4 T. Z: r8 q9 u1 [0.0000
& I8 { |0 Q/ J2.6667
/ c" c5 e! k/ B8 E% ?$ F* @" W
-0.0000 - B+ b5 F6 i! X# p3 l
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+ z8 Z; c0 X( E* p7 ?! _
!注释符号; 系统默认为自变量>0, 若不要求用free命令. % X/ t5 ~. c+ S" \- E7 ~
!在出来report windows之前可选择显示对此规划进行灵敏度分析等 按solve键, 在reports window中出现以下内容:LP OPTIMUM FOUND AT STEP
, l. i9 b+ g0 b9 U E0 s2 5 ^+ l; j8 c9 C- p2 N3 Z# X# b
OBJECTIVE FUNCTION VALUE
+ H6 m0 t( X! N1)
1 {, k2 ?8 d4 X0 B: j+ x145.0000
: R+ ~- G. s9 i+ P
VARIABLE6 E! Y: Z3 R2 W
VALUE* g& T1 ` \- R$ @
REDUCED COST
- c8 E# }6 K) m2 l6 UX' N" P) D5 G) p# o
10.000000" R9 Y2 c8 u/ Z" t9 g9 b$ M
0.000000
9 c% T; {0 g6 a8 G
Y i a8 q* U2 i# _ |6 a0 x% @. ]8 W
3.000000! N5 F: D" R# I7 Z" S5 e; M
0.000000 - y2 K; [, ]( Q V1 z$ ?. U
ROW
6 x5 O& M g5 z+ e! D) N) bSLACK OR SURPLUS4 e5 l; j$ l9 P! h/ z5 A
DUAL PRICES 6 O1 ] d) V1 k6 d3 C% Q1 Q6 {8 k, ^
2)2 o- D2 Q. {9 B/ C. B7 s N! ^
0.000000
' L2 h4 p! r5 l7 T8 T2.500000 6 `7 a( ?0 B% d; y
3)/ s+ B4 k: U) N1 F
9.0000006 l8 ]) J) f9 i0 X# p3 W h/ E
0.000000 j" W. {( C" E7 L6 ^" [! {$ N( `
4)
$ H6 p9 m! ?7 g0 o6 _9 I/ d1 F( N0.000000
. ?; @* n7 }. T% |/ n! O7.500000 F1 B$ {' k# t* }
NO. ITERATIONS=
. Y$ D6 ~; j3 [, L2
8 b6 b$ j5 {4 F" ERANGES IN WHICH THE BASIS IS UNCHANGED:
5 x1 S: ~' z2 l1 c6 M- G! gOBJ COEFFICIENT RANGES
9 w+ \' }+ D9 }5 OVARIABLE
2 X. |3 |$ X$ A* n5 J9 H/ |CURRENT
; U+ O* Z ~2 p8 t) lALLOWABLE
$ a g+ N' E/ _, N1 X# W3 BALLOWABLE
# ~0 z4 _6 _( p$ G- {' |COEF# X4 |. `8 z$ T( I0 g3 c8 I
INCREASE5 o K7 J$ F @+ ?
DECREASE
- t: j$ T1 Q) m# t) f% [; ]
X& N' d& `: W- A
10.000000
, n. m$ k# L. V! l. E @; \INFINITY1 p2 T+ ^; ~+ J3 i! T% @7 `' V; b
2.500000 5 e8 f6 Z: h' i4 U% M
Y
4 `: M- B/ w r* P: i+ ~15.000000, Z6 K6 Y; u* n$ \9 K
5.000000+ R. _3 w5 [2 U1 [; B& Q+ Y
15.000000
% T$ b" G: Y7 |, X2 ~0 A* lRIGHTHAND SIDE RANGES
! ~- ~3 D( {+ k
ROW$ l D+ T# P- Z0 E6 }
CURRENT
: J: M& W0 } j9 d, v# p- CALLOWABLE
- e. W c6 b2 S- \+ r/ ?) aALLOWABLE
! |+ r1 r5 o7 K0 m4 l6 c: M3 h% KRHS
/ i! a8 @0 B* B; D4 _4 f& ^9 a- IINCREASE
1 U- A+ S9 x! @9 MDECREASE
' d+ Y4 ?! h! J( e/ e; ^& r) e. U8 h
2
- h" @' v+ ^2 h; e3 T- [10.000000% |3 m- T8 l% G' x* L
6.000000
' d% {8 `, @9 }+ x2 j* n10.000000
. z" l: l9 J3 c6 N& m5 m
3
9 c. |/ j% e* `* M$ K. a6 H12.0000007 `; c9 x: e( c0 z$ m6 K/ f
INFINITY
\% U9 g: P7 g n4 T% x2 x9.000000
" Q3 J; j6 n$ z8 E4
, m* u7 i+ {+ Q' g9 n16.000000
" E: N$ O# L k- }2 V18.000000& A6 p4 I4 Y& N
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+ M; c, v4 Z
report 窗口得到以下结果:
2 H u+ W' K. A+ ?Global optimal solution found at iteration:; N7 {6 A- z6 x: Q a+ n4 {
2 8 Q# f8 B: } ]! O- c8 J
Objective value:
! r, O3 d3 X* `1 j- L' z7.750000 5 l0 q, ^' n, H
Variable- Z0 {0 B' s) k
Value
: X5 z( Z: \4 d* f9 b4 n; c& Z' v* OReduced Cost
4 h; B' l4 i5 X- r: @0 B FX12 b6 g2 S C% s# Z# c
0.5000000
: t, @# n- O3 ?* D- Y% d0.000000
) U/ Z% [) T0 E |- L4 SX3' F# |$ y* j6 k) s C* N! p
0.2500000
& m6 E/ a3 e% D% J6 z c( J0.000000
4 h! h$ z' q6 K4 I' Z* u6 L
. p" U' `5 m; c# J( j- u
X2
/ Q4 A& Y9 x# n! s5 g( A0.0000008 M2 J. w4 o( P: f9 o6 \
0.5000000 7 c; |7 a4 p# p- i
X4
: R" I y( s* d a6 k. Y0.0000004 _5 M1 p3 o! N/ f% A+ L+ B3 j
2.750000
3 g F+ Q* K3 n+ D' O2 iX5
/ @/ D$ {5 w% K% _* j! E) E( _0.000000# _! O2 D: g8 K8 y
2.250000
9 V$ \: Y* x7 {( G! X8 M& f
Row6 O9 q7 E: ^" y1 W+ ?& x1 ^8 i
Slack or Surplus1 v6 E$ O: ]' F% z4 V$ d
Dual Price
+ v; E$ K% N2 w7 n, w+ l& ~) I$ j10 G" X5 V( l5 L7 y2 K! n1 j
7.750000
- x& i$ w; Z7 O4 P3 a' V-1.000000
/ X! A3 i& R, z" W4 O. u2
$ }7 _* Z- Z9 N0 }0.000000 X" ?! Y* Y1 M( W
-2.750000
# ]# S2 W8 p' o8 a) t! w T p3 U38 k# e, D* N' l; m0 c
0.000000
7 O7 A: M- g# M+ C+ {-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;. q) ^# T2 [* v2 m- S! q ^- r
! this is a commnent; x<=100; y<=120; x+2*y<=160; 按运行按钮在solution report 窗口得到以下结果: Global optimal solution found at iteration:
5 p' D5 p* q( ~9 R; f4 U2
$ C7 ~ r( G+ \5 Q0 w4 L5 e, _. DObjective value:
! z, X7 I* ?- Z3 U |% q! `# F+ R: ?* U& N; u9 X1 ^
14500.00
2 E7 d7 \! o: r6 o9 ?/ s! b+ fVariable6 }; L) M1 F& @9 A6 X* ?
Value' @4 P7 ]; n2 n5 _
Reduced Cost
; z# {8 ^1 ? M, f% t v! vX% l5 m2 t% k8 o% H; g0 ? V( v- d
100.0000' z0 y6 x" K8 t/ u& H$ J% V2 d
0.000000
9 b& P) l! I+ G+ n l9 s+ O7 ?4 cY: v8 h" z4 P+ V; Q
30.00000% {; |: m) E) `0 h) m
0.000000
' u8 i6 L/ f( C& Z5 k
Row
$ @, y I5 J, R2 b. S( i7 Z$ ~Slack or Surplus
" S N" v1 U: F% sDual Price
) w0 C2 e$ |. E% q. D1
* g( C% g7 M, _5 W R: m7 G, r14500.005 z, [- l. @) n, ?$ l4 W
1.000000
9 {. {# K, a9 L- J: R3 r' V8 l% z2
+ q2 |9 J: y( n8 n+ S. M8 c1 V0.0000009 p2 V) G- B% k+ {: {
25.00000
& W3 s7 O: H& h" Q0 M# }# J8 e9 I
3
; S; k, i O4 }$ f( ^90.00000% m- _7 H' `. L2 L9 F) B2 {# s
0.000000 4( O. Q+ f. _7 C7 J1 G( G% {# v
0.000000
8 J8 m) h. G) @6 F! F
/ \7 ~# d0 u9 T$ S7 F9 k( _2 q1 [75.00000 |