pulp icon indicating copy to clipboard operation
pulp copied to clipboard

Model Solution Status for Gurobi Seems Wrong

Open ebongo1 opened this issue 4 years ago • 4 comments

Details for the issue

I am running an optimization model and trying to get the status of the solution after it solves. I have just switched to checking the model.sol_status as opposed to model.status since those two things are not the same thing in PuLP. See below dictionaries for reference.

LpStatus: {0: 'Not Solved', 1: 'Optimal', -1: 'Infeasible', -2: 'Unbounded', -3: 'Undefined'}

LpSolution: {0: 'No Solution Found', 1: 'Optimal Solution Found', 2: 'Solution Found', -1: 'No Solution Exists', -2: 'Solution is Unbounded'}

I also noticed in the gurobi_api.py code that these are the Gurobi statuses used to set the various PuLP statuses:

gurobiLpStatus = { GRB.OPTIMAL: constants.LpStatusOptimal =1, GRB.INFEASIBLE: constants.LpStatusInfeasible = -1, GRB.INF_OR_UNBD: constants.LpStatusInfeasible = -1, GRB.UNBOUNDED: constants.LpStatusUnbounded = -2, GRB.ITERATION_LIMIT: constants.LpStatusNotSolved = 0, GRB.NODE_LIMIT: constants.LpStatusNotSolved = 0, GRB.TIME_LIMIT: constants.LpStatusNotSolved = 0, GRB.SOLUTION_LIMIT: constants.LpStatusNotSolved = 0, GRB.INTERRUPTED: constants.LpStatusNotSolved = 0, GRB.NUMERIC: constants.LpStatusNotSolved = 0 }

So the issue I am having is that I set a time limit on the solver to stop after a certain amount of time, and Gurobi has found some solution, however the model.sol_status is reporting -1 which is "No Solution Exists" which I don't think is correct. It should either be "No Solution Found" since it hasn't had enough time to finish solving to find one, or it should be "Solution Found" meaning it found a feasible solution, but just might not be optimal. I attached a screen shot of the command prompt output I am seeing. The Gurobi status for it is equal to 9 which means the time limit was reached (which is more accurate than saying the model is infeasible).

image

Useful extra information

I'm opening this issue because:

  • [x] PuLP has a bug
  • [ ] PuLP needs a feature
  • [x] PuLP has another problem

I'm using PuLP on:

  • [x] Windows: ( version: ___ )
  • [ ] Linux: ( distro: ___ )
  • [ ] Mac OS: ( version: ___ )
  • [ ] Other: ___

I'm using python version:

  • [ ] 2.7
  • [ ] 3.4
  • [ ] 3.5
  • [ ] 3.6
  • [x] Other: 3.7.6

I installed PuLP via:

  • [x] pypi (pip install pulp)
  • [ ] github (pip install -U git+https://github.com/coin-or/pulp)
  • [ ] Other: ___

I have also:

  • [ ] Tried out the latest github version: https://github.com/coin-or/pulp
  • [x] Searched for an existing similar issue: https://github.com/coin-or/pulp/issues?utf8=%E2%9C%93&q=is%3Aissue%20

ebongo1 avatar May 20 '21 13:05 ebongo1

From what I see in your logs, you actually found a solution (10, actually). Can you share the .mps file or .json file with the problem so we can see what went wrong? This page shows how: https://coin-or.github.io/pulp/guides/how_to_export_models.html

Also: What interface to gurobi are you using? Is it the GUROBI or the GUROBI_CMD? In case it's the former, we do not yet correctly identify the integer feasible status see https://github.com/coin-or/pulp/blob/799ee632cea4a297aa7ad9f25a27fb2ccbad1415/pulp/apis/gurobi_api.py#L114

try using GUROBI_CMD?

pchtsp avatar Jun 12 '21 17:06 pchtsp

It's been a few weeks since I moved on from this issue so I don't have the exact .mps file to share with you... and I am using GUROBI. I just tried to switch it to GUROBI_CMD and it gave me an error (attached picture of the error). And it would be really helpful to have that status available in the future. image

ebongo1 avatar Jun 15 '21 20:06 ebongo1

Hi, I have the same problem and I have not find a solution to this problem until now. I use gurobi in pulp and optimize a problemn with a rolling horizon method. The problem is a huge one, so I set a gap and a timelimit. Every time the timelimit is hit (gurobi status=9), pulp can not retrieve a solution. Hence, the values of the variables are "None".

CMueller12 avatar Oct 25 '22 07:10 CMueller12

Hi, I solve my problem by modifying gurobi_api.py. Instead of only "GRB.TIME_LIMIT: constants.LpStatusNotSolved" I changed it to two rows with " GRB.TIME_LIMIT and model.SolCount>0: constants.LpStatusOptimal, GRB.TIME_LIMIT and model.SolCount==0: constants.LpStatusNotSolved,"

CMueller12 avatar Mar 02 '23 08:03 CMueller12