A Python implementation of the cutting stock problem solver
Project description
Cutting Stock Problem
This is a Python implementation of the cutting stock problem.
The problem is described here: https://en.wikipedia.org/wiki/Cutting_stock_problem
Installation
This project uses uv for fast Python package management. If you don't have uv installed, you can install it with:
curl -LsSf https://astral.sh/uv/install.sh | sh
Setup Development Environment
-
Clone the repository:
git clone <repository-url> cd cutting_stock
-
You can run commands directly with uv without activating the environment or manually installing dependencies:
uv run cutting_stock
Command Line Options
-r, --roll_length: The length of the roll. E.g. -r 12.0
-l, --lengths: The lengths of the items. Must be a list of floats. E.g. -l 3.4 3.0 2.7
-q, --quantities: The quantities of the items. Must be a list of floats. E.g. -q 34 13 5
-s, --solver: The solver to use. Must be either GLPK or ECOS. E.g. -s GLPK
-g, --ge_required: If specified, the constraint is >= instead of ==.
--verbose: If specified, the output will be more verbose.
Example
uv run python cutting_stock.py -r 12.0 -l 3.4 3.0 2.7 -q 34 13 5
This produces the following output:
> uv run cutting-stock
Required pieces:
███ 3.4m ×34 ▓▓▓ 3.0m ×13 ▒▒▒ 2.7m ×5
Stock length: 12m
Solution: 16 stocks of 12m each, 23.9m waste
Use 10× → 3.4m |3.4m |3.4m |1.8m
█████|█████|█████|···· (12m stock)
Use 2× → 3.4m |3.4m |2.7m|2.5m
█████|█████|▒▒▒▒|···· (12m stock)
Use 3× → 3.0m |3.0m |3.0m |3.0m
▓▓▓▓▓|▓▓▓▓▓|▓▓▓▓▓|▓▓▓▓▓ (12m stock)
Use 1× → 3.0m |2.7m|2.7m|2.7m|0.9m
▓▓▓▓▓|▒▒▒▒|▒▒▒▒|▒▒▒▒|···· (12m stock)
Development
Running Tests
uv run pytest
Code Formatting and Linting
uv run ruff check src/
Dependencies
- scipy: Scientific computing library
- numpy: Numerical computing library
- cvxpy: Convex optimization library
- cvxopt: Convex optimization library
License
MIT License
Project details
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 cutting_stock-0.1.0.tar.gz.
File metadata
- Download URL: cutting_stock-0.1.0.tar.gz
- Upload date:
- Size: 70.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1414800b14efe1863a29cf743e87a01331dc0104f10c472d61098ed7a5f4bb18
|
|
| MD5 |
a1d42b383a110b7182c406aa86f0bb4b
|
|
| BLAKE2b-256 |
891de1cb4807debcfd2a312140a2e2bccebd8d4f9ac28b4c1a4dcd714bea53a9
|
File details
Details for the file cutting_stock-0.1.0-py3-none-any.whl.
File metadata
- Download URL: cutting_stock-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a18b2853e10cd6ff7448c5814032fcf9d66af03d11c43743a3711cb452e3f773
|
|
| MD5 |
088efc34bde12a3c298a2d47f0e3367e
|
|
| BLAKE2b-256 |
cd9f306b0449b7421c40fa611b3b4dd4459b9c6256b8c6f3f87a844f16e2b170
|