Problem variants
1D Bin Packing
Pack items of varying weights into bins of fixed capacity. Minimize number of bins.
Knapsack
Select items with values and weights to maximize total value within a weight budget.
2D Bin Packing
Pack rectangles into sheets. Common in cutting stock and container loading.
Set Cover / Partition
Cover a universe of elements with minimum subsets from a collection.
Bin packing example
python
import nerox
import numpy as np
client = nerox.Client()
bin_capacity = 100
item_weights = [34, 23, 67, 12, 45, 78, 9, 55, 33, 21, 60, 48]
job = client.optimize.bin_packing(
item_weights=item_weights,
bin_capacity=bin_capacity,
solver="gpu",
)
result = job.wait()
print(f"Bins used: {result.objective:.0f}") # minimize this
for bin_idx, items in enumerate(result.bins):
total = sum(item_weights[i] for i in items)
print(f"Bin {bin_idx}: items={items} load={total}/{bin_capacity}")Knapsack example
python
# 0/1 Knapsack: maximize value subject to weight capacity
values = [10, 6, 8, 14, 5, 9, 12, 3, 7, 15]
weights = [5, 4, 6, 8, 3, 7, 9, 2, 5, 10]
capacity = 25
job = client.optimize.knapsack(
values=values,
weights=weights,
capacity=capacity,
solver="gpu",
)
result = job.wait()
selected = [i for i, x in enumerate(result.solution) if x]
print(f"Selected items: {selected}")
print(f"Total value: {sum(values[i] for i in selected)}")
print(f"Total weight: {sum(weights[i] for i in selected)}")Applications
Cargo loading — pack containers to minimize shipping trips
Cloud resource allocation — assign workloads to servers to minimize instance count
Cutting stock — minimize material waste in sheet/roll cutting
Financial lot sizing — round fractional positions to integer share quantities
Network traffic engineering — assign flows to links within bandwidth limits
