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.

Extend the interface

The interface python-scip already provides many of the SCIP callable library methods. You may also extend python-scip 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.

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

Uploaded Source

Built Distributions

PySCIPOpt-1.4.8-cp36-cp36m-win_amd64.whl (508.7 kB view details)

Uploaded CPython 3.6m Windows x86-64

PySCIPOpt-1.4.8-cp35-cp35m-win_amd64.whl (475.5 kB view details)

Uploaded CPython 3.5m Windows x86-64

PySCIPOpt-1.4.8-cp27-cp27m-win_amd64.whl (507.3 kB view details)

Uploaded CPython 2.7m Windows x86-64

File details

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

File metadata

  • Download URL: PySCIPOpt-1.4.8.tar.gz
  • Upload date:
  • Size: 490.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for PySCIPOpt-1.4.8.tar.gz
Algorithm Hash digest
SHA256 4836c57a915046d70ffcad5c2f233cc6773e13a219086e8dd24fc1dbec8bba84
MD5 c66f9d7c3edfab2d0aaa373530dc393d
BLAKE2b-256 d63a3c9ca943914f633c5a4b889258f91c3d740d980430a6dc44ac199242ddb2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for PySCIPOpt-1.4.8-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 49223c1a6f428cc2f511c1665f16fe90f5aa3916c9c0e098d368962d3f147bc4
MD5 e6d3a5f26da97c5b5b0225f383ac8e01
BLAKE2b-256 8441dd7b751ade5f4725f29c5375b6a02a1e1e369a03f7d0aac68e07264dbfd8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for PySCIPOpt-1.4.8-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 91870fe2e97ae894275ff35b9b1c0ead73390a0930150f7003b9228018975c52
MD5 15147c56e77a1a3cf970735ac6256dd2
BLAKE2b-256 002d42873872484710b28afa09f90d7db2f68e902e802b23aa2bb403d1a6da2b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for PySCIPOpt-1.4.8-cp27-cp27m-win_amd64.whl
Algorithm Hash digest
SHA256 c4bb502318f5b6f4cc6348b7d169ee64ab409fb0cb7396e160a2f2042ba7429d
MD5 d397a5f8159f910d4a52cd46bdc1999e
BLAKE2b-256 377d3365308a24e94b8f4c2014253ba92cfdf6f88f2e619623c9082ac664b89e

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