0
# PySCIPOpt
1
2
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.
3
4
## Package Information
5
6
- **Package Name**: PySCIPOpt
7
- **Language**: Python (with Cython extensions)
8
- **Installation**: `pip install pyscipopt`
9
- **Version**: 4.3.0
10
11
## Core Imports
12
13
```python
14
import pyscipopt
15
```
16
17
Most common usage imports the main components:
18
19
```python
20
from pyscipopt import Model, quicksum, quickprod
21
```
22
23
For advanced usage with custom handlers:
24
25
```python
26
from pyscipopt import (
27
Model, Benders, Benderscut, Branchrule, Nodesel,
28
Conshdlr, Eventhdlr, Heur, Presol, Pricer, Prop,
29
Reader, Sepa, LP
30
)
31
```
32
33
Mathematical functions for nonlinear expressions:
34
35
```python
36
from pyscipopt import exp, log, sqrt, sin, cos
37
```
38
39
Constants for working with solver status and callbacks:
40
41
```python
42
from pyscipopt import SCIP_STATUS, SCIP_RESULT, SCIP_STAGE
43
```
44
45
## Basic Usage
46
47
```python
48
from pyscipopt import Model, quicksum
49
50
# Create optimization model
51
model = Model("production_planning")
52
53
# Add variables
54
x = model.addVar(name="product_x", vtype="I", lb=0) # Integer variable
55
y = model.addVar(name="product_y", vtype="C", lb=0, ub=100) # Continuous variable
56
57
# Add constraints
58
model.addCons(2*x + 3*y <= 100, name="resource_constraint")
59
model.addCons(x + y >= 10, name="minimum_production")
60
61
# Set objective (maximize profit)
62
model.setObjective(5*x + 3*y, "maximize")
63
64
# Solve the problem
65
model.optimize()
66
67
# Check results
68
if model.getStatus() == 'optimal':
69
print(f"Optimal objective value: {model.getObjVal()}")
70
print(f"x = {model.getVal(x)}")
71
print(f"y = {model.getVal(y)}")
72
else:
73
print(f"Optimization status: {model.getStatus()}")
74
```
75
76
## Architecture
77
78
PySCIPOpt is built on SCIP's plugin-based architecture, providing Python access to:
79
80
- **Model**: Central optimization model managing variables, constraints, and solving
81
- **Variables and Constraints**: Core optimization components with extensive constraint types
82
- **Expression System**: Polynomial and nonlinear expression handling with operator overloading
83
- **Plugin Framework**: Extensible handlers for custom branching, cutting, pricing, and heuristics
84
- **Solver Interface**: Direct access to SCIP's advanced optimization algorithms and parameters
85
86
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.
87
88
## Capabilities
89
90
### Core Model and Optimization
91
92
Central model management including problem setup, variable/constraint creation, objective setting, solving, and solution access. Provides the foundation for all optimization workflows.
93
94
```python { .api }
95
class Model:
96
def __init__(self, problemName='model', defaultPlugins=True, ...): ...
97
def addVar(self, name='', vtype='C', lb=0.0, ub=None, obj=0.0, ...): ...
98
def addCons(self, cons, name='', initial=True, separate=True, ...): ...
99
def setObjective(self, coeffs, sense='minimize', clear='true'): ...
100
def optimize(self): ...
101
def getObjVal(self): ...
102
def getVal(self, var): ...
103
def getStatus(self): ...
104
```
105
106
[Core Model and Optimization](./core-model.md)
107
108
### Variables and Constraints
109
110
Comprehensive variable types (continuous, integer, binary) and constraint system including linear constraints, SOS constraints, logical constraints (AND, OR, XOR), indicator constraints, and cardinality constraints.
111
112
```python { .api }
113
class Variable:
114
# Variable objects representing optimization variables
115
def name(self): ...
116
def getLbLocal(self): ...
117
def getUbLocal(self): ...
118
119
class Constraint:
120
# Constraint objects representing problem constraints
121
pass
122
123
def addVar(self, name='', vtype='C', lb=0.0, ub=None, obj=0.0, ...): ...
124
def addCons(self, cons, name='', initial=True, separate=True, ...): ...
125
def addConsSOS1(self, vars, weights=None, name="SOS1cons", ...): ...
126
def addConsIndicator(self, cons, binvar=None, ...): ...
127
def addConsCardinality(self, consvars, cardval, ...): ...
128
```
129
130
[Variables and Constraints](./variables-constraints.md)
131
132
### Expression System
133
134
Polynomial and general expression classes supporting arithmetic operations, constraint creation, and nonlinear expression trees. Enables natural mathematical notation in Python.
135
136
```python { .api }
137
class Expr:
138
# Arithmetic operations: +, -, *, /, **
139
# Comparison operations: <=, >=, == (for constraints)
140
def degree(self): ...
141
def normalize(self): ...
142
143
class GenExpr:
144
# General expressions for nonlinear functions
145
pass
146
147
class ExprCons:
148
# Constraint created from expressions
149
def __init__(self, expr, lhs=None, rhs=None): ...
150
151
class Term:
152
# Monomial terms in polynomial expressions
153
def __init__(self, *variables): ...
154
155
def quicksum(termlist): ...
156
def quickprod(termlist): ...
157
```
158
159
[Expression System](./expressions.md)
160
161
### Mathematical Functions
162
163
Nonlinear mathematical functions for advanced modeling including exponential, logarithmic, trigonometric, and square root functions that integrate with the expression system.
164
165
```python { .api }
166
def exp(expr): ...
167
def log(expr): ...
168
def sqrt(expr): ...
169
def sin(expr): ...
170
def cos(expr): ...
171
```
172
173
[Mathematical Functions](./math-functions.md)
174
175
### Plugin Framework
176
177
Extensible plugin system for custom optimization algorithms including Benders decomposition, branching rules, constraint handlers, heuristics, presolving, pricing, propagation, and separation.
178
179
```python { .api }
180
class Benders: ...
181
class Benderscut: ...
182
class Branchrule: ...
183
class Nodesel: ...
184
class Conshdlr: ...
185
class Eventhdlr: ...
186
class Heur: ...
187
class Presol: ...
188
class Pricer: ...
189
class Prop: ...
190
class Reader: ...
191
class Sepa: ...
192
class LP: ...
193
```
194
195
[Plugin Framework](./plugins.md)
196
197
### Parameters and Configuration
198
199
Comprehensive parameter system for fine-tuning solver behavior, setting time limits, numerical tolerances, algorithmic choices, and accessing solver statistics.
200
201
```python { .api }
202
def setParam(self, name, value): ...
203
def getParam(self, name): ...
204
def setEmphasis(self, emphasis, quiet=True): ...
205
def getTotalTime(self): ...
206
def getGap(self): ...
207
```
208
209
[Parameters and Configuration](./parameters.md)
210
211
## Solver Status and Constants
212
213
```python { .api }
214
# Solver status constants
215
SCIP_STATUS = {
216
'UNKNOWN', 'OPTIMAL', 'INFEASIBLE', 'UNBOUNDED',
217
'TIMELIMIT', 'NODELIMIT', 'MEMLIMIT', ...
218
}
219
220
# Callback result constants
221
SCIP_RESULT = {
222
'DIDNOTRUN', 'FEASIBLE', 'INFEASIBLE', 'CUTOFF',
223
'SEPARATED', 'BRANCHED', 'SUCCESS', ...
224
}
225
226
# Solution process stages
227
SCIP_STAGE = {
228
'INIT', 'PROBLEM', 'SOLVING', 'SOLVED', ...
229
}
230
```
231
232
## Utility Functions
233
234
```python { .api }
235
def multidict(D):
236
"""
237
Creates multidictionaries for organizing structured data.
238
239
Args:
240
D (dict): Dictionary with keys mapping to values or lists
241
242
Returns:
243
list: [keys, dict1, dict2, ...] where each dict contains
244
corresponding values for each key
245
"""
246
```