Skip to main content

Python interface and modeling environment for SCIP

Project description

This project provides an interface from Python to the [SCIP Optimization Suite](http://scip.zib.de).

[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/PySCIPOpt/Lobby) [![PySCIPOpt on PyPI](https://img.shields.io/pypi/v/pyscipopt.svg)](https://pypi.python.org/pypi/pyscipopt) [![TravisCI Status](https://travis-ci.org/SCIP-Interfaces/PySCIPOpt.svg?branch=master)](https://travis-ci.org/SCIP-Interfaces/PySCIPOpt) [![AppVeyor Status](https://ci.appveyor.com/api/projects/status/fsa896vkl8be79j9/branch/master?svg=true)](https://ci.appveyor.com/project/mattmilten/pyscipopt/branch/master)

Documentation

Please consult the [online documentation](http://scip-interfaces.github.io/PySCIPOpt/docs/html) or use the help() function directly in Python or ? in IPython/Jupyter.

See [CHANGELOG.md](CHANGELOG.md) for added, removed or fixed functionality.

Installation

See [INSTALL.md](INSTALL.md) for instructions.

Building and solving a model

There are several [examples](examples/finished) and [tutorials](examples/tutorial). 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

` {.sourceCode .python} from pyscipopt import Model `

  1. Create a solver instance.

` {.sourceCode .python} model = Model("Example") # model name is optional `

  1. Access the methods in the scip.pyx file using the solver/model instance model, e.g.:

` {.sourceCode .python} 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 enum`s, `struct`s or SCIP variable types are included in `scip.pxd <br>

  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](CONTRIBUTING.md).

Gotchas

### Ranged constraints

While ranged constraints of the form

` {.sourceCode .} lhs <= expression <= rhs `

are supported, the Python syntax for [chained comparisons](https://docs.python.org/3.5/reference/expressions.html#comparisons) can’t be hijacked with operator overloading. Instead, parenthesis must be used, e.g.,

` {.sourceCode .} 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 set`s or as keys of `dict`s. They are not hashable and comparable. The issue is that comparisons such as `x == y will be interpreted as linear constraints, since Variable`s 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](https://github.com/SCIP-Interfaces/PySCIPOpt/issues/136)

Therefore, you should use the following settings when trying to work with dual information:

` {.sourceCode .python} 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-3.0.0.tar.gz (609.1 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

PySCIPOpt-3.0.0-cp38-cp38-win_amd64.whl (657.3 kB view details)

Uploaded CPython 3.8Windows x86-64

PySCIPOpt-3.0.0-cp37-cp37m-win_amd64.whl (626.2 kB view details)

Uploaded CPython 3.7mWindows x86-64

PySCIPOpt-3.0.0-cp36-cp36m-win_amd64.whl (625.3 kB view details)

Uploaded CPython 3.6mWindows x86-64

PySCIPOpt-3.0.0-cp35-cp35m-win_amd64.whl (576.2 kB view details)

Uploaded CPython 3.5mWindows x86-64

File details

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

File metadata

  • Download URL: PySCIPOpt-3.0.0.tar.gz
  • Upload date:
  • Size: 609.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.6

File hashes

Hashes for PySCIPOpt-3.0.0.tar.gz
Algorithm Hash digest
SHA256 a2900892064fc42c2bb9984b106ef9db832a6cdd535ff90f1a9aa6dfd8662e96
MD5 60963bfcddfd1f3ea9cf78762db5942a
BLAKE2b-256 e1447570e5f58459b5ec9535a70265fc483e4d75bc0af32afad81b6ba5667f1f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: PySCIPOpt-3.0.0-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 657.3 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.0

File hashes

Hashes for PySCIPOpt-3.0.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 729e27aaed5c91bd22b49dd37e4df6813d5492340ec2eb75082783e217707d16
MD5 d9748c7ec92e53491129fd7f28d5afc2
BLAKE2b-256 ed666904b21927f39d5dba3e9a0474bb246ff3fc11b3500292c4291942a92714

See more details on using hashes here.

File details

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

File metadata

  • Download URL: PySCIPOpt-3.0.0-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 626.2 kB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.5

File hashes

Hashes for PySCIPOpt-3.0.0-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 c81151dfbfff0678c41f25b957f809576f07eed35c34133131b01f77a748020c
MD5 57bc34cd3358e8c19ba2257be46e4716
BLAKE2b-256 f3e78ba770c536097306b33c17927258ddc92f09e5f00d4affe779e2ab8196fc

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for PySCIPOpt-3.0.0-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 2f3a69a538a42eaee31b19688ef806b0989d9e449256eaced92e122f8292906b
MD5 96ea4654c7b5d109747fe9c2a95ceaaa
BLAKE2b-256 5a47347a74b2d104bade155f596cff654e9db069e7bf32dbed598a0e070ea444

See more details on using hashes here.

File details

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

File metadata

  • Download URL: PySCIPOpt-3.0.0-cp35-cp35m-win_amd64.whl
  • Upload date:
  • Size: 576.2 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.23.0 setuptools/28.8.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.5.4

File hashes

Hashes for PySCIPOpt-3.0.0-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 d830c0d436f8ce1827b5ee105e68f662fae73b4391716d5c21d1437d59fe9fb4
MD5 0653c6b240561ad1c7a855cdc4040c6c
BLAKE2b-256 c38c29de82e99d70ab59c2f94c04b2e3ce1edc98152f9044659990e9979ee9a0

See more details on using hashes here.

Supported by

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