binpacking

2.0.1 · active · verified Thu Apr 16

The `binpacking` library provides heuristic algorithms for distributing weighted items into bins. It supports scenarios with either a fixed number of bins or a fixed volume per bin, accepting data as lists, dictionaries, tuples, or CSV files. The current version is 2.0.1, and it has an active release cadence, with major updates and bug fixes released periodically.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates the two primary bin packing functions: `to_constant_volume` for packing into bins with a maximum capacity, and `to_multiple_bins` for packing into a predefined number of bins. Items are provided as a dictionary where keys are item identifiers and values are their weights or sizes.

import binpacking

# Example 1: Pack items into bins with a constant volume limit
items_by_weight = {'itemA': 10, 'itemB': 20, 'itemC': 30, 'itemD': 40, 'itemE': 15}
max_bin_volume = 50
bins_constant_volume = binpacking.to_constant_volume(items_by_weight, max_bin_volume)
print(f"Bins (constant volume {max_bin_volume}): {bins_constant_volume}")

# Example 2: Pack items into a fixed number of bins
num_target_bins = 2
bins_multiple_bins = binpacking.to_multiple_bins(items_by_weight, num_target_bins)
print(f"Bins (fixed number {num_target_bins}): {bins_multiple_bins}")

# For NumPy accelerated functions, ensure it's installed via: pip install binpacking[numpy]
# from binpacking.matrices import to_constant_volume_numpy # (advanced usage)

view raw JSON →