To avoid interfering with system packages, it's best to use a virtual environment:
python3 -m venv venv # creates a virtual environment called venv
source venv/bin/activate # activates the environment. On Windows use: venv\Scripts\activate
pip install pyscipopt
Remember to activate the environment (source venv/bin/activate or equivalent) in each terminal session where you use PySCIPOpt.
Note that some configurations require the use of virtual environments.
For information on specific versions, installation via Conda, and guides for building from source,
please see the online documentation.
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. 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:
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.pxi file using the solver/model
instance model, e.g.:
x = model.addVar("x")
y = model.addVar("y", vtype="INTEGER")
model.setObjective(x + y)
model.addCons(2*x - y*y >= 0)
model.optimize()
sol = model.getBestSol()
print("x: {}".format(sol[x]))
print("y: {}".format(sol[y]))
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_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.
Using PySCIPOpt?
If your project or company is using PySCIPOpt, consider letting us know at scip@zib.de. We are always interested
in knowing how PySCIPOpt is being used, and, given permission, would also appreciate adding your company's logo
to our website.
If you are creating models with some degree of complexity which don't take too long to solve, also consider
sharing them with us. We might want to add them to tests/helpers/utils.py to help make our tests more robust, or add them to our examples.
@incollection{MaherMiltenbergerPedrosoRehfeldtSchwarzSerrano2016,
author = {Stephen Maher and Matthias Miltenberger and Jo{\~{a}}o Pedro Pedroso and Daniel Rehfeldt and Robert Schwarz and Felipe Serrano},
title = {{PySCIPOpt}: Mathematical Programming in Python with the {SCIP} Optimization Suite},
booktitle = {Mathematical Software {\textendash} {ICMS} 2016},
publisher = {Springer International Publishing},
pages = {301--307},
year = {2016},
doi = {10.1007/978-3-319-42432-3_37},
}
as well as the corresponding SCIP Optimization Suite report when you use this tool for a publication or other scientific work.
Seeking Maintainers
PySCIPOpt is sustained by volunteer effort, and as the project grows we are inviting more contributors and maintainers to join the team.
What needs to be done
These are the core responsibilities:
Community support: Going over the open issues regularly. Occasionally visiting Stack Overflow and OR.SE, as users also ask questions there.
PR review: Reviewing user pull requests, making sure that the CHANGELOG is updated, and all added methods are tested.
API coverage: keep expanding PySCIPOpt's coverage of SCIP's C API.
Documentation: help keep the documentation up to date, and add new tutorials/examples.
Releases: there should be a PySCIPOpt release with every SCIP release, at a minimum.
Even if you are not interested in becoming a maintainer, but would like to help out occasionally, that would be very welcome as well!