简体   繁体   中英

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?

simply set the time limit on the model itself:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM