pip install mip
If the command fails, it may be due to lack of permission to install globally available Python modules. In this case, use:
pip install mip --user
The default installation includes pre-compiled libraries of the MIP Solver CBC for Windows, Linux and MacOS. If you have the commercial solver Gurobi installed in your computer, Python-MIP will automatically use it as long as it finds the Gurobi dynamic loadable library. Gurobi is free for academic use and has an outstanding performance for solving MIPs. Instructions to make it accessible on different operating systems are included bellow.
Gurobi Installation and Configuration (optional)¶
For the installation of Gurobi you can look at the Quickstart guide for your operating system. Python-MIP will automatically find your Gurobi installation as long as you define the
GUROBI_HOME environment variable indicating where Gurobi was installed.
Pypy installation (optional)¶
Python-MIP is compatible with the just-in-time Python compiler Pypy.
Generally, Python code executes much faster in Pypy.
Pypy is also more memory efficient.
To install Python-MIP as a Pypy package, just call (add
--user may be necessary also):
pypy3 -m pip install mip
Using your own CBC binaries (optional)¶
Python-MIP provides CBC binaries for 64 bits versions of MacOS, Linux and Windows that run on Intel hardware. These binaries may not be suitable for you in some cases:
if you plan to use Python-MIP in another platform, such as the Raspberry Pi, a 32 bits operating system or FreeBSD, for example;
if you want to build CBC binaries with special optimizations for your hardware, i.e., using the
-march=nativeoption in GCC, you may also want to enable some optimizations for CLP, such as the use of the parallel
AVX2instructions, available in modern hardware;
if you want use CBC binaries built with debug information, to help elucidating some bug.
In the CBC page page there are instructions on how to build CBC from source on Unix like platforms and on Windows. Coinbrew is a script that makes it easier the task of downloading and building CBC and its dependencies. The commands bellow can be used to download and build CBC on Ubuntu Linux, slightly different packages names may be used in different distributions. Comments are included describing some possible customizations.
# install dependencies to build sudo apt-get install gcc g++ gfortran libgfortran-9-dev liblapack-dev libamd2 libcholmod3 libmetis-dev libsuitesparse-dev libnauty2-dev git # directory to download and compile CBC mkdir -p ~/build ; cd ~/build # download latest version of coinbrew wget -nH https://raw.githubusercontent.com/coin-or/coinbrew/master/coinbrew # download CBC and its dependencies with coinbrew bash coinbrew fetch Cbc@master --no-prompt # build, replace prefix with your install directory, add --enable-debug if necessary bash coinbrew build Cbc@master --no-prompt --prefix=/home/haroldo/prog/ --tests=none --enable-cbc-parallel --enable-relocatable
Python-MIP uses the
CbcSolver shared library to communicate with CBC. In Linux, this file is named
libCbcSolver.so, in Windows and MacOS the extension should be
.dylp, respectively. To force Python-MIP to use your freshly compiled CBC binaries, you can set the
PMIP_CBC_LIBRARY environment variable, indicating the full path to this shared library. In Linux, for example, if you installed your CBC binaries in
/home/haroldo/prog/, you could use:
Please note that CBC uses multiple libraries which are installed in the same directory. You may also need to set one additional environment variable specifying that this directory also contains shared libraries that should be accessible. In Linux and MacOS this variable is
LD_LIBRARY_PATH, on Windows the
PATH environment variable should be set.
In Linux, to make these changes persistent, you may also want to add the
export lines to your