Python Interface and Modeling Environment for SCIP

6.1.0 · active · verified Thu Apr 16

PySCIPOpt is a Python interface and modeling environment for the SCIP Optimization Suite, a powerful mixed-integer programming (MIP) and mixed-integer nonlinear programming (MINLP) solver. It allows users to formulate and solve optimization problems using Python syntax. The library is actively maintained with frequent releases, often coinciding with new major versions of the underlying SCIP solver.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create a simple linear programming model, add variables, define an objective function, add constraints, optimize the model, and retrieve the solution. It also shows how to check the optimization status and explicitly free problem data.

from pyscipopt import Model, SCIP_STATUS

# Create a SCIP model
model = Model("Simple_LP")

# Add variables
x = model.addVar("x", vtype="CONTINUOUS", lb=0.0)
y = model.addVar("y", vtype="CONTINUOUS", lb=0.0)

# Set the objective function: Maximize x + 2y
model.setObjective(x + 2*y, "maximize")

# Add constraints
model.addCons(x + y <= 10, "c1")
model.addCons(2*x + y <= 15, "c2")

# Optimize the model
model.optimize()

# Check the solution status and print results
if model.getStatus() == SCIP_STATUS.OPTIMAL:
    print(f"Optimal solution found.")
    print(f"Objective value: {model.getObjVal()}")
    print(f"x: {model.getVal(x)}")
    print(f"y: {model.getVal(y)}")
else:
    print(f"Problem could not be solved to optimality. Status: {model.getStatus()}")

# Clean up the model (important for repeated modifications/solves)
model.freeProb()

view raw JSON →