This project provides an interface from Python to the SCIP Optimization Suite. Starting from v8.0.3, SCIP uses the Apache2.0 license. If you plan to use an earlier version of SCIP, please review SCIP's license restrictions.
Please consult the online documentation or use the help()
function directly in Python or ?
in IPython/Jupyter.
See CHANGELOG.md for added, removed or fixed functionality.
Using Conda
DO NOT USE THE CONDA BASE ENVIRONMENT TO INSTALL PYSCIPOPT.
Conda will install SCIP automatically, hence everything can be installed in a single command:
Using PyPI and from Source
See INSTALL.md for instructions. Please note that the latest PySCIPOpt version is usually only compatible with the latest major release of the SCIP Optimization Suite. The following table summarizes which version of PySCIPOpt is required for a given SCIP version:
SCIP | PySCIPOpt |
---|---|
9.1 | 5.1+ |
9.0 | 5.0.x |
8.0 | 4.x |
7.0 | 3.x |
6.0 | 2.x |
5.0 | 1.4, 1.3 |
4.0 | 1.2, 1.1 |
3.2 | 1.0 |
Information which version of PySCIPOpt is required for a given SCIP version can also be found in INSTALL.md.
There are several examples and tutorials. These display some functionality of the interface and can serve as an entry point for writing more complex code. Some of the common usecases are also available in the recipes sub-package. You might also want to have a look at this article about PySCIPOpt: https://opus4.kobv.de/opus4-zib/frontdoor/index/index/docId/6045. The following steps are always required when using the interface:
1) It is necessary to import python-scip in your code. This is achieved by including the line
2) Create a solver instance.
3) Access the methods in the scip.pxi
file using the solver/model instance model
, e.g.:
The Python interface can be used to define custom plugins to extend the functionality of SCIP. You may write a pricer, heuristic or even constraint handler using pure Python code and SCIP can call their methods using the callback system. Every available plugin has a base class that you need to extend, overwriting the predefined but empty callbacks. Please see test_pricer.py
and test_heur.py
for two simple examples.
Please notice that in most cases one needs to use a dictionary
to specify the return values needed by SCIP.
PySCIPOpt already covers many of the SCIP callable library methods. You may also extend it to increase the functionality of this interface. The following will provide some directions on how this can be achieved:
The two most important files in PySCIPOpt are the scip.pxd
and scip.pxi
. These two files specify the public functions of SCIP that can be accessed from your python code.
To make PySCIPOpt aware of the public functions you would like to access, you must add them to scip.pxd
. There are two things that must be done in order to properly add the functions:
1) Ensure any enum
s, struct
s or SCIP variable types are included in scip.pxd
2) Add the prototype of the public function you wish to access to scip.pxd
After following the previous two steps, it is then possible to create functions in python that reference the SCIP public functions included in scip.pxd
. This is achieved by modifying the scip.pxi
file to add the functionality you require.
We are always happy to accept pull request containing patches or extensions!
Please have a look at our contribution guidelines.
While ranged constraints of the form
are supported, the Python syntax for chained comparisons can't be hijacked with operator overloading. Instead, parenthesis must be used, e.g.,
Alternatively, you may call model.chgRhs(cons, newrhs)
or model.chgLhs(cons, newlhs)
after the single-sided constraint has been created.
You can't use Variable
objects as elements of set
s or as keys of dict
s. They are not hashable and comparable. The issue is that comparisons such as x == y
will be interpreted as linear constraints, since Variable
s are also Expr
objects.
While PySCIPOpt supports access to the dual values of a solution, there are some limitations involved:
Therefore, you should use the following settings when trying to work with dual information:
Please cite this paper
as well as the corresponding SCIP Optimization Suite report when you use this tool for a publication or other scientific work.