Skip to main content

A Python implementation of the cutting stock problem solver

Project description

Cutting Stock Problem

A CVXPY implementation of the 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

  1. Clone the repository:

    git clone <repository-url>
    cd cutting_stock
    
  2. 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

cutting_stock-0.1.1.tar.gz (70.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cutting_stock-0.1.1-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file cutting_stock-0.1.1.tar.gz.

File metadata

  • Download URL: cutting_stock-0.1.1.tar.gz
  • Upload date:
  • Size: 70.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.2

File hashes

Hashes for cutting_stock-0.1.1.tar.gz
Algorithm Hash digest
SHA256 b3106bf3da77e95e1475950370fa252a93f9641623d8aa51f00e186b132f5b79
MD5 8d438c0509f7a6ee440c526eb8fa610d
BLAKE2b-256 c6aed29bb06aec158a909afdff73a6f45c9e14f73bb4df8d42e48e0f261dceca

See more details on using hashes here.

File details

Details for the file cutting_stock-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for cutting_stock-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fe27c84a5e8c037128aaa796fd86ea58500b308cf67ddcbcc1b91d07c5e06b12
MD5 b33881e6fea8f6e62ad80377fce20a79
BLAKE2b-256 511c11d033b78b24abc249a11be0ccbc9953f40082ee6a6453cdfc0d19677cc0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page