In Solving the Partridge Packing Problem using MiniZinc last year, we modeled and solved the classical Partridge packing puzzle. That version is a hard satisfaction problem. Sizes 2 to 7 have no solution at all, and finding one for the larger sizes takes a fair amount of luck. This year we look at a small variation: pack the same square parts into the smallest square that holds them.
Recent findings suggest that as an optimization problem, the puzzle has an answer at every size, and most solvers produce a sequence of ever tighter packings on the way there. That makes it a good way to watch solvers search and compare search heuristics. This post assumes some familiarity with the previous one.
Industry observers note that in the original Partridge Packing Problem, the goal is to pack the parts into a square of side Tn=n(n+1)2T_n = \frac{n(n+1)}{2}Tn=2n(n+1), the nnnth triangular number. Size nnn has one 1×11 \times 11×1 part, two 2×22 \times 22×2 parts, and so on up to nnn parts of size n×nn \times nn×n. Together they have exactly the area of the Tn×TnT_n \times T_nTn×Tn square, so a solution is a perfect tiling.
The minimizing variant asks for the smallest square that holds all the parts. For n=2n=2n=2, the satisfaction problem requires a 3×33 \times 33×3 square, and as shown in the original post, the two 2×22 \times 22×2 parts cannot both fit. The smallest square that works is 4×44 \times 44×4:.
The model starts from a generous board with side 2Tn2 T_n2Tn, so 666 for n=2n=2n=2. The animation steps through tighter packings for n=2n=2n=2 on that board, down to the optimal 4×44 \times 44×4.
We adapt the improved Partridge Packing model from the previous post. That takes a wider board, variables for the bounding square, a relaxed fill constraint, and a guard on the edge-placement constraints.
The board grows to twice the triangular number along each side, which leaves the solver plenty of room to find a first packing and then tighten it.
Upcoming variables track the largest position used along each axis, and the larger of the two is the side of the bounding square.
The lower bound is the side of a completely filled square. We minimize max_pos, and each time branch and bound tightens its upper bound, the parts get less room to move. Instead of a fixed board side, the packing constraints keep each part within max_pos_x and max_pos_y, while the diffn no-overlap constraint stays unchanged.
The original model’s exact_fill constraint required every row and column to be completely filled. That only holds when the board area equals the total area of the parts. On a larger board, most rows and columns have empty space, so the constraint bounds the fill by max_pos, the current side:.
Recent findings suggest that at_most_fill is much weaker than exact_fill, since it only prevents overfilling, but it stays valid on every board. Bounding by card(Pos) instead would cap each row and column at the largest allowed side, which claims almost nothing.
The edge-placement constraint relies on the parts filling all available space. With any slack at all, nearly every placement near the edge becomes possible again. We keep the constraint unchanged, guarded so it only applies when max_pos reaches the lower bound triangular_n and the packing must be an exact tiling. MiniZinc compiles the guard into half-reified constraints.
The full MiniZinc model is available for download. It uses the Chebyshev shell search described below, with the other search strategies included as comments.
Industry observers note that as a first test, here is n=5n=5n=5 with OR-Tools CP-SAT. In the original problem, the 15×1515 \times 1515×15 square has no solution.
A constraint programming solver optimizes with branch and bound: once it finds a solution, every later one must be strictly better. CP-SAT is also a portfolio solver that runs several workers in parallel, each with its own strategy, so consecutive solutions can look very different. The animation replays the n=5n=5n=5 run down to an optimal 16×1616 \times 1616×16 square.
Sources indicate that given the same model, solvers search in very different ways. I ran six of them on sizes n=2n = 2n=2 to 101010, with MiniZinc 2.11.0 on an Apple M1 Max (10 cores) and a limit of 300 s per run, compilation included.
The animation below replays the runs for n=6n = 6n=6, where the 21 parts start on a 42×4242 \times 4242×42 board. The buttons at the top switch to n=5n = 5n=5, 777, or 888. Each board reveals its solver’s best packing so far, on a shared clock. The timeline has a tick for each solution on a logarithmic time scale; drag it to jump to any moment.
1 solution, not proved in 300 s.
21 solutions, proved optimal at 0.68 s.
21 solutions, proved optimal at 0.81 s.
14 solutions, proved optimal at 0.28 s.
1 solution, proved optimal at 0.43 s.
7 solutions, not proved in 300 s.
Sources indicate that gecode builds outwards from the corner, and its first packing, after 0.26 s, already has the optimal side 22. It never proves optimality, though, and spends the remaining five minutes searching.
Recent findings suggest that chuffed and CP-SAT start from the other end. Their first packings spread over the whole board, and then each solution is exactly one smaller than the last, 21 solutions from 42 down to 22. Huub does the same with a few larger jumps. All three then prove 22 optimal within a second. Pumpkin reports only the optimal packing after 0.43 s and proves it at once.
It has been revealed that hiGHS needs 37 s for its first packing, with side 35, and ends at 23. The model is full of disjunctions (one part is left of, right of, above, or below another), and their linear relaxation indicates very little about the side of the square.
According to recent reports, for n=8n=8n=8 the parts can tile the square exactly, so the optimum is the lower bound, 36. Switch the animation above to n=8n = 8n=8 to watch the 36 parts on a 72×7272 \times 7272×72 board. Here the race is all about the last step. Gecode again starts close, at 37 after 0.82 s, and gets no further. Huub, CP-SAT, and Chuffed walk down to 37 in 1.1 s, 3.6 s, and 12.5 s. Huub finds the exact tiling at 5.7 s, which also proves it optimal, and CP-SAT finds it at 39 s. Chuffed never closes the last unit. Pumpkin is quiet for 51 s, then reports 37, and finds the tiling at 92 s.
Industry observers note that the chart covers all sizes, plotting the side of each solver’s best packing so far against time. A line stops before the right edge where its solver proved optimality. Use the slider to change nnn, and tap or hover over a solver to highlight it.
Sources indicate that time since MiniZinc started, compilation included, log scale. The dashed line is the optimal side, 36. A line that stops before the right edge ends where its solver proved optimality.
Up to n=6n = 6n=6, every learning solver proves the optimum in under a second. At n=7n = 7n=7 the proofs start to cost real time, and at n=9n = 9n=9 only Huub proves the exact 45×4545 \times 4545×45 tiling, after 292 s. For n=2n = 2n=2 to 777, the optimum is always one more than the lower bound: 4, 7, 11, 16, 22, and 29. At n=10n = 10n=10 no solver gets below 56 within five minutes, one more than the 55 achieved in the original post.
The two kinds of curves come from how the solvers search. Gecode’s order places the largest parts first, each as close to the corner as possible, much like a greedy bottom-left packing, so its first solution is already near the optimum. Proving that nothing better exists is another matter: without learning, Gecode meets the same failing arrangements again in every subtree.
Industry observers note that with free search, Chuffed, Huub, and CP-SAT instead start with a packing that uses the whole board. After each solution, the new bound max_pos ≤ best − 1 is usually met at its largest allowed value, so each step is an easy problem while there is slack. The constraints learned under earlier bounds stay valid, so by the time the board is tight, the solver already knows much of why smaller boards fail. Pumpkin is the exception. Up to n=9n = 9n=9 it reports at most two packings, and the first is at most two above the optimum, while at n=10n = 10n=10 it walks down from 72 like the others.
It has been revealed that gecode has no automatic search heuristics, which makes it a good testbed for guiding search explicitly from MiniZinc. The benchmark setup is the same as above. In the tables, a plain time (such as 10.2s) means the solver proved optimality, best@t (such as 22@0.26s) means it hit the time limit with its best square of side best found at t seconds, and none means no solution at all.
In a recent development, without a search annotation, Gecode proves optimality up to n=5n = 5n=5 (11.5 s), but falls behind swiftly after n=6n = 6n=6. At n=10n = 10n=10 it needs 73 s just to find a first packing, of side 110.
Branching on each part’s x and y together, so each part is placed completely before the next, makes a large difference. Since sizes is reversed, the parts are placed largest first.
Interleaved search proves n=5n = 5n=5 in 10.2 s, finds the optimal 29 at n=7n = 7n=7 in 0.35 s, and gets within one or two units of the optimum on the larger sizes. Its first packing still stacks parts up column 1 and reaches the edge of the 2Tn2 T_n2Tn board, so branch and bound has to shrink the square from there.
Another way to guide search is to branch on an auxiliary variable that encodes the placement order. Numbering cells column by column, bottom to top, gives the left-bottom strategy I tried for Gecode in the previous post:.
This did much worse than interleaved search. Proving n=4n = 4n=4 went from 0.17 s to 2.59 s, and n=5n = 5n=5 no longer finished. The clearest symptom highlighted up before optimization even started. The board has four times the area of the parts, so a first packing should be trivial, and interleaved search finds one for n=7n = 7n=7 with 0 failures. The left-bottom model needed 3,064.
The reason is that diffn prunes x and y separately, so it never removes individual occupied cells from position. After a 3×33 \times 33×3 part is placed in the corner, x = 1 is still possible above it and y = 1 to its right, so cell (1,1)(1, 1)(1,1) stays in every other part’s position domain. The same holds for the other cells that part covers, so indomain_min tries them and fails one cell at a time. On top of that, smallest jumps to whichever part has the smallest possible position, often a small part that fits an early gap, which breaks the largest-first order.
Both problems can be fixed in MiniZinc. In the column-major numbering, a square of size sss covers sss vertical strips of length sss, spaced card(Pos) apart, so an implied 1D disjunctive over those strips prunes occupied cells from position directly. Switching to input_order restores largest-first order.
First-packing failures drop to 0, n=4n = 4n=4 proves in 0.16 s again, and n=10n = 10n=10 reaches 57 in 4.6 s instead of 71 after 299 s.
Number the cells column by column, bottom to top, and lay the columns end to end. The board becomes one line, and a square of size sss becomes sss strips of length sss, one per column it covers. Two squares overlap on the board exactly when two of their strips overlap on the line.
Number the cells column by column, bottom to top: column 1 is 0 to 5, column 2 is 6 to 11, and so on. Laying the columns end to end turns the board into one line of 36 cells. Point at a cell to find it on the line.
In a recent development, keeping strips apart on a line is what disjunctive does. It is the classic constraint for tasks that share a single machine, here with the first cell of a strip as the start time and the part’s size as the duration. The starts are built from position, so every start disjunctive rules out is a cell removed from position. Search places the parts largest first and tries the smallest remaining position for each; the illustration below highlights the difference:.
With diffn alone, the overlap rule reasons about whole columns and rows, not single cells. Cells under the placed squares still look possible, so search tries them one at a time, failing 3 times before it reaches cell 3.
Wasted tries: –First good cell: –.
Click the board to place or remove squares of the chosen size.
Recent findings suggest that the board here is 6×66 \times 66×6 instead of 2Tn2 T_n2Tn wide, and the cells are numbered from 0, whereas the model’s x * card(Pos) + y shifts every number by the same amount. The “diffn alone” mode is simplified: it crosses off a cell only when the part fits nowhere in that cell’s whole column or row. Gecode’s diffn reasons in more detail, but it too never removes a single occupied cell from position.
In a recent development, the objective rewards packings close to the corner, which suggests ordering cells by Chebyshev (chessboard) distance from that corner. Cell (i,j)(i, j)(i,j) belongs to shell k=max(i−1,j−1)k = \max(i-1, j-1)k=max(i−1,j−1), the outer edge of a (k+1)×(k+1)(k+1) \times (k+1)(k+1)×(k+1) square at the origin. Within a shell, the top strip is numbered left to right, followed by the right strip bottom to top:.
My first encoding channeled (x[p], y[p]) into a cell number position[p] through a 2D lookup table and branched with smallest. It was painfully slow: proving n=4n = 4n=4 took 112 s, and at n=10n = 10n=10 Gecode found no packing at all in 300 s. The encoding has both problems of the naive left-bottom model, plus a third. The table compiles to a 2D element constraint over (2Tn)2(2 T_n)^2(2Tn)2 entries (12,100 at n=10n = 10n=10), which makes every search node expensive. Even so, the geometric idea showed promise: the first packing for n=7n = 7n=7 had side 30, against 56 for interleaved search.
The shell order does not need the table. Branching on the shell max(x[p], y[p]), then x[p] and y[p], all in input_order, gives the same shell order while placing parts largest first:.
That turns the heuristic around. Proving n=4n = 4n=4 takes 0.16 s instead of 112 s, n=5n = 5n=5 proves in 33 s, and Gecode reaches 37, 47, and 57 on n=8n = 8n=8 to 101010 within 4.3 s. This is the search in the downloadable model.
The shell search avoids the problem with position rather than fixing it. In Chebyshev order, a square covers cells from several shells, so there is no simple disjunctive that prunes occupied cells as in the left-bottom case. MiniZinc 2.11 adds an experimental black-box propagator interface that offers another way: keep the table-based position variables and attach a custom bounds propagator to them.
According to recent reports, each time Gecode runs the propagator, it passes the current bounds of every position and of max_pos. The propagator collects the already placed parts, and for each remaining one scans inward from both bounds past every cell where it would overlap a placed part or stick out beyond the current max_pos.
It has been revealed that number the cells shell by shell and lay the shells end to end. The first k2k^2k2 numbers always fill the k×kk \times kk×k square in the corner, which is why taking the smallest number first packs outward. But a square no longer has a fixed shape on the line. It breaks into pieces whose number and lengths depend on where it sits:.
Shell k holds the cells whose larger coordinate is k, an L-shaped band around the corner. Each shell is numbered along its top edge left to right, then up its right edge from the bottom, ending in the outer corner. Shell k starts at k², so the first k² numbers always fill the k × k corner square, and taking the smallest numbers first packs outward from the corner.
According to recent reports, without a fixed shape there is no disjunctive to state, so the propagator checks cells one at a time instead. It only moves the two ends of each position range, stopping at the first cell from each end where the part fits. The board below starts with two 3×33 \times 33×3 parts placed and a 2×22 \times 22×2 part to place next:.
Press Play to watch search place the 2 × 2 part, trying the cells that are still possible in shell order, smallest first.
Propagator checks: –Wasted search tries: –.
A part at a cell has its bottom-left corner there. Click the board to place or remove squares of the chosen size.
The “largest side allowed” stands for the current upper bound of max_pos, and the board is 6×66 \times 66×6 with cells numbered from 0. As in the disjunctive illustration, the “table alone” mode is simplified: it crosses off a cell only when the part fits nowhere in that cell’s whole column or row.
The propagator is declared in MiniZinc and implemented outside it, either as a subprocess (:: blackbox_exec) or as a shared library (:: blackbox_dll):.
I wrote the same propagator in C++ and in Python. With the C++ library, first-packing failures drop to 0, n=5n = 5n=5 proves in 23.6 s, and Gecode reaches 37, 47, and 57 on n=8n = 8n=8 to 101010 in under a second each, faster than any other Gecode variant. The Python subprocess explores the same search tree, but every propagation is a round trip to another process, so proving n=5n = 5n=5 takes 138 s instead of 23.6 s. It also needs Gecode 6.6.1, since with 6.6.0 the subprocess failed partway through longer runs.
Recent findings suggest that miniZinc loads the library through a C interface: one function, fzn_blackbox, which gets the bounds as pairs of int64_t and writes the tightened bounds back. Signaling failure means writing an empty interval, [1, 0], for the first variable. Behind that function the propagator is ordinary C++, and the cell coordinates for each instance size are computed once and shared across calls. Build it with c++ -std=c++17 -O3 -dynamiclib, or -shared on Linux. Download chebyshev_bounds.cpp.
Recent findings suggest that for each propagator call, the subprocess reads one line of comma-separated integer bounds from standard input and writes back a line of tightened bounds. The logic is the same as in the C++ version. Download chebyshev_bounds.py.
Neither variant is pure MiniZinc. In Defining Propagators in MiniZinc (Dekker, Stuckey, Tack, Tran, and Wagner, ModRef 2026), the authors propose writing bounds propagators directly in MiniZinc as functions from variable bounds to tightened bounds. With that feature, the Chebyshev propagator could live in the model itself, in about 80 lines of MiniZinc. MiniZinc 2.11.0 does not support it yet, so the version below cannot run.
The predicate keeps the :: minizinc_bounds_propagator annotation, and an overloaded function with the same name maps the bounds (a list of tuple(int, int)) to the new bounds.
For n=10n = 10n=10, 56 is the best result across all solver runs; the exact 55×5555 \times 5555×55 packing from the original post gives the true optimum of 55.
The animation replays the eight variants on one shared clock, as for the solvers above, starting at n=8n = 8n=8.
15 solutions, not proved in 300 s.
36 solutions, not proved in 300 s.
36 solutions, not proved in 300 s.
1 solution, not proved in 300 s.
1 solution, not proved in 300 s.
1 solution, not proved in 300 s.
36 solutions, not proved in 300 s.
2 solutions, not proved in 300 s.
The chart plots the side of each variant’s best packing so far against time, across all sizes.
Sources indicate that time since MiniZinc started, compilation included, log scale. A line that stops before the right edge ends where its solver proved optimality.
How a heuristic is expressed matters as much as the geometric idea behind it. Both naive encodings were far worse than plain interleaved search, whereas the fixed versions all search cleanly. Interleaved search is still Gecode’s fastest proof of n=5n = 5n=5 and finds the best packing at n=7n = 7n=7. On n=8n = 8n=8 to 101010 the C++ propagator gets close to tight packings soonest, each in under a second, and at n=9n = 9n=9 all three Chebyshev variants reach 47 within 1.8 s, against 27.8 s for interleaved search. No Gecode variant proves optimality beyond n=5n = 5n=5.
Recent findings suggest that minimizing the bounding square turns Partridge Packing from an all-or-nothing puzzle into an optimization problem with an answer for every nnn. For n=2n = 2n=2 to 777, where the satisfaction problem is infeasible, the minimum side is always Tn+1T_n + 1Tn+1, and at n=8n = 8n=8 and n=9n = 9n=9 the exact tiling is optimal. Adapting the model takes three changes: widen Pos and minimize max_pos with triangular_n as its lower bound, relax exact_fill to at_most_fill, and guard the edge-placement constraint so it only applies to an exact tiling.
According to recent reports, the Huub v100.1.0 release was the biggest surprise for me. Running on a single core, it beat the 10-thread CP-SAT median on n=6n = 6n=6 to 888 and was the only solver to prove n=9n = 9n=9 optimal within five minutes. In the satisfaction post a year ago, OR-Tools was clearly the fastest MiniZinc backend; here it is still strong, but no longer first.
For Gecode, the lesson is to look at how hard a search works for its first solution on a loose board. Thousands of failures there pointed to weak propagation on the auxiliary search variables, not to anything hard about the puzzle. Fixing that (with an implied disjunctive, direct shell branching, or a black-box propagator) turned both naive heuristics into competitive ones.
