Skip to content

coinor_cbc interface gives incorrect solutions for MIP problems #236

Open
@cdiener

Description

@cdiener

Problem description

The coinor_cbc interface will give incorrect solutions. Sometimes this happens on the first optimizations and sometimes on later ones, but it is definitely inconsistent.

Code Sample

Create a minimal, complete, verifiable example.

In [1]: from cobra.test import create_test_model

In [2]: from cobra.medium import minimal_medium

In [3]: mod = create_test_model("textbook")

In [4]: mod.solver
Out[4]: <optlang.cplex_interface.Model at 0x7f3c1bba5cd0>

In [5]: minimal_medium(mod, 0.1, minimize_components=True)
Out[5]: 
EX_glc__D_e    10.000000
EX_nh4_e        2.866361
EX_pi_e         0.367870
dtype: float64

In [6]: minimal_medium(mod, 0.1, minimize_components=True)
Out[6]: 
EX_glc__D_e    10.000000
EX_nh4_e        2.866361
EX_pi_e         0.367870
dtype: float64

In [7]: mod.solver = "coinor_cbc"
OSQP and CBC are specialized solvers for quadratic programming (QP) and mixed-integer programming (MIP) problems and may not perform well on general LP problems. So unless you intend to solve a QP or MIP problem, we recommend to change the solver back to a general purpose solver like `model.solver = 'glpk'` for instance.

In [8]: mod.optimize()
Out[8]: <Solution 0.874 at 0x7f3c1baa6cd0>

In [9]: minimal_medium(mod, 0.1, minimize_components=True)
Out[9]: 
EX_glc__D_e    8.259189
EX_nh4_e       0.545280
EX_pi_e        0.367870
dtype: float64

In [10]: minimal_medium(mod, 0.1, minimize_components=True)
Out[10]: 
EX_glc__D_e    2.389862
EX_nh4_e       0.545280
EX_o2_e        3.484045
EX_pi_e        0.367870
dtype: float64

This should always return a solution with 3 components.

Context

optlang has no show_versions.... need to fix the template here.

It is optlang 1.5.1 with cobra 0.22 though.

The cbc interface also fails a lot of other cobrapy tests due to some bugs in the interface, For instance gapfilling will expose a bug where variables are added twice.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions