|
第二章 线性规划 本章, 我们介绍三种解决线性规划问题的软件: 第一种: 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 =
F6 {. T$ J# f. `8 v0 _% B1 x-2
" q$ S; r q! U% Y4 `-1
* Z1 M* G. z4 E' P$ A, z( _
3 ' B+ r' ]6 U: }, H9 b* S) z& d
-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 =
; T" ], Q' u1 [& O) G9 r1+ [5 _$ I5 w, Z' X# \
2
/ I% r+ p/ ?& g. Q. s4+ @8 [4 W7 D2 _. I
-1 . K" R% I6 `! e4 t& a5 u8 b1 ?
2& g% K# r; `2 G) `7 H
3! o" b: m5 e9 F0 ~9 E7 E1 K
-1
' @$ X& e7 u* h- B- f1
& m2 X3 P3 T2 j# Q0 s1$ s5 e# w' e% R8 {3 E' V5 q( A& M7 j
07 |3 D& C7 K3 I5 V% u
1
' l9 I3 W# }% V! b1
- y" G5 I5 W4 s! O( X6 z-1
7 I8 k" v6 Q( I6 h" p6 o0
4 }4 q9 E# i+ `6 }0
9 ?# m4 R7 i. G) e0
2 g* L5 Q# {0 I! D! s8 q% N0 \! \
0
+ m/ e; V* k& t- K+ X3 u0 o-1
# @6 G p( r# P3 V9 ^0
4 w: ?4 m) U/ L; t2 g! k0
/ u5 `& m. P V7 ~6 k0
0 }7 P v! T* s% j0 D3 r, N: Y) A0
# N' R9 s1 i- Z: D0 z1 m-1% z. w& ~( c! p9 h7 e7 }
0
/ P6 h# ^" A$ U# ?% l& h0
' j C" F( t8 T' U$ G/ b8 G0
* N, e" D; S3 [. B; \02 I$ o3 U! k9 l0 O
-1
Please input the resource array of the program b(m)_T=[6,12,4,0,0,0,0]' b =
4 u1 Y- ]; x* S" n6
& D# Z) n! b; D/ w12
7 z+ M* ^+ p6 a+ c( F* O2 d1 v# F0 ]4
4 N. I# r/ `" \: Y; I$ v5 K0 t) C0
' O6 }/ P2 y6 B$ O: j$ A+ {0
, A, q: W, c+ a- }3 }8 N
0 2 a" O; P3 o9 r6 k6 M" ?! K! }
0 Optimization terminated successfully. The optimization solution of the programming is: x =
) ]& {& x, {$ c( m# P0.0000 " i/ W; p; ?) B4 V" E, ~
2.6667
' i% D1 @2 s& A" c+ S$ l8 z-0.0000
% d- P9 {( ]& [( [2 [& q4.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 end7 ^- s& g- f& Q
!注释符号; 系统默认为自变量>0, 若不要求用free命令.
1 X& B; w8 m. [5 ?/ O!在出来report windows之前可选择显示对此规划进行灵敏度分析等
按solve键, 在reports window中出现以下内容:LP OPTIMUM FOUND AT STEP% A& t5 z" e+ G2 \
2
( O# c3 m/ W6 e/ K9 yOBJECTIVE FUNCTION VALUE
- ~4 C: \, p5 u/ [1)
6 c- l( y2 b+ R5 E145.0000
. ?1 `' w' I" b: B
VARIABLE
! _1 }" y/ |4 K+ s1 u5 g% g- D6 fVALUE0 b) C8 _- G, n: S3 N
REDUCED COST 6 D1 z2 e' s; c" i8 s
X
) @, m7 j( L; y! C- R; m1 Z10.000000
* e) ]$ b/ ~2 R0 V w4 U0.000000
) M% b3 g4 ?, m; @4 yY
& Y6 Z! [' c1 B1 q) Y3 G3.000000$ W; I3 f2 f# d% o6 M
0.000000
+ ^( [ Y8 K y& e( r- vROW
# I+ j8 m/ g- Q5 M3 cSLACK OR SURPLUS c7 k5 h: ]+ x m+ [
DUAL PRICES
& F% @( I$ a4 {3 ^% u4 D+ G, i
2)
0 i$ C4 W7 E4 i0.000000+ B/ K; f" Y( @) Q
2.500000 6 _6 E; y3 H W b$ n
3)1 |6 m5 F6 ?: c
9.000000
- f V# r& D h. e' _0.000000 5 H6 {9 B) s, A6 x/ P7 _5 e' Q
4)# B* p! _& w8 _3 Q' V
0.000000
k B/ @" `5 H7.500000
H; O q7 e6 z& f- s6 DNO. ITERATIONS=% \5 ]. L$ F/ b
2
/ G" K* w7 L5 j) b4 |8 x$ a
RANGES IN WHICH THE BASIS IS UNCHANGED: 0 E" J! ?, J: L5 t$ Y+ n
OBJ COEFFICIENT RANGES
8 N. T9 U' }% l4 g3 k9 h: gVARIABLE
2 M1 m& b; a6 d, G: dCURRENT
; q8 m) n+ n% G1 }+ L: L9 XALLOWABLE
7 c( E- B) b; C. qALLOWABLE
1 J1 m- n! B# y sCOEF
; e% T% u) @( X5 y3 ~( AINCREASE
, Y8 E+ d8 s. P7 ~+ zDECREASE
& J; K4 F- L" ?' ^# u1 WX
. _; D* h I0 ^0 ~. I/ U" g10.000000( \9 `& a& f/ @' R) p
INFINITY
$ L" [1 t4 `+ C$ {* o" h2.500000
7 ?" [. A* `- L" aY9 X6 l& ]* Q7 ~% U0 o$ l1 i( E
15.000000
/ @9 D: M; q8 `% V2 \/ h5.000000
( r/ u: X% Y, ~. w15.000000
+ E/ u2 D0 m# D0 J: `7 D1 d
RIGHTHAND SIDE RANGES $ L+ m v4 d1 [7 p1 f. I3 F
ROW
! K! z! `8 r/ Z$ X. MCURRENT5 C' I6 F1 d$ H7 F: y5 }5 [
ALLOWABLE
# u4 O7 P; E: c3 ], k& XALLOWABLE ; H) W7 d5 P' ^
RHS V, o- b7 b$ O$ }
INCREASE, |" q; I: |: [! H7 n
DECREASE
6 }8 T- P: h4 Y; F6 K
, S# |- Z) H8 W0 B) ~" R3 x27 \" R8 x5 Q) O+ U6 s* G! {
10.000000: W, Y6 |4 G8 E8 E% Y
6.000000
- ?) A, g' Z( C- L10.000000
3 }, G6 D/ j/ O: f1 F. y30 N Z! h+ }- j) ?
12.000000; A* h7 i' g3 {( B4 g
INFINITY& p+ n7 |/ {& t4 [# A0 b, r4 L( Z
9.000000
0 L1 T! J7 ^6 v- k3 k5 o
4+ e' r- K/ ~0 [
16.000000
O3 I y/ }/ r18.0000001 N$ f4 }) F2 s8 @7 ^$ a/ S
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
* S( n8 F6 a. R" B! x, G5 j: Xreport 窗口得到以下结果:
# M% W" ]! n' S' S% ~5 L& Q8 a% @# pGlobal optimal solution found at iteration:# [% h/ P7 W* I" J1 ?( U& ~" Z
2
0 P0 s: G8 f! u& V( B' WObjective value:+ m8 R$ n( I/ V/ C8 ~
7.750000
, ^# e/ h Q2 P, a8 P YVariable! X% p4 M6 S7 @6 G8 V& a
Value0 t' ?# @& Y" u! M% f' J
Reduced Cost
5 c( _; B3 S" m" w) x: ~( ?
X1- F$ O- O6 @' S$ W# _
0.50000009 }0 Q" ?; ^7 |3 G8 p6 x
0.000000
3 S" a1 B! A( U3 Z8 uX3
/ Q5 \. v* B9 I7 B9 X/ n& j/ X* N0.2500000
1 b. `9 a4 G9 H0.000000
* O( g5 y* d5 V) |
7 x/ X8 |# q8 O
X2* P7 Q, X5 }% r+ p7 r/ T7 |
0.000000
+ X3 j* ?; F# H) z' G8 _# y- a0.5000000 " \$ u6 J! o# M. L2 |
X4% J, g" P' P2 I7 Z4 Q# B
0.000000
! F5 O+ j e b2 f! E2 D" T6 t! ~2.750000
; N5 @/ o6 Q2 i% ZX5+ S4 O+ x* \- b4 Y1 b0 R' e
0.000000- V& i% P: l5 A$ r. b. m
2.250000
3 B) Z* z4 `9 [) |3 z. o
Row; j; g8 \* {4 m6 V0 ~4 c+ p
Slack or Surplus) O3 z9 ?5 Y d/ Z/ T
Dual Price
/ n9 a6 U6 u6 s3 y6 _9 r1
4 k7 _0 u* A* f, l5 s6 k7.7500007 _/ @/ K% N0 ~5 K: x
-1.000000
+ i* B9 d) v. a# h' L
2
7 ^5 d6 |6 Y$ N1 B. q% L0.000000! P3 b2 ]4 e8 D$ I
-2.750000
, d1 s- ~+ [+ |7 p3
1 s8 t. C/ J* I; x$ ^0 M0.000000; j/ p- n& r3 D3 _
-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;: o* Y! c, v; \
! this is a commnent; x<=100; y<=120; x+2*y<=160; 按运行按钮在solution report 窗口得到以下结果: Global optimal solution found at iteration:
5 {1 S* t' K" n8 C3 i2 1 Y# q# x: T# s! B4 x5 j
Objective value:
) Q3 o3 J/ c- ]+ N/ [0 v' a9 }3 ]7 @- Y7 g. c. g0 k6 q
14500.00 ! ~' o9 V( K! X* x- z8 k+ {$ ^5 D
Variable# L( s6 d% Y6 ?9 x4 U# B
Value, D# K! ?+ ~0 k% p: x4 S
Reduced Cost 1 W( R' [" T& x& I+ s( U
X
2 v! O# v% Z% p2 F; {5 }100.0000
0 M2 _& _* w8 S& X5 Q0.000000
# |) a7 a& F* @! U& ~) k& FY
- }2 T9 F+ y( |0 ]1 Y; J4 i7 f( V1 ^30.00000
- ^0 q7 D8 h& B; k0.000000
8 B: ^; v/ z0 p! x, DRow2 q; Q1 V' q/ H- s: w- @0 [
Slack or Surplus y" R a6 b- e0 S* y$ h
Dual Price
+ h% W( d% r. F3 X/ a1
V. K. J9 | z4 ?14500.00
7 a/ \( ]1 Y$ j7 S1.000000
& ?* M$ f, ~, T: X: U1 s2
" `" ~4 ^! e* Z' X+ f4 H3 b0.000000
; F- {2 P# ~+ {3 A. ]25.00000
. S# Q; \' y2 }: r; F3* z9 v; v2 M/ r3 B: g
90.00000
# @8 J! u Z& v; F3 `0.000000
4
& J; o) k& d2 K; F6 Z0.000000$ d; l% F. s% }6 p f& f
+ c* a& K. B+ @/ e7 S0 ?3 o! Z75.00000 |