3D Bin Packing

1.1.2 · maintenance · verified Mon Apr 13

py3dbp is a Python library for solving the 3D Bin Packing problem, an optimization challenge focused on fitting items of various sizes into a finite number of bins. The current stable version is 1.1.2, released in July 2020. The library appears to be in maintenance mode with infrequent updates.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to define bins and items, add them to a Packer instance, and then execute the packing algorithm. It also shows how to retrieve the fitted and unfitted items per bin. The `pack` method parameters `bigger_first` and `distribute_items` are highlighted due to their importance in packing strategy.

from py3dbp import Packer, Bin, Item

# Initialize packer
packer = Packer()

# Add bins
packer.add_bin(Bin('large-box', 12.0, 12.0, 5.5, 70.0))
packer.add_bin(Bin('medium-box', 11.0, 8.5, 5.5, 70.0))

# Add items
packer.add_item(Item('item-1', 5.0, 3.0, 2.0, 5.0))
packer.add_item(Item('item-2', 4.0, 4.0, 3.0, 3.0))
packer.add_item(Item('item-3', 6.0, 2.0, 1.0, 2.0))

# Pack items into bins
# Default parameters: bigger_first=False, distribute_items=False, number_of_decimals=3
packer.pack(bigger_first=True, distribute_items=True)

# Print results
for bin_obj in packer.bins:
    print(f"\nBin: {bin_obj.name}, Volume: {bin_obj.get_total_volume()} cubic units, Weight: {bin_obj.get_total_weight()} kg")
    print("  Fitted items:")
    for item in bin_obj.items:
        print(f"    - {item.name} (WHL: {item.width}x{item.height}x{item.depth}, Weight: {item.weight}kg)")
    print(f"  Unfitted items: {len(bin_obj.unfitted_items)}")
    for item in bin_obj.unfitted_items:
        print(f"    - {item.name} (WHL: {item.width}x{item.height}x{item.depth}, Weight: {item.weight}kg)")

view raw JSON →