kishorkukreja/awesome-supply-chain/2d-bin-packing

Claude Code and agent skill by kishorkukreja/awesome-supply-chain

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

When the user wants to pack 2D rectangular items into bins, optimize 2D cutting patterns, or minimize material waste in 2D packing. Also use when the user mentions "2D packing," "rectangular packing," "sheet packing," "2D bin packing problem," "guillotine cutting," "two-dimensional packing," or "rectangle packing optimization." For 1D problems, see 1d-cutting-stock. For 3D problems, see 3d-bin-packing.

Install

npx vskill@latest install kishorkukreja/awesome-supply-chain/2d-bin-packing

SKILL.md

2D Bin Packing

You are an expert in 2D bin packing and rectangular packing optimization. Your goal is to help pack rectangular items into 2D bins or sheets while minimizing waste, number of bins used, or maximizing space utilization.

Initial Assessment

Before solving 2D bin packing problems, understand:

  1. Problem Type
  • Pack into fixed-size bins (minimize bins used)?
  • Pack into variable-size bins (minimize total area)?
  • Single large bin (maximize utilization)?
  • Cutting from sheets (minimize waste)?
  1. Item Characteristics
  • How many items to pack? (10s, 100s, 1000s)
  • Item dimensions: width x height
  • Can items be rotated? (90-degree rotation allowed?)
  • Are items all different or some identical?
  • Any item priorities or grouping requirements?
  1. Bin/Sheet Specifications
  • Bin dimensions: width x height
  • Fixed or variable bin sizes?
  • Unlimited bins or limited quantity?
  • Any margin/spacing requirements between items?
  1. Cutting Constraints
  • Guillotine cuts only? (straight cuts across entire sheet)
  • Free-form packing allowed?
  • Maximum number of cutting stages?
  • Trim loss acceptable?
  1. Optimization Objective
  • Minimize number of bins used?
  • Minimize total area/material cost?
  • Maximize utilization percentage?
  • Minimize cutting complexity?

2D Bin Packing Framework

Problem Classification

1. 2D Bin Packing Problem (2D-BPP)

  • Pack rectangles into minimum number of identical bins
  • All items must be packed
  • Items cannot overlap
  • Items typically axis-aligned

2. 2D Strip Packing Problem

  • Fixed width, minimize height
  • Single strip (bin with infinite height)
  • Minimize total height used

3. 2D Cutting Stock Problem

  • Cut items from larger sheets
  • Minimize material waste
  • Often with guillotine constraints

4. Rectangle Packing Problem

  • Pack into single large rectangle
  • Maximize number of items packed
  • Or maximize space utilization

5. Two-Dimensional Knapsack

  • Items have values
  • Maximize total value in fixed bin
  • Items may not all fit

Mathematical Formulation

Basic 2D Bin Packing Model

Decision Variables:

  • x_i, y_i = coordinates of item i's bottom-left corner
  • b_i = bin number assigned to item i
  • w_j = 1 if bin j is used, 0 otherwise
  • r_i = 1 if item i is rotated, 0 otherwise

Objective: Minimize ∑ w_j (minimize bins used)

Constraints:

  1. Non-overlap: items in same bin don't overlap
  2. Containment: items fit within bin boundaries
  3. Assignment: each item assigned to exactly one bin
  4. Rotation (optional): items can be rotated 90°

Complexity:

  • NP-hard problem
  • No polynomial-time optimal algorithm (unless P=NP)
  • Requires heuristic or metaheuristic approaches

Algorithms and Solution Methods

Exact Methods

Branch and Bound

  • Guarantees optimal solution
  • Only practical for small problems (<20-30 items)
  • Exponential time complexity

Integer Programming Formulation

python
from pulp import *
def solve_2d_bin_packing_ip(items, bin_width, bin_height, max_bins=None):
"""
2D Bin Packing using Integer Programming
Parameters:
- items: list of (width, height) tuples
- bin_width: width of each bin
- bin_height: height of each bin
- max_bins: maximum number of bins to consider
Returns optimal packing solution
Note: Only practical for small problems (<20 items)
"""
n = len(items)
if max_bins is None:
max_bins = n # Worst case: one item per bin
bins = range(max_bins)
item_ids = range(n)
# Create problem
prob = LpProblem("2D_Bin_Packing", LpMinimize)
# Decision variables
# x[i,b] = x coordinate of item i in bin b
x = LpVariable.dicts("x",
[(i, b) for i in item_ids for b in bins],
lowBound=0, upBound=bin_width, cat='Continuous')
# y[i,b] = y coordinate of item i in bin b
y = LpVariable.dicts("y",
[(i, b) for i in item_ids for b in bins],
lowBound=0, upBound=bin_height, cat='Continuous')
# a[i,b] = 1 if item i assigned to bin b
a = LpVariable.dicts("assign",
[(i, b) for i in item_ids for b in bins],
cat='Binary')
# w[b] = 1 if bin b is used
w = LpVariable.dicts("use_bin", bins, cat='Binary')
# Objective: minimize number of bins
prob += lpSum([w[b] for b in bins]), "Total_Bins"
# Constraints
# 1. Each item assigned to exactly one bin
for i in item_ids:
prob += lpSum([a[i,b] for b in bins]) == 1, f"Assign_{i}"
# 2. Item fits within bin boundaries
for i in item_ids:
for b in bins:
prob += x[i,b] + items[i][0] <= bin_width + (1 - a[i,b]) * bin_width, \
f"Fit_Width_{i}_{b}"
prob += y[i,b] + items[i][1] <= bin_height + (1 - a[i,b]) * bin_height, \
f"Fit_Height_{i}_{b}"
# 3. Bin is used if any item assigned to it
for b in bins:
for i in item_ids:
prob += a[i,b] <= w[b], f"Bin_Used_{i}_{b}"
# 4. Non-overlapping constraints (simplified - full version more complex)
# This is a simplified model; full non-overlap requires additional binary variables
# Solve
status = prob.solve(PULP_CBC_CMD(msg=1, timeLimit=300))
if LpStatus[status] != 'Optimal':
return None
# Extract solution
solution = {
'num_bins': int(value(prob.objective)),
'bins': []
}
for b in bins:
if w[b].varValue > 0.5:
bin_items = []
for i in item_ids:
if a[i,b].varValue > 0.5:
bin_items.append({
'item_id': i,
'x': x[i,b].varValue,
'y': y[i,b].varValue,
'width': items[i][0],
'height': items[i][1]
})
solution['bins'].append(bin_items)
return solution
Heuristic Methods

First Fit Decreasing Height (FFDH)

  • Sort items by decreasing height
  • Pack items left-to-right on shelves
  • Start new shelf when item doesn't fit
python
def first_fit_decreasing_height(items, bin_width, bin_height):
"""
First Fit Decreasing Height (FFDH) Algorithm
Classic shelf-based packing heuristic
- Sorts items by decreasing height
- Packs items left-to-right on shelves
- Opens new shelf/bin when needed
Parameters:
- items: list of (width, height, item_id) tuples
- bin_width: bin width
- bin_height: bin height
Returns packing solution
"""
# Sort by decreasing height, then decreasing width
sorted_items = sorted(items, key=lambda x: (x[1], x[0]), reverse=True)
bins = []
for item_width, item_height, item_id in sorted_items:
placed = False
# Try to place in existing bins
for bin_idx, bin_data in enumerate(bins):
shelves = bin_data['shelves']
# Try each shelf
for shelf in shelves:
if (shelf['remaining_width'] >= item_width and
shelf['height'] >= item_height):
# Place on this shelf
x = bin_width - shelf['remaining_width']
y = shelf['y']
bin_data['items'].append({
'id': item_id,
'x': x,
'y': y,
'width': item_width,
'height': item_height
})
shelf['remaining_width'] -= item_width
placed = True
break
if placed:
break
# Try to create new shelf in this bin
if not placed:
current_height = sum(s['height'] for s in shelves)
if current_height + item_height <= bin_height:
# Create new shelf
new_shelf = {
'y': current_height,
'height': item_height,
'remaining_width': bin_width - item_width
}
shelves.append(new_shelf)
bin_data['items'].append({
'id': item_id,
'x': 0,
'y': current_height,
'width': item_width,
'height': item_height
})
placed = True
break
# Need new bin
if not placed:
new_bin = {
'items': [{
'id': item_id,
'x': 0,
'y': 0,
'width': item_width,
'height': item_height
}],
'shelves': [{
'y': 0,
'height': item_height,
'remaining_width': bin_width - item_width
}]
}
bins.append(new_bin)
return {
'num_bins': len(bins),
'bins': bins,
'utilization': calculate_utilization(bins, bin_width, bin_height)
}
def calculate_utilization(bins, bin_width, bin_height):
"""Calculate space utilization percentage"""
total_item_area = 0
for bin_data in bins:
for item in bin_data['items']:
total_item_area += item['width'] * item['height']
total_bin_area = len(bins) * bin_width * bin_height
return (total_item_area / total_bin_area * 100) if total_bin_area > 0 else 0

Next Fit Decreasing Height (NFDH)

  • Similar to FFDH but only considers current bin
  • Simpler but less efficient

Best Fit Decreasing Height (BFDH)

  • Tries to find best shelf for each item
  • Better utilization than FFDH
python
def best_fit_decreasing_height(items, bin_width, bin_height):
"""
Best Fit Decreasing Height Algorithm
Finds the shelf with minimum remaining space that fits the item
"""
sorted_items = sorted(items, key=lambda x: (x[1], x[0]), reverse=True)
bins = []
for item_width, item_height, item_id in sorted_items:
best_bin = None
best_shelf = None
min_waste = float('inf')
# Find best fitting shelf
for bin_idx, bin_data in enumerate(bins):
for shelf_idx, shelf in enumerate(bin_data['shelves']):
if (shelf['remaining_width'] >= item_width and
shelf['height'] >= item_height):
waste = shelf['remaining_width'] - item_width
if waste < min_waste:
min_waste = waste
best_bin = bin_idx
best_shelf = shelf_idx
if best_bin is not None:
# Place on best shelf
shelf = bins[best_bin]['shelves'][best_shelf]
x = bin_width - shelf['remaining_width']
y = shelf['y']
bins[best_bin]['items'].append({
'id': item_id,
'x': x,
'y': y,
'width': item_width,
'height': item_height
})
shelf['remaining_width'] -= item_width
else:
# Try to create new shelf or new bin
placed = False
for bin_idx, bin_data in enumerate(bins):
shelves = bin_data['shelves']
current_height = sum(s['height'] for s in shelves)
if current_height + item_height <= bin_height:
new_shelf = {
'y': current_height,
'height': item_height,
'remaining_width': bin_width - item_width
}
shelves.append(new_shelf)

This is the start of the file. Read the full SKILL.md on GitHub.

Security

  • Security scanPassed, 95 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

Repository stars
74
Repository forks
18
7-day trend score
22

Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/kishorkukreja/awesome-supply-chain/2d-bin-packing/badge)](https://verified-skill.com/skills/kishorkukreja/awesome-supply-chain/2d-bin-packing)

Something wrong with this skill or its page? Tell us.