3

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!

Jordi
  • 361
  • 1
  • 4
  • 14
  • Possible duplicate of [How to pass MIP gap parameter to Gurobi with PULP](https://stackoverflow.com/questions/46374529/how-to-pass-mip-gap-parameter-to-gurobi-with-pulp) – abc Jan 08 '19 at 20:10
  • Thanks for the suggestion. However, I checked out this post already and both options mentioned in the post don't seem to work for me. In particular, GUROBI_CMD(options=["MIPGap=0.9"] throws "ValueError: too many values to unpack (expected 2)" and GUROBI(epgap=0.9) throws "pulp.solvers.PulpSolverError: GUROBI: Not Available." Moreover gurobipy cannot be installed ("No matching distribution found for gurobipy"). So none of the options works... – Jordi Jan 09 '19 at 08:13
  • what about `GUROBI_CMD(options=["MIPGap","0.9"])`? I don't have Gurobi installed so I cannot try. – abc Jan 09 '19 at 08:17
  • Thanks again for your quick reply. Throws the same error: "ValueError: too many values to unpack (expected 2)" – Jordi Jan 09 '19 at 08:18
  • 1
    The pulp code creating options does `cmd += ' ' + ' '.join(['%s=%s' % (key, value) for key, value in options])` so `GUROBI_CMD(options=[("MIPGap","0.9")])` should work – abc Jan 09 '19 at 08:25

2 Answers2

4

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.

Jordi
  • 361
  • 1
  • 4
  • 14
1

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.

Hannes
  • 11
  • 1