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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions mip/cbc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1108,9 +1108,13 @@ def cbc_cut_callback(osi_solver, osi_cuts, app_data, depth, npass):

return OptimizationStatus.OPTIMAL
if res == 2:
return OptimizationStatus.UNBOUNDED
if res == 3:
return OptimizationStatus.INFEASIBLE
if res == 3:
# Dual is infeasible. Primal can be infeasible or unbounded.
if cbclib.Cbc_isProvenInfeasible(self._model):
return OptimizationStatus.INFEASIBLE
else:
return OptimizationStatus.UNBOUNDED
return OptimizationStatus.ERROR

# adding cut generators
Expand Down
50 changes: 49 additions & 1 deletion test/mip_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pytest
import networkx as nx
from mip import Model, xsum, OptimizationStatus, MAXIMIZE, BINARY, INTEGER
from mip import ConstrsGenerator, CutPool, maximize, CBC, GUROBI, Column
from mip import ConstrsGenerator, CutPool, maximize, minimize, CBC, GUROBI, Column
from os import environ
import math

Expand Down Expand Up @@ -653,3 +653,51 @@ def test_float(solver: str, val: int):
assert y.x == float(y)
# test linear expressions.
assert float(x + y) == (x + y).x

@pytest.mark.parametrize("solver", SOLVERS)
def test_relaxed_model_infeasible(solver: str):
"""Tests for infeasible relaxed models"""
m = Model(solver_name=solver)
x = m.add_var(lb=0, ub=math.inf, var_type=INTEGER)
m += x >= 1
m += x <= -1
m.objective = maximize(x)
assert m.optimize(relax=True) == OptimizationStatus.INFEASIBLE

m = Model(solver_name=solver)
x = m.add_var(lb=0, ub=math.inf, var_type=INTEGER)
m += x >= 1
m += x <= -1
m.objective = minimize(x)
assert m.optimize(relax=True) == OptimizationStatus.INFEASIBLE

m = Model(solver_name=solver)
x = m.add_var(lb=0, ub=math.inf, var_type=INTEGER)
y = m.add_var(lb=0, ub=math.inf, var_type=INTEGER)
m += x + y <= 1
m += x + y >= 2
m.objective = maximize(x)
assert m.optimize(relax=True) == OptimizationStatus.INFEASIBLE

@pytest.mark.parametrize("solver", SOLVERS)
def test_relaxed_model_unbounded(solver: str):
"""Tests for unbounded relaxed models"""
m = Model(solver_name=solver)
x = m.add_var(lb=-math.inf, ub=math.inf, var_type=INTEGER)
m.objective = minimize(x)
assert m.optimize(relax=True) == OptimizationStatus.UNBOUNDED

m = Model(solver_name=solver)
x = m.add_var(lb=0, ub=math.inf, var_type=INTEGER)
m += x >= 10
m.objective = maximize(x)
assert m.optimize(relax=True) == OptimizationStatus.UNBOUNDED

@pytest.mark.parametrize("solver", SOLVERS)
def test_relaxed_model_optimal(solver: str):
"""Tests for optimal relaxed models"""
m = Model(solver_name=solver)
x = m.add_var(lb=0, ub=math.inf, var_type=INTEGER)
m += x >= 2
m.objective = minimize(x)
assert m.optimize(relax=True) == OptimizationStatus.OPTIMAL