-
Notifications
You must be signed in to change notification settings - Fork 3
[Model] Numerical3DimensionalMatching #808
Description
Motivation
NUMERICAL 3-DIMENSIONAL MATCHING (P143) from Garey & Johnson, A3 SP16. A strongly NP-complete number-partition problem: given three disjoint sets W, X, Y each of size m with positive integer sizes satisfying B/4 < s(a) < B/2 for each element a, can they be partitioned into m triples (one element from each set) such that each triple sums to a given bound B? This is a numerical strengthening of 3-Dimensional Matching (3DM) — while 3DM asks only about set membership in triples, N3DM additionally requires that sizes within each triple sum to a target. The size constraint B/4 < s(a) < B/2 forces each triple to contain exactly three elements. N3DM is a key intermediate problem for establishing strong NP-completeness of scheduling, packing, and other numerical problems.
Associated rules:
- [Rule] 3-DIMENSIONAL MATCHING to NUMERICAL 3-DIMENSIONAL MATCHING #390/[Rule] 3-DIMENSIONAL MATCHING to NUMERICAL 3-DIMENSIONAL MATCHING #826: 3-DIMENSIONAL MATCHING → Numerical3DimensionalMatching (NP-completeness proof, Theorem 4.4)
- [Rule] NUMERICAL 3-DIMENSIONAL MATCHING to NUMERICAL MATCHING WITH TARGET SUMS #391/[Rule] NUMERICAL 3-DIMENSIONAL MATCHING to NUMERICAL MATCHING WITH TARGET SUMS #827: Numerical3DimensionalMatching → NumericalMatchingWithTargetSums
- [Rule] Numerical 3-Dimensional Matching to Two-Processor Flow-Shop with Bounded Buffer #484: Numerical3DimensionalMatching → TwoProcessorFlowShopWithBoundedBuffer
Definition
Name: Numerical3DimensionalMatching
Reference: Garey & Johnson, Computers and Intractability, A3 SP16
Mathematical definition:
INSTANCE: Disjoint sets W, X, and Y, each containing m elements, a size s(a) ∈ Z^+ for each element a ∈ W ∪ X ∪ Y satisfying B/4 < s(a) < B/2, and a bound B ∈ Z^+, where the total sum of all sizes equals mB.
QUESTION: Can W ∪ X ∪ Y be partitioned into m disjoint sets A_1, A_2, ..., A_m such that each A_i contains exactly one element from each of W, X, and Y and such that, for 1 ≤ i ≤ m, Σ_{a ∈ A_i} s(a) = B?
Note: The constraint B/4 < s(a) < B/2 ensures each triple contains exactly three elements (no subset of one or two can sum to B, and no four or more can fit). This property is used in reductions to establish strong NP-completeness of downstream problems.
Variables
- Count: m^2 (one binary variable for each possible pairing of X and Y elements, given W elements are fixed by index)
- Per-variable domain: binary {0, 1}
- Meaning: Variable z_{j,k} = 1 if elements w_i, x_j, y_k form the i-th triple (where the W-element assignment is implicit). The constraints require: (1) each element appears in exactly one selected triple, and (2) s(w_i) + s(x_j) + s(y_k) = B for each selected triple.
Schema (data type)
Type name: Numerical3DimensionalMatching
Variants: none (sizes are positive integers)
| Field | Type | Description |
|---|---|---|
sizes_w |
Vec<i64> |
Sizes s(w_i) for elements of W (length m) |
sizes_x |
Vec<i64> |
Sizes s(x_j) for elements of X (length m) |
sizes_y |
Vec<i64> |
Sizes s(y_k) for elements of Y (length m) |
bound |
i64 |
Target sum B that each triple must achieve |
Notes:
- This is a feasibility (decision) problem:
Value = Or. - Key getter methods:
num_groups()(= m = |W| = |X| = |Y|),bound()(= B). - The invariant B/4 < s(a) < B/2 should be validated on construction.
- Renamed from
set_w/set_x/set_ytosizes_w/sizes_x/sizes_yfor clarity (the fields store sizes, not set elements).
Complexity
- Decision complexity: NP-complete in the strong sense (Garey & Johnson, 1979; transformation from 3DM, Theorem 4.4). No pseudo-polynomial algorithm exists unless P = NP.
- Best known exact algorithm: O*(3^m) via dynamic programming on subsets, tracking which elements from each set have been used. Brute-force: O((m!)^2) by enumerating all matchings.
- Concrete complexity expression:
"3^num_groups"(fordeclare_variants!) - References:
- M.R. Garey and D.S. Johnson (1979). Computers and Intractability. W.H. Freeman. Theorem 4.4.
Extra Remark
Full book text:
INSTANCE: Disjoint sets W, X, and Y, each containing m elements, a size s(a) in Z^+ for each element a in W union X union Y, and a bound B in Z^+.
QUESTION: Can W union X union Y be partitioned into m disjoint sets A_1,A_2,...,A_m such that each A_i contains exactly one element from each of W, X, and Y and such that, for 1 <= i <= m, sum_{a in A_i} s(a) = B?
Reference: [Garey and Johnson, ----]. Transformation from 3DM (see proof of Theorem 4.4).
Comment: NP-complete in the strong sense.
Note: The book's base definition does not include the B/4 < s(a) < B/2 constraint. This restriction is a property of the strong NP-completeness construction (Theorem 4.4) that is preserved in downstream reductions. Our definition includes it because all standard uses of N3DM rely on this restriction.
How to solve
- It can be solved by (existing) bruteforce. (Enumerate all matchings of W, X, Y into triples; check if each triple sums to B.)
- It can be solved by reducing to integer programming. (Binary ILP with variables z_{i,j,k} = 1 if (w_i, x_j, y_k) form a triple; constraints: each element used exactly once, and s(w_i) + s(x_j) + s(y_k) = B for each selected triple. Companion rule issue to be filed separately.)
- Other: Subset-DP in O*(3^m).
Example Instance
Input:
W = {w_1, w_2}, X = {x_1, x_2}, Y = {y_1, y_2}, m = 2, B = 15
Sizes: s(w_1) = 4, s(w_2) = 5, s(x_1) = 4, s(x_2) = 5, s(y_1) = 5, s(y_2) = 7
Constraint check:
- B/4 = 3.75, B/2 = 7.5. All sizes: 4, 5, 4, 5, 5, 7 — all in (3.75, 7.5) ✓
- Total = 4+5+4+5+5+7 = 30 = 2 × 15 = mB ✓
Valid matching:
- A_1 = (w_1, x_1, y_2): 4 + 4 + 7 = 15 = B ✓
- A_2 = (w_2, x_2, y_1): 5 + 5 + 5 = 15 = B ✓
All 6 elements used exactly once. Each triple has one element from each set. Each triple sums to B. ✓
Answer: YES — this is the unique valid matching (1 out of 4 possible matchings).
Non-trivial structure: The identity matching (w_1,x_1,y_1) and (w_2,x_2,y_2) gives sums 4+4+5=13 ≠ 15 and 5+5+7=17 ≠ 15. The correct matching requires swapping y_1 and y_2.
Negative modification: Change s(y_2) = 6 (still in (3.75, 7.5)). Now total = 29 ≠ 2×15 = 30, so the instance violates the total-sum constraint and is invalid. Instead, change B = 14 with same sizes: total = 30 ≠ 2×14 = 28. Also invalid. For a valid NO instance: s(w_1)=4, s(w_2)=5, s(x_1)=4, s(x_2)=5, s(y_1)=6, s(y_2)=6, B=15. Total = 30 = 2×15 ✓. But (w_1,x_1,y_?): 4+4+y=15 requires y=7, not available. (w_1,x_2,y_?): 4+5+y=15 requires y=6 ✓ → A_1=(w_1,x_2,y_1 or y_2). Then A_2=(w_2,x_1,y_remaining): 5+4+6=15 ✓. So this is YES. Try: s(y_1)=4, s(y_2)=8. But 8 > B/2=7.5. Invalid. Try sizes where no matching works: s(w_1)=4, s(w_2)=5, s(x_1)=4, s(x_2)=6, s(y_1)=5, s(y_2)=6, B=15. Total=30 ✓. (w_1,x_1,y_?): 8+y=15, y=7 — none. (w_1,x_2,y_?): 10+y=15, y=5 → (w_1,x_2,y_1). Then (w_2,x_1,y_2): 5+4+6=15 ✓. Still YES. Hard to find NO with m=2 and the B/4 constraint. The simplest NO: same sizes but B=16. Total=30 ≠ 32. Invalid. Answer: NO instances are structurally hard to construct for m=2 with the size constraint; this is expected since the NP-hardness comes from larger m.
Python validation script
from itertools import permutations
W = [4, 5]; X = [4, 5]; Y = [5, 7]; B = 15
m = 2
# Check constraints
assert all(B/4 < s < B/2 for s in W + X + Y)
assert sum(W) + sum(X) + sum(Y) == m * B
# Find all valid matchings
valid = []
for px in permutations(range(m)):
for py in permutations(range(m)):
if all(W[i] + X[px[i]] + Y[py[i]] == B for i in range(m)):
valid.append((px, py))
assert len(valid) == 1
px, py = valid[0]
assert px == (0, 1) and py == (1, 0)
print(f"Valid matchings: {len(valid)} (unique, non-identity)")
for i in range(m):
print(f" A_{i+1} = (w{i+1}, x{px[i]+1}, y{py[i]+1}) = {W[i]}+{X[px[i]]}+{Y[py[i]]}={B}")Metadata
Metadata
Assignees
Labels
Type
Projects
Status