This package allows you to solve CVXPY problems using the python-mip package as a backend solver. It works for mixed integer linear problems.
This allows you to use CBC from CVXPY without needing to manually install CBC. By default, CVXOPT calls CyLP to use CBC and requires CBC to be manually installed. python-mip, on the other hand, comes with CBC bundled through pypi.
This package is based heavily off the CyLP/CBC interface and is slower: on smaller problems mip_cvxpy interface takes perhaps 1.3x as long as CyLP, and on larger problems perhaps 5x as long (see the benchmark in the test suite). CyLP has a significant advantage in natively supporting sparse matrices and vectorisation.
Install from pypi
pip install mip_cvxpy
Use as a custom solver
import numpy as np
import cvxpy as cp
from mip_cvxpy import PYTHON_MIP
n = int(1e3)
vars = cp.Variable(n, integer=True)
objective = cp.Maximize(cp.sum(vars))
constraints = [
vars[0] == 1,
vars <= np.linspace(10, n + 10, num=n),
]
problem = cp.Problem(objective, constraints)
optimal_value = problem.solve(solver=PYTHON_MIP())
print(problem.status)
You can pass additional solver options like
optimal_value = problem.solve(solver=solver, max_seconds=10, other_option=7)
This is equivalent to
import mip
m = mip.Model()
m.max_seconds=10
m.other_option=7
...