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.

Gitter PySCIPOpt on PyPI TravisCI Status AppVeyor Status TravisCI Test Coverage Code Health

Installation

See INSTALL.rst for instructions.

Building and solving a model

There are several examples provided in the tests folder. 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.

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

Uploaded Source

Built Distributions

PySCIPOpt-2.0.1-cp36-cp36m-win_amd64.whl (553.3 kB view details)

Uploaded CPython 3.6m Windows x86-64

PySCIPOpt-2.0.1-cp35-cp35m-win_amd64.whl (518.2 kB view details)

Uploaded CPython 3.5m Windows x86-64

PySCIPOpt-2.0.1-cp27-cp27m-win_amd64.whl (551.1 kB view details)

Uploaded CPython 2.7m Windows x86-64

File details

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

File metadata

  • Download URL: PySCIPOpt-2.0.1.tar.gz
  • Upload date:
  • Size: 531.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/2.7.14

File hashes

Hashes for PySCIPOpt-2.0.1.tar.gz
Algorithm Hash digest
SHA256 bbdd71788bcd07565526d5f7093ebdaae07603eeff2af802f61cb0903a38917c
MD5 f3b05cfd3a57b886da395d831f0f2ab2
BLAKE2b-256 4412aaca02cf935e405f7b6a2a821d5ec16ad322e0f34472c986c36a5717b6b7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: PySCIPOpt-2.0.1-cp36-cp36m-win_amd64.whl
  • Upload date:
  • Size: 553.3 kB
  • Tags: CPython 3.6m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.6

File hashes

Hashes for PySCIPOpt-2.0.1-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 ed5c1669263a513d39efadc84b3d00772bc5106079906a93d51cc1b066d3a4e5
MD5 3099a71b114d8a2ab3c7f0cfd2b0c4d5
BLAKE2b-256 2c9240722f060cfba85f69df02dc7c8a3d3c69bb32465e032dd8bee90db1be1a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: PySCIPOpt-2.0.1-cp35-cp35m-win_amd64.whl
  • Upload date:
  • Size: 518.2 kB
  • Tags: CPython 3.5m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/28.8.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.5.3

File hashes

Hashes for PySCIPOpt-2.0.1-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 4736749dc852c18ba2725f309d3f4f6b9b79df25eef1e9a0752d7f86c642665f
MD5 f690ffce9fae1f230b42cac75e6a951d
BLAKE2b-256 5de2fb5cbb5044f2105b033ef551a8a9fa14ce743bc6bc7e8f6d8346a8a7928e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: PySCIPOpt-2.0.1-cp27-cp27m-win_amd64.whl
  • Upload date:
  • Size: 551.1 kB
  • Tags: CPython 2.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/2.7.15

File hashes

Hashes for PySCIPOpt-2.0.1-cp27-cp27m-win_amd64.whl
Algorithm Hash digest
SHA256 1dfc36ef4b159dd148a3a0adf9f69695ca03beeae1463fe1197c45f00cfe3211
MD5 4aeb9a8143b0b5d2b178815eebbd15df
BLAKE2b-256 d9f1a0b1336f0a081e6b6397009cfe2c5c3379fa78d4d1aa59a16f557e062045

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