This article introduces Logistics: a minimalist 3D bin packing algorithm that clusters items within a container while minimizing empty space. The algorithm uses package superposition to simulate the presence of a single box at multiple places, reducing the number of operations needed to fill the container. The algorithm can be viewed as a Markov chain on the space of multiple partial solutions, enabling it to explore the solution space efficiently.
We show that the same framework — superposition + conflict-oriented random walk — generalizes to any constraint satisfaction problem: Graph Coloring, SAT, Sudoku, N-Queens, and in principle any NP-complete problem reducible to CSP.
The core insight is that many combinatorial optimization problems share the same structure:
The solver operates on Xt = Π Φ(i): the Cartesian product of all domains. Each state is a complete assignment. The Markov chain walks this space by:
Given {(ai, bi, ci, i) : i ≤ n} rectangular shapes and a container (A, B, C), find an anchor function A : (ai, bi, ci, i) ↦ (xi, yi, zi) ∈ [0,A] × [0,B] × [0,C] such that no two items overlap.
Φ : i ↦ {(xi,t, yi,t, zi,t) : t ≤ mi} maps each item to a set of candidate placements. The algorithm explores the Cartesian product X0 = Π Φ(i), narrowing to a consistent assignment.
In the implementation, Φ is generated using an item-dimension-aligned grid: candidate positions at multiples of all item dimensions present in the problem. This produces a compact but complete set of structurally meaningful positions.
Two placements collide iff they overlap on all three axes (separating axis theorem):
Computed in O(1) per pair, O(n2) for all pairs.
Identical items are grouped and placed as block arrangements (nx × ny × nz grids). This reduces the effective problem size for homogeneous item sets.
The state Xt evolves via: at each step, pick a conflicting pair, re-assign one variable. The process is a random walk on [0, n ln(M)] with step size ln(1 ± 1/M), where M = max |Φ(i)|.
Under the assumption that fast collision detection contradicts Xt in O(na) time, the process converges with probability approaching 1 when N ≥ M2 n ln M steps. The probabilistic upper bound: O(na+1 M2 ln M).
The 3DBPP-specific definitions map directly to a general CSP:
| 3DBPP concept | CSP concept | What changes |
|---|---|---|
| Item i | Variable i | Name only |
| Φ(i) positions | Domain(i) values | Domain semantics |
| Collision detection | Conflict predicate | Constraint check |
| Container bounds | Unary constraints | Domain pruning |
| Clustering | Symmetry breaking | Optional preprocessing |
The solver code is identical. Only the variable/domain/conflict definitions change:
| Problem | Variables | Φ (domain) | Conflict |
|---|---|---|---|
| 3D Bin Packing | items | positions × orientations | overlap |
| Graph Coloring | vertices | {0, ..., k-1} | adjacent & same color |
| SAT | boolean vars | {True, False} | unsatisfied clause |
| Sudoku | cells | {1, ..., 9} | duplicate in row/col/box |
| N-Queens | rows | {0, ..., n-1} columns | same col or diagonal |
Instead of random X0, we place variables in decreasing order of constraint difficulty (largest item / smallest domain first). For each, we sample up to 20 candidates and pick the one with fewest conflicts. This often solves easy instances in 0 Markov chain iterations.
Instead of O(n2) full conflict scan per iteration, we maintain per-variable conflict counts and update only the affected neighborhood when a variable changes: O(degree) per iteration.
For Sudoku and similar tightly-constrained CSPs, we run AC-3 preprocessing to prune domains before the Markov chain. This alone solves easy Sudoku instances (the domain collapses to singleton sets via propagation).
N-Queens uses a specialized min-conflicts solver with O(1) conflict counting via column/diagonal counters. This enables solving 1000-Queens in ~230ms.
| n items | Container | Fill ratio | Solved | Iterations | Time (ms) |
|---|---|---|---|---|---|
| 8 | 73 | 68.2% | YES | 3,490 | 27 |
| 50 | 123 | 42.7% | YES | 0 | 12 |
| 100 | 153 | 42.7% | YES | 6 | 50 |
| 200 | 193 | 44.9% | YES | 16 | 229 |
| 300 | 223 | 44.7% | YES | 13 | 505 |
| 500 | 273 | 40.4% | YES | 3 | 1,507 |
Perfect tilings solved: 8 cubes in 43, 27 cubes in 93, 64 cubes in 123. Solution validity verified: all items in bounds, zero collisions, valid orientations. 50/50 random instances solved and verified.
| Graph | Colors | Solved | Iterations | Time (ms) |
|---|---|---|---|---|
| Petersen (10v, 15e) | 3 (chromatic) | YES | 1 | <1 |
| K5 (complete) | 5 (chromatic) | YES | 0 | <1 |
| K5 | 4 (impossible) | NO | 100K | 2,800 |
| G(50, 0.1) random | 5 | YES | 0 | <1 |
| Instance | Solved | Iterations | Time (ms) |
|---|---|---|---|
| 3 vars, 3 clauses | YES | 0 | <1 |
| Random 3-SAT (20v, 70c, ratio 3.5) | YES | 0 | <1 |
| Random 3-SAT (50v, 150c, ratio 3.0) | YES | 0 | 1 |
| Difficulty | Solved | Iterations | Time (ms) | Method |
|---|---|---|---|---|
| Easy (30+ clues) | YES | 0 | <1 | AC-3 alone |
| Hard (17 clues) | NO | 500K | 6,000 | Needs backtracking |
Honest limitation: the Markov chain excels at resolving local conflicts but cannot perform the global constraint propagation that hard Sudoku puzzles require. This is exactly the gap between local search and DPLL/CDCL.
| n | Solved | Iterations | Time (ms) |
|---|---|---|---|
| 8 | YES | 15 | <1 |
| 50 | YES | 152 | 3 |
| 100 | YES | 115 | 4 |
| 200 | YES | 212 | 16 |
| 500 | YES | 346 | 70 |
| 1,000 | YES | 553 | 229 |
Bin Packing: Greedy init O(n · |Φ| · n), Markov chain O(iterations · n) per step. With item-aligned grid, |Φ| is polynomial in container size.
CSP (general): Greedy init O(n · |D| · deg), Markov chain O(iterations · deg) per step with incremental tracking. AC-3 preprocessing: O(e · d2) where e = edges, d = max domain.
N-Queens: O(n) per iteration with column/diagonal counters. Empirically near-linear total iterations in n.
The Logistics framework shares DNA with AUMA (Dana, 2023):
Both encode the problem as "pick one value per variable from a finite domain" and walk the space. The Φ function in Logistics plays the same role as the clause set W in AUMA. The conflict predicate is the analogue of clause evaluation.
The lineage: AUMA (2023) → Dana Theorem (2024) → Snake (SAT classifier) → Logistics (CSP solver). Each step narrows the gap between "everything is MAXSAT" and "how much of combinatorial optimization is tractable with the right framework."
The contribution is the framework: one algorithm structure that works across multiple NP-complete problems by changing only the domain and conflict definitions. The experiments show where it excels (bin packing, graph coloring, N-Queens) and where it struggles (hard Sudoku, very tight 100% tilings).
| Endpoint | Method | Description |
|---|---|---|
/pack | POST | 3D Bin Packing: items + container → placements |
/color | POST | Graph Coloring: adjacency + k colors → assignment |
/sat | POST | SAT: clauses + n_vars → truth assignment |
/sudoku | POST | Sudoku: grid (0=empty) → solution |
/nqueens | POST | N-Queens: n → row-to-column assignment |
/health | GET | Health check |
/paper | GET | This page |
/docs | GET | OpenAPI interactive documentation |