0

How can I pass the environment parameters, like the time_limit or optimality gap for GUROBI solver in cvxpy?

Here is what I tried according to cvxpy documentation which gives this error: AttributeError: 'dict' object has no attribute '_cenv'

import cvxpy as cp
problem = cp.Problem(objective, constraints)

...

env = {
    "time_limit": 1
}
problem.solve(solver='GUROBI', env=env)

The process for CPLEX is more straightforward I guess. I couldn't find a solution for GUROBI though.

BehRouz
  • 1,209
  • 1
  • 8
  • 17

1 Answers1

0

GUROBI has an Env method which can be accessed in python with gurobipy. Env shouldn't be a dict.

Here is what I did:

import gurobipy
import cvxpy as cp
problem = cp.Problem(objective, constraints)

...

env = gurobipy.Env()
env.setParam('TimeLimit', 10) # in seconds

problem.solve(solver='GUROBI', env=env)

BehRouz
  • 1,209
  • 1
  • 8
  • 17