python-mip icon indicating copy to clipboard operation
python-mip copied to clipboard

Model read .mps file appears to not work

Open mlk621 opened this issue 5 years ago • 2 comments

Describe the bug I am using the Model.read function as described in the Quick Start guide under "Saving, Loading and Checking Model Properties." The description says that it works to load a .mps file. I have a .mps file describing a model I'd like to use. When I use the function as the directions give, it appears the file isn't loaded. Nothing about the problem is available in the model object, it gives 0 rows, 0 columnst, etc.

To Reproduce My .mps file contents are below. This file type isn't supported to upload, so copy-pasting here instead. Github does some odd things for the formatting... This is a much smaller file that produces the same error, than the one I'd like to eventually load.

NAME SETPAR ROWS N OBJ E c1 E c2 COLUMNS INT1 'MARKER' 'INTORG' x1 OBJ 1 x1 c1 1 x2 OBJ 1 x2 c1 1 x3 OBJ 1
x3 c1 1 x4 OBJ 1 x4 c1 1 x5 OBJ 1
x5 c1 1 x6 OBJ 1 x6 c2 1 x7 OBJ 1 x7 c2 1 x8 OBJ 1 x8 c2 1 x9 OBJ 1 x9 c2 1 x10 OBJ 1 x10 c2 1

INT1END   'MARKER'                 'INTEND'

RHS RHS1 c1 1 RHS1 c2 1 ENDATA

Here's the code I use. The attributes that get printed are all 0, as if nothing was loaded from the file. Also, I've noted that in examples "from mip import " is used. This is not good python programming as we don't know what is loaded by "" and should be avoided. It would be better to offer a standard like "import mip" since then when functions are called such as "mip.Model()" we know exactly where Model came from.

`# import mip from mip import *

file_dir = '/my/file/dir/' f_name = 'testsetpartition.mps'

m = Model() m.read(file_dir+f_name)

print("Model name:", m.name) print("Number of variables (columns):", m.num_cols) print("Number of rows:", m.num_rows) print("Number of nz:", m.num_nz) print("Number of :", m.num_int)`

Expected behavior I expected to be able to load the model and so m.numcols, for example should return 10.

Desktop (please complete the following information):

  • Operating System, version: Windows 10, version 1809
  • Python version: 3.6.10 |Anaconda, Inc.| (default, May 7 2020, 19:46:08) [MSC v.1916 64 bit (AMD64)]
  • Python-MIP version (we recommend you to test with the latest version): 1.10.0

Additional context I just installed this today. This is the first time I'm attempting to use python mip.

mlk621 avatar Jul 27 '20 19:07 mlk621

Hello @mlk621 ! Could you attach the mps file, so that I can check here ?

h-g-s avatar Jul 28 '20 00:07 h-g-s

Hi @h-g-s! Github wouldn't let me attach the .mps file directly. It said that file format isn't allowed. I had just copy-pasted a very small example above into the comment, but it didn't format correctly either with the "code" format or just as text.

I've attached my small toy problem that produces the same error as a .txt file here, so you'll just have to save it as a .mps file. testsetpartition.txt

mlk621 avatar Jul 28 '20 15:07 mlk621