0
# Solver Interfaces
1
2
Comprehensive collection of solver interfaces supporting both open-source and commercial optimization solvers. PuLP provides a universal interface that abstracts solver-specific details while enabling access to advanced solver features.
3
4
## Capabilities
5
6
### Default and Auto-Detection
7
8
PuLP automatically detects available solvers and provides a default solver for immediate use without configuration.
9
10
```python { .api }
11
# Default solver instance (automatically detected)
12
LpSolverDefault: LpSolver # Pre-configured default solver
13
14
def getSolver(solver, *args, **kwargs):
15
"""
16
Instantiate a solver by name with optional parameters.
17
18
Parameters:
19
- solver (str): Solver name (e.g., 'PULP_CBC_CMD', 'GLPK_CMD')
20
- *args: Positional arguments for solver constructor
21
- **kwargs: Keyword arguments for solver constructor
22
23
Returns:
24
LpSolver: Configured solver instance
25
"""
26
27
def listSolvers(onlyAvailable=False):
28
"""
29
List all solver names known to PuLP.
30
31
Parameters:
32
- onlyAvailable (bool): If True, only list solvers that are available/installed
33
34
Returns:
35
list: List of solver name strings
36
"""
37
38
def getSolverFromDict(data):
39
"""
40
Create solver instance from dictionary configuration.
41
42
Parameters:
43
- data (dict): Solver configuration dictionary
44
45
Returns:
46
LpSolver: Configured solver instance
47
"""
48
49
def getSolverFromJson(filename):
50
"""
51
Create solver instance from JSON configuration file.
52
53
Parameters:
54
- filename (str): Path to JSON configuration file
55
56
Returns:
57
LpSolver: Configured solver instance
58
"""
59
```
60
61
Usage examples:
62
63
```python
64
# Use default solver
65
prob.solve() # Uses LpSolverDefault
66
67
# List available solvers
68
available = listSolvers(onlyAvailable=True)
69
print("Available solvers:", available)
70
71
# Get specific solver by name
72
cbc_solver = getSolver('PULP_CBC_CMD')
73
status = prob.solve(cbc_solver)
74
```
75
76
### Base Solver Classes
77
78
Foundation classes that define the solver interface and provide common functionality for all solver implementations.
79
80
```python { .api }
81
class LpSolver:
82
"""
83
Generic LP Solver base class providing the common interface for all solvers.
84
"""
85
def __init__(self, mip=True, msg=True, **kwargs):
86
"""
87
Initialize solver with basic options.
88
89
Parameters:
90
- mip (bool): Enable mixed integer programming support
91
- msg (bool): Enable solver output messages
92
- **kwargs: Additional solver-specific options
93
"""
94
95
def available(self):
96
"""
97
Check if the solver is available on the system.
98
99
Returns:
100
bool: True if solver can be used
101
"""
102
103
def solve(self, problem):
104
"""
105
Solve the given optimization problem.
106
107
Parameters:
108
- problem (LpProblem): Problem to solve
109
110
Returns:
111
int: Solution status code
112
"""
113
114
class LpSolver_CMD:
115
"""
116
Base class for command-line solvers that use subprocess calls.
117
"""
118
def __init__(self, path=None, keepFiles=False, mip=True, msg=True, **kwargs):
119
"""
120
Initialize command-line solver.
121
122
Parameters:
123
- path (str, optional): Path to solver executable
124
- keepFiles (bool): Keep temporary files for debugging
125
- mip (bool): Enable mixed integer programming
126
- msg (bool): Show solver output
127
"""
128
129
class PulpSolverError(Exception):
130
"""
131
Exception raised for solver-specific errors.
132
"""
133
```
134
135
### Open-Source Solvers
136
137
Free and open-source optimization solvers that provide robust performance for most optimization problems.
138
139
```python { .api }
140
class PULP_CBC_CMD:
141
"""
142
PuLP's default CBC (COIN-OR Branch and Cut) solver.
143
Excellent for mixed integer linear programming problems.
144
"""
145
def __init__(self, path=None, keepFiles=False, mip=True, msg=True,
146
cuts=True, presolve=True, dual=True, strong=True, **kwargs): ...
147
148
class COIN_CMD:
149
"""
150
COIN-OR linear programming solver (CLP) via command line.
151
Fast for pure linear programming problems.
152
"""
153
def __init__(self, path=None, keepFiles=False, mip=False, msg=True, **kwargs): ...
154
155
class COINMP_DLL:
156
"""
157
COIN-OR solver via DLL interface for Windows systems.
158
"""
159
def __init__(self, mip=True, msg=True, **kwargs): ...
160
161
class GLPK_CMD:
162
"""
163
GNU Linear Programming Kit command-line interface.
164
Well-established open-source solver with good documentation.
165
"""
166
def __init__(self, path=None, keepFiles=False, mip=True, msg=True, **kwargs): ...
167
168
class PYGLPK:
169
"""
170
GLPK Python interface for direct library calls.
171
"""
172
def __init__(self, mip=True, msg=True, **kwargs): ...
173
174
class GLPK:
175
"""
176
Alias for GLPK_CMD - automatically selects best available GLPK interface.
177
"""
178
179
class HiGHS:
180
"""
181
HiGHS solver Python interface - modern high-performance open-source solver.
182
Excellent performance for both LP and MIP problems.
183
"""
184
def __init__(self, mip=True, msg=True, **kwargs): ...
185
186
class HiGHS_CMD:
187
"""
188
HiGHS solver command-line interface.
189
"""
190
def __init__(self, path=None, keepFiles=False, mip=True, msg=True, **kwargs): ...
191
192
class CYLP:
193
"""
194
CyLP interface to COIN-OR solvers with advanced Python integration.
195
Provides access to low-level solver features.
196
"""
197
def __init__(self, mip=True, msg=True, **kwargs): ...
198
```
199
200
### Commercial Solvers
201
202
High-performance commercial optimization solvers for demanding applications requiring maximum speed and advanced features.
203
204
```python { .api }
205
class CPLEX_CMD:
206
"""
207
IBM CPLEX command-line interface.
208
Industry-leading commercial solver for large-scale optimization.
209
"""
210
def __init__(self, path=None, keepFiles=False, mip=True, msg=True, **kwargs): ...
211
212
class CPLEX_PY:
213
"""
214
IBM CPLEX Python interface using the docplex library.
215
Direct API access to CPLEX features and parameters.
216
"""
217
def __init__(self, mip=True, msg=True, **kwargs): ...
218
219
class CPLEX:
220
"""
221
Alias for CPLEX_CMD - automatically selects best available CPLEX interface.
222
"""
223
224
class GUROBI:
225
"""
226
Gurobi optimizer Python interface.
227
High-performance commercial solver with excellent Python integration.
228
"""
229
def __init__(self, mip=True, msg=True, **kwargs): ...
230
231
class GUROBI_CMD:
232
"""
233
Gurobi optimizer command-line interface.
234
"""
235
def __init__(self, path=None, keepFiles=False, mip=True, msg=True, **kwargs): ...
236
237
class XPRESS:
238
"""
239
FICO Xpress optimizer Python interface.
240
Commercial solver with strong MIP performance.
241
"""
242
def __init__(self, mip=True, msg=True, **kwargs): ...
243
244
class XPRESS_CMD:
245
"""
246
FICO Xpress command-line interface.
247
"""
248
def __init__(self, path=None, keepFiles=False, mip=True, msg=True, **kwargs): ...
249
250
class XPRESS_PY:
251
"""
252
FICO Xpress Python interface with direct library access.
253
"""
254
def __init__(self, mip=True, msg=True, **kwargs): ...
255
256
class MOSEK:
257
"""
258
MOSEK optimization solver for linear, quadratic, and conic problems.
259
Specialized for continuous optimization with high accuracy.
260
"""
261
def __init__(self, mip=True, msg=True, **kwargs): ...
262
263
class COPT:
264
"""
265
Cardinal Optimizer (COPT) Python interface.
266
Modern commercial solver with competitive performance.
267
"""
268
def __init__(self, mip=True, msg=True, **kwargs): ...
269
270
class COPT_CMD:
271
"""
272
Cardinal Optimizer command-line interface.
273
"""
274
def __init__(self, path=None, keepFiles=False, mip=True, msg=True, **kwargs): ...
275
276
class COPT_DLL:
277
"""
278
Cardinal Optimizer DLL interface for Windows systems.
279
"""
280
def __init__(self, mip=True, msg=True, **kwargs): ...
281
```
282
283
### Specialized and Academic Solvers
284
285
Solvers for specific problem types, research applications, and specialized optimization domains.
286
287
```python { .api }
288
class SCIP_CMD:
289
"""
290
SCIP (System for Constraint Integer Programming) command-line interface.
291
Academic solver excellent for constraint programming and MIP.
292
"""
293
def __init__(self, path=None, keepFiles=False, mip=True, msg=True, **kwargs): ...
294
295
class SCIP_PY:
296
"""
297
SCIP Python interface for direct library access.
298
"""
299
def __init__(self, mip=True, msg=True, **kwargs): ...
300
301
class SCIP:
302
"""
303
Alias for SCIP_CMD - automatically selects best available SCIP interface.
304
"""
305
306
class FSCIP_CMD:
307
"""
308
Fast SCIP command-line interface - optimized version of SCIP.
309
"""
310
def __init__(self, path=None, keepFiles=False, mip=True, msg=True, **kwargs): ...
311
312
class FSCIP:
313
"""
314
Alias for FSCIP_CMD.
315
"""
316
317
class CHOCO_CMD:
318
"""
319
CHOCO constraint programming solver.
320
Specialized for constraint satisfaction and constraint optimization problems.
321
"""
322
def __init__(self, path=None, keepFiles=False, mip=True, msg=True, **kwargs): ...
323
324
class MIPCL_CMD:
325
"""
326
MIPCL (Mixed Integer Programming Class Library) command-line interface.
327
Academic mixed integer programming solver.
328
"""
329
def __init__(self, path=None, keepFiles=False, mip=True, msg=True, **kwargs): ...
330
331
class CUOPT:
332
"""
333
NVIDIA cuOpt GPU-accelerated optimization solver.
334
Specialized for large-scale routing and scheduling problems.
335
"""
336
def __init__(self, mip=True, msg=True, **kwargs): ...
337
```
338
339
### SAS Solvers
340
341
Integration with SAS analytics platform for enterprise optimization workflows.
342
343
```python { .api }
344
class SAS94:
345
"""
346
SAS 9.4 optimization solver interface.
347
Enterprise analytics platform integration.
348
"""
349
def __init__(self, mip=True, msg=True, **kwargs): ...
350
351
class SASCAS:
352
"""
353
SAS Cloud Analytic Services (CAS) solver interface.
354
Cloud-based SAS optimization services.
355
"""
356
def __init__(self, mip=True, msg=True, **kwargs): ...
357
358
class SASsolver:
359
"""
360
Base class for SAS solver implementations.
361
"""
362
def __init__(self, mip=True, msg=True, **kwargs): ...
363
```
364
365
### Legacy and Deprecated Solvers
366
367
Historical solver interfaces maintained for backward compatibility.
368
369
```python { .api }
370
class YAPOSIB:
371
"""
372
YAPOSIB (Yet Another Python Optimization Solver Interface Binding).
373
Legacy interface for various solvers - deprecated in favor of direct interfaces.
374
"""
375
def __init__(self, mip=True, msg=True, **kwargs): ...
376
```
377
378
## Usage Examples
379
380
```python
381
# Basic solver usage
382
prob = LpProblem("Example", LpMinimize)
383
x = LpVariable("x", 0, 10)
384
prob += x
385
status = prob.solve() # Uses default solver
386
387
# Specify solver explicitly
388
status = prob.solve(PULP_CBC_CMD(msg=0)) # CBC without output
389
status = prob.solve(GLPK_CMD()) # GLPK solver
390
status = prob.solve(HiGHS()) # HiGHS solver
391
392
# Commercial solver with options
393
gurobi_solver = GUROBI(msg=True, timeLimit=3600)
394
if gurobi_solver.available():
395
status = prob.solve(gurobi_solver)
396
else:
397
print("Gurobi not available, using default")
398
status = prob.solve()
399
400
# Solver selection based on problem type
401
def select_solver(problem_size, has_integers=False):
402
if problem_size > 100000:
403
# Large problems - try commercial first
404
for solver_class in [GUROBI, CPLEX, XPRESS]:
405
solver = solver_class(msg=0)
406
if solver.available():
407
return solver
408
409
if has_integers:
410
# MIP problems - use CBC or HiGHS
411
return PULP_CBC_CMD(msg=0)
412
else:
413
# Pure LP - HiGHS is very fast
414
return HiGHS(msg=0)
415
416
# Dynamic solver configuration
417
solver_config = {
418
'solver_name': 'PULP_CBC_CMD',
419
'msg': False,
420
'cuts': True,
421
'presolve': True
422
}
423
solver = getSolver(**solver_config)
424
status = prob.solve(solver)
425
426
# Check solver availability
427
print("Available solvers:")
428
for solver_name in listSolvers(onlyAvailable=True):
429
print(f" {solver_name}")
430
431
# Solver performance comparison
432
import time
433
solvers_to_test = [PULP_CBC_CMD(), HiGHS(), GLPK_CMD()]
434
for solver in solvers_to_test:
435
if solver.available():
436
start = time.time()
437
status = prob.solve(solver)
438
elapsed = time.time() - start
439
print(f"{solver.__class__.__name__}: {elapsed:.3f}s, Status: {LpStatus[status]}")
440
```