| 1 |
# Example of export OpenOpt LP to MPS file |
|---|
| 2 |
# you should have lpsolve and its Python binding properly installed |
|---|
| 3 |
# (you may take a look at the instructions from openopt.org/LP) |
|---|
| 4 |
|
|---|
| 5 |
# You can solve problems defined in MPS files |
|---|
| 6 |
# with a variety of solvers at NEOS server for free |
|---|
| 7 |
# http://neos.mcs.anl.gov/ |
|---|
| 8 |
# BTW they have Python API along with web API and other |
|---|
| 9 |
|
|---|
| 10 |
from numpy import * |
|---|
| 11 |
from openopt import LP |
|---|
| 12 |
f = array([15,8,80]) |
|---|
| 13 |
A = mat('1 2 3; 8 15 80; 8 80 15; -100 -10 -1') # numpy.ndarray is also allowed |
|---|
| 14 |
b = [15, 80, 150, -800] # numpy.ndarray, matrix etc are also allowed |
|---|
| 15 |
Aeq = mat('80 8 15; 1 10 100') # numpy.ndarray is also allowed |
|---|
| 16 |
beq = (750, 80) |
|---|
| 17 |
|
|---|
| 18 |
lb = [4, -80, -inf] |
|---|
| 19 |
ub = [inf, -8, inf] |
|---|
| 20 |
p = LP(f, A=A, Aeq=Aeq, b=b, beq=beq, lb=lb, ub=ub, name = 'lp_1') |
|---|
| 21 |
# or p = LP(f=f, A=A, Aeq=Aeq, b=b, beq=beq, lb=lb, ub=ub) |
|---|
| 22 |
|
|---|
| 23 |
# if file name not ends with '.MPS' or '.mps' |
|---|
| 24 |
# then '.mps' will be appended |
|---|
| 25 |
success = p.exportToMPS('asdf') |
|---|
| 26 |
# success is False if a error occurred (read-only file system, no write access, etc) |
|---|
| 27 |
# elseware success is True |
|---|
| 28 |
|
|---|
| 29 |
# objFunValue should be 204.48841578 |
|---|
| 30 |
# x_opt should be [ 9.89355041 -8. 1.5010645 ] |
|---|