Python interface and modeling environment for SCIP
This project provides an interface from Python to the SCIP Optimization Suite.
Please consult the online documentation or use the
help() function directly in Python or
? in IPython/Jupyter.
See INSTALL.md for instructions.
Building and solving a model
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. 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:
- It is necessary to import python-scip in your code. This is achieved by including the line
from pyscipopt import Model
- Create a solver instance.
model = Model("Example") # model name is optional
- Access the methods in the
scip.pyxfile using the solver/model instance
x = model.addVar("x") y = model.addVar("y", vtype="INTEGER") model.setObjective(x + y) model.addCons(2*x - y*y >= 0) model.optimize()
Writing new plugins
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_heur.py for two simple
Please notice that in most cases one needs to use a
specify the return values needed by SCIP.
Extending the interface
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.pyx. 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:
- Ensure any
structs or SCIP variable types are included in
- Add the prototype of the public function you wish to access to
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.pyx 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
lhs <= expression <= rhs
are supported, the Python syntax for chained comparisons can't be hijacked with operator overloading. Instead, parenthesis must be used, e.g.,
lhs <= (expression <= rhs)
Alternatively, you may call
model.chgRhs(cons, newrhs) or
model.chgLhs(cons, newlhs) after the single-sided constraint has been
You can't use
Variable objects as elements of
sets or as keys of
dicts. They are not hashable and comparable. The issue is that
comparisons such as
x == y will be interpreted as linear constraints,
Variables are also
While PySCIPOpt supports access to the dual values of a solution, there are some limitations involved:
- Can only be used when presolving and propagation is disabled to ensure that the LP solver - which is providing the dual information - actually solves the unmodified problem.
- Heuristics should also be disabled to avoid that the problem is solved before the LP solver is called.
- There should be no bound constraints, i.e., constraints with only one variable. This can cause incorrect values as explained in #136
Therefore, you should use the following settings when trying to work with dual information:
model.setPresolve(pyscipopt.SCIP_PARAMSETTING.OFF) model.setHeuristics(pyscipopt.SCIP_PARAMSETTING.OFF) model.disablePropagation()
Release history Release notifications
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size & hash SHA256 hash help||File type||Python version||Upload date|
|PySCIPOpt-2.1.5-cp27-cp27m-win_amd64.whl (549.9 kB) Copy SHA256 hash SHA256||Wheel||cp27|
|PySCIPOpt-2.1.5-cp35-cp35m-win_amd64.whl (523.9 kB) Copy SHA256 hash SHA256||Wheel||cp35|
|PySCIPOpt-2.1.5-cp36-cp36m-win_amd64.whl (567.9 kB) Copy SHA256 hash SHA256||Wheel||cp36|
|PySCIPOpt-2.1.5.tar.gz (546.5 kB) Copy SHA256 hash SHA256||Source||None|