-
Notifications
You must be signed in to change notification settings - Fork 3
[Rule] PARTITION to BIN PACKING #396
Description
Source: PARTITION
Target: BIN PACKING
Motivation: Establishes NP-completeness of BIN PACKING via polynomial-time reduction from PARTITION. This is one of the most natural and well-known reductions in combinatorial optimization: a set of integers can be split into two equal-sum halves if and only if the same integers (as item sizes) can be packed into exactly 2 bins of capacity S/2. BIN PACKING is NP-complete in the strong sense (also via reduction from 3-PARTITION), but this simpler reduction from PARTITION suffices for weak NP-completeness.
Reference: Garey & Johnson, Computers and Intractability, SR1, p.226
GJ Source Entry
[SR1] BIN PACKING
INSTANCE: Finite set U of items, a size s(u)∈Z^+ for each u∈U, a positive integer bin capacity B, and a positive integer K.
QUESTION: Is there a partition of U into disjoint sets U_1,U_2,…,U_K such that the sum of the sizes of the items in each U_i is B or less?
Reference: Transformation from PARTITION, 3-PARTITION.
Comment: NP-complete in the strong sense. NP-complete and solvable in pseudo-polynomial time for each fixed K≥2. Solvable in polynomial time for any fixed B by exhaustive search.
Reduction Algorithm
Summary:
Given a PARTITION instance A = {a_1, ..., a_n} with sizes s(a_i) ∈ Z^+ and total sum S = Σ s(a_i), construct a BIN PACKING instance as follows:
- Items: For each element a_i ∈ A, create an item u_i with size s(u_i) = s(a_i), cast from
u64toi32(matching thepartition_knapsack.rstype conversion pattern viai32::try_from). - Bin capacity: Set B = ⌊S/2⌋ (cast to
i32). If S is odd, there is no balanced partition, and 2 bins of capacity ⌊S/2⌋ cannot hold all items since ⌊S/2⌋ + ⌊S/2⌋ = S - 1 < S.
Implementation trait: ReduceTo<BinPacking<i32>> (witness-capable). The codebase BinPacking<W> is an optimization model (Value = Min<i32>, minimizes number of bins used) with no explicit K parameter. However, the binary partition assignment (0 or 1, indicating which subset) directly serves as a valid 2-bin packing configuration (bin 0 or bin 1). Solution extraction is identity: target_solution.to_vec().
Correctness:
- (PARTITION feasible → BIN PACKING optimal ≤ 2): If there exists A' ⊆ A with Σ_{a ∈ A'} s(a) = S/2, then placing A' items in bin 0 and the rest in bin 1 gives each bin total size exactly S/2 = B. The optimal BinPacking value is ≤ 2. ✓
- (BIN PACKING optimal ≤ 2 → PARTITION feasible): If the optimal packing uses ≤ 2 bins of capacity B = S/2, then items in each bin sum to ≤ S/2. Since total = S, each bin sums to exactly S/2, yielding a valid partition. ✓
- (Odd S case): If S is odd, total capacity 2⌊S/2⌋ = S - 1 < S, so ≥ 3 bins are needed. Both answers are NO. ✓
- (Witness round-trip): Every optimal BinPacking witness using bins {0, 1} extracts (identity) to a satisfying Partition assignment. Use
assert_satisfaction_round_trip_from_optimization_target(Source=Or, Target=Min). ✓
Size Overhead
| Target metric (code name) | Expression (source getters) |
|---|---|
num_items |
num_elements |
Derivation: Each PARTITION element maps to exactly one BIN PACKING item (n items total). The bin capacity B = ⌊S/2⌋ is a scalar data parameter, not a structural size field. Construction is O(n).
Validation Method
- Closed-loop test: construct a PARTITION instance, reduce to
BinPacking<i32>, solve withBruteForce::find_witness, verify viaassert_satisfaction_round_trip_from_optimization_target. - Solution extraction: identity mapping — bin assignment [0, 1, 0, 1, ...] directly is the partition assignment.
- Edge cases: test with odd total sum (optimal bins > 2, no balanced partition), even sum with no valid partition (e.g., {1, 2, 6, 7}, sum = 16, no subset sums to 8).
Example
Source instance (PARTITION):
A = {5, 3, 8, 2, 4, 6} (n = 6 elements)
Total sum S = 5 + 3 + 8 + 2 + 4 + 6 = 28; target half-sum = 14.
A balanced partition exists: A' = {8, 6} (sum = 14), A \ A' = {5, 3, 2, 4} (sum = 14).
Constructed BIN PACKING instance:
| Item i | Size s(u_i) |
|---|---|
| 0 | 5 |
| 1 | 3 |
| 2 | 8 |
| 3 | 2 |
| 4 | 4 |
| 5 | 6 |
Bin capacity B = 14.
Optimal solution:
- Bin 0: items {2, 5} (sizes 8, 6). Total = 14 ≤ 14 ✓
- Bin 1: items {0, 1, 3, 4} (sizes 5, 3, 2, 4). Total = 14 ≤ 14 ✓
- Bins used: 2 → BIN PACKING feasible → PARTITION feasible.
Solution extraction:
- Config = [1, 1, 0, 1, 1, 0] (items 0,1,3,4 in bin 1; items 2,5 in bin 0)
- Partition assignment is identical: elements {0,1,3,4} in subset 1, elements {2,5} in subset 0.
Negative example:
A = {1, 2, 6, 7} (n = 4, sum S = 16, even).
B = 8. No subset of {1, 2, 6, 7} sums to 8. Optimal BinPacking needs ≥ 3 bins → PARTITION infeasible. ✓
References
- [Garey & Johnson, 1979]: [
garey1979] Michael R. Garey and David S. Johnson (1979). Computers and Intractability: A Guide to the Theory of NP-Completeness. W.H. Freeman. - [Karp, 1972]: [
Karp1972] Richard M. Karp (1972). "Reducibility among combinatorial problems". In: Complexity of Computer Computations. Plenum Press.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status