or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

core-model.mdexpressions.mdindex.mdmath-functions.mdparameters.mdplugins.mdvariables-constraints.md
tile.json

tessl/pypi-pyscipopt

Python interface and modeling environment for SCIP optimization solver

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/pyscipopt@4.3.x

To install, run

npx @tessl/cli install tessl/pypi-pyscipopt@4.3.0

index.mddocs/

PySCIPOpt

A comprehensive Python interface to the SCIP Optimization Suite that enables mathematical programming and constraint solving within Python applications. PySCIPOpt provides a complete modeling environment for linear programming (LP), mixed integer programming (MIP), and constraint satisfaction problems (CSP) through an intuitive Python API that wraps the powerful SCIP solver.

Package Information

  • Package Name: PySCIPOpt
  • Language: Python (with Cython extensions)
  • Installation: pip install pyscipopt
  • Version: 4.3.0

Core Imports

import pyscipopt

Most common usage imports the main components:

from pyscipopt import Model, quicksum, quickprod

For advanced usage with custom handlers:

from pyscipopt import (
    Model, Benders, Benderscut, Branchrule, Nodesel, 
    Conshdlr, Eventhdlr, Heur, Presol, Pricer, Prop, 
    Reader, Sepa, LP
)

Mathematical functions for nonlinear expressions:

from pyscipopt import exp, log, sqrt, sin, cos

Constants for working with solver status and callbacks:

from pyscipopt import SCIP_STATUS, SCIP_RESULT, SCIP_STAGE

Basic Usage

from pyscipopt import Model, quicksum

# Create optimization model
model = Model("production_planning")

# Add variables
x = model.addVar(name="product_x", vtype="I", lb=0)  # Integer variable
y = model.addVar(name="product_y", vtype="C", lb=0, ub=100)  # Continuous variable

# Add constraints
model.addCons(2*x + 3*y <= 100, name="resource_constraint")
model.addCons(x + y >= 10, name="minimum_production")

# Set objective (maximize profit)
model.setObjective(5*x + 3*y, "maximize")

# Solve the problem
model.optimize()

# Check results
if model.getStatus() == 'optimal':
    print(f"Optimal objective value: {model.getObjVal()}")
    print(f"x = {model.getVal(x)}")
    print(f"y = {model.getVal(y)}")
else:
    print(f"Optimization status: {model.getStatus()}")

Architecture

PySCIPOpt is built on SCIP's plugin-based architecture, providing Python access to:

  • Model: Central optimization model managing variables, constraints, and solving
  • Variables and Constraints: Core optimization components with extensive constraint types
  • Expression System: Polynomial and nonlinear expression handling with operator overloading
  • Plugin Framework: Extensible handlers for custom branching, cutting, pricing, and heuristics
  • Solver Interface: Direct access to SCIP's advanced optimization algorithms and parameters

This design enables everything from simple linear programming to complex mixed-integer programming with custom algorithmic components, making it suitable for research, education, and production optimization applications.

Capabilities

Core Model and Optimization

Central model management including problem setup, variable/constraint creation, objective setting, solving, and solution access. Provides the foundation for all optimization workflows.

class Model:
    def __init__(self, problemName='model', defaultPlugins=True, ...): ...
    def addVar(self, name='', vtype='C', lb=0.0, ub=None, obj=0.0, ...): ...
    def addCons(self, cons, name='', initial=True, separate=True, ...): ...
    def setObjective(self, coeffs, sense='minimize', clear='true'): ...
    def optimize(self): ...
    def getObjVal(self): ...
    def getVal(self, var): ...
    def getStatus(self): ...

Core Model and Optimization

Variables and Constraints

Comprehensive variable types (continuous, integer, binary) and constraint system including linear constraints, SOS constraints, logical constraints (AND, OR, XOR), indicator constraints, and cardinality constraints.

class Variable:
    # Variable objects representing optimization variables
    def name(self): ...
    def getLbLocal(self): ...
    def getUbLocal(self): ...

class Constraint:
    # Constraint objects representing problem constraints
    pass

def addVar(self, name='', vtype='C', lb=0.0, ub=None, obj=0.0, ...): ...
def addCons(self, cons, name='', initial=True, separate=True, ...): ...
def addConsSOS1(self, vars, weights=None, name="SOS1cons", ...): ...
def addConsIndicator(self, cons, binvar=None, ...): ...
def addConsCardinality(self, consvars, cardval, ...): ...

Variables and Constraints

Expression System

Polynomial and general expression classes supporting arithmetic operations, constraint creation, and nonlinear expression trees. Enables natural mathematical notation in Python.

class Expr:
    # Arithmetic operations: +, -, *, /, **
    # Comparison operations: <=, >=, == (for constraints)
    def degree(self): ...
    def normalize(self): ...

class GenExpr:
    # General expressions for nonlinear functions
    pass

class ExprCons:
    # Constraint created from expressions
    def __init__(self, expr, lhs=None, rhs=None): ...

class Term:
    # Monomial terms in polynomial expressions
    def __init__(self, *variables): ...

def quicksum(termlist): ...
def quickprod(termlist): ...

Expression System

Mathematical Functions

Nonlinear mathematical functions for advanced modeling including exponential, logarithmic, trigonometric, and square root functions that integrate with the expression system.

def exp(expr): ...
def log(expr): ...
def sqrt(expr): ...
def sin(expr): ...
def cos(expr): ...

Mathematical Functions

Plugin Framework

Extensible plugin system for custom optimization algorithms including Benders decomposition, branching rules, constraint handlers, heuristics, presolving, pricing, propagation, and separation.

class Benders: ...
class Benderscut: ...
class Branchrule: ...
class Nodesel: ...
class Conshdlr: ...
class Eventhdlr: ...
class Heur: ...
class Presol: ...
class Pricer: ...
class Prop: ...
class Reader: ...
class Sepa: ...
class LP: ...

Plugin Framework

Parameters and Configuration

Comprehensive parameter system for fine-tuning solver behavior, setting time limits, numerical tolerances, algorithmic choices, and accessing solver statistics.

def setParam(self, name, value): ...
def getParam(self, name): ...
def setEmphasis(self, emphasis, quiet=True): ...
def getTotalTime(self): ...
def getGap(self): ...

Parameters and Configuration

Solver Status and Constants

# Solver status constants
SCIP_STATUS = {
    'UNKNOWN', 'OPTIMAL', 'INFEASIBLE', 'UNBOUNDED', 
    'TIMELIMIT', 'NODELIMIT', 'MEMLIMIT', ...
}

# Callback result constants  
SCIP_RESULT = {
    'DIDNOTRUN', 'FEASIBLE', 'INFEASIBLE', 'CUTOFF',
    'SEPARATED', 'BRANCHED', 'SUCCESS', ...
}

# Solution process stages
SCIP_STAGE = {
    'INIT', 'PROBLEM', 'SOLVING', 'SOLVED', ...
}

Utility Functions

def multidict(D):
    """
    Creates multidictionaries for organizing structured data.
    
    Args:
        D (dict): Dictionary with keys mapping to values or lists
        
    Returns:
        list: [keys, dict1, dict2, ...] where each dict contains
              corresponding values for each key
    """