Python interface and modeling environment for SCIP optimization solver
npx @tessl/cli install tessl/pypi-pyscipopt@4.3.0A 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.
pip install pyscipoptimport pyscipoptMost common usage imports the main components:
from pyscipopt import Model, quicksum, quickprodFor 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, cosConstants for working with solver status and callbacks:
from pyscipopt import SCIP_STATUS, SCIP_RESULT, SCIP_STAGEfrom 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()}")PySCIPOpt is built on SCIP's plugin-based architecture, providing Python access to:
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.
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): ...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, ...): ...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): ...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): ...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: ...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): ...# 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', ...
}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
"""