本章, 我们介绍三种解决线性规划问题的软件:
第一种: 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 =
-2
" G/ M6 X: |' ?: w
-1
3
-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 =
1; P) V6 d) q0 Q4 R) {- ?& C) a4 J8 L
2% o$ m M8 x& i: C b, k; R8 G/ [" h
4% N# d- O q7 Q4 E l. T
-1
2* Q6 a& C* |1 Y! ?: M
39 k) |$ [4 Z7 Z7 `. L- m
-14 J9 L A+ Z+ G
1
+ _) Q |' a n
1' I. [. e* M! M; g$ {' ~
0 D' I% {6 w8 l9 E
1
1
8 r; I( I- q$ f+ v# C
-1
0+ F# y* A/ `' W; [, f# h! g
0' w# T* K/ o2 P: ^. w5 T2 H! O; b
0
07 z6 U2 J" u& ]* D- ~
-19 n: M5 j) p; b+ X3 b
0
0
0
0
-1
0
! W( Z( d$ k! j/ J* s
0% l, {7 Q7 ?1 A1 ~7 I
0% n/ z$ |: B: b, P( {3 ]- O& l
0+ {3 r0 N6 o; v N5 R; b
-1
Please input the resource array of the program b(m)_T=[6,12,4,0,0,0,0]'
b =. F/ }: ~& V2 [, l4 x
6
+ v# @9 i6 k% }4 V1 K! e) c5 Z
12
4
; j0 d6 X; z: s% N J# {, `# Z
0
) `0 o% e1 V8 f
0
0
2 s5 ]# m4 O' M3 g0 r
0
Optimization terminated successfully.
The optimization solution of the programming is:
x =& I5 n/ ?- ^5 b4 G& k3 j, s
0.0000
- i8 f n% x' G) R0 Z/ f6 k9 ]4 }
2.6667
; i9 J+ _* k- `; p/ G ?5 s( H
-0.0000
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) F0 k, ]# m) \- p+ V5 A( E1 |
!注释符号; 系统默认为自变量>0, 若不要求用free命令.
!在出来report windows之前可选择显示对此规划进行灵敏度分析等
按solve键, 在reports window中出现以下内容:
LP OPTIMUM FOUND AT STEP% z; v3 T2 ?8 r
2
OBJECTIVE FUNCTION VALUE
1)8 _! R1 [" ^6 b: r w4 C
145.0000
VARIABLE0 a$ l t! Q6 @+ g, _8 m) t$ b
VALUE
REDUCED COST
& c& W0 T) [0 @
X
10.000000
0.000000
Y. r3 `- r2 `. T3 c' P" a/ s' j
3.000000
0.000000
$ A# L8 `# n* v2 I* ^5 h$ ^
ROW
SLACK OR SURPLUS9 v3 |# n+ v# O! m; P
DUAL PRICES
( c: c( [2 s, J$ Q( W$ s7 R# \
2)
0.0000000 k; |2 O) Z: @$ q0 R) d+ ]& u2 [
2.500000
3)
9.0000001 i( K! Z) G3 m# s
0.000000
l0 Z5 R) F; q6 F
4)8 c! v" d/ U4 y, `
0.000000* ~( u. y) }: s
7.500000
NO. ITERATIONS=6 m" U2 s7 @. h# C; Z
2
" p7 \+ s' G2 D- D0 }- a# U- n3 J! t- s
RANGES IN WHICH THE BASIS IS UNCHANGED:
OBJ COEFFICIENT RANGES
VARIABLE3 e ?8 ], _6 Z
CURRENT& x% h1 v9 o6 Y" F3 W+ \
ALLOWABLE
ALLOWABLE
COEF
INCREASE2 R6 [8 V: u, w+ n! ~! k- j
DECREASE
! B" o; f3 z& B. p8 A8 U) s9 J' N
X
10.0000000 Q3 e" K, j6 j) N
INFINITY
2.500000
/ t: x& \/ H9 N
Y+ L: z ~( W% [. ^
15.000000 M7 o" w/ O# I8 o$ q
5.000000
15.000000
, T& B/ g4 t3 }4 {% G, Z+ b) B
RIGHTHAND SIDE RANGES
# Y! l' N. l: {. W! u
ROW
CURRENT5 G8 [9 j# O! m( @" P+ M% k% l. s4 i
ALLOWABLE
ALLOWABLE
n/ J7 u! X7 Y7 k) h
RHS5 o4 U) {: r3 A; n. ~# N! ~8 y% M
INCREASE9 v2 }9 j3 `: G8 s
DECREASE
/ I( z; ?" p U! L% ?4 Q
2
10.0000008 o) I& _4 G& T0 ^# e7 Q4 [
6.0000006 O, t) j9 y, x7 }0 A, o* ^
10.000000
3
12.0000002 N8 k1 T6 e0 y# E6 ^7 K
INFINITY
9.000000
4
16.000000
18.000000
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 r2 A$ A* R: T5 `0 b
( T* b* u0 {2 e& a8 k, M7 F
Global optimal solution found at iteration:1 g4 T. Z! h# q+ }) E
2
Objective value:5 D( D, ^" m! j) G& [
7.750000
$ {* A$ Q5 x( g6 p. M3 S: H [
Variable5 X) H4 ^( b! R, \) T3 g
Value d* [0 n' ?2 }; t/ O- w) s
Reduced Cost
4 Z( T; P" M: K$ z: ?( C
X1
0.5000000
0.000000
X3" _" q" y0 }, p5 g4 `* }8 E
0.2500000
0.000000
X2
0.000000
0.5000000
8 V a* a9 J& x& g Y1 W1 r* }& {$ p
X4# Y3 a' E3 s( n M8 v
0.000000
2.750000
X5
0.000000; ?" P! s8 d% ^
2.250000
Row) n: j( y5 {, j+ {3 w! _5 W8 S
Slack or Surplus
Dual Price
& p, N/ r( Z- C+ W9 h8 R
1; a6 V% A, ^. ]' I5 z X: N- ] H# q
7.750000
-1.000000
2
0.0000006 C! I. O/ m# E' j1 v2 o
-2.750000
+ Q) Q8 B) E. H: Y
3
0.0000008 c/ F$ b( M/ u, d7 n/ e
-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;
! this is a commnent;
x<=100;
y<=120;
x+2*y<=160;
按运行按钮在solution report 窗口得到以下结果:
Global optimal solution found at iteration:& ?2 a$ p; n3 Y+ {* S% _
2
Objective value:
14500.00
Variable
Value
Reduced Cost
, D5 n! U8 K, k1 ]2 R( V- g$ y! U
X
100.0000# ^ F" r( w$ {
0.000000
Y
30.00000. J4 ?' i3 p. o' x
0.000000
Row) C7 S( [1 B* D) X# Y( g) x
Slack or Surplus1 F4 R" _8 O/ i1 C6 s
Dual Price
/ y0 L3 h, W. C. h3 I
1
14500.008 ^3 j7 a0 \8 q
1.000000
, @! N2 x& O, q! g% f
2( m, [+ G+ X8 A" n
0.000000# N9 b ]' _3 m0 I$ \
25.00000
* O& z0 \7 X- O k, b* e
3
90.000001 T6 z: M$ m1 s. M" E
0.000000
4
0.000000- C! Y* F: U/ S
75.00000
62.5 KB, 下载次数: 14, 下载积分: 体力 -2 点
| 欢迎光临 数学建模社区-数学中国 (http://www.madio.net/) | Powered by Discuz! X2.5 |