Skip to content

jurasofish/mip_cvxpy

Repository files navigation

mip-cvxpy

PyPI | Test

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.

Installation

Install from pypi

pip install mip_cvxpy

Usage

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)

Additional solver options

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

About

Solve MILP CVXPY problems using python-mip

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages