You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You have n items with sizes w1, w2, ..., wn and m bins with equal capacity C. Your goal is to pack all items into the minimum number of bins such that the total size of items in each bin does not exceed its capacity.
Small Concrete Example:
Items: sizes [6, 8, 3, 5, 7, 4] (6 items)
Bin capacity: C = 10
Optimal packing (4 bins): {6,4}, {7,3}, {8}, {5}
Input/Output:
Input: Item sizes and bin capacity
Output: Assignment of each item to a bin, minimizing the number of bins used
Why It Matters
Warehouse & Logistics: Companies like Amazon and DHL solve bin packing daily to minimize shipping containers, trucks, and storage space. Reducing bins by 5% saves millions in transportation costs.
Memory Allocation: Operating systems use bin packing algorithms to allocate memory pages to reduce fragmentation and improve cache efficiency.
Cloud Resource Scheduling: Virtual machine provisioning across physical servers is a bin packing variant—packing VMs into servers to minimize energy consumption and data center utilization.
Manufacturing & Cutting Stock: Paper mills, glass cutters, and textile manufacturers face cutting stock problems—minimizing waste by optimally cutting rolls or sheets into required pieces.
Modeling Approaches
Approach 1: Integer Linear Programming (ILP) – Flow-Based
Decision Variables:
x[i][j] ∈ {0, 1}: Item i is assigned to bin j
y[j] ∈ {0, 1}: Bin j is used (has at least one item)
Minimize: max_bin
Subject to:
load[j] = Σ{i: bin[i]=j} wi ∀j (load computation)
load[j] ≤ C ∀j (capacity)
max_bin ≥ bin[i] ∀i (track highest-indexed bin)
bin[i] ∈ [1..m] ∀i
Trade-offs: Global constraints enable stronger propagation. Better scaling than ILP for medium instances. Supports symmetry-breaking naturally.
Approach 3: Local Search / Metaheuristics
Heuristic: First-Fit Decreasing (FFD)
Sort items by size in descending order
For each item, place it in the first bin with sufficient space
If no bin has space, open a new bin
FFD(items, capacity):
sort items descending by size
bins = []
for item in items:
for bin in bins:
if bin.load + item.size ≤ capacity:
bin.add(item)
continue to next item
bins.append(new Bin with item)
return bins.length
Trade-offs: FFD achieves ~11/9 OPT (within 11/9 times optimal). Fast (O(n log n)) and scales to thousands of items. No guarantee of optimality but excellent practical performance.
Example MiniZinc Model
int: n=6; % number of itemsint: m=10; % max bins (upper bound)int: C=10; % bin capacityarray[1..n] ofint: w= [6,8,3,5,7,4]; % item weights% Decision variablesarray[1..n] ofvar1..m: bin; % bin assignment for each itemarray[1..m] ofvar0..C: load; % total load per binvar1..m: num_bins; % number of bins used% Constraintsconstraintforall(jin1..m) (
load[j] =sum(iin1..nwherebin[i]=j) (w[i])
);
constraintforall(jin1..m) (
load[j] <=C
);
constraintnum_bins=max(iin1..n) (bin[i]);
% Symmetry-breaking: bins are used in orderconstraintforall(jin2..m) (
load[j-1] >0\/load[j] =0
);
solveminimizenum_bins;
output ["Bins used: ", show(num_bins), "\n"];
Key Techniques
1. First-Fit Decreasing (FFD) Heuristic
Sort items by size in decreasing order, then greedily pack into the first available bin. This heuristic guarantees a solution within 7⁄8 of the theoretical lower bound and is the baseline for most practical applications.
2. Lower Bounds & Relaxations
Trivial bound: ⌈Σwi / C⌉ (sum of sizes divided by capacity)
LP relaxation: Relax assignments to continuous [0,1]; optimal LP value provides a lower bound
Branch-and-bound: Prune branches where LB ≥ current best solution
3. Constraint Propagation & Global Constraints
Bin load reasoning: Preprocess to detect items that must go together
Arc consistency: Reduce variable domains through constraint propagation
4. Variable Ordering Heuristics
Largest-first: Branch on largest items first
Minimum load bin heuristic: Assign items to bins with lowest current load
Impact-based search: Prioritize items whose assignment most constrains the remaining problem
Challenge Corner
Question for Reflection:
Symmetry Breaking: The naive model has m! symmetries (permutations of bins). Design three different symmetry-breaking constraints:
Ordering by load (e.g., load[1] ≥ load[2] ≥ ...)
Ordering by smallest item in each bin
Channel to a "next" variable array
Online vs. Offline: In the online variant, items arrive one at a time. How does FFD perform compared to the offline optimum? Research the competitive ratio.
Multi-Capacity Bins: Extend the model to handle bins of different capacities. What new heuristics would you introduce?
References
Coffman Jr., E. G., et al. (2013). "Bin Packing Approximation Algorithms: Survey and Classification." In Handbook of Combinatorial Optimization (pp. 455–531). — Comprehensive survey covering approximation ratios and variants.
Rossi, F., Van Beek, P., & Walsh, T. (Eds.). (2006). Handbook of Constraint Programming. Elsevier. Chapter on global constraints and packing problems.
Hooker, J. N. (2012). Integrated Methods for Optimization (2nd ed.). Springer. — Branch-and-bound with constraint propagation.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Problem Statement
You have
nitems with sizesw1, w2, ..., wnandmbins with equal capacityC. Your goal is to pack all items into the minimum number of bins such that the total size of items in each bin does not exceed its capacity.Small Concrete Example:
[6, 8, 3, 5, 7, 4](6 items)C = 10{6,4},{7,3},{8},{5}Input/Output:
Why It Matters
Warehouse & Logistics: Companies like Amazon and DHL solve bin packing daily to minimize shipping containers, trucks, and storage space. Reducing bins by 5% saves millions in transportation costs.
Memory Allocation: Operating systems use bin packing algorithms to allocate memory pages to reduce fragmentation and improve cache efficiency.
Cloud Resource Scheduling: Virtual machine provisioning across physical servers is a bin packing variant—packing VMs into servers to minimize energy consumption and data center utilization.
Manufacturing & Cutting Stock: Paper mills, glass cutters, and textile manufacturers face cutting stock problems—minimizing waste by optimally cutting rolls or sheets into required pieces.
Modeling Approaches
Approach 1: Integer Linear Programming (ILP) – Flow-Based
Decision Variables:
x[i][j]∈ {0, 1}: Item i is assigned to bin jy[j]∈ {0, 1}: Bin j is used (has at least one item)Constraints:
Trade-offs: Straightforward, works for small instances (~100 items). Solves to optimality but slow for larger instances.
Approach 2: Constraint Programming (CP) – Symbolic
Decision Variables:
bin[i]∈ [1..m]: Bin assigned to item iload[j]∈ [0..C]: Total load of bin jmax_bin∈ [1..m]: Maximum bin index usedConstraints:
Trade-offs: Global constraints enable stronger propagation. Better scaling than ILP for medium instances. Supports symmetry-breaking naturally.
Approach 3: Local Search / Metaheuristics
Heuristic: First-Fit Decreasing (FFD)
Trade-offs: FFD achieves ~11/9 OPT (within 11/9 times optimal). Fast (O(n log n)) and scales to thousands of items. No guarantee of optimality but excellent practical performance.
Example MiniZinc Model
Key Techniques
1. First-Fit Decreasing (FFD) Heuristic
Sort items by size in decreasing order, then greedily pack into the first available bin. This heuristic guarantees a solution within 7⁄8 of the theoretical lower bound and is the baseline for most practical applications.
2. Lower Bounds & Relaxations
3. Constraint Propagation & Global Constraints
load[1] ≥ load[2] ≥ ... ≥ load[m]4. Variable Ordering Heuristics
Challenge Corner
Question for Reflection:
Symmetry Breaking: The naive model has m! symmetries (permutations of bins). Design three different symmetry-breaking constraints:
Online vs. Offline: In the online variant, items arrive one at a time. How does FFD perform compared to the offline optimum? Research the competitive ratio.
Multi-Capacity Bins: Extend the model to handle bins of different capacities. What new heuristics would you introduce?
References
Coffman Jr., E. G., et al. (2013). "Bin Packing Approximation Algorithms: Survey and Classification." In Handbook of Combinatorial Optimization (pp. 455–531). — Comprehensive survey covering approximation ratios and variants.
Rossi, F., Van Beek, P., & Walsh, T. (Eds.). (2006). Handbook of Constraint Programming. Elsevier. Chapter on global constraints and packing problems.
Hooker, J. N. (2012). Integrated Methods for Optimization (2nd ed.). Springer. — Branch-and-bound with constraint propagation.
MiniZinc: (www.minizinc.org/redacted) — Bin packing model library and benchmarks.
Beta Was this translation helpful? Give feedback.
All reactions