2D strip packing solver with Python API
Project description
Strip Packing Problem
This repository implements a 2D strip-packing solver based on combinatorial Benders cuts (as described in the Operations Research paper: https://pubsonline.informs.org/doi/abs/10.1287/opre.2013.1248).
Requirements
- CMake >= 3.16
- C++17 compiler (
g++/clang++) - Bundled HiGHS dependency at
third_party/highs - Optional: GoogleTest (only for unit tests)
Build
cmake -S . -B build -DSTRIP_PACKING_BUILD_TESTS=ON
cmake --build build -j
The executable is produced at build/spp (or ./spp if you build in-source).
Run
Only these CLI arguments are accepted:
--time_buget <seconds>or--time_budget <seconds>: maximum runtime budget for solving--problem_path <path>: path to a single.TXTinstance file
Examples:
./build/spp --time_buget 60 --problem_path ./test/2sp/HT01.TXT
./build/spp --problem_path ./test/2sp/HT01.TXT
If --problem_path is omitted, the default is ./test/2sp/HT01.TXT.
Output
After solving, the program reports:
state: completedandheight: <value>when solved within time budgetstate: timeoutwhen the run exceeds the time budget or stops in pending/approximate mode
If time budget is 0, the solver returns state: timeout immediately.
Input Format
The solver expects a .TXT file with:
- First line: number of items
n - Second line: strip width
W - Next exactly
nlines:item_id width height
The parser validates:
- file can be opened
nandWare positive integers- each item row has exactly 3 integers
- item width/height are positive
- number of parsed item rows must equal
n
Tests
Run all configured tests:
cd build
ctest --output-on-failure
Current test set includes:
- unit tests for selected utility/rotation behavior (when GoogleTest is available)
- parser validation tests for malformed/valid input
- CLI integration tests for argument validation, known-height regressions, and timeout reporting
Benchmark (Paper Comparison)
We benchmarked the solver on the canonical test/2sp instances copied into benchmark_instances:
BENG01..10CGCUT01..03GCUT01..04HT01..09NGCUT01..12
Run command used for each instance:
./build/spp --time_buget 120 --problem_path <instance.TXT>
Results are stored in:
research/spp_run_120_results.csv
This CSV includes both:
- solver output (
solver_height_120s) - paper-reported BLUE results (
opt_height_or_bound,blue_runtime_sec,proven_optimal)
Summary (38 instances total):
| Set | Instances | Matched Paper Optimum | Timeout (-1) |
|---|---|---|---|
| BENG | 10 | 10 | 0 |
| CGCUT | 3 | 1 | 2 |
| GCUT | 4 | 3 | 1 |
| HT | 9 | 8 | 1 |
| NGCUT | 12 | 12 | 0 |
| Total | 38 | 34 | 4 |
Interpretation:
- On all instances solved within the 120s limit, the returned height matches the paper optimum for this benchmark slice.
- The current implementation times out on 4/38 instances (
CGCUT02,CGCUT03,GCUT04,HT08), while the paper's BLUE implementation reports optimal solutions for them. - This supports that the solver behaves as an exact method when it closes an instance, but is currently weaker than the paper implementation in robustness/performance on harder cases.
License
MIT. See LICENSE.
Python API (PyPI)
The package exposes:
pack(items: list[tuple[int, int]], bin_width: int, branch_and_bound: bool, benders: bool, timeout: int) -> spp_resultplot_pack(result: spp_result)
spp_result contains:
placements: dict[int, tuple[int, int]]where key is item index and value is(x, y)items: list[tuple[int, int]]original input items
Additional fields are also provided: bin_width, state, and height.
Example:
from spp import pack, plot_pack
items = [(3, 4), (2, 5), (4, 2)]
res = pack(items=items, bin_width=6, branch_and_bound=True, benders=True, timeout=30)
print(res.state, res.height, res.placements)
if res.state == "completed":
fig, ax = plot_pack(res)
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
File details
Details for the file zephyr_pack-0.2.0.tar.gz.
File metadata
- Download URL: zephyr_pack-0.2.0.tar.gz
- Upload date:
- Size: 3.5 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1b24cce72a6909d5ace505362b4e7f187de4c3455e77902e40b17f578a04ecad
|
|
| MD5 |
4ebde4a3913f7cea1c800778143edf41
|
|
| BLAKE2b-256 |
26fe91413f966f2fce3af1457f2f9091ac8ef96a78ec0f5683bf32c69533826e
|