Skip to main content

Solve MILP CVXPY problems using python-mip

Project description

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

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

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

Details for the file mip-cvxpy-0.0.2.tar.gz.

File metadata

  • Download URL: mip-cvxpy-0.0.2.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/54.1.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.7.10

File hashes

Hashes for mip-cvxpy-0.0.2.tar.gz
Algorithm Hash digest
SHA256 a259a7d94494be5461a7554a797ebd47ccf9e7aaacb03696ebf41599981b908b
MD5 b386205902f3ccdc8d3cfe363153aa52
BLAKE2b-256 2c2e19ee1cb6a634b09f681d2c83fbdb2b7a2d4c0bf7a92a5fd24cbe17b20c22

See more details on using hashes here.

File details

Details for the file mip_cvxpy-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: mip_cvxpy-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 8.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/54.1.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.7.10

File hashes

Hashes for mip_cvxpy-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 bee6f3fc6147d2bdc0d1a58a2bf371248434536d6de3583e6b258f6c66dd514f
MD5 44baa1a7d0194e39efa1dfe1f73d1aba
BLAKE2b-256 8f9dec0d980692d72f3e1fef54c3cc9362182a6c2606b39b3ceee11025fb1980

See more details on using hashes here.

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