A Benders Decomposition Library in Python
Project description
BendersLib: A Benders Decomposition Library in Python
BendersLib (benders.dev) is a Python library that supports a range of Benders decomposition variants, including Classical Benders Decomposition, Combinatorial Benders Decomposition, L-shaped Method, Integer L-shaped Method, Generalized Benders Decomposition, and Logic-based Benders Decomposition. While BendersLib provides built-in implementations of these methods, it is designed to be extensible. Users can implement custom Benders decomposition methods by customizing subproblem solvers and cut generators, and defining callback functions for enhancement strategies. BendersLib is solver agnostic and has built-in interfaces for popular Mathematical Programming and Constraint Programming solvers. Its support for rapid prototyping and high extensibility are designed to meet the needs of both researchers and practitioners in Operations Research and related fields.
Links
| Resource | Link |
|---|---|
| Documentation | https://benders.dev |
| Source Code | https://github.com/phguo/benderslib |
| PyPI | https://pypi.org/project/benderslib/ |
Quick Start
Install BendersLib and a solver of your choice (e.g., Gurobi) using pip.
pip install "benderslib[gurobi]"
python -c "import benderslib as bd; print(bd.__url__)"
# Should output "https://benders.dev"
BendersLib enables switching from a standard Mathematical Programming model to Benders decomposition with only a few lines of code.
from benderslib import AnnotatedBenders, ClassicalBenders
from benderslib.solvers import Gurobi
from gurobipy import Model, GRB
# Create a standard Gurobi model
model = Model()
x = model.addVar(name="x", vtype=GRB.INTEGER)
y = model.addVar(name="y", vtype=GRB.CONTINUOUS)
model.addConstr(x + y >= 15)
model.addConstr(2 * x + 5 * y >= 30)
model.setObjective(3 * x + 4 * y)
model.update()
# Complicating variable
complicating_vars = ["x"]
# Create and solve using Benders decomposition
benders = AnnotatedBenders(
model,
solver=Gurobi,
complicating_vars=complicating_vars,
benders=ClassicalBenders
)
benders.solve()
print(f"Objective: {benders.result.obj}")
print(f"Solution: {benders.result.solution}")
The output will be similar to the following, showing the Benders decomposition process and results.
====================================================================================
BendersLib (v0.5.1, Apache-2.0, https://benders.dev) (C) 2021-2026 Peng-Hui Guo
------------------------------------------------------------------------------------
Benders Decomposition:
- Method: ClassicalBenders
- Complicating Var. No.: 1 [Integer: 1, Binary: 0, Continuous: 0]
- Optimality Cut: ClassicalOCGen
- Feasibility Cut: ClassicalFCGen
Master Problem:
- Variable No.: 2 [Integer: 1, Binary: 0]
- Constraint No.: 0
- Solver: Gurobi
Sub Problem:
- Variable No.: 1 [Integer: 0, Binary: 0]
- Constraint No.: 2
- Solver: Gurobi
Benders Parameters:
- All default
------------------------------------------------------------------------------------
Iter., LB, UB, Obj., Gap(%), Runtime(s)
------------------------------------------------------------------------------------
1, 0.00, 60.00, 60.00, 100.00, 0.00
------------------------------------------------------------------------------------
Benders Result:
- Status: OPTIMAL
- Incumbent: 45.0000
- Bound: 45.0000
- Gap (abs.): 0.0000
- Gap (rel.): 0.00%
- Solutions No.: 2
- Iteration No.: 2
- Cuts No.: 1 [Optimality: 1, Feasibility: 0]
- Solve Time (sec.): 0.01 [Master: 0.01, Sub: 0.00]
====================================================================================
Objective: 45.0
Solution: {'x': 15.0, 'y': 0.0}
License
- BendersLib's source code is licensed under the Apache-2.0 License.
References
- Benders, J. F. (1962). Partitioning procedures for solving mixed-variables programming problems. Numerische Mathematik, 4(1), 238–252. https://doi.org/10.1007/BF01386316
- Codato, G., & Fischetti, M. (2006). Combinatorial Benders’ cuts for mixed-integer linear programming. Operations Research, 54(4), 756–766. https://doi.org/10.1287/opre.1060.0286
- Geoffrion, A. M. (1972). Generalized Benders Decomposition. Journal of Optimization Theory and Applications, 10(4), 237–260. https://doi.org/10.1007/BF00934810
- Van Slyke, R. M., & Wets, R. (1969). L-shaped linear programs with applications to optimal control and stochastic programming. SIAM Journal on Applied Mathematics, 17(4), 638–663. https://doi.org/10.1137/0117061
- Laporte, G., & Louveaux, F. V. (1993). The integer L-shaped method for stochastic integer programs with complete recourse. Operations Research Letters, 13(3), 133–142. https://doi.org/10.1016/0167-6377(93)90002-X
- Hooker, J. N., & Ottosson, G. (2003). Logic-based Benders Decomposition. Mathematical Programming, 96(1), 33–60. https://doi.org/10.1007/s10107-003-0375-9
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file benderslib-0.5.1.tar.gz.
File metadata
- Download URL: benderslib-0.5.1.tar.gz
- Upload date:
- Size: 70.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c1c03991bda81f8696492eeca523725729a487a15ba76524b10ea319f1288fbd
|
|
| MD5 |
5855cb888f073f90d897d1df76f00672
|
|
| BLAKE2b-256 |
5eeda4fd9874be33add5cbc7531a1faaaaaf46a50f8c1462575f072527a2075c
|
Provenance
The following attestation bundles were made for benderslib-0.5.1.tar.gz:
Publisher:
pypi_publish.yml on phguo/BendersLib
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
benderslib-0.5.1.tar.gz -
Subject digest:
c1c03991bda81f8696492eeca523725729a487a15ba76524b10ea319f1288fbd - Sigstore transparency entry: 1399434321
- Sigstore integration time:
-
Permalink:
phguo/BendersLib@a993cb2d5a8d1061ee30f2ee31b97b79e8c1ecf0 -
Branch / Tag:
refs/tags/v0.5.1 - Owner: https://github.com/phguo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi_publish.yml@a993cb2d5a8d1061ee30f2ee31b97b79e8c1ecf0 -
Trigger Event:
release
-
Statement type:
File details
Details for the file benderslib-0.5.1-py3-none-any.whl.
File metadata
- Download URL: benderslib-0.5.1-py3-none-any.whl
- Upload date:
- Size: 90.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0154525a88ff89b9a42dabb7c83f198f1073c838f8ad37a455b9205e2fc64040
|
|
| MD5 |
277911dbe335388ee3e7576f227927cb
|
|
| BLAKE2b-256 |
4e0305b08021527030fd6daedc1db44cdc9d8913daa29cbc7dfc49f3168361f5
|
Provenance
The following attestation bundles were made for benderslib-0.5.1-py3-none-any.whl:
Publisher:
pypi_publish.yml on phguo/BendersLib
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
benderslib-0.5.1-py3-none-any.whl -
Subject digest:
0154525a88ff89b9a42dabb7c83f198f1073c838f8ad37a455b9205e2fc64040 - Sigstore transparency entry: 1399434335
- Sigstore integration time:
-
Permalink:
phguo/BendersLib@a993cb2d5a8d1061ee30f2ee31b97b79e8c1ecf0 -
Branch / Tag:
refs/tags/v0.5.1 - Owner: https://github.com/phguo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi_publish.yml@a993cb2d5a8d1061ee30f2ee31b97b79e8c1ecf0 -
Trigger Event:
release
-
Statement type: