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.

Installation

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:

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

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

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-2.1.8.tar.gz (560.5 kB view details)

Uploaded Source

Built Distributions

PySCIPOpt-2.1.8-cp36-cp36m-win_amd64.whl (579.2 kB view details)

Uploaded CPython 3.6m Windows x86-64

PySCIPOpt-2.1.8-cp35-cp35m-win_amd64.whl (535.0 kB view details)

Uploaded CPython 3.5m Windows x86-64

PySCIPOpt-2.1.8-cp27-cp27m-win_amd64.whl (560.6 kB view details)

Uploaded CPython 2.7m Windows x86-64

File details

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

File metadata

  • Download URL: PySCIPOpt-2.1.8.tar.gz
  • Upload date:
  • Size: 560.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.1.0 requests-toolbelt/0.9.1 tqdm/4.34.0 CPython/2.7.15

File hashes

Hashes for PySCIPOpt-2.1.8.tar.gz
Algorithm Hash digest
SHA256 97f12fae64f314ba83acc4582d39ce3253285018550a192817da9af3aa02a2d1
MD5 c770393e431ea6b32be91ce4c270bb60
BLAKE2b-256 24e3fce4f55ccba987110c14465cac36a80dd636317480cc632c5671289592a3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: PySCIPOpt-2.1.8-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 579.2 kB
  • Tags: CPython 3.6m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.34.0 CPython/3.6.8

File hashes

Hashes for PySCIPOpt-2.1.8-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 63cc01e6ee0d358b2d6dfb4b87183856ce26bea5aa7fa3abfce3a50766ec2844
MD5 249d15d8321728783966553fa0b6fd8b
BLAKE2b-256 c921d5dd4509143f87dde6e6002864fea82c167ea46760787912cf23ea5bc543

See more details on using hashes here.

File details

Details for the file PySCIPOpt-2.1.8-cp35-cp35m-win_amd64.whl.

File metadata

  • Download URL: PySCIPOpt-2.1.8-cp35-cp35m-win_amd64.whl
  • Upload date:
  • Size: 535.0 kB
  • Tags: CPython 3.5m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/28.8.0 requests-toolbelt/0.9.1 tqdm/4.34.0 CPython/3.5.4

File hashes

Hashes for PySCIPOpt-2.1.8-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 93c9462906a4464e52e2466493ee4c77b7abe210f3f96679c79a90332c1b6ea3
MD5 a73166fad97691531545e5a7e63da7a4
BLAKE2b-256 c9b40f4d38bca547a4edb1da73b2da13c6a7db5b77db23044f2afc87fc00be11

See more details on using hashes here.

File details

Details for the file PySCIPOpt-2.1.8-cp27-cp27m-win_amd64.whl.

File metadata

  • Download URL: PySCIPOpt-2.1.8-cp27-cp27m-win_amd64.whl
  • Upload date:
  • Size: 560.6 kB
  • Tags: CPython 2.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.34.0 CPython/2.7.16

File hashes

Hashes for PySCIPOpt-2.1.8-cp27-cp27m-win_amd64.whl
Algorithm Hash digest
SHA256 56117906e3fc0431d4afc04da035886825c7b713a66a2317a44537233f693485
MD5 6835a4ce0263c218b3cfa1c6f8fe633e
BLAKE2b-256 314d697ea1a00d77731b2f95f2e7dde1401d0d6f82c35d0fc371d7a21275e82a

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