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

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

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

Uploaded Source

Built Distributions

PySCIPOpt-2.2.1-cp36-cp36m-win_amd64.whl (585.3 kB view details)

Uploaded CPython 3.6m Windows x86-64

PySCIPOpt-2.2.1-cp35-cp35m-win_amd64.whl (540.1 kB view details)

Uploaded CPython 3.5m Windows x86-64

PySCIPOpt-2.2.1-cp27-cp27m-win_amd64.whl (567.3 kB view details)

Uploaded CPython 2.7m Windows x86-64

File details

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

File metadata

  • Download URL: PySCIPOpt-2.2.1.tar.gz
  • Upload date:
  • Size: 567.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.0 CPython/2.7.15

File hashes

Hashes for PySCIPOpt-2.2.1.tar.gz
Algorithm Hash digest
SHA256 1a159274c2dfe666e304a963280e2a15955c883d551520e41294dd1907d93a96
MD5 9cd7b7499f0acaf3509ef1ea385cd13d
BLAKE2b-256 1bd18e726d079ca6f4c3f578bf88e1fa4a8cf45e03627cc13ee8003fb8712f28

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for PySCIPOpt-2.2.1-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 d55b478dc5b37e835587cbecae40155d5ee8fce70638f8d20e7a843cf988ad6e
MD5 37192e5b9319cd56a12e2481951944e1
BLAKE2b-256 62948b52b73d5e28dbfd57fc37a8d12a4221e540f72bf97fa776804cb9b85346

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for PySCIPOpt-2.2.1-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 9edc72213a678f5c0c8826ee32a7b43f9d7f9e551f2e6cd032c8961d517887da
MD5 66ea2839fa0f997ef369ca836a86333b
BLAKE2b-256 20a9d1cbf443c89491ccee1f62bf3ea8c79373813a2841ea4b12521a2e61bddd

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for PySCIPOpt-2.2.1-cp27-cp27m-win_amd64.whl
Algorithm Hash digest
SHA256 59352d55249a5b93b9ed68891ed417c317c9130133743340ef5cdc0df6b3b7ea
MD5 b08c5146fe8607c8ea052a0841a3ce58
BLAKE2b-256 fc41277c40f2ead042f8ace149024aacc0a9d9f13e9dd68d025f7c4b83f4db4f

See more details on using hashes here.

Supported by

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