Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: unbounded/infeasible status mismatch for CBC relaxed models #342

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

modosist
Copy link

@modosist modosist commented Apr 2, 2023

Hi, thanks for the awesome work on the library! I believe that I found a small bug in handling of result from CBC relaxed models.

Current version of python-mip (tested version 1.15.0 on Apple M1) does not work correctly for the relaxations of following ILPs

import mip
m = mip.Model(solver_name="CBC")
x = m.add_var(var_type=mip.INTEGER)
m += x >= 1
m += x <= -1
m.objective = mip.maximize(x)
print(m.optimize(relax=True))
# returns OptimizationStatus.UNBOUNDED, although program is infeasible
import mip
m = mip.Model(solver_name="CBC")
x = m.add_var(var_type=mip.INTEGER)
m.objective = mip.maximize(x)
print(m.optimize(relax=True))
# returns OptimizationStatus.INFEASIBLE, although program is unbounded

Comparing the python-mip CBC solver

python-mip/mip/cbc.py

Lines 1110 to 1113 in 6044fc8

if res == 2:
return OptimizationStatus.UNBOUNDED
if res == 3:
return OptimizationStatus.INFEASIBLE

and actual CBC code for Cbc_solveLinearProgram

https://github.com/coin-or/Cbc/blob/f3a8af7b627ac068853d847c67d05614dcd99d39/src/Attic/Cbc_C_Interface.cpp#L1753-L1761

I concluded that the status codes for infeasible and unbounded programs are swapped in the python-mip code. Moreover, looking at CBC code, I believe that status 3 from Cbc_solveLinearProgram should be interpreted as primal formulation is either unbounded or infeasible (as dual infeasibility may lead primal to be either unbounded or infeasible); however, I could not find documentation for CBC on these status codes so I cannot be certain what the CBC developers meant by this status code. Therefore, I added a followup check for this status code to see whether the primal formulation is infeasible or unbounded.

I never worked with CBC before so hopefully I did not miss some detail.

@CLAassistant
Copy link

CLAassistant commented Apr 2, 2023

CLA assistant check
All committers have signed the CLA.

@sebheger
Copy link
Collaborator

sebheger commented Apr 3, 2023

@modosist Thanks for fixing this bug. Would you please add the tests you posted to the code base?

@modosist
Copy link
Author

modosist commented Apr 4, 2023

@modosist Thanks for fixing this bug. Would you please add the tests you posted to the code base?

Sure, I will prepare some tests! Hopefully I will get to it within a week.

BTW: I found out that similar issue is also within Gurobi wrapper (although it is not related to relaxed models)

python-mip/mip/gurobi.py

Lines 777 to 778 in 6044fc8

if status == 4: # INF_OR_UNBD
return OptimizationStatus.UNBOUNDED

However, this one probably needs more discussion: should python-mip also return UNBOUNDED_OR_INFEASIBLE status or should python-mip check which of the outcomes actually holds? I do not know whether Gurobi has similar API to asking for primal formulation infeasibility, but their recommendation is to re-run the optimization with setting of specific parameter see here. Should I open an issue for this?

@rschwarz
Copy link
Contributor

rschwarz commented Apr 4, 2023

BTW: I found out that similar issue is also within Gurobi wrapper

Yes, and something related happens with the (WIP) HiGHS wrapper as well. The status codes from the solver and the mip library don't map one-to-one, see

python-mip/mip/highs.py

Lines 1005 to 1008 in 9082252

self._lib.kHighsModelStatusInfeasible: OS.INFEASIBLE,
self._lib.kHighsModelStatusUnboundedOrInfeasible: OS.UNBOUNDED,
# ... or should it be INFEASIBLE?
self._lib.kHighsModelStatusUnbounded: OS.UNBOUNDED,

@sebheger
Copy link
Collaborator

sebheger commented Apr 4, 2023

Might be closely related to this here #285

@modosist
Copy link
Author

modosist commented Apr 7, 2023

I added a few tests for the relaxed models. The tests will fail on Gurobi (and looking at code from @rschwarz , HiGHS should fail as well). I will address the remaining solvers in another issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants