Packing Boundary-Anchored Rectangles and Squares
Therese Biedl, Ahmad Biniaz, Anil Maheshwari, and Saeed Mehrabi

TL;DR
This paper presents efficient algorithms for boundary-anchored packing problems, maximizing total area of interior-disjoint rectangles or squares anchored at boundary points of a square, with solutions depending on point arrangements.
Contribution
It introduces linear-time and polynomial-time algorithms for boundary-anchored packing problems under specific point configurations.
Findings
Linear-time algorithm for points sorted along the boundary.
An $O(n^4)$-time algorithm for points on two opposite sides.
Effective solutions for maximizing total area of anchored rectangles and squares.
Abstract
Consider a set of points on the boundary of an axis-aligned square . We study the boundary-anchored packing problem on in which the goal is to find a set of interior-disjoint axis-aligned rectangles in such that each rectangle is anchored (has a corner at some point in ), each point in is used to anchor at most one rectangle, and the total area of the rectangles is maximized. Here, a rectangle is anchored at a point in if one of its corners coincides with . In this paper, we show how to solve this problem in time linear in , provided that the points of are given in sorted order along the boundary of . We also consider the problem for anchoring squares and give an -time algorithm when the points in lie on two opposite sides of .
Peer Reviews
No public reviews on file for this paper yet. If you reviewed it on a platform where reviews are public (OpenReview, ICLR, NeurIPS, ICML), you can paste yours below so the community can read it here.
Videos
No videos yet. Explain this paper in a talk, walkthrough, or lecture? Add one.
Packing Boundary-Anchored Rectangles and Squares††thanks: A preliminary version of this paper appeared in the proceedings of 29th Canadian Conference on Computational Geometry (CCCG 2017) [3]. The work of TB and AM is supported in part by Natural Sciences and Engineering Research Council of Canada (NSERC).
Therese Biedl
David R. Cheriton School of Computer Science, University of Waterloo, Waterloo, Canada. [email protected], [email protected]
Ahmad Biniaz
David R. Cheriton School of Computer Science, University of Waterloo, Waterloo, Canada. [email protected], [email protected]
Anil Maheshwari
School of Computer Science, Carleton University, Ottawa, Canada. [email protected], [email protected]
Saeed Mehrabi
School of Computer Science, Carleton University, Ottawa, Canada. [email protected], [email protected]
Abstract
Consider a set of points on the boundary of an axis-aligned square . We study the boundary-anchored packing problem on in which the goal is to find a set of interior-disjoint axis-aligned rectangles in such that each rectangle is anchored (has a corner at some point in ), each point in is used to anchor at most one rectangle, and the total area of the rectangles is maximized. Here, a rectangle is anchored at a point in if one of its corners coincides with . In this paper, we show how to solve this problem in time linear in , provided that the points of are given in sorted order along the boundary of . We also consider the problem for anchoring squares and give an -time algorithm when the points in lie on two opposite sides of .
1 Introduction
Let be an axis-aligned square in the plane, and let be a set of points in . Call a rectangle anchored at a point if is a corner of . The anchored rectangle packing (ARP) problem is to find a set of interior-disjoint axis-aligned rectangles in such that each rectangle in is anchored at some point in , each point in is a corner of at most one rectangle in , and the total area of the rectangles in is maximized; see Figure 1(a). It is not known whether this problem is NP-hard. The best known approximation algorithm for this problem achieves ratio due to Balas et al. [1], who also studied several variants of this problem.
In this paper, we study a variant of the anchored packing problem in which all the points of lie on the boundary of . We refer to this variant as the boundary-anchored rectangle packing (BARP) problem when the anchored objects are rectangles (see Figure 1(b)), while when we require to anchor squares instead of rectangles, we call the problem the boundary-anchored square packing (BASP) problem. We first present an algorithm that solves the BARP problem in linear time, provided that the points of are given in sorted order along the boundary of (Section 2). Despite the simplicity of our algorithm, its correctness proof is non-trivial (Section 3). Then, we consider the BASP problem and give an algorithm for this problem when the points in are on two opposite sides of (Section 4).
Related results.
The rectangle packing problem is related to strip packing and bin packing problems, which are well-known optimization problems in computational geometry. Rectangle packing problems have applications in map labeling [7, 10]. Balas et al. [1] studied several variants of the anchored packing problem; namely, the lower-left anchored rectangle packing problem in which points of are required to be on the lower-left corners of the rectangles in , the anchored square packing problem in which every anchored rectangles is required to be a square, and the lower-left anchored square packing problem which is a combination the two previous problems. For the lower-left rectangle packing problem, Freedman [9] conjectured that there is a solution that covers of the area of . The best known lower bound of of the area of is due to Dumitrescu and Tóth [4]. Balas et al. [1] presented approximation algorithms with ratios and for anchored rectangles and anchored square, respectively. They also presented a 1/3-approximation algorithm for the lower-left anchored square packing problem, and proved that the analysis of the approximation factor is tight. Balas and Tóth [2] studied the combinatorial structure of maximal anchored rectangle packings and showed that the number of such distinct packings with the maximum area can be exponential in the number of points of ; they give an exponential upper bound of , where denotes the th Catalan number.
Finally, Iturriaga and Lubiw [6] studied the elastic labeling in which we are given a set of points on the boundary of a rectangle and the goal is to anchor rectangles to these points such that no two of them overlap. Here, elastic means that the label can have varying width and height, but each rectangle has a pre-specified fixed area. This problem is different than BARP as for the objectives of the two problems for instance, or having no pre-specified restriction on the area of the anchored rectangles in the latter.
2 Boundary-Anchored Rectangles
In this section, we give a linear-time algorithm for the BARP problem. Before describing the algorithm, we first briefly argue that BARP is solvable in polynomial time.
An outline.
It is easy to see [1] that in any rectangle packing the boundaries of rectangles must lie on the grid : the union of the boundary of and the extension of inward rays from all points until they hit the opposite boundary. For each point , there are potential rectangles of anchored at , and so we have a total of candidate rectangles from which we must pick an independent set (with respect to their intersection graph) such that the sum of the weights (defined to be the area of each rectangle) is maximized. If all points are on the boundary, then it is easy to represent each rectangle as a string (i.e., a Jordan curve) such that all strings have a point on the infinite face and two strings intersect if and only if not both rectangles should be taken; see Figure 2. This class of graphs is known as the outer-string graphs for which it is known that maximum-weight independent set is solvable in time, where denotes the number of segments in a geometric representation of the input graph [8]. As such, BARP is solvable in time, but this is rather slow.
In this section, we give key insights that lead to a much faster algorithm. Define a cell to be a maximal rectangle not intersected by lines of the grid . Given an optimum solution , define a hole of to be a maximal connected region of that is not covered by , see Figure 3(b). We show the following in Section 3:
Theorem 2.1**.**
An optimal solution either covers all of , or it has exactly one hole which is a single cell.
It is quite easy to test whether all of can be covered (see Lemma 3.7). In particular, this is always feasible if two points have the same -coordinate or the same -coordinate. In consequence, for the following discussion we assume that no two points have the same - or -coordinate. If we cannot cover all of , then we want to minimize the size of the hole. However, there are a quadratic number of cells, and more crucially, not all cells are feasible; i.e., could be holes. The second key result is therefore the following (by Theorem 2.2):
Lemma 2.1**.**
Given the (at most four) points defining the boundary of a cell , we can test in time whether some packing covers .
This immediately gives an algorithm to find the best solution of type : consider the cells in order, test whether they are feasible and then find the corresponding packing that maximizes the area among those that are feasible. However, it is not necessary to test each cell individually. We can characterize exactly when a cell is feasible, based solely on where the supporting lines of (which are either the boundary of or rays emanating from some points) have their endpoints. Hence, we do not need to look at individual cells, but at the list of points on the four sides, to find the minimum area hole. In the following, we describe this in more details.
We write (resp., and ) for the points of on the bottom (resp., left, top and right) side. For a point in the plane, we denote by and the - and -coordinates of , respectively. The following theorem, which we will prove in Section 3, characterizes possible optimal solutions; Figure 7 on page 7 illustrates these configurations.
Theorem 2.2**.**
Any BARP instance has an optimal solution with rectangles. Moreover (up to rotating the instance by a multiple of and/or reflecting horizontally) the anchor-points used by satisfy one of the following:
, and is the leftmost point of . 2. 2.
, and one of the following holds:
- a
* is the bottommost point of and is the leftmost point of , or* 2. b
* and are the two points of with the closest -coordinates.* 3. 3.
, and have closest -coordinates with , and is the lowest point in . 4. 4.
, and have closest -coordinates with , and and have the closest -coordinates with .
Algorithm.
Our algorithm proceeds as follows. For each of the four rotations, for each of the two reflections, and for each rule 1, 2(a), 2(b), 3, and 4 in Theorem 2.2, compute the corresponding point set. Each of these up to 40 point sets defines a cell , and a packing that covers (see also Lemma 3.5). The algorithm returns the one that has the smallest hole .
Having , and sorted along the boundary of , we can also compute sorted lists of and in linear time. The closest pair within each or between two of them can be computed in linear time.
The correctness will be proved in Section 3. The proof does not use that is a square, only that it is an axis-aligned rectangle. We hence have:
Theorem 2.3**.**
The boundary anchored rectangle packing problem for points, given in sorted order on the boundary of a rectangle, can be solved in time.
3 Correctness of the Algorithm
We first consider the cases when the square can be covered entirely by a packing.
Observation 3.1**.**
Assume one of the following holds.
- i
there exists a point on a corner of , or 2. ii
there exist two points that have the same -coordinates, or 3. iii
there exist two points that have the same -coordinates.
Then we can cover all of with anchored rectangles.
Proof.
In case (i), one rectangle anchored at can cover all of . In case (ii) and (iii), two rectangles anchored at can cover all of . ∎
Since these conditions are easily tested, we assume for most of the remaining section that none of (i)–(iii) holds. (We will see that this implies that there must be a hole.)
We need some notation. Throughout this section, let be an optimal solution for the BARP problem. The term “rectangle” now means one of the rectangles used by . Define to be the graph whose vertices are the rectangle-corners that are not corners of , and whose edges are coincident with the rectangle-sides not on the boundary of ; see Figure 3(b).
We define a max-segment of to be a maximal chain of collinear edges of . We say that is introduced if at least one endpoint of belongs to and is used as anchor-point for some rectangle of . For example, in Figure 3(b), is introduced but is not. Every edge belongs to exactly one max-segment ; we say that is introduced if is. In Figure 3(b), , and are introduced. We already know [1] that all boundaries of rectangles can be assumed to lie on the grid , but we need to strengthen this and prove the following:
Lemma 3.1**.**
There exists an optimal solution such that all max-segments of are introduced.
Proof.
Let be an optimal solution that, among all optimal solutions, minimizes the number of max-segments. Assume for contradiction that there exists a max-segment that is not introduced. After rotation we may assume that is horizontal. Let be the vertical slab defined by the two vertical lines through the endpoints of ; see Figure 4.
Consider moving upward in parallel, i.e., shortening the rectangles with their bottom sides on and lengthening the rectangles with their top sides on . Observe first that these rectangles indeed can be shortened/lengthened, because none of them can be anchored at a point on : the only points of that are possibly in are its ends, but neither of them anchors a rectangle since is not introduced. If this move of increases the coverage, then was not optimal, a contradiction. If this decreases the coverage, then moving downward in parallel would increase the coverage, a contradiction. So the covered area must remain the same during the move. Shift up until it hits either the boundary of or intersects some other horizontal max-segment of . If hits the boundary of , then disappears and will be deleted from . If intersects some other horizontal max-segment of (which may be inside or only share an endpoint with the translated ) then the two max-segments merge into one. Either way we decrease the number of max-segments, which contradicts the choice of and proves the lemma. ∎
From now on, without further mentioning, we assume that is an optimal solution where all max-segments are introduced. We also assume that, among all such optimal solutions, minimizes the number of rectangles.
Lemma 3.2**.**
Every internal vertex of has degree three or four.
Proof.
Every internal vertex of resides on the corner(s) of axis-aligned rectangle(s), and so has degree at least 2 and at most 4. Assume for contradiction that there is a vertex of that has degree exactly 2, and let and be its neighbours. After possible rotation, we may assume that lies to the left of , and lies above , as depicted in Figure 5. Thus, is the bottom-right corner of some rectangle , and no other rectangle has on its boundary. This implies that the region to the right of and below belongs to some hole . So rectangle is anchored either on the left or the top side of ; after a possible diagonal flip we assume that it is anchored on the left.
Define and to be the points of that introduced and , respectively; we know that these must be on respectively since has degree 2. By definition of “introduced” some rectangle is anchored at . We claim that cannot have as its top-right corner. Assume for contradiction that it has. Then we can expand (if needed) to cover the entire rectangle spanned by and ; this can only increase the coverage. In particular, the expanded covers all of . We know that since was anchored on the left side of . This contradicts that has the minimum number of rectangles, so has as its top-left corner.
If the right side of is a sub-segment of , then we can stretch to the right to increase the coverage of , contradicting optimality. So must be a strict super-segment of , which in particular implies that is interior and has no leftward edge. Since is a vertex, it must have a rightward edge; let be the vertex of to the right of . Let be the rectangle whose bottom-left corner is ; this exists since edge is the boundary of some rectangle(s), but the area below belongs to hole . Rectangle cannot be anchored on the right, otherwise we could expand to cover all of and reduce the number of rectangles, a contradiction. So is anchored on the top, which implies that , else they would overlap.
If the bottom side of is a sub-segment of , then we can stretch down to increase the coverage of . So is a strict super-segment of , which implies that is interior. We iterate this process three times as follows. (i) Let be the vertex of that is below , and let be the rectangle whose top-left corner is . Argue as before that is anchored at the right endpoint of the max-segment through , therefore the left side is a strict super-segment of and is interior. (ii) Let be the vertex of that is to the left of , and let be the rectangle whose top-right corner is . Argue as before that is anchored at the bottom endpoint of the max-segment through , therefore the top side is a strict super-segment of and is interior. (iii) Finally, let be the vertex of that is above (possibly ). Now observe that the max-segment through cannot reach the boundary of without intersecting or . Therefore, is not introduced—a contradiction. ∎
We assumed that neither case (ii) nor (iii) of Observation 3.1 holds, which means that any grid-line of the grid has exactly one end in . So, we can direct the edges of the grid (and with it the edges of ) from the end in to the end not in . See also Figure 7. Define a guillotine cut to be a max-segment of for which both endpoints are on the boundary of .
Lemma 3.3**.**
If there is no guillotine cut, then has a hole . Furthermore, is a rectangle, is not incident to the boundary of , and the boundary of is a directed cycle of .
Proof.
We claim that no vertex of on the boundary of is a sink. For if the unique edge incident to were directed from some vertex to , then by Lemma 3.1 and the way we directed the edges of , the point that introduced would be on the opposite side and hence the max-segment would be a guillotine cut. Likewise no interior vertex can be a sink, because by the previous lemma, which implies that two incident edge of have the same orientation (horizontal or vertical). One of them then becomes outgoing at since we direct edges along grid-lines. So has no sink, which implies that it has a directed cycle . The region enclosed by has no point on the boundary, so no rectangle anchored on the boundary can cover parts of it without intersecting . So the interior region of is a hole not incident to the boundary. We know that is a rectangle since it has no vertex of degree 2 by the previous lemma, hence in particular no reflex vertex. ∎
We use the previous lemma in the proof of our following stronger claim.
Lemma 3.4**.**
If has holes, then it has a hole that is a rectangle. Furthermore, every interior corner of has an incoming edge that lies on .
Proof.
We prove by induction on the cardinality of . If is empty then and we are done. Assume that is not empty. If there is no guillotine cut, then is a rectangle by Lemma 3.3 which is interior and whose boundary is a directed cycle; this satisfies all claims. Assume now that there is a guillotine-cut , say it is horizontal. Since case (ii) of Observation 3.1 does not hold, not both and can belong to , say . Segment divides into two rectangles and with above ; see Figure 6(a). There is a rectangle that is anchored at ; up to a vertical flip we may assume that is inside . Observe that must cover all of , else we could find a solution with more coverage or fewer rectangles. Thus is an anchored-rectangle packing for with anchor-points in . Notice that must be optimal for , else we could get a better packing for by adding to it. It cannot cover all of since had holes. Therefore, has a hole and by induction hypothesis is a rectangle; observe that is also a rectangular hole in . This finishes our proof of the first claim.
Now, consider a corner of that is interior to . If is interior to , then by induction hypothesis it has an incoming edge that lies on . Assume that is not interior to and thus it lies on and . Consider an interior vertical edge of ; see Figures 6(b) and 6(c). Observe that is directed upwards because otherwise the max-segment containing it would have intersect . It follows that all interior vertical edges of are directed upwards. Therefore the vertical edge of that is incident to is also upward and hence incoming to as desired. ∎
Hence, hole must satisfy this hole-condition on the edge directions (at least for some optimal solution ); that is, every interior corner of has an incoming edge that lies on . It turns out that this condition is also sufficient.
Lemma 3.5**.**
Let be a rectangle whose sides lie on . If satisfies the hole-condition, then there exists a packing that covers .
Proof.
Let (for some ) be the points of that defined the grid lines on which the sides of reside. We distinguish cases (1)–(4) depending on how many sides of are interior, where case (2) splits further into cases (2a) and (2b) depending on whether the sides are adjacent or parallel. After possible rotation, the hole is situated as shown in Figure 7. Every interior corner of has an incoming edge that is on , which (up to reflection) forces the location of some of as indicated in the figure. In all cases, one verifies that rectangles anchored at suffice to cover . ∎
We are now ready to prove Theorem 2.1. To this end, we first show the following:
Lemma 3.6**.**
If has holes, then it has exactly one hole , and is a cell of .
Proof.
Lemma 3.4 shows that we may assume to be a rectangle that satisfies the hole-condition. By Lemma 3.5, we can cover with anchored rectangles, which by maximality of means that is unique.
If is not a cell, then it is bisected by some grid-line into two pieces and . If some satisfies the hole-condition (i.e., all interior corners have incoming edges on ), then we can create a packing that covers , which contradicts the minimality of . In fact, by inspecting the possible configurations of in cases (1), (2a), (2b), (3), and (4), as well as possible placements of the “undecided” anchor-points and the orientation/direction of (see Figure 8, which shows all but one case), we observe that satisfies the hole-condition as we can cover in each of these cases. So, there is a contradiction in all cases, and must be one cell. ∎
By Lemma 3.6, we have characterized solutions that have holes. It remains to characterize solutions that do not have holes; i.e., to show that conditions (i)–(iii) of Observation 3.1 are necessary.
Lemma 3.7**.**
If can be covered with anchored rectangles, then one of (i), (ii) or (iii) holds.
Proof.
Let be a packing that covers all of . If has no edge, then all of must be covered by one rectangle, which hence must be anchored at a corner of and (i) holds. So assume that has edges. By Lemma 3.3, since has no hole there must be a guillotine-cut , say it is horizontal. If both and are in then (ii) holds and we are done, so assume and .
Recall the rectangles and from the proof of Lemma 3.4 and observe that covers all of using anchor-points in . Apply induction to . If (i) holds for them, then has a point on a corner of , which by is also a corner of and we are done. If (ii) holds for them, then two points in have the same -coordinate and we are done. Finally (iii) cannot hold for because the top side of has no point of on it since . ∎
We are finally ready to prove Theorem 2.2. Let be the optimal solution with the minimum number of rectangles. If covers all of , then by Lemma 3.7 one of (i)–(iii) holds. If (i) holds, then the corner in will be chosen under rule (1). (In these and all other cases, “chosen” means “after a suitable rotation and/or reflection”.) If (ii) or (iii) holds then the two points with the coinciding coordinate will be chosen under rule (2b).
If has holes, then by Lemma 3.4 its unique hole is a cell such that all interior corners of have incoming edges on . Let be the points that introduce interior sides of . We know that has one of the types shown in Figure 7, and hence will be considered under the corresponding rule. Moreover, all point sets that fit the type can be realized by Lemma 3.5. So must be the one that minimizes the area, which corresponds to the points minimizing the -distance resp. -distance. So one of rules 1, 2a, 2b, 3 or 4 applies to the points and Theorem 2.2 holds.
4 Boundary-Anchored Squares
Recall that is an axis-aligned square in the plane and is a set of points on the boundary of . In the boundary anchored square packing (BASP) problem we want to find a set of disjoint axis-aligned squares in that are anchored at points of and maximize the total area. For this problem we are unable to find a grid—as we did for rectangle packing—that discretizes the problem such that the sides of every square in an optimal solution lie on that grid. It might be tempting to obtain a grid as follows. For every point on the bottom side of we add the following lines to the grid (see Figure 9(a)):
- (0)
one vertical line through , 2. (0)
one horizontal line through the top side of the largest square in that has on its bottom-left corner, and one for a similar square that has on its bottom-right corner, and 3. (0)
for every other point on the bottom side of , we add one horizontal line through the top side of the square that has the segment as its bottom side.
We add similar lines for points that are on the left side, the right side, and the top side of . Let be the resulting grid. We construct a set of points for which no optimal solution of the BASP is introduced by . Figure 9(b) shows a set of six points with an optimal solution associated for them. A point lies on the bottom side of and at distance from the bottom-left corner of , for a small . Five points arranged on the top side of from left to right such that is the mid-point of the top side of , , and , for a small that is much less than . Any optimal solution for this setting contains the largest square in that has on its bottom-left corner. Also any optimal solution contains the two squares that are anchored at and as depicted in Figure 9(b). The solution shown in Figure 9(b) is optimal. Any optimal solution contains two squares of side-length and one square of side-length that are anchored at . The square of side-length is not defined by , no matter on which of it is anchored.
In the rest of this section we consider two special cases where the points of lie only on one side of , or on two opposite sides of . Later we will see that the two opposite-side case can be reduced to some instances of the one-side case.
4.1 Points on one side
In this section we consider a version of the BASP problem where the points of lie only on one side of . We consider a more general version where is rectangle and the points of lie on a longer side of . To avoid confusion in our notation, we use to represent such a . Let and denote the width and height of , respectively. We assume that the longer side of is parallel to the -axis and points of lie on the bottom side of ; see Figure 10. We introduce a grid such that any optimal solution for this problem is defined by . This grid contains the following lines:
- (0)
a vertical line through , 2. (0)
a horizontal line through the top side of the largest square in that has on its bottom left-corner, and one for a similar square that has on its bottom-right corner, 3. (0)
for every other point , that is at distance at most from , we add one horizontal line through the top side of the square that has the segment as its bottom side, and 4. (0)
one vertical line through the right side of the largest square in that has on its bottom-left corner, and one for a similar square that has on its bottom-right corner.
Based on the construction of , we define a set of squares that are obtained as follows. For every point we add to three types of squares (see Figure 10(a)):
- T1
the largest square in that has on its bottom-left corner, and the largest square in that has on its bottom-right corner, 2. T2
for every other point , that is within distance from , we add a square that has the segment as its bottom side, and 3. T3
for every other point to the right (resp. left) of , which is within distance from , we add a square of side length that has on its bottom-left corner (resp. bottom-right corner).
The set contains squares and all of them are introduced by . We say that a square is introduced by a grid if at least three of its sides lie on the grid. The following lemma enables us to discretize the problem.
Lemma 4.1**.**
Consider an optimal solution for the variant of the BASP problem where the points lie only on the bottom side of the input rectangle. Then, all squares of the solution belong to .
Proof.
Our proof is by contradiction. Consider an optimal solution for this problem and assume that it contains a square that does not belong to . Without loss of generality we assume that has a point on its bottom-left corner. Since is not of type (T1), the top side of does not lie on the top side of . Also, the right side of does not lie on the right side of . If the right side of does not touch any other square in , then we can enlarge and increase the total area of which contradicts its optimality. Let be the square that touches the right side of . Let be the point that is anchored on. Since is not of type (T2), is the bottom-right corner of . Moreover, since is not of type (T3), is not a largest square that is anchored at .
So, we have two touching squares and and none of them are maximum squares. See Figure 10(b). Without loss of generality assume that is not smaller than . By concurrently enlarging and shrinking by a small amount, the gain in the area of would be larger than the loss in the area of . This will increase the total area of which contradicts its optimality. ∎
As a consequence of Lemma 4.1, to solve the BASP problem, it suffices to find a subset of non-overlapping squares in with maximum area. For every square , we introduce a closed interval with the bottom side of . We set the weight of to be the area of . Let be the set of these intervals. Any maximum-weight independent set of intervals in corresponds to a set of non-overlapping squares in with maximum area. A maximum-weight independent set of intervals, given in sorted order of their left endpoints, can be computed in time [5]. The set contains squares and can be computed within the same time bound. Consequently, can be computed in time. Having the points of sorted from left to right, the sorted order of the intervals in can be obtained within the same time bound. Thus, the total running time of our algorithm is .
4.2 Points on two opposite sides
In this section we study a version of the BASP problem where the points of lie on two opposite sides of square . We show how to reduce an instance of this problem into instances of the one-sided version. Since the one-sided version can be solved in time, this reduction implies an -time solution for the two-sided version. We refer to a square that is anchored at a top point (resp. bottom point) by a top square (resp. a bottom square).
Lemma 4.2**.**
For any optimal solution for the BASP problem, where the input points lie only on the top and bottom sides of the input square, there exists no horizontal line that intersects both a top square and a bottom square in its interior.
Proof.
Suppose for a contradiction that such line exists, say it intersects a top square and a bottom square . Since crosses both and , the height of plus the height of is larger than (the height of the boundary square). This implies that their total width is also larger than . Since and are non-overlapping, there is a vertical line which separates from . These two facts imply that the width of the boundary square is larger than , which is a contradiction. ∎
By Lemma 4.2, for every optimal solution there exists a horizontal line that separates its top squares from its bottom squares; refer to such a line as a separating line. We introduce a set of horizontal lines and claim that for every optimal solution of the BASP problem, there exists a separating line that belongs to . Assume that is the unit square, and its bottom-left corner is the origin. For a point , let denotes its -coordinate. First, we add to the horizontal line . Then, for every point on the bottom side of we add the following lines to (see Figure 11(a)):
- (0)
; this line represents the top side of the largest square that has on its bottom-right corner. 2. (0)
; this line represents the top side of the largest square that has on its bottom-left corner. 3. (0)
for every point on the bottom side of , we add ; this line represents the top side of the square that is anchored at and has another corner at . 4. (0)
for every point on the bottom side of , we add ; this line represents the the top side of the square that is anchored at and has another corner at the mid-point of the segment .
Then, for every point on the top side of , we add to the lines analogous to items (1)–(4).
Lemma 4.3**.**
For any optimal solution of the BASP problem, there exists a separating line that belongs to .
Proof.
Consider an optimal solution for this problem. Let be the largest square in and, without loss of generality, assume that is a bottom-square and that is the bottom-left corner of ; see Figure 11(b). By Lemma 4.2, there exists a separating line for . Let be the line that touches the top side of ; observe that is separating since it intersects no top square by Lemma 4.2. If is below the line , then due to maximality of , is also a separating line for and belongs to . Assume that is above .
The rest of our proof is by contradiction. By a similar reasoning as in the proof of Lemma 4.2, we argue that is the only bottom square that touches . However, there might be arbitrarily many top squares that touch . Let denote the -coordinate of . We continuously move up and down within the vertical range , for a very small amount . Then, the -coordinate of is , where . While moving in this range, we change (enlarge or shrink) some squares of as follows and keep track of their area (see Figure 11(b)):
- •
We change in such a way that its top side always lies on . Thus, the are of would be .
- •
Observe that the right side of does not touch the boundary square because otherwise would have been added to by item (2). There can be only one square in that touches the right side of . If such a square exists, then let denote that square, and assume that it is anchored at a point ; see Figure 11(b). The point is on the bottom-right corner of because otherwise would have been added to by item (3). We change in such a way that its left side always touches the right side of . Thus, the area of is
- •
Let be the set of all top squares that touch . We change these squares in such a way that their bottom sides touch . The area of every such square is .
- •
We construct a set of top squares as follows. Consider every square and let be anchored at a point . If there is a top square in that touches from the side that does not contain , then we add to . Let be anchored at as depicted in Figure 11(b). The point is not on the boundary of because otherwise would have been added to by item (3). Also, the square does have the same size as because otherwise would have been added to by item (4); in fact is smaller than . We change in such a way that it always touches . Thus, by moving in the above range, the area of will be .
Let be the set of the above squares; i.e., . After performing the above adjustments, the squares in remain non-overlapping. Also the squares in remain unchanged. Thus, by moving on the vertical range , we obtain a valid solution for the BASP problem. For a given , the total area of the squares in is
[TABLE]
where denotes the cardinality of . As discussed above, the area of is of the form for some constant . This implies that for some constants , , and . This means that is a convex function on the domain . Thus, the maximum value of is attained at an endpoint of the domain, but not at . Therefore, the original solution , for which has -coordinate , cannot be an optimal solution for the BASP problem. ∎
The set contains lines per point of , and thus, lines in total. These lines can be computed in time. By Lemma 4.3, for every optimal solution there exists a separating line in . Therefore, by checking every line in and taking the one that maximizes the total area of the two one-sided instances of the problem (one for each side of ), we can solve the two-sided version of the problem in time.
Remark.
A restricted version of the BASP problem, where every point of should be assigned a non-zero square, can be solved in time for the one-sided case, and in time for the two-sided case. In the one-sided case, we have a constant number of squares/intervals per point because we only need to check its two neighbors. By a similar reason, in the two-sided case we get a constant number of lines per point, and thus, lines in total.
5 Conclusion
In this paper, we considered the anchored rectangle and square packing problems in which all points are on the boundary of the square . By exploiting the properties of an optimal solution, we gave an optimal linear-time exact algorithm for the rectangle packing problem. Observe that our algorithm covers nearly everything for large (contrasting with the fraction of achieved in the non-boundary case [1]). For there are (up to rotation) at least points in , which define vertical slabs. Rule (1) or (2b) will consider the narrowest of them as hole, which has area at most if has area 1. So, we cover a fraction of of . We also considered the square packing problem when the points on are on two opposite sides of , and gave an -time algorithm for this problem.
The most interesting open question is to determine the complexity of the BARP or BASP problem for when the points of can lie in the interior of . Is it polynomial-time solvable? As a first step, it would be interesting to characterize which polygonal curves on could be boundaries of a hole in a solution. Moreover, the complexity of the BASP problem when the points of are on all four sides of remains open.
Acknowledgement.
The authors thank Paz Carmi and Luís Fernando Schultz Xavier da Silveira for helpful discussions on the problem.
The reference list from the paper itself. Each links out to its DOI / PubMed record.
- 1[1] Kevin Balas, Adrian Dumitrescu, and Csaba D. Tóth. Anchored rectangle and square packings. In proceedings of the 32nd International Symposium on Computational Geometry (So CG 2016), Boston, MA, USA , pages 13:1–13:16, 2016.
- 2[2] Kevin Balas and Csaba D. Tóth. On the number of anchored rectangle packings for a planar point set. Theor. Comput. Sci. , 654:143–154, 2016.
- 3[3] Therese C. Biedl, Ahmad Biniaz, Anil Maheshwari, and Saeed Mehrabi. Packing boundary-anchored rectangles. In proceedings of the 29th Canadian Conference on Computational Geometry (CCCG 2016), Ottawa, Canada , 2017.
- 4[4] Adrian Dumitrescu and Csaba D. Tóth. Packing anchored rectangles. Combinatorica , 35(1):39–61, 2015.
- 5[5] Ju Yuan Hsiao, Chuan Yi Tang, and Ruay Shiung Chang. An efficient algorithm for finding a maximum weight 2-independent set on interval graphs. Inform. Process. Lett. , 43(5):229–235, 1992.
- 6[6] Claudia Iturriaga and Anna Lubiw. Elastic labels around the perimeter of a map. J. Algorithms , 47(1):14–39, 2003.
- 7[7] Konstantinos G. Kakoulis and Ioannis G. Tollis. Labeling algorithms. In Roberto Tamassia, editor, Handbook on Graph Drawing and Visualization. , pages 489–515. Chapman and Hall/CRC, 2013.
- 8[8] J. Mark Keil, Joseph S. B. Mitchell, Dinabandhu Pradhan, and Martin Vatshelle. An algorithm for the maximum weight independent set problem on outerstring graphs. Comput. Geom. , 60:19–25, 2017.
