Skip to main content

Solve MILP CVXPY problems using python-mip

Project description


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.


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())

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()

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mip-cvxpy-0.0.2.tar.gz (4.3 kB view hashes)

Uploaded Source

Built Distribution

mip_cvxpy-0.0.2-py3-none-any.whl (8.6 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page