Skip to main content

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.

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

Release files for PySCIPOpt 2.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for PySCIPOpt 2.0.2
File Size Uploaded
PySCIPOpt-2.0.2.tar.gz 511.0 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for PySCIPOpt 2.0.2
File Interpreter ABI Platform
PySCIPOpt-2.0.2-cp36-cp36m-win_amd64.whl CPython 3.6 CPython 3.6 pymalloc Windows x86-64 Details
PySCIPOpt-2.0.2-cp35-cp35m-win_amd64.whl CPython 3.5 CPython 3.5 pymalloc Windows x86-64 Details
PySCIPOpt-2.0.2-cp27-cp27m-win_amd64.whl CPython 2.7 CPython 2.7 pymalloc Windows x86-64 Details

Total release size: 2.0 MB

Release files / PySCIPOpt-2.0.2.tar.gz

Download URL PySCIPOpt-2.0.2.tar.gz
Size 511.0 kB
Tags Source
SHA-256 checksum
How to use checksums
df5a695f38663a0bc77c22b95c6b38acda00acf1a964d21ae697791ec5bea6f0
BLAKE2b-256 checksum
How to use checksums
0ab7508c7e3c99825e8dec5cc6a4fe92bff019b562478cdf49941dca607423e3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/2.7.15

Release files / PySCIPOpt-2.0.2-cp36-cp36m-win_amd64.whl

Download URL PySCIPOpt-2.0.2-cp36-cp36m-win_amd64.whl
Size 529.9 kB
Tags CPython 3.6 CPython 3.6 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
02cbef104234d81d72dc72737418effbc9a2729a2c5f9c9351f819acb705cef9
BLAKE2b-256 checksum
How to use checksums
03d510fa2c71ac1006faa80c8149dc6ad38d45c596c30a2958563f2385c04b59
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.6

Release files / PySCIPOpt-2.0.2-cp35-cp35m-win_amd64.whl

Download URL PySCIPOpt-2.0.2-cp35-cp35m-win_amd64.whl
Size 488.7 kB
Tags CPython 3.5 CPython 3.5 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
300c119c27aebdfaf2d917848bd2ba40de4f9d35c89d81f2ea727a6c4036cb30
BLAKE2b-256 checksum
How to use checksums
8f0d6e5ec3622265b67758c03135cf6bbfd8cc3847f0bf3649157815d14986ea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/28.8.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.5.4

Release files / PySCIPOpt-2.0.2-cp27-cp27m-win_amd64.whl

Download URL PySCIPOpt-2.0.2-cp27-cp27m-win_amd64.whl
Size 517.5 kB
Tags CPython 2.7 CPython 2.7 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
744b87203e9c1f579aec56f77c396353c326ea53a25d27f3685cee95ff0cea3d
BLAKE2b-256 checksum
How to use checksums
82a6c7ebe3c9fc0db9ffc1090b9d4c5dce82344b598a5c8cdd8961fcaff2e6f4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/2.7.15

Release history Release notifications | RSS feed

6.2.1

41 release files

6.2.0

41 release files

6.0.0

33 release files

5.7.1

33 release files

5.7.0

33 release files

5.6.0

31 release files

5.5.0

25 release files

5.4.1

25 release files

5.4.0

25 release files

5.2.1

25 release files

5.1.1

21 release files

5.0.1

21 release files

4.3.0

1 release file

4.2.0

1 release file

4.1.0

1 release file

4.0.0

1 release file

3.5.0

1 release file

3.4.0

1 release file

3.3.0

1 release file

3.2.2

1 release file

3.2.1

1 release file

3.2.0

4 release files

3.1.5

4 release files

3.1.4

4 release files

3.1.3

1 release file

3.1.2

1 release file

3.1.1

1 release file

3.1.0

1 release file

3.0.4

4 release files

3.0.3

4 release files

3.0.2

4 release files

3.0.1

4 release files

3.0.0

5 release files

2.2.3

4 release files

2.2.2

4 release files

2.2.1

4 release files

2.2.0

4 release files

2.1.9

4 release files

2.1.8

4 release files

2.1.7

4 release files

2.1.6

4 release files

2.1.5

4 release files

2.1.4

4 release files

2.1.3

4 release files

2.1.2

4 release files

2.1.1

4 release files

2.1.0

4 release files

This release

2.0.2 This release

4 release files

2.0.1

4 release files

2.0.0

4 release files

1.4.9

4 release files

1.4.8

4 release files

1.4.7

4 release files

1.4.6

3 release files

1.4.5

4 release files

1.4.4

4 release files

1.4.3

4 release files

1.4.2

4 release files

1.4.1

4 release files

1.4.0

4 release files

1.3.1

4 release files

1.3.0

4 release files

1.2.0

2 release files

1.1.3

4 release files

1.1.2

4 release files

1.1.1

3 release files

1.1.0

3 release files

1.0.2

1 release file

1.0.1

3 release files

1.0.0

4 release files

1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page