'How to set Gurobi parameter in Pulp
I am using Pulp with Python to specify an LP problem. I want to solve this using Gurobi. The following does work:
prob.solve(pulp.GUROBI_CMD())
However, now I want to specify a MIP Gap. This should be a parameter of the Gurobi solver according to this page.
What is the syntax to define this parameter (at, say, 0.05)?
Edit: I checked this post, but none of the suggestions works:
- GUROBI_CMD(options=["MIPGap=0.9"] throws "ValueError: too many values to unpack (expected 2)"
- prob.solve(GUROBI(epgap = 0.9)) throws "pulp.solvers.PulpSolverError: GUROBI: Not Available." Moreover gurobipy cannot be installed ("No matching distribution found for gurobipy").
Hope anyone can give any suggestions on how to tackle this problem!
Solution 1:[1]
Brought to the idea in a previous comment that the syntax of the "options" parameter might by wrong (thanks!), I found that a correct syntax is:
prob.solve(pulp.GUROBI_CMD(options=[("MIPgap", 0.9)]))
This works! Thanks a lot.
Solution 2:[2]
I had the issue myself, but none of the proposed solutions worked. Especially since I tried to pass several parameters, I couldn't figure out the syntax from the proposed solutions.
Deriving from the error message that we need tuples, the following worked for me:
prob.solve(pulp.GUROBI_CMD(options=[('MIPGap', '0.004'), ("TimeLimit", "300"), ("MIPFocus", "1")]))
Hope this helps other people with the same error.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Jordi |
Solution 2 | Hannes |