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.
pip install pyscipoptVerified import paths — ran on the pinned version, not inferred.
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.
Review the `CHANGELOG.md` for v6.0.0 and SCIP 10 release notes. Update code to use new features like IIS and exact solving, and adjust any deprecated or removed API calls.
Always call `model.freeTransform()` before attempting to modify variables, constraints, or the objective of an already optimized model. For a full cleanup, use `model.freeProb()`.
If precise dual values are critical, set appropriate SCIP parameters to disable presolving, propagation, and heuristics (e.g., `model.setParam('presolving/maxrounds', 0)`, `model.setParam('relaxing/maxrounds', 0)`, `model.setParam('heuristics/activated', 'off')`). Refer to SCIP documentation for specific parameters.For ranged constraints, explicitly parenthesize the expression: `model.addCons(lhs <= (expression <= rhs), "cons_name")`. Alternatively, add single-sided constraints and modify bounds later using `chgRhs` or `chgLhs`.
For older versions, or if experiencing `scip/scip.h` not found errors, install the SCIP Optimization Suite separately and set the `SCIPOPTDIR` environment variable to its base directory before installing PySCIPOpt.
Ensure you have the SCIP Optimization Suite installed. If not bundled by PySCIPOpt (versions < 4.4.0) or for source builds, manually install SCIP and set the environment variable `SCIPOPTDIR` to the base directory of your SCIP installation (e.g., `export SCIPOPTDIR=/path/to/SCIPOptSuite`). Then retry `pip install pyscipopt`.
Run `pip install pyscipopt` (preferably within a virtual environment) or activate the correct Python environment where it was installed.
Call `model.freeTransform()` before making any modifications to the model after it has been optimized. For a full reset, use `model.freeProb()`.
Use explicit parentheses for ranged constraints: `model.addCons(lhs <= (expression <= rhs))`.