coin-or / coin-or/pulp

Model Solution Status for Gurobi Seems Wrong

Open
#445 4 comments 0 reactions 0 assignees View on GitHub
gurobi
Dominant language
Python
Stars
2.5k
Forks
432
PR merge metrics
No merged PRs in 30d

Description

### 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](https://user-images.githubusercontent.com/83773112/118991169-7ddc2100-b951-11eb-9168-53da7736e327.png)

### 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

Contributor guide

Open the contributing guide

Research direction

Start in gurobi_api.py by tracing how Gurobi status 9 is converted into model.status and model.sol_status after a time-limited solve. Reproduce the reported case with a feasible solution, then verify that the resulting PuLP status distinguishes no solution from a solution found before adding or updating tests for the mapping.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend-api-design
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.