Git Product home page Git Product logo

pyscipopt's Introduction

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

Build Status

How to install

See INSTALL.md for instructions.

How to build a model using PySCIPOpt

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. 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

  2. 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(2x - yy >= 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.

How to 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.

pyscipopt's People

Contributors

mattmilten avatar rschwarz avatar fserra avatar drehfeldt avatar ambros-gleixner avatar gregorch avatar gerald-gamrath avatar jakobwitzig avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.