Loading/Parsing Mathematical Programming System files
Asked Answered
M

2

6

In order not to reinvent the wheel I tried to find some code to parse
Mathematical Programming System files but I didnt find any implementations in python.

enter image description here

Is there any code allready available for this?

Update

Reading Mathematical Prog. files

Example MPS (afiro.mps: link1, link2)
Contains:

  1. objective function, one row, n columns
  2. table with restrictions, m rows, n columns
  3. right table, one column, m rows

Many languages have packages for reading and writing these files.

Messily answered 15/11, 2017 at 11:38 Comment(12)
And what's the expected output of the parser?Pensionary
Load the tables in 3 arraysMessily
Not many LP/MIP solvers are written in Python (for performance reasons).Obola
It makes perfect sense Erwin.Messily
I'll probably change the project requirementsMessily
Parsing the MPS file and solving the system are different problems. I think that parsing that should be easy with Python + PLY, but I could not guess exactly what are the 3 arrays that you want. I could have a try if you give me the exact result on this example.Sydney
Indeed no conceptual reason to have the MPS reader "close" to the solver. In practice, most solvers have MPS readers built-in. MPS files can become very large and we want to read these very fast and produce immediately a data structure (sparse matrix) suited for the solver (column wise storage of the nonzeros).Obola
@ErwinKalvelagen many languages have packages for reading and writing these files. But I cannot find anything for python.Messily
@SergeBallesta I think it may be a little bit hard to make a parser for this, if there is a package for it, it would be way betterMessily
Unfortunately, asking for libraries is explicitely off topic on SO. From the help center: Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spamSydney
Yes, I know, I want to parse this and I just said that other languages have libraries, it would be great if python had one but it does not in my knowledge. So if anyone has /knows a code for this it would be great.Messily
I will close this question Serge in a day or two if no one knows a wayMessily
V
2

The question does not address the specifics, e.g. pure python vs. c-wrapper-based, nor any license-issues.

But well... two things which worked for me in the past (the former was more tested for my own IPM-method on the netlib dataset; the latter looked good too):

Dirty code to use netlib's test cases with scipy's solvers based on the former approach.

cvxopt

MPS-reading is somewhat hidden here and here.

Looks pretty much python-only to me.

One should be careful about potentially modifications already done to the problem by cvxopt, at least when asking cvxopt for the matrix-form. I don't remember right now what to expect here (and it also did not matter much in my cases).

Warning: cvxopt is known for a non-trivial installation-process on windows, if you try to install the whole project!

There are also some warnings about what features of MPS-files are not supported.

GLPK + swiglpk

Basically swig-based bindings for GLPK. Available here (probably most newest python-bindings to GLPK). If using this, use it together with GLPK's manual and some understanding of SWIG (or else ).

This one should be more controllable in terms of what we read (see manual)!

Violaviolable answered 16/11, 2017 at 13:51 Comment(0)
J
1

You can use pysmps package in Python. It can simply be installed through pip install pysmps. Further details can be found in:

https://pypi.org/project/pysmps/

https://github.com/jmaerte/pysmps

Juju answered 11/3, 2021 at 9:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.