Leevi L
Leevi L

Reputation: 1809

How to set a timeout for gurobi using python

I want to solve ILPs using the python interface to gurobi. I also want to set a timeout of 5 minutes. I tried

e = gurobipy.Env()
e.setParam('TimeLimit', 5*60)
m = gurobipy.Model(env=e)

but i get the error

File "env.pxi", line 18, in gurobipy.Env.init (../../src/python/gurobipy.c:2821) TypeError: init() takes exactly 2 positional arguments (1 given)

although according to the documentation gurobipy.Env() doesn't have parameters without default values. Also, in the documentation it says

Env() creates a client environment on a compute server.

so I am wondering if this is even the most efficient way to set a simple time limit for gurobi. What's a good way to timelimit gurobipy?

Upvotes: 6

Views: 13109

Answers (1)

Leevi L
Leevi L

Reputation: 1809

simply set the time limit on the model itself:

m = gurobipy.model()
m.setParam('TimeLimit', 5*60)

Upvotes: 13

Related Questions