A common class of problems in data structures requires handling a sequence of online requests. In a dynamic resource allocation problem, one has to handle a sequence of allocation and deallocation requests. A good allocation algorithm would run fast, and allocate items in a way that uses as few resources as possible to store the items.
Classical solutions disallow the algorithm from reallocating already-placed items except during deletion. In our problem, the algorithm is allowed to reallocate already-placed items with additional cost. Instead of bounding the running time of the algorithm, we focus on trying to bound the reallocation costs required to handle the sequence of requests, while minimising the amount of space required to handle all the requests.
In this paper, we look at online circle packing, where we try to dynamically pack a set of circles of unequal areas into a unit square while allowing for reallocations. Our work builds on insights from the Split Packing paper by Fekete, Morr, and Scheffer [splitpacking_ws, splitpacking]. The Split Packing paper derives the optimal packing density of squares and obtuse triangles (triangles with an internal angle of at least ). The optimal packing density of a region is the largest value such that any set of circles with total area at most can be packed into the region. To simplify our discussion, we sometimes refer to the optimal packing density of a region as the “capacity” of the region.
As shown in the paper [splitpacking_ws, splitpacking], the optimal packing density for squares is equal to the combined area of the two circles in the configuration shown in Figure 1(c). The optimal packing density for obtuse triangles is the incircle area of the triangle. The Split Packing Algorithm, defined in the paper, is an offline algorithm that packs circles into squares and obtuse triangles to optimal packing density. Figure 1 shows example circle packings produced by the Split Packing Algorithm and our Online Split Packing Algorithm.
1.1 The Problem of Online Circle Packing
In online circle packing, we are given a fixed region, and an online sequence of insertion and deletion requests for circles of varying sizes into the region. In between requests, all circles need to be packed within the bounds of the region such that no two circles overlap. While traditionally circles are not to be moved once placed, in our setting, at any point of time, the algorithm is allowed to reallocate sets of circles, at a cost proportional to the sum of the areas of the circles reallocated (volume cost). We do not require reallocations to be in place, meaning that when a set of circles is to be reallocated to new positions, we can see them as being simultaneously removed from the packing, then placed in their new locations. (This is in contrast to requiring circles to be moved one at a time to their new locations.) We aim to bound the total reallocation cost incurred by the algorithm throughout the packing.
An allocation algorithm is said to have a packing density of on a region if it can handle any sequence of insertion and deletion requests into the region, as long as the total area of the circles in the region at any point of time is at most . The algorithm achieves optimal packing density on a region if it attains a packing density equal to the region’s capacity.
Our main result is the Online Split Packing Algorithm, an dynamic circle packing algorithm based on the original Split Packing Algorithm. The Online Split Packing Algorithm can be used to pack circles into squares and right angled triangles.
For insertions only into a square, the algorithm achieves optimal packing density, with an amortised reallocation cost of for inserting a circle of area .
For insertions only into a right angled triangle of side lengths , and , where , the algorithm can achieve optimal packing density, with an amortised reallocation cost of for inserting a circle of area .
For insertions and deletions into a region (a square or a right-angled triangle) of capacity , the algorithm achieves a packing density of , where can be defined to be arbitrarily small. Consequently, we add an amortised reallocation cost of for inserting a circle of area . In other words, we achieve an amortised reallocation cost of for squares, and for right angled triangles.
1.3 Challenges of Online Circle Packing
The problem of packing circles into a square is a difficult problem in general. The decision problem of whether a set of circles of possibly unequal areas can be packed into a square has been shown to be NP-hard [demaine2010circle]. Given equal circles, the problem of finding the smallest square that can fit these circles only has proven optimal solutions for [locatelli2002packing]. Packing a square to optimal packing density has only been recently solved with Split Packing in 2017.
The best known algorithm for online packing of squares into squares is given by Brubach [improvedsquareintosquare], with a packing density of . By embedding circles in squares, we obtain an online circle packing algorithm with a packing density of [splitpacking]. The optimal packing density for offline packing of circles into squares, as given by Split Packing, is .
The required arrangement of circles in a tight packing is highly dependent on the size distribution of the circles. The Split Packing Algorithm achieves optimal packing density by packing circles in a top-down, divide and conquer fashion that starts with sorting and partitioning the circles by size. Small changes to the inputs result in very different packings.
Our algorithm packs an online sequence of circles tightly by allowing for reallocations. When packing with reallocations, we aim to repack only a part of the configuration at a time. We do this by making use of a binary tree structure similar to the original Split Packing Algorithm. By designing a new packing strategy, we maintain a tree where left children are packed tightly, while extra slack is kept in the rightmost node of each level (this refers to nodes on the right spine of the binary tree) to allow for circle movement. New circles are recursively inserted into the rightmost node of each level, where it eventually triggers a repack of an entire subtree at a certain level to allocate the circle.
1.4 Related Work
There is a large amount of existing work for online resource allocation problems that do not allow items to be reallocated once placed. For example, online square packing into squares has been studied by Han et al. [onlineremovablesquarepacking] and Fekete and Hoffman [square_into_square]. See also similar online packing problems, like squares in unbounded strips [onlinesquarepacking], packing of rectangles [ontwodimensionalpacking] and multiple variants of online bin packing [improvedsquareintosquare, online_multidim_bin_packing, Epstein2005, onlinecubes, onespaceboundedtwodimensional].
While resource allocation problems that allow for reallocations are less commonly studied, there is existing work that employs similar models to achieve better bounds than if reallocations were not permitted. Ivković and Lloyd [ivkovic2009fully] study dynamic resource allocation for bin packing. They provide an algorithm that is -competitive with the best practical offline algorithms when reallocations are allowed. This beats the lower bound of on the competitive ratio if reallocations are not considered. Berndt et al. [berndt2014fully] studies this problem further and achieves better upper and lower bounds. There is also work that focuses on bounding the reallocation cost from reallocating items rather than algorithm running times. A closely related work to our own is online square packing with reallocations by Fekete et al. [fekete2017efficient]. Bender et al. studies dynamic resource allocation with reallocation costs in problems like scheduling [bender2015reallocation], memory allocation [bender2014cost] and maintaining modules on an FPGA [maintainingarrays]. Our work also takes ideas from packed memory arrays [cacheobliviousbtrees, adaptivepma].
There has been plenty of work on circle packing. Most existing work focuses on the global, offline optimisation problem of packing either equal or unequal circles into various shapes. Many existing results for circle packing are collected in the packomania website [packomania]
. Many heuristic methods have also been developed for offline circle packing. An example is[george1995packing]
, which explores a mix of different strategies, like nonlinear mixed integer programming, genetic algorithms and quasi-random techniques, to fit circles of unequal sizes into a rectangle. Offline packings of equal-size spheres into a cube are looked into in[spherepacking]. We refer the reader to [circleliteraturereview] for a review of other circle and sphere packing methods.
There has also been some recent work on the online circle packing. However, this work on online circle packing focuses on minimising the number of square bins used to pack an online sequence of circles. Hokama et al. [hokama2016bounded] provides an asymptotic competitive ratio of , and gives a lower bound of for the problem. The upper bound was improved to in [lintzmayer2017online]. We have not found existing work that takes into account the possibility of reallocations for online circle packing.
2 Background - The Split Packing Algorithm
In this section, we briefly describe the original Split Packing Algorithm. Given a square or obtuse triangle as the region, and any set of circles with total area at most the capacity of the region, the Split Packing Algorithm can pack the set of circles into the region.
The algorithm works in a top down, divide-and-conquer fashion. In the simple case, if the Split Packing Algorithm is given a single circle to be packed into a region, the circle is simply placed into the center of the region. If given at least two circles to be packed, the algorithm partitions the circles into two sets, splits the region into two smaller subregions, and recursively packs each set of circles into its corresponding subregion.
The Split Packing paper describes how a region of capacity is to be split into two smaller regions of capacities and respectively, where . If the original region is an obtuse triangle, is its incircle area. As shown in Figure 1(b), the two subregions will be right angled triangles, defined by squeezing circles of areas and respectively into the left and right corners of the original triangle, which has been oriented such that the obtuse angle is at the top. If the original region is a square, is as shown in Figure 1(c). As shown in Figure 1(d), the two subregions will be isosceles right angled triangles, defined by squeezing circles of areas and respectively into opposite corners of the square.
In both cases, the capacities of the two subregions will then be and respectively. The Split Packing paper proves that as long as , the two subregions will not overlap each other. Note that the two subregions may not be contained within the original region, as shown in Figure 2. To account for this, Split Packing rounds the corners of triangles to form hats, which will remain within the bounds of their parent regions.
Each region has an inherent ideal split key, which is expressed as a ratio of the capacities of the two subregions, when split in a specific way. For obtuse triangles, the split is created by drawing a single vertical line down from the corner with the obtuse angle to perpendicularly intersect the opposite edge, partitioning the triangle into two right angled triangles. The ideal split key for a square is , an even split. Using the ideal split key of the region, the Split Packing Algorithm then partitions the set of circles into two sets. Sizes and are then defined to be the sums of the areas of the circles in each set.
The paper goes further to describe how the same method can be used to pack objects of similar shapes into the same regions. However, the Split Packing Algorithm described is strictly offline, and a method to do this Split Packing dynamically has not been explored.
Similar to the original Split Packing Algorithm, the Online Split Packing Algorithm has a binary tree structure, where each region is recursively split into two smaller nonoverlapping subregions. The root node is the original region we are packing circles into, which is either a square or a right angled triangle. A square splits into two right angled triangles, and a right angled triangle splits into two smaller right angled triangles.
[-Right Angled Triangle] For any , we refer to a right angled triangle with side lengths , and as an -right angled triangle. is the ratio of the lengths of the two shortest sides. In Figure 3, a right-angled triangle is oriented such that the hypotenuse is at the bottom. We can split the triangle vertically into two sides. The long side is closer to the side with length , and the short side is closer to the side with length .
[-shape] To simplify our discussion of the amortised reallocation cost for both right angled triangles and squares later on, we define an -shape to refer to:
A -right angled triangle or a square if
An -right angled triangle if
Splitting an -shape will form two more -shapes, for the same value of . For the case of packing a square, the root node, a square, is a -shape, and all descendants of the root node will be -right angled triangles.
We define the following terms:
(-curve): We say the long/short side of a triangle has a -curve if its corresponding corners have been trimmed to an arc of a circle with area , so that such a circle fits snugly into the corner. Figure 3(a) is a triangle with a -curve on the long side.
(-semihat): A triangle with a -curve on the long side.
(-hat): A triangle where both sides have a -curve.
(--semihat): The intersection between a -hat and a -semihat. It is a triangle where the short side has a -curve, and the long side has a -curve. A -hat can also be thought of as a --semihat.
(Full triangle): A -hat. A full triangle has no rounded corners.
(Capacity): The capacity of a region (which can be a square or a right angled triangle) is the optimal packing density of the shape, as defined in Section 1.
(Total Size): The total size of a region is the sum of the areas of the circles within the region’s bounds. We write to represent the total area of a set of circles .
The circles contained in a region refers to the circles within a region’s bounds (including circles packed into the region’s descendants). An empty region contains no circles.
In this paper, we use the term “triangles” to refer to full triangles, hats and semihats formed from right angled triangles.
4 The Online Split Packing Algorithm
This section describes the Online Split Packing Algorithm. Our algorithm relies on insights from the Split Packing Algorithm for packing circles into a square. We first discuss a version of the algorithm that only handles insertions. Deletions will be discussed in Section 8.
The root of the binary tree is the original region the circles are to be packed into. Sections 5.3 and 5.4 describe how a shape is subdivided into two nonoverlapping subregions, which serve as its two children in the binary tree. The left child of the shape will be packed with a modified version of the original Split Packing Algorithm (Described later in Lemma 5.1), while the right child is recursively packed by our algorithm. As left children are packed with the original Split Packing Algorithm, we only need to concern ourselves with the rightmost node in each level of the binary tree. An example of this can be seen in Figure 4(b).
[Tight and Slack Shapes] A rightmost node of the binary tree is called a:
Tight Shape if the total size of the circles contained within the left child of is equal to the capacity of the left child.
Slack Shape if is not a tight shape and the right child of is a full triangle.
An empty square is split along its diagonal into two right angled triangles, and an empty right angled triangle is split by its ideal capacities (Definition 5.3) as seen in Figure 3. Thus, the initial state of the binary tree (representing an empty region, containing no circles) is an infinite chain of ideal splits, like shown in Figure 4(a). We note that the full height of the tree does not need to be represented in an actual implementation. The tree only needs to be built as deep as the deepest inserted circle, and extended when needed.
[Packing Invariant] Let be a rightmost node of capacity , containing the circles . The packing invariant is said to hold on if:
is either a square or a -semihat for some .
The total size of the circles in is at most .
If is a -semihat with , then there exists a circle in with size at least .
The packing invariant is said to hold on the binary tree if it holds on the rightmost child shape of every level of the binary tree.
[Shape Invariant] The shape invariant holds on a binary tree if on every level, the rightmost node is either a tight shape or a slack shape.
We maintain the two invariants (Definition 5, 5) in between all insertion requests. Both invariants initially hold as the root node is a square, and all rightmost descendants from there are full triangles (-semihats), so all rightmost nodes are slack shapes. There are also no circles in any of the shapes. We show in Section 5.5 that the shape invariant always holds, and we show in Section 6.3 that the packing invariant always holds.
4.1 Inserting a Circle
Algorithm 1 is used to insert a new circle into a shape . A new circle is first inserted into the root of the binary tree, and is then recursively inserted into the right child of each subsequent node, until a repack is triggered at some level, which allocates the circle to a position in the packing. Repack() refers to our repacking algoirthm, which is described in Section 5. Repack completely rebuilds the subtree consisting of the node and its descendants, incurring a reallocation cost proportional to the total size of the circles within the subtree.
[Insertion Invariant] Whenever Algorithm 1 recursively calls itself, the total size of the circle to be packed and the circles already in is at most the capacity of the shape.
Let be the set of circles to be packed into the right child. Let be the set of circles packed into the left child. Let and represent the left and right children respectively. There are two possible cases where we use the recursive call InsertCircle(). If totalSize() + , it is clear the invariant is maintained. If is tightly packed, suppose that . As is tightly packed, , so , which contradicts the invariant. ∎
During insertion, the invariant described in Lemma 1 is maintained, as we only recurse if there is enough room for the circle to be inserted in the child. Lemma 4.1 immediately follows from Lemma 1, and is used to show that the algorithm can handle any sequence of circle insertions with total size at most the capacity of the root node.
As long as the total size of the circles in the entire packing (including the newly inserted circle) is at most the capacity of the root node, Algorithm 1 will only call Repack() when the total size of the circles in is at most the capacity of .
The insertion invariant holds at the root node by the precondition of this lemma, and thus holds through all recursive calls of the algorithm by Lemma 1. By the insertion invariant, the total size of the circles in is at most the capacity of . ∎
5 The Repack Operation
The Repack operation is a recursive algorithm that repacks all the circles contained in a single shape, by completely rebuilding the subtree associated with the shape. To repack a set of circles into a shape ( is a square or some -semihat) of capacity , we divide the shape into the left and right children, two smaller shapes of capacities and respectively, where . The set of circles is also partitioned into two sets and , to be packed into the left and right children respectively. Before splitting the shape , the Repack algorithm, given and , must first decide , , and .
We describe how Repack works for -semihats and squares. Note that a square splits into two -right angled triangles, and an -right angled triangle splits into two -right angled triangles with the same value of . In Section 5.3 we define the ideal capacities and (Definition 5.3), where , which represents the best possible split of the triangle.
5.1 Repacking a Triangle
Let be a -semihat (for some ) of capacity , formed from an -right angled triangle. Suppose the ideal capacities of its long and short sides are and respectively. To decide , , and , there are four cases, with Case 1 having the highest priority and Case 4 having the lowest. For Cases 3 and 4, we make use of defined by the following expression: (an explanation for is given in Lemma 4)
Case 1: There exists a circle in of size
Place the largest circle in , and the remaining circles in . The left child will be packed tightly (), while the right child has the remaining space.
Case 2: has total size
Place all the circles in , while remains empty. The capacities and of the left and right children will be their respective ideal capacities, and .
Case 3: We first iterate through the circles from the largest to the smallest, and greedily pack the circles into the left side while keeping its total size below , as shown in Algorithm 2. This results in the total size of being of the form , for some . We keep the result of Algorithm 2 if . The left child will be packed tightly (), while the right child has the remaining space. Note that this means and . If , we move on to Case 4 instead.
We place the two largest circles in , and the remaining circles in . The left child will be packed tightly (), while the right child has the remaining space.
Once the capacities and of the left and right child have been determined, we split the triangle in a way that matches these capacities. See Section 5.3 for a description of the splitting procedure. and will be the capacities of the long and short children respectively. The long child will be the left child, and the short child will be the right child. The children are then packed as follows:
The circles are packed into the left child using the Split Packing Algorithm for Semihats in Lemma 5.1.
The circles are recursively packed into the right child with the Repack algorithm.
The following lemma is used for the Repack Algorithm on triangles. Lemma 5.1 describes how the original Split Packing Algorithm can be modified to pack circles into a semihat. (The Split Packing Algorithm works for -hats, but is not defined on semihats)
[Split Packing Algorithm for Semihats] Suppose that the Split Packing Algorithm in [splitpacking_ws, splitpacking] is able to pack a set of circles into a -hat with capacity . If at least one circle in of size at least , then the circles can be packed into a --semihat of capacity .
A --semihat is a hat where the -curve of the long side has been enlarged to form a -curve. At each level of the recursion, the Split Packing Algorithm splits a hat into two smaller hats (which we can refer to as the long and short child, depending on which side it comes from), and greedily assigns circles to be packed recursively into the smaller hats (using the Split procedure, detailed in the Split Packing paper). At each level, the long child will be the hat containing the -curve of the original hat. As the largest circle is always the first circle to be assigned, and the assignment of the first circle is arbitrary, we can always choose to assign the largest circle to the long side, which will contain the -curve. This way, we will end up with a packing of the original hat, where the largest circle has been packed snugly into the -curve of the original --semihat. Thus all circles in will also be within the bounds of the --semihat. ∎
5.2 Repacking a Square
Let be a square of capacity . To decide , , and , there are two cases.
Case 1: has total size
We start with all the circles in the left side. We iterate through the circles from the largest to the smallest, and greedily remove circles from the left side while keeping its total size above , as shown in Algorithm 3. This results in the total size of being of the form , for some .
The left child will be packed tightly (), while the right child has the remaining space. Note that this means and .
Case 2: has total size
Place all the circles in , while remains empty. The capacities and of the left and right children will each be .
Section 5.4 describes how a square is split into two triangles given and . The children are then packed as follows:
The circles are packed into the left child with the Split Packing Algorithm.
The circles are recursively packed into the right child with the Repack algorithm.
5.3 Splitting Triangles
The Split Packing paper [splitpacking_ws, splitpacking] describes how a triangle (hat) splits into two smaller triangles (hats). Details are given in Section 2. We do the same thing with semihats (Figure 6). On an -right angled triangle, we call the two smaller semihats the long and short children, corresponding to whether they came from the long or short side.
[Ideal Capacities of a Triangle] Consider splitting a triangle by its split ratio as defined in [splitpacking_ws, splitpacking]. This refers to drawing a vertical line from the right-angled corner to perpendicularly intersect the hypotenuse as shown in Figure 3. We refer to the capacities of the long and short children as their ideal capacities, denoted by and respectively.
The ideal capacities and of an -right angled triangle of capacity obey the following properties:
Referring to Figure 3, as the three triangles are similar, the shortest side of the long child will be of length , so . Similarly, the shortest side of the short child will be of length , so . Finally, . ∎
Suppose a semihat with capacity is split into long and short children with capacities and respectively. The Split Packing paper [splitpacking_ws, splitpacking] shows that if , the two children will not overlap. In our algorithm, we always have . If , a -semihat splits into a --semihat on the long side (for some ), and a full triangle on the short side (Figure 5(a)). If , a -semihat splits into a -semihat on the long side, and a -semihat on the short side (for some , Figure 5(b)).
5.4 Splitting Squares
5.5 Invariants and Properties of the Repack Algorithm
The binary tree is only modified through calls to the Repack Algorithm. The shape invariant (Definition 5) holds for all nodes generated by Repack, as only Case 2 of Repack on both squares and triangles generate non-tight shapes. In these cases, slack shapes are generated. Lemma 5.5 also easily holds from the description of Case 2. We show in Section 6.3 that the packing invariant (Definition 5) will hold on the subtree generated by the Repack Algorithm.
[Post-Repack Property] After the Repack algorithm repacks an -shape, if the shape is a slack shape, the right child will be empty (contains no circles within its bounds). The capacity of the right child will also be of the capacity of its parent.
We look at Case 2 for Repack on both triangles and squares. Both cases produce empty right childs. Let be the capacity of the right child, and be the capacity of its parent. We have for triangles, and for squares. ∎
6 Proof of Correctness
6.1 Triangle Splitting - Properties
[Relationship between capacity of a child and its -curve (triangles)] Consider an -right angled triangle of capacity split into long and short children of capacities and respectively. Let and be the ideal capacities of the triangle (Definition 5.3). If , we write for some . Let be the smallest -curve that needs to be formed on the short side of the long child (Figure 5(a)) for the resulting semihat to be within the bounds of the triangle . We can express in terms of as follows:
Similarly, if we instead have , we can write for some . Let be the smallest -curve that needs to be formed on the long side of the short child (Figure 5(b)) for the resulting semihat to be within the bounds of the triangle . We can express in terms of as follows:
Appendix A.1 ∎
[Triangle Packing Lemma (Short Child)] Let be the expression defined in terms of (short child) in Lemma 6.1 (where , ). Define as follows:
Then for all , we have .
Appendix A.2 ∎
6.2 Square Splitting - Properties
[Relationship between capacity of a child and its -curve (squares)] Consider an square of capacity with a child of capacity . If , we write for some . Let be the smallest -curve that needs to be formed either side of the child triangle (Figure 7) for the resulting hat to be within the bounds of the square . We can express in terms of as follows:
Appendix A.3 ∎
[Square Packing Lemma] Let be the expression defined in terms of in Lemma 6.2 (where ). We then have for .
Appendix A.4 ∎
6.3 Correctness of Repack
The binary tree is only modified through calls to the Repack Algorithm. We show that the packing invariant (Definition 5) will hold on the subtree generated by the Repack Algorithm. This means that every node recursively generated by the Repack Algorithm must obey this invariant. When we call Repack(,) in Algorithm 1, statements 1 and 3 of the packing invariant continue to hold on as they held previously. Statement 2 holds by Lemma 4.1.
We note that circles are only packed in left children. Therefore, to show that the algorithm will always produce packings within the bounds of the region, we only need to show that the circles in left children are always packed within the bounds of the left child. The circles do not overlap as the bounds of the left children do not overlap.
As the only precondition for Lemma 4.1 to hold is for the total size of all circles in the sequence of insertions to be at most the capacity of the root note, this shows that the Online Split Packing Algorithm packs to optimal packing density.
Correctness of Repack on Triangles (-semihats):
The algorithm packs all the circles in the left child within its bounds.
The packing invariant (Definition 5) is maintained when recursing into the right child.
The algorithm packs a set of circles into a -semihat with capacity . The left child will be a --semihat, for some , with capacity . The right child will be a -semihat, for some , with capacity . We do the proof for each of the four cases of the repacking algorithm. We first note the following:
To prove (1), using Lemma 5.1, we only need to show that:
If the -semihat was instead a full triangle, the circles can be packed into the left child with the Split Packing Algorithm.
The largest circle in has size at least .
To prove (2), we show that totalSize() and that there exists a circle in with size at least .
Consider an imaginary circle of size totalSize(). Running Repack on is equivalent to a Split Packing of into a -hat, where the largest circle is placed into the left child.
By the Split Packing analogy, the largest circle alone can be packed into the left child using Split Packing. By the invariant, the largest circle also has size of at least .
It is clear that the circles in have total size at most . The right child is a full triangle (as ), so .
If the original -semihat was a full triangle, then the left child is also a full triangle with capacity . As totalSize(), the Split Packing Algorithm can pack them into the left child. By the invariant, the largest circle, which will be in , also has size of at least .
There are no circles in , and the right child is a full triangle (), so the invariant trivially holds.
If the original -semihat was a full triangle, then the left child is also a full triangle with capacity totalSize(). Thus the Split Packing Algorithm can pack them into the left child.
Due to Case 1, the largest circle will have size , and so will be the first circle to be placed in . By the invariant, this circle has size at least .
It is clear that totalSize(), the capacity of the right child.
Take any circle in . If , then at the point circle was visited by the greedy algorithm, it would have been added to . Thus we must have .
For , let be the expression in terms of defined in Lemma 6.1.
The capacity of the right child is , so . By Lemma 4, as , we have , so the invariant holds.
Case 4: ( is defined in Lemma 4)
We first show that the two largest circles have sizes in .
Take the largest circle . or Case 1 would apply. So otherwise it would be greedily packed into , and Case 3 would apply. Thus all circles in have sizes at most .
has at least one circle, or Case 2 would apply. Any circle in must have size at least or the greedy algorithm would have packed it into . As the largest circle is in by the greedy algorithm, there are at least two circles with size at least . Thus the two largest circles must have sizes in .
Now let the largest two circles be . We show that .
By Lemma 6.3, for all . Thus . If , then the greedy algorithm would place these two circles into , and would then have total size at least , so Case 3 would apply. Thus we must have .
Because , the left child will not be a full triangle. We show that the these two circles fit into the left child (which is the long child).
As both , , we have .
Let be the expression in terms of defined in Lemma 6.1. As is monotonically increasing with , we have . (subbing ).
As , we must have . Thus , so by Lemma 6.3, we have .
Thus , , so the Split Packing Algorithm can pack them into the left child.
By the invariant, the largest circle, which will be in , has size of at least .
It is clear that the circles in have total size at most . As , we must have , the right child is a full triangle, so .
The following lemmas were used in the proof in Case 4. Their proofs are in Appendix A. for all .
Appendix A.5 ∎
If , then we have , where is defined in Lemma 6.1 for the long child (by letting ).
Appendix A.6 ∎
Correctness of Repack on Squares:
The algorithm packs all the circles in the left child within its bounds.
The packing invariant (Definition 5) is maintained when recursing into the right child.
The algorithm packs a set of circles into a square with capacity . The left child will be a -hat of capacity , for some , while the right child will be a full triangle of capacity . We do the proof for each of the two cases of the packing algorithm. We first note that:
To prove (1), we note that the Split Packing Algorithm can pack a set of circles into a -hat of capacity if and every circle in has size at least .
To prove (2), we show that and that there exists a circle in with size at least .
It is clear that . The right child is a full triangle, so .
It is clear that . The left child is a full triangle, so .
There are no circles in , and the right child is a full triangle (), so the invariant trivially holds.
7 Proof of Cost Bound
In this section, we show an amortised reallocation cost of when inserting a circle of size into an -shape. If the region is a square, the cost bound becomes . Note that the depends only on the shape of the root node, as the children of -shapes are also -shapes. By Lemma 5.5, the capacity of the right child of a slack -shape is of its parent’s capacity. This allows us to prove Lemma 7 and Corollary 7.
When inserting a circle of size into an -shape of capacity , Algorithm 1 passes through at most slack shapes.
If the current shape is a slack shape, the ratio of the capacity of the right child to its parent’s is . As each slack shape reduces the shape size by a factor of , the circle passes through at most slack shapes before the circle itself must be larger than the right child’s capacity. ∎
Algorithm 1 always terminates after a finite number of steps.
Algorithm 1 terminates when it calls Repack(.) If the current shape is a tight shape, at least one circle is in the left child. Thus, the algorithm will recurse through at most tight shapes, where is the amount of circles added so far. By Lemma 7, a circle passes through a finite number of slack shapes. The algorithm thus will terminate as each shape is either tight or slack. ∎
Algorithm 1 only repacks slack shapes. Thus, we define a potential function that allocates potential only to slack shapes. The reallocation cost of repacking a shape is at most the capacity of . When a slack shape is newly instantiated after a repack, the right child is initialised as empty (Lemma 5.5). When the shape is to be repacked, the right child, including the newly-inserted circle, would be over capacity. As the capacity of the right child of a slack shape is always exactly of its parent’s capacity, we define the potential allocated to a slack shape as .
With this amount of potential, the shape only needs to draw potential from itself to repack itself. Immediately after a repack, the shape, as well as all its descendants, will store potential. This is as all newly instantiated slack shapes have empty right childs (Lemma 5.5). A newly-inserted circle only contributes to the potential of the slack shapes it passes through, including the one it eventually repacks. As a newly-inserted circle of size only passes through at most slack shapes, the amortised cost of inserting a circle of size is . Thus we have the following result (Theorem 7):
In the case of insertions only, using the Online Split Packing Algorithm, we obtain an amortised cost of to insert a circle of size into an -shape.
8 Online Split Packing for Insertions and Deletions
Given any tight online packing algorithm for insertions only, there is a simple way to extend it to a packing algorithm where both insertions and arbitrary deletions are allowed, by allowing an arbitrarily small amount of slack space. For any fixed , the algorithm will achieve a packing density of on a shape of capacity .
The basic idea is to perform deletions lazily, only actually removing deleted items through repacking when we run out of space. For the Insert operation in Algorithm 4, removing and repacking all the active objects in has a reallocation cost at most the capacity of . After the repack, the total size of is at most , so between repacks, at least of insertions must have been done. Thus we need an additional amortised cost of when inserting an object of size . Suppose that the original insertion algorithm has an amortised reallocation cost of when inserting an object of size . When we allow deletions using Algorithm 4, we then have an amortised cost of per insertion. We note that Algorithm 4 does not need to know the value of being used.
Applying this method in the context of circle packing with the earlier described Online Split Packing Algorithm for insertions only, we obtain the following result (Theorem 8):
When allowing for both insertions and deletions into an -shape of capacity , for any fixed , the Online Split Packing Algorithm achieves a packing density of , with an amortised reallocation cost of for inserting a circle of area . More specifically, for the insertion and deletion of circles into a square, we obtain an amortised reallocation cost of .
We have adapted the Split Packing Algorithm to handle an online sequence of insertions and deletions with a packing density arbitrarily close to optimal by allowing for reallocations. Our cost bound is asymptotically equal across -shapes with differing values of .
The Split Packing algorithm has also been shown to work for packing shapes other than circles, like squares and octagons, into triangles. The paper goes on to define a new type of shape, a “Gem”, which represents the most general type of shape that the Split Packing Algorithm can handle. Due to the close relationship between the algorithms, it is likely that a similar of generalisation would apply to the Online Split Packing Algorithm.
We note that the deletion procedure defined in Section 8 works for any tight packing algorithm for insertions only into a fixed space. The deletion procedure can also be shown to work not only for tight packing algorithms, but also for packing algorithms that achieve packing densities that are arbitrarily close to the optimal.
The current reallocation cost bounds apply only to volume costs. A possible direction of future work would be to understand how the cost bounds differ for the other cost models like unit cost (constant cost for each circle reallocation).
Appendix A Appendix: Proofs of Lemmas
This appendix contains the proofs which have been omitted from the main description of the Online Split Packing Algorithm in the paper.
a.1 Lemma 6.1: Triangle -curve size
Suppose that the bounds causes a -curve to be formed for some .
For the case of the long child, we have three similar triangles, corresponding to the incircle areas of , and respectively. In the case of the short child, the incircles are of areas , and instead.
Let the length of the shortest sides of these triangles be , and respectively.
a.2 Lemma 4: Triangle Packing Lemma
Define , and , we have
For , we need