Acessibilidade / Reportar erro

ALMOST SQUARING THE SQUARE: OPTIMAL PACKINGS FOR NON-DECOMPOSABLE SQUARES

ABSTRACT

We consider the problem of finding the minimum uncovered area (trim loss) when tiling non- overlapping distinct integer-sided squares in an N × N square container such that the squares are placed with their edges parallel to those of the container. We find such trim losses and associated optimal packings for all container sizes N from 1 to 101, through an independently developed adaptation of Ian Gambini’s enumerative algorithm. The results were published as a new sequence to The On-Line Encyclopedia of Integer Sequences®. These are the first known results for optimal packings in non-decomposable squares.

Keywords:
cutting and packing; enumeration; operational research

1 INTRODUCTION

This article addresses a problem we call 2OKPN (2-dimensional Orthogonal Knapsack Problem in an N × N square), defined by:

Given an N × N square container and the set of N − 1 square items sized {1 × 1, 2 × 2, · · · , N − 1 × N − 1}, find a packing of a subset of the items with the minimum uncovered area (trim loss), obeying:

  1. All packed items must be placed entirely inside the container;

  2. no two packed items may overlap;

  3. all packed items must be placed with their edges parallel to those of the container.

2OKPN can be considered the meeting point of two related problems: the OR (Operational Research) researcher’s 2-dimensional Orthogonal Knapsack Problem (2OKP) and the mathematician’s Squaring the Square (STS).

2OKP (among other variations) searches for a packing of rectangular items into a rectangular container to minimize the trim loss. Therefore it is a generalization of 2OKPN to rectangles of arbitrary width and height. Although exact solution methods have been proposed - see Iori et al. (2021)IORI M, DE LIMA VL, MARTELLO S, MIYAZAWA FK & MONACI M. 2021. Exact solution techniques for two-dimensional cutting and packing. European Journal of Operational Research , 289(2): 399-415. for a survey - the fact that the problem is NP-hard motivates research on heuristics, which have less computational cost but usually find only “good” suboptimal solutions. See Wei et al. (2009)WEI L, ZHANG D & CHEN Q. 2009. A least wasted first heuristic algorithm for the rectangular packing problem. Computers & Operations Research , 36(5): 1608-1614., Wei et al. (2011)WEI L, OON WC, ZHU W & LIM A. 2011. A skyline heuristic for the 2D rectangular packing and strip packing problems. European Journal of Operational Research , 215(2): 337-346., Leung et al. (2012)LEUNG SC, ZHANG D, ZHOU C & WU T. 2012. A hybrid simulated annealing metaheuristic algorithm for the two-dimensional knapsack packing problem. Computers & Operations Research, 39(1): 64-73. and Shiangjen et al. (2018)SHIANGJEN K, CHAIJARUWANICH J, SRISUJJALERTWAJA W, UNACHAK P & SOMHOM S. 2018. An iterative bidirectional heuristic placement algorithm for solving the two-dimensional knapsack packing problem. Engineering Optimization, 50(2): 347-365..

STS (among other variations) looks for perfect squared squares: squares that can be tiled by distinct smaller squares with no trim loss. The classical solution approach models the packing as an electrical network, each square corresponding to a wire (Figure 1). The wire has unit resistance, and the current that flows through is numerically equal to the side length of the square. To find perfect squared squares, a graph algorithm enumerates these networks and converts them into the perfect packings they represent (Brooks et al. (1940)BROOKS RL, SMITH CAB, STONE AH, TUTTE WT ET AL. 1940. The dissection of rectangles into squares. Duke Mathematical Journal, 7(1): 312-340.). Whenever this enumeration finds a perfect squared square, it corresponds to the optimal solution of some 2OKPN instance, for example Figure 1 is the optimal 2OKPN solution for N = 110. But since Brooks’ method can only find perfectly decomposable squares (zero trim loss), it cannot be used to solve 2OKPN in general. Although Biró & Boros (1984)BIRÓ M & BOROS E. 1984. Network flows and non-guillotine cutting patterns. European Journal of Operational Research, 16(2): 215-221. later generalized these networks to handle the non-perfect case, we have not attempted to adapt these methods to solve 2OKPN.

Figure 1
Example electrical network corresponding to a perfect squared square.

2 ENUMERATIVE METHOD

Working on STS, Gambini (1999)GAMBINI I. 1999. A method for cutting squares into distinct squares. Discrete Applied Mathematics, 98(1-2): 65-80. proved that 110 is the minimum side length of a square that admits perfect decomposition. Questions like the one he answered (“what is the smallest...”) generate renewed interest in STS, even though much is already known about the problem. In fact, YouTube channel Numberphile created a video featuring STS and some “what is the smallest” questions. By now, the number of views almost reaches 1 million.

Gambini’s result was derived from a search algorithm henceforth called g. Given an N × N square container, g searches for a perfect decomposition by considering all possible placements of distinct smaller squares on delimited plates of the container. A plate is a line segment formed by the top edges of already placed squares (Figure 2). It is delimited if the plates to its left and right are both higher than it (a container wall is always considered higher). For example, in Figure 2, the leftmost and rightmost plates are the only delimited ones.

Figure 2
Example of plates in a square container.

Gambini argues that a perfect packing (zero trim loss) can always be achieved by placing each square at the leftmost end of the smallest-width delimited plate (henceforth SWD plate). This inspires a backtracking algorithm for finding perfect packings, where each square is considered for placement at the SWD plate. The backtracking step occurs when the width of the next SWD plate is smaller than the side of any unplaced square. Figure 3 illustrates part of the execution of g for a 5 × 5 square container.

Figure 3
Partial execution sequence of g for a 5 × 5 square container. The “X” means that no square fits on the current SWD, therefore backtracking occurs.

The original purpose of g is to find perfect dissections with zero trim loss. Therefore, for non- decomposable N-sided containers, the algorithm terminates without finding a solution. Further, in the context of 2OKPN, there is no guarantee that g will find the packing with minimum trim loss, since the backtracking step may cut away the path to such a packing.

Even so, we have independently devised an adaptation to the algorithm that allowed us to solve 2OKPN. It consists of modifying the set of available squares by including extra units of the 1 × 1 square. For example, suppose we know N = 100 (which is non-decomposable) admits a packing with 1 unit trim loss. Then, by adding an extra 1 × 1 square to the set of available squares used by g, the algorithm will find the solution (using both 1 × 1 units). Removing the excess square, we are left with the packing shown in Figure 4. Hereafter we write g(N, e 1) to denote the packing obtained by g on an N × N container when g is supplied e 1 extra units of the 1 × 1 square. Notice that the actual packing found by g may contain less than e 1 extra units.

Figure 4
Minimum trim loss packing for an N = 100 square container. In the detail, the trim loss is indicated by a 1 × 1 grey square.

We initially thought the idea was novel (although simple), but later found Lesh et al. (2004)LESH N, MARKS J, MCMAHON A & MITZENMACHER M. 2004. Exhaustive approaches to 2D rectangular perfect packings. Information Processing Letters, 90(1): 7-14. had mentioned it as a suggestion (but not implemented it).

Since our objective was to solve every 2OKPN from N = 1 to N = 101, we created a method to make use of information obtained from previous solutions. We call it SUB, for speculative upper bound. To explain it, consider e1(N) the minimum trim loss possible on an N × N square container, a quantity only dependent on N, and that is unknown a priori. When g solves an N-sided square, we take note of e1(N). Later, when solving for N + 1, we take e1(N) as a speculative upper bound e1¯(N+1) for e1(N+1). Also, we define the lower bound e1¯(N+1)=0 (we know by Gambini’s proof that 1 is a lower bound, but we chose not to rely on this result and instead rediscover it). What follows is a search for the exact value of e1(N+1) which resembles a binary search, and we describe by the procedure:

  • 1. (Initialization): Assign e1¯(N+1)0 and e1¯(N+1)e1(N) .

  • 2. (Validate speculative upper bound): Execute gN+1,e1¯(N+1) . If no solution is found, assign e1¯(N+1)e1¯(N+1)+1 and e1¯(N+1)max2e1¯(N+1),1 , then repeat step 2. Otherwise, if g found a solution that uses e g extra units of the 1 × 1 square, assign e1¯(N+1)eg and go to step 3.

  • 3. (Binary search): If e1¯(N+1)e1¯(N+1) , go to step 4. Otherwise, execute

  • g N + 1 , e 1 ¯ ( N + 1 ) + e 1 ¯ ( N + 1 ) / 2

  • If no solution is found, assign e1¯(N+1)e1¯(N+1)+1 . Otherwise, if g found a solution that uses e g extra units of the 1 × 1 square, assign e1¯(N+1)eg . In any case, repeat step 3.

  • 4. (Solution found): The minimum trim loss possible is e1(N+1)=e1¯(N+1) .

Step 1 is necessary because the initial value of e1¯(N+1) (which is e1(N)) may not be a valid upper bound for e1(N+1). But when step 1 completes, this is no longer an issue, and the remaining steps implement a binary search attempting to execute g as few times as possible. Note that the “max” operator in step 2 is necessary because e1¯(N+1) may have been 0 before the reassignment.

3 PROBLEM REDUCTION

Given an instance of 2OKPN, we call trivial the solution where the N − 1 × N − 1 and 1 × 1 squares are the only ones packed. The trivial solution has trim loss N 2 ((N − 1)2 + 1) = 2(N − 1). As for other solutions, consider what happens when a square with side length J > N/2 is packed: after it, no square larger than N − J can be packed. Therefore, a lower bound L J on the achievable trim loss is:

L J = max 0 , N 2 - J 2 + j = 1 N - J j 2 (1)

Consequently, the J × J square can only be present in a non-trivial optimal solution if:

L J < 2 ( N - 1 ) (2)

J 2 + j = 1 N - J j 2 > ( N - 1 ) 2 + 1 (3)

- J 3 3 + J 2 N + 3 J 2 2 - J N 2 - J N - J 6 + N 3 3 - N 2 2 + 13 N 6 - 2 > 0 (4)

If N is understood as a parameter, the left-hand side of the inequality in Equation 4 is a polynomial p N (J) on the variable J. According to the Cardano formula, it has three roots j 1, j 2 and j 3:

j 1 = N - 25 + 96 N - 11 4 (5)

j 2 = N - 1 (6)

j 3 = N + 25 + 96 N + 11 4 (7)

Since N ∈ ℕ*, all three roots are real numbers. If we further restrict ourselves to N > 2, then j 1 < j 2 < N < j 3. Also, the derivative of p N (J) at J = j 1 is always negative when N > 2 (we omit this calculation), therefore p N (J) is positive for all J < j 1 and negative for all j 1 < J < j 2.

With this, the solution to the inequality in Equation 2 where 0 < J < N − 1 and N > 2 is

J < N - 25 + 96 N - 11 4 (8)

In other words, squares larger than the right-hand side of Equation 8 can be removed without compromising optimality. We reduce the 2OKPN instances in this way before executing the enumerative algorithm described in the previous section.

4 RESULTS

At the time of writing, we have solved all 2OKPN instances with 1 ≤ N ≤ 101 and thus proposed a new sequence (A334905) to The On-Line Encyclopedia of Integer Sequences® (OEIS Foundation Inc. (2022)OEIS FOUNDATION INC. 2022. The On-Line Encyclopedia of Integer Sequences. Available at: https://oeis.org.
https://oeis.org...
). The Nth term of the sequence is the trim loss of the solution to 2OKPN. The link https://oeis.org/A334905 is the entry for the sequence, and illustrations of the optimal packings obtained (Figure 4 is an example) can be viewed at https://oeis.org/A334905/a334905_3.pdf.

All results were obtained by a single-threaded program running on a computer with Inter(R) Core(TM) i5-2410M CPU @ 2.30GHz and 4GB physical memory. In what follows, we omit instances with N < 15 because they have trivial optimal solution. Figure 5 illustrates the total time taken (in hours) to solve each 2OKPN instance for 15 ≤ N ≤ 101 and their optimal trim losses. For the full numerical data, see Table 1. Trim loss and execution time are correlated, in the sense that, in 99% of the cases where e1(N+1)e1(N), solving for N + 1 takes more (resp. less) time than solving for N when e1(N+1) is greater (resp. less) than e1(N).

Figure 5
Total solution time for 2OKPN instances.

Table 1
Solution time of 2OKPN instances, in seconds.

Figures 6, 7 and 8 break down the duration of individual executions of g for each N (there are three separate figures for ease of presentation). Note that Figure 6 measures time in minutes, whilst Figures 7 and 8 measure time in hours. Before inspecting the empirical data, one may predict that the duplication of e1¯(N+1) in step 2 of SUB would likely lead to long search times because the search tree of g(N+1,e1¯(N+1)) gets bigger as e1¯(N+1) increases. But this hypothesis is proved false by the aforementioned Figures, since the darkest-colored cells are almost always to the left of the bold cell in each row of these Figures. In other words, for the majority of the values of N, SUB spends more time executing g(N, X) where X<e1(N) than it does where Xe1(N). This means that proving that a solution is optimal takes more time than finding this solution.

Figure 6
Breakdown of times (in minutes) for g(N, X) as executed during the solution procedure, for N < 42. Bold cells indicate e1(N)=X. Values are rounded to one decimal place.

Figure 7
Breakdown of times (in hours) for g(N, X) as executed during the solution procedure, for 42 ≤ N < 74. Bold cells indicate e1(N)=X. Values are rounded to one decimal place.

Figure 8
Breakdown of times (in hours) for g(N, X) as executed during the solution procedure, for N ≥ 74. Bold cells indicate e1(N)=X. Values are rounded to one decimal place.

Another way to look at this is to notice that g(N, X ) for X<e1(N) amounts to an exhaustive search, as opposed to Xe1(N), where the search is terminated as soon as a solution is found. So even though the search tree is bigger in the latter case, its exploration stops early when a solution is found, whereas in the first case the whole tree must be traversed, taking more time.

Lastly, notice SUB will have to execute g(N,e1(N)-1) at some point to prove that X=e1(N) is the optimal solution for N. Therefore, if SUB had executed g(N, X′) for any X'<e1(N)-1 prior to this, it turns out (a posteriori) to have been a waste of time, since the search tree of g(N, X′) is contained in the tree of g(N,e1(N)-1).

5 CONCLUSION

We considered the problem of finding the minimum uncovered area (trim loss) when tiling non-overlapping distinct integer-sided squares in an N × N square container. We solved it for all container sizes N from 1 to 101 using a binary search procedure called SUB, an independently developed adaptation of Ian Gambini’s enumerative algorithm (here called g). The results were published as a new sequence to The On-Line Encyclopedia of Integer Sequences®. Though this text was only concerned with this particular problem, notice that the solution procedures developed here can be readily applied to the more general case of packing rectangles in a rectangular container.

We showed that it is effective to use the optimal trim loss of the previous container to initialize the N × N search. But SUB still cannot avoid calling g(N, X) with X smaller than the optimal number e1(N) of extra 1 × 1 squares, because this is necessary to refute that there exists a packing with X<e1(N). The empirical data proved that these calls represent most of the search time, whilst g(N, X′) for Xe1(N) takes actually less time than intuition would predict a priori. As future work, we suggest to use these observations as starting point to develop different solution procedures aiming to reduce the overall search time.

ACKNOWLEDGMENTS

This study was financed in part by the Coordenação de Aperfeiçoamento de Pessoal de Nível Superior - Brasil (CAPES) – Finance Code 001. The authors thank the anonymous referees for their helpful comments that improved the quality of the manuscript.

References

  • BIRÓ M & BOROS E. 1984. Network flows and non-guillotine cutting patterns. European Journal of Operational Research, 16(2): 215-221.
  • BROOKS RL, SMITH CAB, STONE AH, TUTTE WT ET AL. 1940. The dissection of rectangles into squares. Duke Mathematical Journal, 7(1): 312-340.
  • GAMBINI I. 1999. A method for cutting squares into distinct squares. Discrete Applied Mathematics, 98(1-2): 65-80.
  • IORI M, DE LIMA VL, MARTELLO S, MIYAZAWA FK & MONACI M. 2021. Exact solution techniques for two-dimensional cutting and packing. European Journal of Operational Research , 289(2): 399-415.
  • LESH N, MARKS J, MCMAHON A & MITZENMACHER M. 2004. Exhaustive approaches to 2D rectangular perfect packings. Information Processing Letters, 90(1): 7-14.
  • LEUNG SC, ZHANG D, ZHOU C & WU T. 2012. A hybrid simulated annealing metaheuristic algorithm for the two-dimensional knapsack packing problem. Computers & Operations Research, 39(1): 64-73.
  • OEIS FOUNDATION INC. 2022. The On-Line Encyclopedia of Integer Sequences. Available at: https://oeis.org
    » https://oeis.org
  • SHIANGJEN K, CHAIJARUWANICH J, SRISUJJALERTWAJA W, UNACHAK P & SOMHOM S. 2018. An iterative bidirectional heuristic placement algorithm for solving the two-dimensional knapsack packing problem. Engineering Optimization, 50(2): 347-365.
  • WEI L, OON WC, ZHU W & LIM A. 2011. A skyline heuristic for the 2D rectangular packing and strip packing problems. European Journal of Operational Research , 215(2): 337-346.
  • WEI L, ZHANG D & CHEN Q. 2009. A least wasted first heuristic algorithm for the rectangular packing problem. Computers & Operations Research , 36(5): 1608-1614.

Publication Dates

  • Publication in this collection
    25 Nov 2022
  • Date of issue
    2022

History

  • Received
    07 Apr 2022
  • Accepted
    14 July 2022
Sociedade Brasileira de Pesquisa Operacional Rua Mayrink Veiga, 32 - sala 601 - Centro, 20090-050 Rio de Janeiro RJ - Brasil, Tel.: +55 21 2263-0499, Fax: +55 21 2263-0501 - Rio de Janeiro - RJ - Brazil
E-mail: sobrapo@sobrapo.org.br