本章, 我们介绍三种解决线性规划问题的软件:
第一种: 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
-1
/ V+ _( z: y+ P% ]6 @: k
3
- T3 V7 i" h! u; _
-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 =& T6 M% j3 T# n: l- {: }' w6 h0 Q
1' B% O* p, Q: R
20 J; j7 ~8 ^$ ]! L2 Y3 h
4
-1
) w: H% W; c% d" ?( W M7 r( ]
21 c% }0 j! T: @. p
3, E* T, L6 I' o9 [, W
-1: H: L% w) z7 E; B
1
/ T: H5 Y, }' l
1
0
1; w; j" w3 R5 P
1
-1" S4 z0 q! C- o* i; Z- a* @$ F
03 V2 [* p6 {( o: o8 a' x
0' O5 O9 O: r9 v+ F( {
0
/ U7 K* U) A9 g% ^
0; c* ^4 h% J' K+ _4 V
-1
0
0
& U& {3 k. e& L8 l
0
0
-1
0
0 `/ D1 p$ x C% b* R: Y
0( R6 x, j, r z
0/ {, H$ b7 j: `" N+ j
-1
Please input the resource array of the program b(m)_T=[6,12,4,0,0,0,0]'
b =
6
12
9 x0 Q3 q2 K- [8 E1 u; m; p
4
0
' a% o/ y- P' I" Y
0
( K! } l2 n0 M0 q5 m; b4 H
0
6 S+ C' h( Q! q, M$ [* C
0
Optimization terminated successfully.
The optimization solution of the programming is:
x =
0.0000
0 V% X) J( h0 T1 B! N" B
2.6667
-0.0000
9 V0 F: {: G8 O# }, a$ Q
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
end7 [' H, a7 ~) _' |# l5 l' x2 B
!注释符号; 系统默认为自变量>0, 若不要求用free命令.
2 R6 Q( g, j9 @2 h) S# t
!在出来report windows之前可选择显示对此规划进行灵敏度分析等
按solve键, 在reports window中出现以下内容:
LP OPTIMUM FOUND AT STEP! y- y' [5 R, ]% r7 x
2
( m ~) Z/ Z; f& n0 z9 x: H/ b
OBJECTIVE FUNCTION VALUE
1)) r4 ~9 @+ T2 v1 V7 E4 V! j0 S4 q) |$ |
145.0000
VARIABLE
VALUE
REDUCED COST
X8 L" V+ Y. C! l8 h7 H' ]9 E
10.000000
0.000000
, }" I- ]0 w, K7 l: J
Y
3.000000# @& L6 P: v/ Z* V1 J
0.000000
ROW; \- V3 b% C& G
SLACK OR SURPLUS
DUAL PRICES
2)
0.000000
2.500000
3)
9.000000* }1 c3 \5 h* L3 G8 `
0.000000
4)* g4 p7 o% |& u; H
0.000000: f2 ?. P0 t' G
7.500000
Y, H5 F0 X6 J/ r. F
NO. ITERATIONS=, a- e+ k- j! H ^! z& u
2
RANGES IN WHICH THE BASIS IS UNCHANGED:
, q/ @. @3 c: {3 q% M
OBJ COEFFICIENT RANGES
VARIABLE
CURRENT
ALLOWABLE
ALLOWABLE
COEF
INCREASE
DECREASE
X* E7 f* L: z3 |7 }; d( k) v
10.000000
INFINITY& a1 c! ~$ F$ }) p; e" N5 z) P
2.500000
2 f$ Q* A8 e& f* y9 G
Y
15.0000001 [" Y* x& @- L7 i. H
5.0000003 O9 P3 _" n8 P/ S
15.000000
RIGHTHAND SIDE RANGES
ROW( B7 j( l1 r) A. }, _ B: W
CURRENT
ALLOWABLE
ALLOWABLE
7 g: L, c* z! _: |9 |) Y1 m$ Z
RHS
INCREASE7 S" n& P- G! u
DECREASE
: L3 [6 m& J4 d$ |
2, x% k7 i: U5 d6 w. @
10.000000/ z: i% E6 w3 \7 N# x$ z4 [4 \
6.000000; o2 Q0 ?8 i& ~' ]
10.000000
: \# f7 n( e# _9 q' [
3
12.000000( j4 f4 J& X, {& h0 D# G
INFINITY
9.000000
' A& |4 g" G' H, m. z
4# g {5 }" c/ p$ b
16.000000
18.0000000 z1 m2 O) p5 x2 c* g
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
2 r; s! d/ x* o, A2 o7 Q/ ^4 ^0 M( v. N
Global optimal solution found at iteration:! ~) C# ^. @/ z U
2
Objective value:
7.750000
/ g q, @$ f* ?2 W% d7 q# S
Variable
Value* ~; |1 Y, C) x
Reduced Cost
X1& M& P9 m' H9 O3 B3 j% y
0.5000000
0.000000
X3
0.2500000' P5 X) u. e+ H& w/ H
0.000000
$ O; M9 l6 d6 _4 J( |
X2
0.000000
0.5000000
: b# U& P, a7 D
X46 [* ] z; x l& f. w: K
0.0000004 x6 t+ h7 Y, T( o/ A* y; q
2.750000
X5
0.000000; D8 v% m9 m/ C- a
2.250000
Row
Slack or Surplus! ]- M) `+ \& F1 `
Dual Price
1
7.750000 P, `: L( L. t5 _& \3 ?
-1.000000
7 T! o7 s- O0 ?& M4 J! @0 {$ N
2
0.000000: ^, W( P: Z9 g- [+ t
-2.750000
0 e# C2 k: E5 c. s9 f
35 j9 I9 s7 G. d* O7 x3 |; L4 [
0.0000007 ^& D4 e+ |$ [0 k9 |
-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 z# l0 m0 X2 }
! this is a commnent;
x<=100;
y<=120;
x+2*y<=160;
按运行按钮在solution report 窗口得到以下结果:
Global optimal solution found at iteration:
2
8 [5 P( ~; _% X: P
Objective value:; N! ?' c1 g; t) o- ~9 T3 }1 d
6 d" F2 v8 S: _- B, X$ U3 j. M
14500.00
Variable
Value
Reduced Cost
8 e+ x# g; r$ \+ ]
X
100.0000" \9 Z8 O4 S8 K- U$ G b" _1 \
0.000000
; t* }& A0 L# w
Y) G- Z* w; C% ]8 X3 Z# F g
30.000008 k6 ]' U' R9 i
0.000000
Row
Slack or Surplus# s0 V( }1 X$ N0 J; S4 [, [' F
Dual Price
1
14500.00. ]- E* W; T, g" B
1.000000
% \3 p: W! _8 X3 W2 ]5 ^
2* u( ^1 v! ^0 y% B% e% Y
0.000000
25.00000
3
90.00000
0.000000
4
0.000000
: ~6 Z* {9 m& S9 D1 W8 R
75.00000
62.5 KB, 下载次数: 14, 下载积分: 体力 -2 点
| 欢迎光临 数学建模社区-数学中国 (http://www.madio.net/) | Powered by Discuz! X2.5 |