本章, 我们介绍三种解决线性规划问题的软件:
第一种: 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
; |- {+ s+ m/ f d8 B" s5 j/ E% Y$ f
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
2- N: x5 [ M* u! J: `
4
-1
2
33 w: u' g$ c3 X1 t% M4 A! K
-19 f3 W) D2 j) C+ B; N
1
3 a" h* e8 h" W1 ?9 x) J( w7 n
1
02 T9 C) R6 a% a6 i$ Q
1
1
4 f# M( R1 ]+ D- U3 A! Z
-1
00 I( R/ i, I, Z( O2 L. h' N
0$ S( T+ x- b2 b) [& U; F8 q( X
0
! G5 b# b! V1 Z3 Q. p
09 H) d0 B0 p1 z5 m; F9 L" _
-15 |# u! O4 n) U* H6 h
04 }) [& {! B. c ?
0
0
0
-1
0
J/ o0 j- q- x+ z
0, J! }" ^6 F( C( ~% F7 f
06 }# T5 F$ O% C$ _8 L" w
0
-1
Please input the resource array of the program b(m)_T=[6,12,4,0,0,0,0]'
b =
6
12
4
% ~, E p, M8 q8 e/ i( w$ z- I
0
4 b% O7 E2 y' n) c) U Q# G
0
0
8 r2 K6 x3 v5 s# c8 N
0
Optimization terminated successfully.
The optimization solution of the programming is:
x =
0.0000
2.6667
5 U% F) r. h Q& b" U) h. X
-0.0000
% X+ U! y. B4 X0 E8 Q& }( ?' q: r
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% E9 O' w! n. `* a5 M$ f1 r% j
!注释符号; 系统默认为自变量>0, 若不要求用free命令.
& h3 t0 w9 e. b
!在出来report windows之前可选择显示对此规划进行灵敏度分析等
按solve键, 在reports window中出现以下内容:
LP OPTIMUM FOUND AT STEP! Z- V$ u, R; w
2
OBJECTIVE FUNCTION VALUE
1)
145.0000
VARIABLE
VALUE- E1 l3 N) m6 t& r; B" V0 N1 w
REDUCED COST
X* |% f( H% C5 `9 p: H0 O- _
10.000000
0.000000
6 L4 ^7 P d. t2 h9 s% X. ]' x: \
Y
3.000000
0.000000
' _) l9 q; _# [" q5 n) Y' }
ROW' r+ O/ O/ |. t# J6 U
SLACK OR SURPLUS
DUAL PRICES
& D: v/ J n! H
2)
0.000000( w' |+ ^: Q {
2.500000
3 L: i1 T' _8 z# K
3)6 W) d) T7 e5 \' C* Q8 o0 }2 A) v
9.000000
0.000000
* {) l" X( i3 o: D+ C- `
4)/ r9 N$ _3 c3 H" _( z5 ~
0.000000
7.500000
8 p5 Y I Y: q
NO. ITERATIONS=7 h) A1 q$ d" N/ O( C
2
RANGES IN WHICH THE BASIS IS UNCHANGED:
OBJ COEFFICIENT RANGES
0 N& z- n6 G& s0 Z) j6 B
VARIABLE+ I* f0 u5 b( t6 i1 ?' m2 G
CURRENT
ALLOWABLE+ w! x H$ Y+ g' V( @; c p
ALLOWABLE
COEF5 \8 N, e1 X8 p1 I! y' x1 J+ u
INCREASE5 w/ M" r/ d9 k$ ^; ~; O" K
DECREASE
X
10.000000) A5 @& }9 |' L8 C
INFINITY/ @4 b( B$ A7 L2 |, t# e* ]# |
2.500000
- X: w4 i5 P7 a1 ` N2 v' o. X
Y( n; o6 e$ t. A; m4 J. v' O# j$ ]# h7 m
15.000000
5.000000
15.000000
RIGHTHAND SIDE RANGES
, K, O, j, Z2 i* e! @2 r
ROW
CURRENT
ALLOWABLE
ALLOWABLE
RHS' r1 ^# Q3 ^6 z: H6 j" f6 e3 I5 e
INCREASE2 z/ ^" Z# I8 l% X
DECREASE
9 o( l- z h8 G
2. S" L, d' w' k& j1 ~9 ]
10.000000
6.000000& H* v& l% ^, s2 X, y9 _) Y
10.000000
! ?* O$ j& x7 W! T5 X% b
3
12.000000
INFINITY$ z: h, y! k, B3 I- M6 H S
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
Global optimal solution found at iteration:
2
Objective value:( S/ ?4 j- X7 i5 b, X; p
7.750000
* v/ @) g# A& ], j% A
Variable
Value8 z( \3 q; W! F5 T7 w6 l" V
Reduced Cost
/ ]3 ]3 I3 u6 g5 s" j/ J* X
X1 b5 y0 ?& m: s, e5 [1 p5 q3 a
0.50000001 W0 k8 _: n6 J4 u, X9 b5 p! E P' U
0.000000
8 s1 S% ^, f8 c! K. n* j9 l; I! |
X3
0.2500000
0.000000
' H# O8 b/ u* F o' L; M
X2
0.000000
0.5000000
+ T: p5 p% Q$ n7 E. e
X4% C7 }( l) n; `4 @" V6 g: n4 S2 I& i
0.000000
2.750000
; ?- D5 E0 q1 g
X5
0.000000
2.250000
7 C0 W" |2 u+ c) k4 K( f- p
Row6 \7 I4 ^* ^' f: ~, f* m
Slack or Surplus
Dual Price
1
7.750000* X6 @) ~& N( B; ]
-1.000000
2# k# C# Y+ |$ R$ w. R1 U
0.0000009 Z. P4 \9 G. F5 [2 g# V: g8 E
-2.750000
3) O+ |8 I+ L" O+ ?7 x3 B
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:+ y) g R- P3 l$ d; Y
2
$ L K1 D9 m: E/ S2 `
Objective value:
9 _2 a. |" @0 D ?: |/ ~
14500.00
Variable a8 ^+ O- O4 M
Value5 s6 I) L; g! l0 g( m1 L5 h
Reduced Cost
: p8 T; \& l) K% [
X
100.0000
0.000000
Y
30.00000* ~: u4 h# o( j* P; o
0.000000
Row0 w! e! C9 Z% O$ [1 u
Slack or Surplus; [7 n, [. [# F6 H0 N& {4 F
Dual Price
1
14500.00
1.000000
6 J0 [$ I8 O" T9 O' v: ?+ Z
2
0.0000003 }/ ?/ _) l0 z6 l
25.00000
3
90.00000# g7 E5 m; \4 _0 H0 t
0.000000
4
0.0000001 E- X" U" ]$ `8 G7 e
3 b3 E- l' w, R% u
75.00000
62.5 KB, 下载次数: 14, 下载积分: 体力 -2 点
| 欢迎光临 数学建模社区-数学中国 (http://www.madio.net/) | Powered by Discuz! X2.5 |