|
Revision 1417, 1.3 kB
(checked in by dmitrey.kroshko, 2 months ago)
|
add converter lp2nlp
|
| Line | |
|---|
| 1 |
""" |
|---|
| 2 |
Example: |
|---|
| 3 |
Let's concider the problem |
|---|
| 4 |
15x1 + 8x2 + 80x3 -> min (1) |
|---|
| 5 |
subjected to |
|---|
| 6 |
x1 + 2x2 + 3x3 <= 15 (2) |
|---|
| 7 |
8x1 + 15x2 + 80x3 <= 80 (3) |
|---|
| 8 |
8x1 + 80x2 + 15x3 <=150 (4) |
|---|
| 9 |
100x1 + 10x2 + x3 >= 800 (5) |
|---|
| 10 |
80x1 + 8x2 + 15x3 = 750 (6) |
|---|
| 11 |
x1 + 10x2 + 100x3 = 80 (7) |
|---|
| 12 |
x1 >= 4 (8) |
|---|
| 13 |
-8 >= x2 >= -80 (9) |
|---|
| 14 |
""" |
|---|
| 15 |
|
|---|
| 16 |
from numpy import * |
|---|
| 17 |
from scikits.openopt import LP |
|---|
| 18 |
f = array([15,8,80]) |
|---|
| 19 |
A = mat('1 2 3; 8 15 80; 8 80 15; -100 -10 -1') |
|---|
| 20 |
b = [15, 80, 150, -800] |
|---|
| 21 |
Aeq = mat('80 8 15; 1 10 100') |
|---|
| 22 |
beq = (750, 80) |
|---|
| 23 |
|
|---|
| 24 |
lb = [4, -80, -inf] |
|---|
| 25 |
ub = [inf, -8, inf] |
|---|
| 26 |
p = LP(f, A=A, Aeq=Aeq, b=b, beq=beq, lb=lb, ub=ub) |
|---|
| 27 |
|
|---|
| 28 |
r = p.solve('cvxopt_lp') |
|---|
| 29 |
""" |
|---|
| 30 |
Other: |
|---|
| 31 |
r = p.solve('glpk') # CVXOPT & glpk must be installed |
|---|
| 32 |
r = p.solve('lpSolve')#lp_solve must be installed |
|---|
| 33 |
or using converter lp2nlp: |
|---|
| 34 |
r = p.solve('nlp:ralg', xtol=1e-8, ftol=1e-7) # for ralg reducing xtol, ftol is usually required |
|---|
| 35 |
r = p.solve('nlp:algencan') |
|---|
| 36 |
r = p.solve('nlp:ipopt') |
|---|
| 37 |
r = p.solve('nlp:scipy_slsqp') |
|---|
| 38 |
""" |
|---|
| 39 |
print 'objFunValue:', r.ff |
|---|
| 40 |
print 'x_opt:', r.xf |
|---|