本章, 我们介绍三种解决线性规划问题的软件:
第一种: 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 =8 T1 Q- n+ s: b3 Y7 n
-2
-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 =5 P. c& g4 O: @# r+ O
11 B$ p/ {0 V7 t( o
2
4
-1
( i( |7 h- R U" t7 W' s* o
2+ G( ]; z& W, i, v
3! _6 j* f% s5 u* y
-1
1
) \% z1 r0 F' B; h/ h, Q
19 w& s9 c1 y- d) G& k0 G$ h
0
1: n& ]$ v# D1 \% [# M6 _7 _
1
-1
0
0' q) m ^, y# s8 a2 J
0
0
-1" r. e8 U7 \6 m/ d7 p/ M7 }
0
0
0# e0 G( @- `' D" e: o9 A
0& {# p. J; H, U2 r6 r
-1
0
0- W* j% G4 N, P8 F, n8 R& g
0
0
-1
Please input the resource array of the program b(m)_T=[6,12,4,0,0,0,0]'
b =
6
12
' w9 |0 L( {! S; j
4
! q3 N9 ]9 {1 g( e& j" k6 [
0
0
0
9 u- @7 u( u1 ~, x. l7 S8 y3 \
0
Optimization terminated successfully.
The optimization solution of the programming is:
x =+ u: U2 ?0 B" F( o" H, ?$ i, l
0.0000
2.6667
, R' T6 V7 u( s$ k$ R/ i0 k0 M9 C
-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* |3 I- j/ M; g$ r2 [
!注释符号; 系统默认为自变量>0, 若不要求用free命令.
!在出来report windows之前可选择显示对此规划进行灵敏度分析等
按solve键, 在reports window中出现以下内容:
LP OPTIMUM FOUND AT STEP
2
OBJECTIVE FUNCTION VALUE
1)) l* p* R {0 X9 I
145.0000
3 `# R6 ?. l+ o, w% k8 L
VARIABLE5 M" c4 X/ |% N- k& U* I
VALUE
REDUCED COST
' S9 e4 G" Y' ?5 A. x+ a7 Q8 _3 f
X
10.0000006 Z3 r. H# v+ q, t0 m9 o
0.000000
* V0 p' s" `4 m* `4 U& a# J
Y$ x' ^ X- a2 u y0 `" `. r
3.000000
0.000000
ROW, } V4 G) e2 C( S) U# b t5 d4 c7 u3 ^( B
SLACK OR SURPLUS, n( s) v6 j4 ^! N
DUAL PRICES
- k, o4 S, ~) [/ J
2)5 ~9 _( p6 G- h8 a/ f
0.000000
2.500000
! ~2 [7 N2 {* P* S* f- q
3)
9.000000' h3 m. K5 l9 {! ]: i" F
0.000000
4)! s/ C) f" m. W) B% |) K
0.000000. J0 y6 n" n8 d( k& X
7.500000
6 P: h; L8 Y, E0 S$ I4 m
NO. ITERATIONS=
2
" Q" l* L4 Y1 O1 {2 Y& x" s2 d
RANGES IN WHICH THE BASIS IS UNCHANGED:
OBJ COEFFICIENT RANGES
+ [' h- S' k$ P7 B1 _
VARIABLE' l% T: M! n0 l0 |$ a: d# X
CURRENT" K4 P8 Q* @+ c9 n* H5 k
ALLOWABLE
ALLOWABLE
COEF. A- h/ u$ J1 E
INCREASE
DECREASE
X/ |: w0 [9 Q1 b, M/ A" E& U) V( x$ y
10.000000
INFINITY) B+ w: Y4 i4 x( U3 `* I9 ]% a0 D
2.500000
* \+ R0 ^6 q9 O) \( g
Y
15.000000' D. T6 J0 L7 b2 v" S
5.000000" n1 A/ X7 k H' Y
15.000000
RIGHTHAND SIDE RANGES
ROW) [4 ^ F% z, O. R
CURRENT/ ]! s# f/ r) j5 b4 s. }
ALLOWABLE
ALLOWABLE
RHS; g, W+ K/ X. {
INCREASE
DECREASE
- w% @2 ~) w& [+ \% f( y
* Z3 q) T8 H# t# [4 X2 w. ^: c
2. x0 c6 O9 f- y4 u6 I. [
10.000000
6.000000
10.000000
3
12.0000007 C! f4 j8 K. v6 k& `
INFINITY
9.000000
4* x `% v/ V% G; u2 j. W0 ~$ |- [1 H6 S
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
Global optimal solution found at iteration:9 J$ ~! S% \9 I6 I! u* f
2
% L) P" }" a7 z# r1 ^' s
Objective value:) p, S* H- `" ^" S) b
7.750000
+ W$ ]$ t+ f3 @& |
Variable! o' [' P( M6 x2 w& _: t5 J
Value) p9 k; w, f6 A1 k. E$ `: w4 ~5 N
Reduced Cost
+ p+ h: @% y$ [' _4 g' ~
X1
0.5000000
0.000000
X3
0.25000009 @0 Y; I- ]) w' C' n! o8 M% ]9 y
0.000000
* }# L. a$ @ S6 w2 [6 Q
X20 W! i+ F$ }6 `6 z) ^% v& H
0.000000
0.5000000
L1 c! u# [0 F
X4
0.000000* _ |3 @) z# Z/ p
2.750000
X5 Y+ x2 \) D& Z4 D
0.000000
2.250000
Row
Slack or Surplus+ K/ k7 f7 p. M l
Dual Price
: y7 M- l4 N+ V0 M1 [$ @7 I
1
7.750000& m- O6 Y& e+ q! p! [6 Z$ o& x
-1.000000
2% Y, c( q) K+ T) M: G/ V, j
0.000000
-2.750000
3* Z$ a. O6 V7 d- p
0.000000
-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;- h7 r& Z- W @6 Y# \8 h' ^
! this is a commnent;
x<=100;
y<=120;
x+2*y<=160;
按运行按钮在solution report 窗口得到以下结果:
Global optimal solution found at iteration:
2
Objective value:
9 U- k3 ] y; T R( I
14500.00
* v( X. }: J9 H! s
Variable1 w0 }' f* k: K9 H' y* k7 `
Value- u+ S4 z! h) l2 B- S3 I+ e/ @
Reduced Cost
X
100.00001 P0 u5 j3 O1 N# {/ D$ b
0.000000
+ n+ V- c7 ?0 {8 M) x3 U
Y
30.00000
0.000000
1 T* U0 G7 ~6 g- y# P. O5 x( K+ w
Row1 R' c* s i* [8 l2 D3 E; d
Slack or Surplus
Dual Price
. Q2 C& l5 m* I' g; ^
1
14500.00 C; g+ k w7 Z" f
1.000000
2
0.000000
25.00000
% r, u" ?* p/ i7 {; n! n
3
90.000000 p6 j; T6 n# n4 \ s3 L9 v
0.000000
4
0.000000
$ z* k; o1 r5 D2 @
75.00000
62.5 KB, 下载次数: 14, 下载积分: 体力 -2 点
| 欢迎光临 数学建模社区-数学中国 (http://www.madio.net/) | Powered by Discuz! X2.5 |