## Abstract

We consider the problem of packing the maximal number of unit squares in a hypograph of a function. A polynomial time algorithm is described to solve this problem for a piecewise linear function.

Show Summary Details# A polynomial algorithm for packing unit squares in a hypograph of a piecewise linear function

#### Open Access

## Abstract

## 1 Introduction

## 2 A theorem about optimal packing

#### Definition 1

#### Theorem 1

#### Proof

## 3 Polynomial algorithm for a piecewise-linear function

#### Theorem 2

## 4 Conclusions

## Problem 1

## Problem 2

## References

## About the article

More options …# Open Engineering

### formerly Central European Journal of Engineering

More options …

Editor-in-Chief: Ritter, William

1 Issue per year

CiteScore 2017: 0.70

SCImago Journal Rank (SJR) 2017: 0.211

Source Normalized Impact per Paper (SNIP) 2017: 0.787

We consider the problem of packing the maximal number of unit squares in a hypograph of a function. A polynomial time algorithm is described to solve this problem for a piecewise linear function.

Keywords: packing unit squares; polynomial algorithm

The problems of rectangular packing and cutting are difficult problems of discrete optimization (for references see [1]). For example, the computational complexity of the problem of packing in a rectangular sheet (*A*, *B*) the maximum number of equal small rectangles (*c*, *d*) (pallet loading problem (PLP)) is unknown. This problem has number 55 in the list of open problems “The Open Problems Project”. It is closely connected with another known problem, 56 in the list of open problems, about the complexity of deciding whether a given number of axis-parallel unit squares can be packed into a simple polygon (without holes). Appearance [2] conjecture the problem to be polynomially solvable. The problem is known to be NP-hard for polygons with holes [3], even if the polygon is an orthogonal polygon with all coordinates being multiples of 1/2. Recently, this version of the problem was shown to be in NP [6], making it NP-complete. This problem arises in wood industry (cutting a log into quadratic plates), in glass industry (cutting defecting pane glass into small equal squares) etc. Applications of analogous problems can be seen in [4, 5]. In this article we consider the problem of packing of unit squares in a hypograph of a function. The article is organized as follows. The second section contains the proof of a theorem about the structure of the optimal packing unit squares in a hypograph of a function. In the third section we propose a polynomial algorithm for the problem with piecewise linear function.

It appears, that a two-dimensional problem about optimum packing unit squares in a hypograph of a function can be reduced to a one-dimensional problem of packing unit intervals in a one-dimensional set which have a trivial solution. If a compact set is represented as a separable union of intervals

$$\begin{array}{}{\displaystyle M=\bigcup _{i\in I}{A}_{i},}\end{array}$$

then the maximum number of single intervals which are possible to pack in this set is given by the obvious formula

$$\begin{array}{}{\displaystyle N=\sum _{i\in I}\lfloor |{A}_{i}|\rfloor .}\end{array}$$

*A hypograph of a function f on the interval* [*a*, *b*] *is the set*

$$\begin{array}{}{\displaystyle H(f,a,b)=\{(x,y)|0\le y\le f(x),a\le x\le b\}.}\end{array}$$

Note that this definition is different from the classical definition of hypograph in [7]. Cleave this set by lines parallel to the *x*-axis with integer *y*-coordinates. We designate these lines by *L _{i}*:

$$\begin{array}{}{\displaystyle {L}_{i}=\{(x,y)|y=i\in \mathbf{N}=\{1,2,\dots \}\}.}\end{array}$$

The intersection of the set *L _{i}* and the hypograph

$$\begin{array}{}{\displaystyle {N}_{i}=\sum _{j\in J}\lfloor |{A}_{i,j}|\rfloor .}\end{array}$$

The following theorem reduces the packing of unit squares to the packing of unit intervals.

*The maximum number N of unit squares in a hypograph H*(*f*, *a*, *b*) *of a function f on the interval* [*a*, *b*] *is given by*

$$\begin{array}{}{\displaystyle N=\sum _{i\in \mathbf{N}}{N}_{i}.}\end{array}$$(1)

This theorem is almost obvious. We prove this claim by induction on the area of a hypograph. If the area of a hypograph is less than 1, then any unit square cannot be packed in such a hypograph. In the same way, any interval *A*_{i,j} = [*a*_{i,j}, *b*_{i,j}] has length less than 1, otherwise, a rectangle

$$\begin{array}{}{\displaystyle {P}_{i,j}\phantom{\rule{thinmathspace}{0ex}}=\phantom{\rule{thinmathspace}{0ex}}\{(x,y)|{a}_{i,j}\le x\le {b}_{i,j},i-1\le y\le i\},}\end{array}$$

lying inside a hypograph *H*(*f*, *a*, *b*), contains unit square. Let for all hypographs of area less then *S*, theorem is valid. Let us show its justice for hypographs of area greater then or equal to *S*. Let us consider a set *H _{1}*(

$$\begin{array}{}{\displaystyle {N}_{1}=\sum _{j\in J}\lfloor |{A}_{1,j}|\rfloor}\end{array}$$

unit squares. All remaining unit squares are above the line *y* = 1. Then these squares with decreased by 1 *y*-coordinate are in the hypograph of a function, *f* (*x*) – 1. By the inductive hypothesis, in the hypograph of a function *f* (*x*) – 1, it can be packed ∑_{i∈N\{1}} *N _{i}* unit squares. Together with squares intersecting a line

Let’s illustrate this theorem by a problem of optimal packing of unit squares in a semicircle of radius 5 (hypograph of a function
$\begin{array}{}\sqrt{25-{x}^{2}}).\end{array}$
We have
$\begin{array}{}{N}_{1}\phantom{\rule{thinmathspace}{0ex}}\phantom{\rule{thinmathspace}{0ex}}=\phantom{\rule{thinmathspace}{0ex}}\phantom{\rule{thinmathspace}{0ex}}\lfloor \sqrt{96}\rfloor ,\phantom{\rule{thinmathspace}{0ex}}{N}_{2}\phantom{\rule{thinmathspace}{0ex}}\phantom{\rule{thinmathspace}{0ex}}=\phantom{\rule{thinmathspace}{0ex}}\phantom{\rule{thinmathspace}{0ex}}\lfloor \sqrt{84}\rfloor ,\phantom{\rule{thinmathspace}{0ex}}\end{array}$
*N*_{3} = ⌊8⌋, *N*_{4} = ⌊6⌋. According to theorem, no more than 32=9+9+8+6 unit squares can be packed in a semicircle of radius 5 and optimal packing is presented in Figure 1.

As another application of this theorem, we consider a problem of packing unit squares in a hypograph *H*(*f*, *a*, *b*) of a function
$\begin{array}{}F(x)\phantom{\rule{thinmathspace}{0ex}}=\phantom{\rule{thinmathspace}{0ex}}\frac{n}{x}.\end{array}$

If this problem can be solved in a polynomial time, then a known unsolved problem of factoring integers in a polynomial time has a positive answer. Let’s designate *N*(*f*, *a*, *b*) as the maximum number of unit squares, which can be packed into a hypograph of a function *H*(*f*, *a*, *b*), then

$\begin{array}{}N(\frac{n}{x},a,b)-N(\frac{n-1}{x},a,b)\end{array}$
is equal to the number of integral points on the graph of the function
$\begin{array}{}f(x)=\frac{n}{x},\end{array}$
*a* ≤ *x* ≤ *b*. As the points (1, *n*), (*n*, 1) lie on the graph of this function, an inequality
$\begin{array}{}N(\frac{n}{x},1,n)-N(\frac{n-1}{x},1,n)\ge 3\end{array}$
tests the primality of *n*. Then, to find prime factors of *n*, one can apply the method of half division of the interval [1, *n*]. Thus, the complexity of a problem of optimum packing of unit squares in a hypograph of a function
$\begin{array}{}H(\frac{n}{x},a,b)\end{array}$
is limited from below by the complexity of factoring integers for which the best algorithms to date do not run in a polynomial time.

In this section we consider a problem of optimum packing of unit squares in a hypograph of a piecewise-linear function and show the existence of a polynomial algorithm for its solution.

Let us consider in the beginning, the case of trapezioidal function:

$$\begin{array}{}f(x)=\left\{\begin{array}{}{c}_{1}+{d}_{1}x,\phantom{\rule{1em}{0ex}}a\le x\le {a}_{1}\\ c,\phantom{\rule{2em}{0ex}}\phantom{\rule{2em}{0ex}}\phantom{\rule{thinmathspace}{0ex}}\phantom{\rule{thinmathspace}{0ex}}{a}_{1}\le x\le {a}_{2}\\ {c}_{2}+{d}_{2}x,\phantom{\rule{1em}{0ex}}{a}_{2}\le x\le b.\end{array}\right.\end{array}$$

Coefficients of this function satisfy the equalities

$$\begin{array}{}{\displaystyle {c}_{1}+{d}_{1}{a}_{1}=c={c}_{2}+{d}_{2}{a}_{2},}\\ \phantom{\rule{thinmathspace}{0ex}}\phantom{\rule{thinmathspace}{0ex}}{c}_{1}+{d}_{1}a={c}_{2}+{d}_{2}b=0,\phantom{\rule{1em}{0ex}}{d}_{1}>0,\phantom{\rule{thinmathspace}{0ex}}{d}_{2}<0.\end{array}$$

The graph of this function is presented in Figure 2.

Then, by Theorem 1, a solution to the problem of packing of unit squares in a hypograph of a function *H*(*f*, *a*, *b*) is given by the formula

$$\begin{array}{}{\displaystyle N(f,a,b)=\sum _{i=1}^{\lfloor c\rfloor}{N}_{i},}\end{array}$$

where

$$\begin{array}{}{\displaystyle {N}_{i}=\lfloor b-a-\frac{i(b-a-{a}_{2}+{a}_{1})}{c}\rfloor .}\end{array}$$

This expression is equal to the number of points of a twodimensional integral lattice without the points on axes of the abscissas in a trapezoid with vertices in points (0, 0), (0, *c*), (*a*_{2} – *a*_{1}, *c*), (*b* – *a*, 0). The formula for the number of integral points in a trapezoid in the vertices (0, 0), (0, *a*), (*b*, *a*), (*c*, 0) is given by

$$\begin{array}{}{\displaystyle N=\sum _{i=1}^{\lfloor a\rfloor}\lfloor c-\frac{i(c-b)}{a}\rfloor}\end{array}$$

Thus, the problem of optimum packing of unit squares in a hypograph of a trapezoidal function is reduced to the problem of counting the number of integral points in a trapezoid. This last problem in the general case of polygons is widely investigated and the existence of polynomial time algorithms is well known (see *e*.*g*. [8, 9]). So, for a solution of this reduced problem there exist effective polynomial algorithms. Thus, the problem of optimum packing of unit squares in the hypograph of trapezoidal function has effective, polynomial algorithms.

Let’s consider the case of a piecewise linear function

$$\begin{array}{}{\displaystyle F(x)=\left\{\begin{array}{}{c}_{1}+{d}_{1}x,\phantom{\rule{thinmathspace}{0ex}}\phantom{\rule{thinmathspace}{0ex}}\mathrm{i}\mathrm{f}\phantom{\rule{thinmathspace}{0ex}}\phantom{\rule{thinmathspace}{0ex}}a\le x\le {a}_{1}\\ {c}_{2}+{d}_{2}x,\phantom{\rule{thinmathspace}{0ex}}\phantom{\rule{thinmathspace}{0ex}}\mathrm{i}\mathrm{f}\phantom{\rule{thinmathspace}{0ex}}\phantom{\rule{thinmathspace}{0ex}}{a}_{1}\le x\le {a}_{2}\\ \dots \phantom{\rule{thinmathspace}{0ex}}\mathrm{i}\mathrm{f}\phantom{\rule{thinmathspace}{0ex}}\dots \\ {c}_{n}+{d}_{n}x,\phantom{\rule{thinmathspace}{0ex}}\mathrm{i}\mathrm{f}\phantom{\rule{thinmathspace}{0ex}}\phantom{\rule{thinmathspace}{0ex}}{a}_{n-1}\le x\le {a}_{n}=b.\end{array}\right.}\end{array}$$

Such a function can be represented as an ordered sequence of vertices of a hypograph considered as a polygon with vertices

$$\begin{array}{}{\displaystyle ({a}_{1},{b}_{1}),\phantom{\rule{thinmathspace}{0ex}}({a}_{2},{b}_{2})\dots ,\phantom{\rule{thinmathspace}{0ex}}({a}_{n},\phantom{\rule{thinmathspace}{0ex}}{b}_{n}),\phantom{\rule{thinmathspace}{0ex}}{a}_{1}<{a}_{2}<\cdots <{a}_{n}.}\end{array}$$

It is easy to see that *O*(*n*) arithmetical operations are sufficient for transforming from one form of presentation to another. Moreover, a problem of optimum packing unit squares in a hypograph of a piecewise linear function can be considered by virtue of the theorem 1, as a problem of counting their numbers with the help of formulas (1), i.e. as counting the sum of integer part of lengths of intervals cutting from a hypograph of a piecewise linear function by the set of lines *y* = *i*, *i* ∈ **N**. Then a problem of counting the sum of integer part of lengths of intervals cutting from a hypograph of a piecewise linear function, considered as a sequence of vertices of a polygon

$$\begin{array}{}{\displaystyle ({a}_{1},{b}_{1}),\phantom{\rule{thinmathspace}{0ex}}({a}_{2},{b}_{2})\dots ,\phantom{\rule{thinmathspace}{0ex}}({a}_{n},\phantom{\rule{thinmathspace}{0ex}}{b}_{n}),\phantom{\rule{thinmathspace}{0ex}}{a}_{1}<{a}_{2}<\cdots <{a}_{n}.}\end{array}$$

by the set of lines *y* = *i*, *i* ∈ **N** is easily decomposed into problems with smaller numbers of vertices, and the sum of such numbers of vertices will be no more than *n*. The main idea consists in cutting a trapezoidal part of a hypograph of a non-unimodal piecewise linear function. Before formulating an algorithm for general case, we shall consider the case of a unimodal piecewise linear function, for which a sequence *b _{i}* is of the form:

$$\begin{array}{}{\displaystyle {b}_{1}\le {b}_{2}\le \cdots \le {b}_{k}\ge {b}_{k+1}\ge \cdots \ge {b}_{n-1}\ge {b}_{n}.}\end{array}$$

Such a polygon can be easily presented in a way in which

$$\begin{array}{}{\displaystyle {b}_{1}={b}_{n-1},\phantom{\rule{thinmathspace}{0ex}}{b}_{2}={b}_{n-2}\dots ,\phantom{\rule{thinmathspace}{0ex}}{b}_{k}={b}_{n-k}\dots}\end{array}$$

Then, counting the sum of the integer part of lengths of intervals cutting from a hypograph of such a function can be reduced to the formula

$$\begin{array}{}{\displaystyle N=\sum _{i=1}^{n/2}{N}_{i},}\end{array}$$

where *N _{i}* is equal to the sum of the integer part of lengths of intervals cutting from a hypograph of trapezoidal function as an appropriate trapezoid with vertices

$$\begin{array}{}{\displaystyle ({a}_{i},\phantom{\rule{thinmathspace}{0ex}}{b}_{i}),\phantom{\rule{thinmathspace}{0ex}}({a}_{i+1},\phantom{\rule{thinmathspace}{0ex}}{b}_{i+1}),\phantom{\rule{thinmathspace}{0ex}}({a}_{n-i-1},\phantom{\rule{thinmathspace}{0ex}}{b}_{n-i-1}),\phantom{\rule{thinmathspace}{0ex}}({a}_{n-i},\phantom{\rule{thinmathspace}{0ex}}{b}_{n-i}).}\end{array}$$

As we already have stated, for calculating *N _{i}* there is a polynomial algorithm based on counting the points of integral lattice in an appropriate trapezoid. Therefore, there is a polynomial algorithm for counting the sum of the integer part of lengths of intervals cutting from a hypograph of a unimodal piecewise linear function by lines

Let’s consider the general case of a piecewise linear function, presented by the sorted list of vertices:

$$\begin{array}{}{\displaystyle ({a}_{1},{b}_{1}),\phantom{\rule{thinmathspace}{0ex}}({a}_{2},{b}_{2})\dots ,\phantom{\rule{thinmathspace}{0ex}}({a}_{n},\phantom{\rule{thinmathspace}{0ex}}{b}_{n}),\phantom{\rule{thinmathspace}{0ex}}{a}_{1}<{a}_{2}<\cdots <{a}_{n}.}\end{array}$$

If this function is not unimodal on the interval [*a*_{1}, *a _{n}*], there is a local minimum of this function

$$\begin{array}{}{\displaystyle {b}_{k-1}>{b}_{k}<{b}_{k+1}.}\end{array}$$

Select the least among such local minima. Let this minimum has an index *k*. Then by a line *y* = *b _{k}*, we cut a hypograph into two parts. The bottom part corresponds to a unimodal function. The upper part corresponds to a function on a smaller interval, and this smaller interval can be divided into two intervals, on each of which it is possible to solve a problem of counting the sum of integer part of lengths of intervals cutting by lines

$$\begin{array}{}{\displaystyle N=N1+N2+N3,}\end{array}$$

where *N*1 corresponds to a solution of a problem for unimodal function, *N*2 is a solution of a problem for function on an interval [*a*′, *a _{k}*],

Then the time of solution *T*(*n*) of considered problem satisfies the recurrent ratio

$$\begin{array}{}{\displaystyle T(n)=P(n)+T(k)+T(n-k),}\end{array}$$

where *P*(*n*) is the time of the solution of a problem for trapezoidal component of a function plus elementary operations on calculation of *k*, *a*′, *b*′. It is easy to show that a solution of the last recurrent ratio requires an easily proved polynomial evaluation *T*(*n*). Thus, taking into account that a problem of calculating the sum of integer parts of intervals cutting by lines *y* = *i* in a hypograph of function is equivalent to a problem of optimum packing of unit squares in a hypograph of this function, the following theorem is proved.

*For a problem of optimum packing of unit squares in a hypograph H*(*f*, *a*, *b*) *of a piecewise linear function f on the interval* [*a*, *b*] *there exists a polynomial algorithm*.

Let’s remark, that the crude estimates allow to evaluate a computing time of the given algorithm as quadratic number of arithmetical operations. That is for a hypograph of function, consisting *n* vertices, the number of arithmetical operations required for calculating the maximum number of unit squares, which can be packed into the hypograph, is evaluated by *O*(*n*^{2}).

The proved theorems make probable a hypothesis about an existence of polynomial algorithm for a general problem of optimum packing the unit squares in a polygon without holes. It is natural to consider at first the following weaker problems.

To prove the existence of a polynomial algorithm for problems of packing of unit squares in a convex polygon.

To prove the existence of a polynomial algorithm for the problem about packing of squares 2 × 2 in a rectilinear polygon without holes, whose all vertices have integer coordinates.

- [1]
H. Dyckhoff, A typology of cutting and packing problems, European Journal of Operational Research 44(1990) 145–159. Web of ScienceCrossrefGoogle Scholar

- [2]
C. Baur and S. P. Fekete, Approximation of geometric dispersion problems, Algorithmica, 30:450-470, 2001. Google Scholar

- [3]
R. J. Fowler, M. S. Paterson, and S. L. Tanimoto. Optimal packing and covering in the plane are NP-complete. Inform. Process. Lett., 12(3):133-137, 1981. CrossrefGoogle Scholar

- [4]
C. Turan and E.N. Amirgaliev. A robust leaky-LMS algorithm for sparse system identification, Proceeding of the 9th international Conference on Discrete Optimization and Operations Research, Vladivostok, Russia, 2016. PP 538-546. Google Scholar

- [5]
Rysbaiyly B., Yunicheva N. An iterative method to calculate the thermal characteristics of the rock mass with inaccurate initial data. Open Engineering. 2016. PP 627-636. Web of ScienceGoogle Scholar

- [6]
Muriel Dulieu, Dania El-Khechen, John Iacono, and Nikolaj van Omme. Packing 2 × 2 unit squares into grid polygons is NP-complete. In Proceedings of the 21st Canadian Conference on Computational Geometry, Vancouver, Canada, August 2009. Google Scholar

- [7]
Rockafellar, Ralph Tyrell (1996), Convex Analysis, Princeton University Press, Princeton, NJ. Google Scholar

- [8]
Alexander I. Barvinok. A polynomial time algorithm for counting integral points in polyhedra when the dimension is fixed. Mathematics of Operations Research, 19(4):769-779, 1994. CrossrefGoogle Scholar

- [9]
M. Beck and S. Robins. Explicit and efficient formulas for the lattice point count in rational polygons using Dedekind-Rademacher sums. Discrete and Computational Geometry, 27(4):443-459, 2002. CrossrefGoogle Scholar

**Received**: 2017-06-13

**Accepted**: 2017-11-19

**Published Online**: 2017-12-29

**Citation Information: **Open Engineering, Volume 7, Issue 1, Pages 403–406, ISSN (Online) 2391-5439, DOI: https://doi.org/10.1515/eng-2017-0045.

© 2017 M. Z. Arslanov *et al*.. This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 License. BY-NC-ND 4.0

## Comments (0)

General note:By using the comment function on degruyter.com you agree to our Privacy Statement. A respectful treatment of one another is important to us. Therefore we would like to draw your attention to our House Rules.