|
第二章 线性规划 本章, 我们介绍三种解决线性规划问题的软件: 第一种: 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 =% [( w0 s; s: W. d" W
-2
( o9 Z1 W8 W6 l/ s: p% E-1
. p/ k9 Q% b& X
3
& q, n3 Y0 N' m B0 M1 i-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 =
! C3 ?! g+ W5 g& g1
1 o- X9 g: ^! R3 q5 V2
6 h# Q1 f* X' [1 P8 R. o4
1 e6 C0 D; T/ _1 ^- X3 Z) Y) U4 w-1
j1 l) Q3 l# [0 ^! P+ C6 N2 f2
# z9 c8 n: z5 h( g3& ~/ N: `+ ?! ~ H0 G! [
-17 j8 X& s! u" U9 S* F
1
: h9 `5 t( ^/ `9 o5 l1/ \# S( V9 r( E
0+ M) |4 ]5 D* D, T9 G5 L! K$ i
1) M/ J$ Q2 |' o' y7 c I
1
% Z" ~. g) ]% m5 h! {" C+ M-1
' P6 Z1 }) p* ]* y' ]0! I, W4 C1 P8 z" @3 e1 e
0
4 ]1 D% ~. j/ c& y5 u0
0 i, k9 Z4 h$ L7 c
0
- d# k; ~/ ?7 X' x. F5 h N) e5 G. g$ x-1
g* E% _) J- t2 H- a0
) s1 C6 }* [8 K: Z+ i; ?1 W0 `0
+ ^/ \; {% P' U0% m" ~7 r; {! z4 F
0& H' Q7 p# }/ B: o4 l
-1
! Z& E: [7 a, Q6 I' |0
+ L& d* q, N8 \ l6 s+ x0
8 D4 k* v: F2 |$ L, D9 P4 b3 e4 F2 c5 W0
6 x1 k Y5 c0 U, x- w1 `0
. H9 W0 D+ Q! H! v a0 Y/ ]-1
Please input the resource array of the program b(m)_T=[6,12,4,0,0,0,0]' b =3 [# X" z, T' o- v2 j1 J; U
6 ; {3 s, g! W6 f% J0 ~$ D+ y
12 6 A) B. p% ^9 {3 A
4
% \- P9 f" H ^2 n$ ]0
! m/ e; S1 F2 k/ t
0
/ z) y! R v- F% D* C8 T0
9 B& q8 ~0 J u0
Optimization terminated successfully. The optimization solution of the programming is: x =/ V! W; g! @0 \" V8 M
0.0000 7 a& L* Y( r) y$ j! x7 F5 p; P% A
2.6667
! ^# o$ \) P4 h. M0 ?' Y% ]-0.0000
7 l0 J1 R6 A/ O) Q# h2 w
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& Q0 U: U: ?. S) B" @! J. M
!注释符号; 系统默认为自变量>0, 若不要求用free命令. 9 x) M' F. N% Q l
!在出来report windows之前可选择显示对此规划进行灵敏度分析等 按solve键, 在reports window中出现以下内容:LP OPTIMUM FOUND AT STEP' a/ `" M8 u2 ]3 [2 E. i2 j- w
2 8 T) [4 o7 J5 d @, J+ n
OBJECTIVE FUNCTION VALUE ! C* M2 ?& @# A+ _+ `% C7 t
1)( V+ } v: l R p9 j0 ]$ P! `3 f
145.0000
3 b" ?4 x" ~2 c0 S& k* FVARIABLE O+ _ ?' N4 I
VALUE
' R& j' k E: oREDUCED COST
8 G5 m+ D$ S" d/ h. k0 d+ X; a. \: XX
) e) X0 V! G0 z' X" V% J10.0000001 g0 F: o# j4 ]& |4 ]
0.000000
! y/ f. ^& I M1 R9 i) sY
8 D+ D/ K# A& }3.000000
$ o% l, ]7 ?% {0.000000
6 A& _; m+ h4 q R t) f" [8 nROW$ X0 ^( I1 i5 s
SLACK OR SURPLUS
! l+ H9 B4 Q5 H3 z8 A! w E7 v4 W3 PDUAL PRICES
8 N( H2 |( d3 W8 P* `' I1 ^0 [
2)
% j- p8 e$ f" F& a* |# x. Q$ O0.000000
% |$ n$ @! m9 D7 x% O% x" z2.500000
' z4 x1 T" L+ t% H! t0 \ i3)9 C' ~# I- F& Q2 C0 e0 I2 W
9.0000000 {# S5 L6 h; k
0.000000
- f& k" o) M, ~2 X: r \+ ^- H
4)
1 P" J2 Y2 M& v6 G0.000000
5 r) }7 u' l# f2 k7 e7.500000 , N$ s5 V0 z/ h3 Q
NO. ITERATIONS=2 K, @, Y+ p z# n, {8 G
2 8 Z4 I) u- Q4 q$ Y
RANGES IN WHICH THE BASIS IS UNCHANGED: 3 q2 N3 v! k* h2 s$ K& y F+ T
OBJ COEFFICIENT RANGES + M4 N2 T9 R6 q4 r8 D
VARIABLE
$ G- D! b, e2 m zCURRENT1 m3 L3 p2 o! E0 U
ALLOWABLE
( A6 _8 j0 v2 JALLOWABLE : p3 S0 M6 ]4 g6 D
COEF
, \$ _& [* F+ k" Q; k4 V/ GINCREASE
$ R! n: c) a0 O2 nDECREASE
3 | u3 H6 Y' F8 YX
. x! L# |6 x7 i6 L ?7 I% a10.000000; v# r8 j0 e5 I4 R
INFINITY2 Q$ C& A. K; V8 u
2.500000
5 [5 C! w6 V G/ j# OY
9 H \5 I" A; {' m. r. b O8 }6 w( @15.000000
' C8 t6 ?7 h6 S0 ]) B: p2 S/ }9 f5.000000. o! c/ |; @, N
15.000000
! L6 M/ p* V- K$ n
RIGHTHAND SIDE RANGES 1 A I# |7 Y2 z
ROW
) q3 _: }5 d: J* S( a) q5 f3 gCURRENT
3 r) B9 r8 e. g3 N; d( E" ^/ JALLOWABLE: s# `1 d- Z/ E3 N, s4 D2 E
ALLOWABLE * t( S; {& j$ `% R4 ~& M/ i
RHS
o: Q. ~1 y# i6 }INCREASE9 f$ {0 }& O5 X) | v# ?" S
DECREASE ( n# }- w! L) s" l9 c3 W
- R7 o; V' ?# @0 O& X/ ~23 @6 H0 e9 ~$ [% K9 l3 a* [8 k
10.000000
8 j* g9 P1 f0 S' g8 c4 t$ f9 k* H6.000000
; T4 P3 R, v3 @4 }( g# g10.000000 3 e& l: z& m" o2 d9 o q
3% n5 d% x6 y% ]: p& i" R) U4 _
12.000000, ]& d$ [4 R' p4 @+ i
INFINITY/ B7 y) v9 o1 U9 D8 y, \
9.000000
' s% p; u) G5 n: B1 v' K! I& o4# z Q; N, e' M# }0 I
16.0000009 z; }$ T6 U* o9 L+ Z
18.000000
# d% ?) |- B$ p* c+ R8 Q% ]$ z6.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
7 t. [0 T3 q" `. A. Rreport 窗口得到以下结果:
: j8 |% r( q) s9 HGlobal optimal solution found at iteration:
% ], ^ G. F) N: l# `) n; h2
: Z2 m1 @2 n; ^1 E) v! zObjective value:
, c& K& f9 n7 |8 Z& k) _7.750000
9 k/ Y' D4 U5 [2 M+ p; T+ BVariable8 d7 I5 i+ }3 _1 z
Value
' w: E8 ^: L. B/ E% D. h: a" zReduced Cost
/ l7 h) x6 C3 N& Y& R0 WX1
) [8 h$ g1 b- l& ^# ]: S0.5000000% B# Y* ^9 N5 |+ Z# G
0.000000
6 e# Z- s2 x8 G+ D
X3
1 u& H s$ K' | F0.25000002 C$ \% H% k, i1 f
0.000000
, y( j- n, _7 q/ K4 b
) R# d5 G3 _- @5 c y; d# D) GX2
% u3 I5 g. k5 ^7 l0.000000
8 v2 z, {' P; @- p0.5000000
- q4 R: J: R. Y2 H- {9 _+ h
X4* z) [6 h3 i+ ]: G. m0 n6 Z
0.000000; s7 z3 ^& s" g
2.750000 . ]+ u& ^& B% p' y/ J" H; K$ A
X58 S- _- K- b& ]/ r9 P4 v; s
0.000000( P9 b3 |; s% B0 D
2.250000 ! ?5 L( \# b" h! ^- B" ]8 g
Row
0 ?, ^& n3 C1 C3 v* sSlack or Surplus
' A! {/ u, ^1 n: hDual Price
6 H+ M' x1 l6 X/ s/ |/ \( H1
2 b& C5 h) ~- @3 {, @7.750000* t' k6 u# E( }' T
-1.000000
+ h7 z: U0 u2 b2 ]
2
$ M+ X, \4 \% f1 I0 \& ^: A, V S0.000000
/ F; _/ U+ h' P% H" V7 U-2.750000 6 Q4 x1 |* b; K/ C* W
3& l' `$ p; F( P H4 ^. B" x M
0.000000* J5 ^* x; u, f
-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;
8 b) O- y4 {) M4 L! this is a commnent; x<=100; y<=120; x+2*y<=160; 按运行按钮在solution report 窗口得到以下结果: Global optimal solution found at iteration:
/ B2 O2 Y. i! r) t7 w! l' X+ V* J2
+ \ b# s; _& m' F$ q% VObjective value:
3 ~! e% ^9 H9 C: F7 q. O4 S5 F/ A6 `- [7 G: J- [
14500.00
- c a: D4 Q5 ?: r2 _+ T2 }- |Variable# d) R$ d S; ^( W7 _7 s
Value; Z6 A, O+ U& d( C, A' _: w" [
Reduced Cost
/ m* _6 J* N/ u1 K$ VX
; ^, a! ?7 o/ h( |8 ~100.0000 s# @& ~7 U' _/ W
0.000000
% J# S3 C; X9 u) ]6 P
Y1 i* R1 _8 N4 n& A& Y% b
30.000008 T0 q: r, ~8 I8 a) S
0.000000
! K& ?; a! Q7 g- U2 \ X+ @& oRow
) T2 y2 y( G7 s' Z5 l" o# @' bSlack or Surplus
/ `5 D- t8 {7 w( J$ @$ s- w( `Dual Price
9 M/ P& E4 H! k+ v, h. X
1" h7 a( i" j) i- {: B5 A% j
14500.00
: E4 i v# W: p; ?6 V, m1.000000 ; d7 J+ m: c! U h- E: {8 D. H
2( M! U" N' ^% r
0.000000, ?/ s) q) e1 `0 G3 C- _
25.00000
( U2 p) J$ H3 q2 U3. [6 I$ B1 ]- B% m. i/ j5 e
90.00000
: `2 y' v3 |: l: @/ e% B0.000000
4
9 h: x: o" o8 B# b) P. e, ]; N2 [7 q0.000000
; A. t1 O% Z" w7 O5 ^6 w3 D/ ?" W* }. u- Z% t' R6 D
75.00000 |