本章, 我们介绍三种解决线性规划问题的软件:
第一种: 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 =( p) P0 Z- z u3 P" z @
-2
3 p5 b' i J! ` ~$ R- ~9 b
-1
5 G7 V6 U; ^7 x3 |
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 [/ r/ A2 z5 Y( M" E% f, C0 n
1; d6 @/ y7 C6 t1 c$ ~- S/ r
22 X: K& E$ F9 m0 f& Z$ H
4
-1
# W& X# C0 K: N0 \ Y+ X
2
3' j( u, ~ @3 i$ h h6 _: |7 |
-1 @& ~' E/ L' H1 B: x% [2 G9 B+ p
1
8 ^! Z3 N7 g! e* c5 H/ p" Z8 M& P
1
08 _$ g: V+ }% K% p
1
1
/ q4 D) g) H- G2 K; b$ @$ {
-1
0
0
0
0
-1- b4 u0 S; a/ B) p* t0 s2 }+ |
0
0
0
0
-1
0
# }: N' T' I" W/ I
0; k, O3 r" b' u3 M% L3 e2 e2 \
0& A" e4 G9 r& P
0
-1
Please input the resource array of the program b(m)_T=[6,12,4,0,0,0,0]'
b =+ ]; N. V9 x6 K7 r
6
12
3 m% _4 `5 I% D: A; x1 L
4
! N7 g; m& P; q, p& R7 A2 A
0
% g5 k$ w% o: ?) o. E3 y. R
0
- b4 |! I7 M! c h! ~- y$ Q
0
! d- A: ~, g: T3 G
0
Optimization terminated successfully.
The optimization solution of the programming is:
x =
0.0000
2 K: |+ g* Q+ {- p
2.6667
6 r! @; e- s6 }, S) T9 d1 H3 f* k: X
-0.0000
- t# k. U6 e% b2 V( S' ^+ d
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
!注释符号; 系统默认为自变量>0, 若不要求用free命令.
!在出来report windows之前可选择显示对此规划进行灵敏度分析等
按solve键, 在reports window中出现以下内容:
LP OPTIMUM FOUND AT STEP
2
OBJECTIVE FUNCTION VALUE
9 @. q% n% i* m" d( _
1)# y* h) O. \6 h* u& D2 G; y
145.0000
VARIABLE: |5 @: w4 n. [+ w- o8 |- L2 a2 M
VALUE4 Z4 J- Q* q6 x# [1 V% O
REDUCED COST
& h3 z' b& a! o1 P! K
X5 V% ] `% D& N' O3 Z: z
10.000000
0.000000
Y0 j3 c+ Q, j! |5 X2 }
3.000000; m4 X- Q# f! l, [- L
0.000000
ROW
SLACK OR SURPLUS
DUAL PRICES
2)
0.000000 L* f* r3 V2 `" j$ ]
2.500000
3). t- A6 K* `5 k) o! D
9.000000
0.000000
3 L3 O; G- }- i
4)
0.0000007 g# C$ a2 z# K
7.500000
NO. ITERATIONS=
2
RANGES IN WHICH THE BASIS IS UNCHANGED:
OBJ COEFFICIENT RANGES
/ i7 n) [; @: ]8 N8 C/ J
VARIABLE
CURRENT
ALLOWABLE, H# K: p% j: ]9 i) o7 B, d
ALLOWABLE
4 q3 B: ~. C3 w$ E$ ~& A/ ?
COEF
INCREASE U( i6 ~9 x% a' e& p* I1 m6 ~. Q
DECREASE
X- ?, m* P3 [4 l( q2 n8 q5 V
10.000000
INFINITY y# A) F; ^1 a6 B9 j
2.500000
Y
15.000000
5.000000* ^1 W$ L5 p/ t! V" R
15.000000
( C1 d3 j' ~& ~2 Z5 W- `6 I, o/ `
RIGHTHAND SIDE RANGES
ROW2 C o3 a5 F y4 S
CURRENT
ALLOWABLE$ D% n- E, [8 x" T' o( g
ALLOWABLE
RHS
INCREASE- x/ W% {6 M A$ X i
DECREASE
26 O; d# r" F7 L2 [# F
10.0000006 e: i0 W: L% W" T
6.000000
10.000000
3
12.000000" o# G5 [- X$ D% u% |7 Z
INFINITY, _/ d f9 ~ k3 N: B% p
9.000000
4) K8 t2 I/ W: W6 [+ F% o8 ^7 V" \6 y
16.0000008 ~+ S$ y9 W' n) L3 J* E8 C
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' r0 M! u1 v' a
Global optimal solution found at iteration:3 t, B6 O* P# @+ ]; v8 g- ~7 [
2
' V$ \7 L' }3 t5 f) a
Objective value:8 o0 |( C% `# q5 z
7.750000
Variable, V& M3 w' d) T- R/ C1 Q
Value% y7 G" O8 L( E' z
Reduced Cost
+ W6 B" `; E4 K6 _) U- p
X17 f! U/ f7 D7 \6 h4 g b$ J
0.5000000' t5 n$ e2 ]/ J1 P
0.000000
+ z+ O( q( m! e3 A: H% _3 h
X35 b) Q1 i! S5 a( @
0.2500000& L* r5 j- f+ e, j: Q7 [
0.000000
X2( I$ a( {0 n u c( J0 a/ F, e
0.000000. F3 [* h! o# N: y
0.5000000
* x5 E0 Q; D. T( ]8 O* Q( B
X4* j: A2 U3 R6 y; a4 c/ F
0.0000002 R9 A" @6 h7 f4 A( B! L) h
2.750000
X5
0.0000002 H# h2 n# T: B/ @$ q; o3 ^
2.250000
Row
Slack or Surplus, M. L1 i+ _ d& F# q
Dual Price
1) U" A! E j7 t, q5 M0 k# P
7.750000
-1.000000
2
0.000000
-2.750000
1 t/ d( A" B1 F. }! k- c
39 q, H+ s8 k9 l! i1 G- j4 S
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;
! this is a commnent;
x<=100;
y<=120;
x+2*y<=160;
按运行按钮在solution report 窗口得到以下结果:
Global optimal solution found at iteration:& o n, w7 z* B _# z; G( x
2
Objective value:
14500.00
0 V# X. i: ^* [4 t4 s
Variable) Y1 T" b, ]' H2 `$ i' I. _6 z
Value
Reduced Cost
4 H8 Y* T' E! b v$ \6 ?: T& x" @% _4 U
X
100.0000
0.000000
Y5 a) A- t) Q: `8 I3 ^" F: Z
30.00000
0.000000
! e% m" D% n2 M
Row
Slack or Surplus
Dual Price
/ R# s4 k W, A5 O: @
1+ I) ~0 m) ~+ _# B1 V% {6 g; H
14500.00
1.000000
2
0.000000# Y# a3 n0 J" w% B3 n0 G
25.00000
3
90.00000
0.000000
4" K# [4 F0 b4 v) }% h
0.000000/ Q( K: i# Y( e! v# v0 R* B) g
4 r9 O. |7 S/ c' c: e8 x; ^
75.00000
62.5 KB, 下载次数: 14, 下载积分: 体力 -2 点
| 欢迎光临 数学建模社区-数学中国 (http://www.madio.net/) | Powered by Discuz! X2.5 |