Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the relative MIP optimality gap after timelimit is met?

Tags:

python

gurobi

I'm working on a large scale MIP. So I have to set the time limit to a reasonable value. But the problem is that after the timelimit is met, I don't know how to evaluate the solution, in another words, the gap between lower and upper bounds. Yes, the gap will be shown on screen. But if there is a way to get its value with Python API? So I can output it or do some following statistcs. I have to solve more than 10 MIP at once, it's hard to find the gaps one by one on screen. Thx for your help!

like image 855
R. Song Avatar asked Dec 15 '25 20:12

R. Song


1 Answers

Your tags indicate that you are using Gurobi with the Python API to solve your models.

To retrieve the relative MIP gap, you can query the MIPGap attribute (see http://www.gurobi.com/documentation/6.5/refman/mipgap.html)

Python example:

from gurobipy import *

model = read("model.mps")
model.params.TimeLimit = 100
model.optimize()
print("Final MIP gap value: %f" % model.MIPGap)
like image 153
Kostja Avatar answered Dec 17 '25 11:12

Kostja



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!