Skip to main content

Python interface and modeling environment for SCIP

Project description

PySCIPOpt

This project provides an interface from the Python programming language to the SCIP solver software.

Build Status

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") # the name is optional

This is equivalent to calling SCIPcreate(&scip); SCIPcreateProbBasic(scip, "Example") in C.

  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)

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.

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

Uploaded Source

Built Distributions

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

PySCIPOpt-1.1.2-py3.6-linux-x86_64.egg (1.5 MB view details)

Uploaded Egg

PySCIPOpt-1.1.2-py2.7-linux-x86_64.egg (1.2 MB view details)

Uploaded Egg

PySCIPOpt-1.1.2-cp36-cp36m-win_amd64.whl (303.1 kB view details)

Uploaded CPython 3.6mWindows x86-64

File details

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

File metadata

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

File hashes

Hashes for PySCIPOpt-1.1.2.tar.gz
Algorithm Hash digest
SHA256 68a76669c9783923552a9b2baf29b646beb96dfbf1799f353c0b24799d8364df
MD5 62b4c15fdfd0f0abc1e765e2cc1759fa
BLAKE2b-256 7dd0ed94b94f18163d5dca8a717f0be6754b8927ab1cd64b36542e13aa0f689d

See more details on using hashes here.

File details

Details for the file PySCIPOpt-1.1.2-py3.6-linux-x86_64.egg.

File metadata

File hashes

Hashes for PySCIPOpt-1.1.2-py3.6-linux-x86_64.egg
Algorithm Hash digest
SHA256 29157e65ebc87fc65a2b46659617ecc1eb4aa0e61c5ed19e133febb1f44d178d
MD5 0b18284f808ab778b475604dc4b6b511
BLAKE2b-256 b3f22f0ecedd7174cd614e1125c6a1867ac35b1057bbfc03164dc1ad6ce48e3a

See more details on using hashes here.

File details

Details for the file PySCIPOpt-1.1.2-py2.7-linux-x86_64.egg.

File metadata

File hashes

Hashes for PySCIPOpt-1.1.2-py2.7-linux-x86_64.egg
Algorithm Hash digest
SHA256 150556678c712c2d748336b6f14f6951ad4de2e3fccf9bea4b3cb6c098f9d8ad
MD5 4b6ba3b1f025784ce94fc25e1893344a
BLAKE2b-256 ec1dab82531beaaf66332a81c8e74dfd96d5b9cfbd8f1d9843512de25a5e8abc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for PySCIPOpt-1.1.2-cp36-cp36m-win_amd64.whl
Algorithm Hash digest
SHA256 da7ea2f4b927342374f703c637c7f46cd591c4b2ce27349574f8ebca67510f0b
MD5 263a507b5f9853443ebaaae3656ae320
BLAKE2b-256 b6fbfcfdbc590886affe2a272535430b09b5b283c016f28536b01ebb6ee6c3c0

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