Skip to main content

Python interface and modeling environment for SCIP

Project description

PySCIPOpt

This project provides an interface from Python to the SCIP Optimization Suite.

Gitter PySCIPOpt on PyPI TravisCI Status AppVeyor Status

Documentation

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.

Installation

Using Conda

Conda version Conda platforms

Conda will install SCIP automatically, hence everything can be installed in a single command:

conda install --channel conda-forge pyscipopt

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. Information which version of PySCIPOpt is required for a given SCIP version can also be found in INSTALL.md.

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:

  1. It is necessary to import python-scip in your code. This is achieved by including the line
from pyscipopt import Model
  1. Create a solver instance.
model = Model("Example")  # model name is optional
  1. Access the methods in the scip.pyx 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.

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.pxd and 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:

  1. Ensure any enums, structs 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.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.

Gotchas

Ranged constraints

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

Variable objects

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, since Variables are also Expr objects.

Dual values

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

Citing PySCIPOpt

Please cite this paper

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

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

PySCIPOpt-3.2.0.tar.gz (629.8 kB view details)

Uploaded Source

Built Distributions

PySCIPOpt-3.2.0-cp38-cp38-win_amd64.whl (584.9 kB view details)

Uploaded CPython 3.8 Windows x86-64

PySCIPOpt-3.2.0-cp37-cp37m-win_amd64.whl (556.1 kB view details)

Uploaded CPython 3.7m Windows x86-64

PySCIPOpt-3.2.0-cp36-cp36m-win_amd64.whl (555.6 kB view details)

Uploaded CPython 3.6m Windows x86-64

File details

Details for the file PySCIPOpt-3.2.0.tar.gz.

File metadata

  • Download URL: PySCIPOpt-3.2.0.tar.gz
  • Upload date:
  • Size: 629.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.8.1

File hashes

Hashes for PySCIPOpt-3.2.0.tar.gz
Algorithm Hash digest
SHA256 e882241016e1914aa40c82ca198d156a26f83ebf02acd9ec5b4b2cefb82d5611
MD5 dc70d66e37211dd9dd4e947ea4bce708
BLAKE2b-256 21a799192ef5e474463e51b34ec2e1ac8981507bfd351da132c96178cf00c5b5

See more details on using hashes here.

File details

Details for the file PySCIPOpt-3.2.0-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: PySCIPOpt-3.2.0-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 584.9 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.8.0

File hashes

Hashes for PySCIPOpt-3.2.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 8fe8201c881448494854d8d45b0ad0061a9d6b8f77672f2354f9638d00857d3f
MD5 39fdedebe3833ae856e6af84651cf457
BLAKE2b-256 ff41ac3c84e179164d4a3874c20e0edfb67204a8cfd1bec855d6270d7e26e23c

See more details on using hashes here.

File details

Details for the file PySCIPOpt-3.2.0-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: PySCIPOpt-3.2.0-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 556.1 kB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.7.5

File hashes

Hashes for PySCIPOpt-3.2.0-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 537eb7e7b716d91d79cfeea7bf425d0e5433c901928bc1d39f71633558f1ee8c
MD5 f639bdceac712a90d22ca70e1ca30fb3
BLAKE2b-256 c2c1c83d29d59bac37c1e60195df91324c5c28a0e94a95d02db72c643b0466cd

See more details on using hashes here.

File details

Details for the file PySCIPOpt-3.2.0-cp36-cp36m-win_amd64.whl.

File metadata

  • Download URL: PySCIPOpt-3.2.0-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 555.6 kB
  • Tags: CPython 3.6m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.6.8

File hashes

Hashes for PySCIPOpt-3.2.0-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 5a6eb96e86120cdc5439bd93f9b1a9856bff4b07b9737558870fc2bf00d4821b
MD5 4b1c57e530a6b600e0228e65f920b372
BLAKE2b-256 3fb63765b1388777494e1211b73c55cc6754b85c0313bc313f5ccc27818709c3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page