reading MIP model in python

57 views
Skip to first unread message

Hanan

unread,
Dec 4, 2017, 8:07:07 AM12/4/17
to Gurobi Optimization
Hi

I am trying to initialize a MIP model from a previous solution with a slightly modified objective to reduce the optimization time.
I've saved all possible file extensions, and was only able to read using model=read('model.mps')

I've read in another post that I should read the mst, however if i try: model=read('model.mst')
I get the following error message:
    model=read('model.mst')
  File "gurobi.pxi", line 2403, in gurobipy.read (../../src/python/gurobipy.c:120766)
  File "gurobi.pxi", line 66, in gurobipy.gurobi.read (../../src/python/gurobipy.c:118659)
gurobipy.GurobiError: Unable to read model

what is the correct way to reload the model with the previous solution?

Regards

Hanan

Hanan

unread,
Dec 5, 2017, 12:39:08 AM12/5/17
to Gurobi Optimization
after giving up on using the read method for the mst file
I went ahead and updated the model variables by reading the mst files
for each row of "var val":
t=model.getVarByName(var)
t.Start=int(val)

this did work, however I expected that optimizing the same, unmodified, model with  Start parameters set to the optimal solution would result in near instantaneous solution
however the optimization time was about the same

this is in contrast to calling optimize() a second time which returns immediately



בתאריך יום שני, 4 בדצמבר 2017 בשעה 15:07:07 UTC+2, מאת Hanan:

Sonja Mars

unread,
Dec 5, 2017, 12:42:34 AM12/5/17
to gur...@googlegroups.com
Hi Hanan,

There are two different read() methods. 

The first one is a model constructer. It can only be used with model files, like for example mps or lp. This is the one where you use model=read("myModel.mps")

The second one can be used to read additional information into the model. It belongs to the model class and it is used in this way:
model.read("myMipStart.mst")


Best regards, 
Sonja 


----
Dr. Sonja Mars
Gurobi Optimization - Technical Support 

Hanan

unread,
Dec 5, 2017, 4:35:39 AM12/5/17
to Gurobi Optimization
Hi Sonja

thanks for the api clarification
however, the performance is the same as with my manual updating of the variables Start parameter
what is the proper procedure to save a full solution after optimization of a MIP so that loading it would be solved (almost) instantly when the model is not modified?

best regards

Hanan


בתאריך יום שלישי, 5 בדצמבר 2017 בשעה 07:42:34 UTC+2, מאת Sonja Mars:

Sonja Mars

unread,
Dec 5, 2017, 4:45:32 AM12/5/17
to gur...@googlegroups.com
Hi,

I am sorry, but you cannot write the full state of a MIP solve to a file. For this you would have to not just save the solution but also the tree and the decisions made on the way. There is no such method in Gurobi.
Reply all
Reply to author
Forward
0 new messages