|
第二章 线性规划 本章, 我们介绍三种解决线性规划问题的软件: 第一种: 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 =. R- u) X* X/ ~4 I( t* V9 j
-2 % y, Z+ c r* C$ C, [* D
-1
8 b# a1 m1 N9 g$ F! S' [2 ~3
" v B, ?+ s6 c! F+ [, o% i" A" t-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 ~( @7 O5 B5 F7 ^% `* K
1
; S6 |7 D- m- v2 _* s5 H& O) e2
. y' h# j; r& w" n1 g4 P% g47 r& e5 [7 y. {! b7 ]
-1
; Z' g1 D; w2 z5 R: k" ~: P3 g21 \8 M* x2 N% L
3& B/ a! u( y4 M: o' p- R8 N6 Y
-1/ \1 X, Q/ \; G" b0 l, k
1
5 v2 d8 Q- K, ?, H, F. I
1
% k( r' _0 z( J0% L0 @& b' T9 T2 Y( p1 W
11 [; v- l, ]; a9 X3 F5 _+ n& {
1 , M+ ?5 O3 j% G6 u
-1
) U8 e( ^) h$ X' e0
2 Q- g8 L+ l3 h/ r! f( ^0/ [$ W' ]8 m, R; C1 u# v& v
0 4 o. o; E7 O- B" {# u m
05 A8 ~- b& s9 x$ m2 a& X2 N
-10 K: J7 s8 K& S5 g
0! `' [ N' ], R; Q* P% g; m$ f2 @
0 6 X/ s% c' \6 R5 C# I& d
0
/ K0 L; w6 w4 l) Z3 N1 P& R0
* _" ~6 b- d! z4 J( x! G i-1
- q$ C h0 W0 _3 D4 J0 " W* J9 t% Z3 ~* p( V8 W! R
0" c2 T; q/ O2 C$ {* v
0
0 Z; P+ ~5 x. N; a7 S/ L1 ?0
* N7 s1 f( @2 U5 w; T. E0 P0 p-1 Please input the resource array of the program b(m)_T=[6,12,4,0,0,0,0]' b =6 u [- r! M# b
6 - f. Y% L1 P, s* c! \5 y3 w
12 : W) j i3 k5 e7 i4 p8 q
4
0 F/ j( O! M! X. ^1 E8 ?0
6 _# H8 I# U( P' z
0
$ R$ N: R2 T, o/ B0
7 T9 w7 w0 y6 _5 M- M- O; x
0 Optimization terminated successfully. The optimization solution of the programming is: x =" m# T* E' Y0 d6 P
0.0000 5 y6 e3 u. x- T2 }5 @ G; W: E
2.6667 / y. D. k; r7 i5 b- G) _. q
-0.0000
) ]' Q; c( n9 W7 z' d6 c4.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 w0 o7 Y; k+ l! ^: ]0 Z
!注释符号; 系统默认为自变量>0, 若不要求用free命令.
% ~; c: @2 Z2 Y/ ` |) o!在出来report windows之前可选择显示对此规划进行灵敏度分析等
按solve键, 在reports window中出现以下内容:LP OPTIMUM FOUND AT STEP! {) ` P: ?. x9 t( ~0 a
2 : C! i3 |4 K2 T9 l
OBJECTIVE FUNCTION VALUE / O" m X; l* d# r( g1 o0 b
1)
7 o" H/ b. Z6 l5 U. s2 j% ]145.0000
* P4 {6 L3 w5 V- G( h/ ~VARIABLE
+ Q& g% C5 e, O: rVALUE
, f- {# f% x# W; Q' j8 AREDUCED COST
7 N. A, a& V' i4 F& b* |X3 I$ \- |0 Y* i
10.000000
; s3 }% ^% l: p% A/ c0.000000
% h; w: l1 d+ U' P( c) c* I. H" z9 a
Y, \* y/ P/ W! ^- I G
3.000000' _0 y- U* X9 ~# i6 X
0.000000
# H7 X4 N5 \" `( ]ROW
9 G! u* T5 p* F% p5 t. a; |SLACK OR SURPLUS
# ?8 l, ]: H8 g) m, h KDUAL PRICES
1 c9 @* q" K" {, f9 U2) n' ~$ E7 h! x$ A) K
0.000000$ Z- @8 g- Y r2 y: @* s
2.500000
( v: |3 E \) W3)
7 b/ D6 B3 A. r7 `# p R; {9.000000
. f8 y% u8 a X0.000000
* K9 q8 S6 \/ u: J3 {6 O m
4)* {* z! j7 V3 |1 I) O* d* Y
0.000000 l2 y2 q* ?. {6 m. P. f& O* D' _
7.500000 ) A1 v, B0 q4 g9 R, n3 F
NO. ITERATIONS=$ E4 d5 K- m# a' N, U
2 I. R O4 Q$ x$ i& D) C, N! {
RANGES IN WHICH THE BASIS IS UNCHANGED: ! S8 E' D. a8 ^' h y
OBJ COEFFICIENT RANGES
& L# V/ M9 }+ c, aVARIABLE" ^" o8 ]; l6 t/ |4 |
CURRENT: b" i& z) M( I1 Y. {0 d$ e
ALLOWABLE6 X7 N7 @2 Y6 Q) n1 [4 t
ALLOWABLE
# g ]" K- W/ D6 DCOEF
+ }( B; m9 a( D9 xINCREASE
4 V/ X& F9 v7 A. D5 D5 vDECREASE
: O+ ]& Y N x2 w& r. Q
X8 e7 f0 ~. i5 J7 b+ j5 `
10.000000: b* d/ H v6 l, N8 `
INFINITY
) U' f' F: O4 S* i" v& U4 U2.500000 * V5 k6 J0 o" _% P' O5 }
Y
9 f' [9 i0 A7 h; B" ~! G% ^15.000000
6 p. a! A8 O( e2 o* F" q$ t5.000000
9 a) F; W- L+ A* {" a15.000000
l0 ~: W% Z9 pRIGHTHAND SIDE RANGES
9 n. ~+ H' s3 V! x- `+ a* y4 z
ROW4 c8 i3 _/ S+ \" C/ ]+ g: {
CURRENT
+ @" K4 @# T% T; k; Y! XALLOWABLE( \/ x# e% U+ }, A+ b8 ]4 j
ALLOWABLE
" {, D% t8 Z) N5 }/ h5 cRHS, N/ v# q; [5 G
INCREASE# B0 V, s5 N5 K6 R& e e% i
DECREASE
( a9 y7 Y' `: W6 ?7 c( U
5 S* |7 T% v) S f5 M' X( v& T
2
9 Y) u" S5 h5 M$ m10.000000$ m3 }% }, f5 I
6.000000
2 n1 b' v: g; q9 Q, r- a' F5 W3 R* P10.000000
4 q# t, H( N& o4 @+ R8 M3: V/ |4 a# ~) u$ |0 J& l8 s; ~) u
12.000000' w+ `- y7 r3 {; n e9 |2 @
INFINITY
6 U/ @% e+ T. `2 K B8 a+ Z9.000000
8 k) N: x. C5 T4
" l8 W) e% N4 J5 r& }7 Y16.000000* v) `% e+ e8 i1 t }* u) q0 M
18.000000# K' r9 q9 y% {. I1 R1 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
: G1 m* J* m* Z kreport 窗口得到以下结果:
8 y H! L; l% k0 z# bGlobal optimal solution found at iteration: G9 Z/ b& e; o; Z% A
2 , b: l4 Q9 {, _: C
Objective value:
7 r, F( B* S7 D4 l+ E3 E7.750000
- o4 N- Y( P. h3 I8 F. Z$ [Variable% X5 O2 r) Z9 _" R) k2 L
Value
9 O- k! H+ i8 GReduced Cost
* ]2 E% f0 e: b4 F( Y( g; ]X1
1 ?! F3 d! r; R1 x0.5000000 \) g+ U: ]% l% F" |
0.000000
; a0 z" O1 E' U1 IX3
7 n# T7 V8 X) P7 |$ u! B* G0.2500000
! }( n7 C6 }# z% P0.000000
5 B( _" i7 N9 \, i& P# O( K$ N; o, d
X2% H ]2 o% I2 i; s0 n7 O
0.0000000 G, y' {( K( J* P& K
0.5000000
s4 Y7 V9 V/ [; o% [1 h# h/ B
X4
% ~: p' m% Y5 q# ~% n4 J% Y0.000000
6 d1 ^% y+ i" `; X+ e! w; v: K+ m8 Q2.750000
( \5 K- i$ w2 f8 ]+ h2 A" v/ I RX5
! B2 R V/ G( W( n1 C8 A1 b0.000000
; ~! `) ?/ Y/ Z2.250000
2 a* q' y, M, E1 A; l/ tRow& c, G# m' _' V' h2 I
Slack or Surplus
2 j. Q7 R& {! A JDual Price
* ~ Z6 z: F2 S+ u5 j* ^5 P1 \
1
( d# x% d$ c2 y! S( D5 F" e7.750000
! t8 F, j5 Z' P- V9 k0 Z: F2 a-1.000000 8 Y; b v8 A3 n5 L
2
0 O* s6 O" ]/ j( S, @/ |0 _0.000000 F5 u3 @ ?) Q4 q; g ?+ f
-2.750000
2 J1 a8 m; ?& w9 E( l2 \8 r( v1 }32 D9 Y! L ?- a$ B0 K' Q: G; M6 r
0.000000* g. E- ]* w. G! D0 }+ d6 G
-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;+ w- W8 [% C; p4 Q
! this is a commnent; x<=100; y<=120; x+2*y<=160; 按运行按钮在solution report 窗口得到以下结果: Global optimal solution found at iteration:
+ `5 s1 j8 a9 u- Z2 ! x+ I9 l- [" x. D: C8 k- A
Objective value:) g' d; I" |/ O" a
# e# }& V `; |' X14500.00 ' u% q; U# f, A; r1 L. g
Variable
& p- g. \+ c9 _, jValue' ^3 f" E0 x* Q: O" T# F; p- b7 s
Reduced Cost
+ a0 j! s1 \7 x0 j9 {8 Y% k2 TX! E% t: J7 t; o2 X+ z8 p! F) [* m
100.0000
* O. q2 S8 l. _( F0.000000
7 W6 ?+ {4 F# H- q: i
Y
; C& U+ \7 K T! R& k+ M30.00000
H) }# Y ]+ Q' c0.000000 1 d& k; A6 |5 a" p" \( R" r, j
Row% O d1 f# F9 U/ I- E N
Slack or Surplus( w3 m! O4 w0 a% v0 e4 E5 g% z( o
Dual Price
5 e- o" v1 x/ Q6 P5 e+ c1& c) q0 W. L1 k3 t$ X
14500.00. u: z* v- `3 b" C8 Z+ V4 d! n3 Q
1.000000
+ F% X" K; ~, t, Q2
6 B2 U U. V5 H+ v6 W0.000000
- [% T8 a" l/ s& _( }2 y25.00000
6 R" c( S' d: o! `
3
' i! j/ G( l C Y2 e( G+ z- b90.00000
! _% `" J" g2 {: j9 b: }; ]! q( y0.000000 49 f. V9 T2 I/ a0 K/ U" e; N! s
0.0000007 G [! s2 T9 L% R+ {
3 k5 Q J( ~% a0 \ d9 i& |
75.00000 |