I have a MPS file like this:
* ENCODING=ISO-8859-1
NAME test.lp
ROWS
N obj1
L Constraint1
G Constraint2
COLUMNS
x obj1 -3
x Constraint1 1
x Constraint2 2
MARK0000 'MARKER' 'INTORG'
y obj1 -2
y Constraint1 2
y Constraint2 -1
MARK0001 'MARKER' 'INTEND'
RHS
rhs Constraint1 5
rhs Constraint2 3
BOUNDS
UP bnd x 10
LI bnd y 0
ENDATA
Can I generate a pulp problem with it? It can generate automatic or I have to read each line?
I've search on the internet and I can export it like this:
var1, prob1 = LpProblem.fromMPS("test.mps")
I am thinking to generate the problem by take each variable in var1 and so on. Have any way to do it automatically? Thanks
Yes, you can generate a pulp problem from an
mpsfile.Please note that the method
pulp.LpProblem.fromMPS("test.mps")that you've found imports a problem from an MPS file, rather than exporting it.You can find more information on how to import and export models using PuLP here: How to import and export models in PuLP
Having said that, the
mpsfile you've included in your example is missing the information about the problem's "sense" (whether to minimize or maximize your objective value). When you import your problem usingpulp.LpProblem.fromMPS("test.mps"), PuLP will interpret it as being a minimization problem, when no sense is included inside thempsfile. If you want to maximize the objective value, you can include the parametersenseto.fromMPS()method like so:NOTES
The mps format is an industry standard. But it is not very flexible with some information not being stored. It stores only variables and constraints. It does not store the values of variables. In other words, after importing the model, you need to call
prob1.solve()to re-generate the variables optimal values.