Department of Computer Science, ETH Zü[email protected]://orcid.org/0000-0001-9164-3674 CISPA Helmholtz Center for Information [email protected]://orcid.org/0000-0002-1368-3205Work done in part while at ETH Zürich. Department of Computer Science, RWTH [email protected]://orcid.org/0000-0003-0177-8028 \CopyrightHans-Joachim Böckenhauer, Fabian Frei, Peter Rossmanith \ccsdescTheory of computation Online algorithms
Removable Online Knapsack and Advice
Abstract
In the proportional knapsack problem, we are given a knapsack of some capacity and a set of variably sized items. The goal is to pack a selection of these items that fills the knapsack as much as possible. The online version of this problem reveals the items and their sizes not all at once but one by one. For each item, the algorithm has to decide immediately whether to pack it or not. We consider a natural variant of this online knapsack problem, which has been coined removable knapsack. It differs from the classical variant by allowing the removal of any packed item from the knapsack. Repacking is impossible, however: Once an item is removed, it is gone for good. We analyze the advice complexity of this problem. It measures how many advice bits an omniscient oracle needs to provide for an online algorithm to reach any given competitive ratio, which is—understood in its strict sense—just the algorithm’s approximation factor. The online knapsack problem is known for its peculiar advice behavior involving three jumps in competitivity. We show that the advice complexity of the version with removability is quite different but just as interesting: The competitivity starts from the golden ratio when no advice is given. It then drops down to for a constant amount of advice already, which requires logarithmic advice in the classical version. Removability comes as no relief to the perfectionist, however: Optimality still requires linear advice as before. These results are particularly noteworthy from a structural viewpoint for the exceptionally slow transition from near-optimality to optimality.
Our most important and demanding result shows that the general knapsack problem, which allows an item’s value to differ from its size, exhibits a similar behavior for removability, but with an even more pronounced jump from an unbounded competitive ratio to near-optimality within just constantly many advice bits. This is a unique behavior among the problems considered in the literature so far.
An advice analysis is interesting in its own right, as it allows us to measure the information content of a problem and leads to structural insights. But it also provides insurmountable lower bounds, applicable to any kind of additional information about the instances, including predictions provided by machine-learning algorithms and artificial intelligence. Unexpectedly, advice algorithms are useful in various real-life situations, too. For example, they provide smart strategies for cooperation in winner-take-all competitions, where several participants pool together to implement different strategies and share the obtained prize. Further illustrating the versatility of our advice-complexity bounds, our results automatically improve some of the best known lower bounds on the competitive ratio for removable knapsack with randomization. The presented advice algorithms also automatically yield deterministic algorithms for established deterministic models such as knapsack with a resource buffer and various problems with more than one knapsack. In their seminal paper introducing removability to the knapsack problem, Iwama and Taketomi have indeed proposed a multiple knapsack problem for which we can establish a one-to-one correspondence with the advice model; this paper therefore even provides a comprehensive analysis for this up until now neglected problem.
keywords:
Removable Online Knapsack, Competitive Ratio, Advice Analysis, Advice Applications, Randomized Algorithms, Machine Learning and AI1 Introduction
In this first section, we briefly summarize what online algorithms and advice are, then informally present the problem whose advice complexity we will be analyzing, and finally describe several applications of such advice complexity results.
1.1 Online Algorithms and Advice Complexity
Online algorithms receive their input piece by piece and have to determine parts of the solution before knowing the entire instance. This often leaves them unable to compete with offline algorithms, which know the entire input in advance, in a meaningful way. In the advice model, we assume an omniscient oracle that provides the online algorithm with some information on how to solve the upcoming instance best. If the oracle can communicate to the algorithm an unlimited amount of such advice, it will of course be able to lead the algorithm to an optimal solution for every instance. The advice complexity measures the minimum amount of information necessary for the online algorithm to achieve any given approximation ratio, which is commonly called strict competitive ratio or competitivity in this context.
Advice complexity is a well-established tool to gauge the information content of an online problem [3, 9, 15]. For a detailed and careful introduction to the theory, we refer to the textbook by Komm [20]. Another classical textbook on online problems is written by Borodin and Yaniv [5]. The trade-off between a low number of transmitted advice bits on the one hand and achieving a good competitive ratio on the other hand has been examined for a wealth of problems—see the survey by Boyar et al. [6]—but one stands out for its peculiar behavior: the knapsack problem.
1.2 Knapsack and Removability
A knapsack instance presents the online algorithm with a sequence of items of different sizes. Upon the arrival of each item, the algorithm has to decide whether to pack it into a knapsack or discard it. The goal is to fill the knapsack as much as possible without ever exceeding the knapsack’s given capacity. This problem is sometimes also referred to as the proportional or simple knapsack problem, as opposed to the general knapsack problem, in which every item has not only a size but also a value.111It is also quite common for the proportional and general knapsack problem to be called unweighted and weighted, respectively. The notion weight is ambiguous, however, as some authors [4] use it for what is called size here, while others [18] use it for what is called the value here or profit elsewhere. For the sake of clarity, we are well advised to avoid the term weight altogether. In the generalized version, the goal is to maximize the total value of all packed items. With no further specification given, we are always referring to the proportional case.
A variant of the knapsack problem has been proposed by Iwama and Taketomi [17] under the name of removable knapsack. In this model, we can discard an item not only when it is first presented to us; we may also remove a packed item from the knapsack at any point. This is possible only once for each item, however; once removed, an item cannot be repacked. As for the classical problem without removability, the capacity of the knapsack may not be exceeded at any point in time. Recently, Rossmanith has introduced a similar relaxed online setting for graph problems where decisions are taken only when constraints make it inevitable [24].
This model is arguably just as natural a way to translate the knapsack problem into the online setting as the more well-examined variant without removability. In many cases, it will not be hard to discard items at regular intervals, only the chance of obtaining specific objects is subject to special circumstances. For a practical example, consider a storage room in which you can store all kinds of objects that you come across over time. In the beginning you can just keep collecting everything, but by doing so you inevitably run out of space before too long. Then you will have to start disposing of some of your possessions to make room for new, potentially more interesting acquisitions. Your goal is to end up with a selection of just the most meaningful and useful items that you could have. This paper analyzes the advice complexity of both the proportional and general removable knapsack problem. It is telling you how much information about upcoming opportunities you need to ensure an outcome that is either optimal or off by at most a given factor.
1.3 Advice Applications
Besides inherently interesting insights into the information complexity of the knapsack problem, our advice algorithms also offer more concrete applications. Any algorithm reading a bounded number of advice bits can be implemented by running a bounded number of deterministic algorithms in parallel and selecting the best result. An advice analysis thus tells us, for example, how to optimally organize a betting pool in a winner-take-all scenario. Our main result in particular provides a smart selection of strategies to be assigned to a mere constant number of actors such that one is guaranteed to be as close to optimality as we desire, no matter how difficult the instances of the general knapsack problem with removability may become.
A further advantage of analyzing the advice complexity of a problem is that the resulting bounds are very versatile. The lower bounds are particularly strong. They show that a certain competitivity cannot be achieved with a given amount of additional information, regardless of the form this advice may take. The oracle is indeed able to convey to the algorithm all kinds of structural information about the adversarial instance; for example, in the case of our knapsack problem, whether items smaller than a given threshold should or must not be ignored, whether replacing packed items by later ones will ever be beneficial, whether the values span more than a certain range, whether an optimal solution fills the knapsack completely, whether there are multiple optimal solutions, and so on. Lower bounds on the competitivity of advice algorithms imply lower bounds for randomized algorithms, and our results indeed improve upon the best bounds known for randomization; Theorem 5.3 even completely closes the remaining gap in the analysis of barely random algorithms for the general knapsack problem.
There are also interesting implications for deterministic algorithms. Consider the multiple knapsack problem in which every item is either rejected or packed into one of knapsacks; the goal is for the algorithm to have in the end one knapsack that is as full as possible. This problem has been analyzed with removability by Iwama and Taketomi in the proportional case. In the conclusion of their paper [17], they pose it as an open problem to analyze this model if we are allowed to copy items and pack them into arbitrarily many of the available knapsacks. It turns out that deterministic algorithms for this problem with different s are equivalent to advice algorithms: An advice algorithm restricted to advice bits can read up to different advice strings. Even if the algorithm reads the entire advice string right at the beginning, before taking any decision, it will thus implement one of deterministic strategies. Having knapsacks and being able to pack each item into several of them at the same time means that we can just simulate each possible strategy in one of the knapsacks and see which one leads to the best result in the end. Conversely, the oracle in our model already knows the optimal choice and can communicate to an advice algorithm which of the knapsacks it should be simulating. Knowing the advice complexity of our problem with only one knapsack therefore automatically yields a comprehensive competitive analysis for this deterministic problem for any . All of this remains true for the general knapsack problem; thus our results provide a comprehensive picture for the proposed model in both the proportional and non-proportional case. We remark that algorithms for the resource buffer model are generally not applicable here. Algorithm by Han et al. [13, Thm. 9], for example, keeps regrou** items in every step and thus crucially relies on having a single large buffer instead of multiple standard-sized knapsacks without an option to shuffle items between them.
2 Preliminaries
Throughout this paper, denotes the binary logarithm. We formally define the removable knapsack problem as follows.
Definition 2.1 (Removable Knapsack Problem).
RemKnap is an online maximization problem. An instance (_1,_1),…,(_n,_n)n_i_ii(i)= _i(i)=_i⊆{1,…,n}()=∑_i∈(i)()=∑_i∈(i)1_0=∅i_i-1_i⊆_i-1∪{i}(_i)≤1iin_n=_n()_i=_ii.
Definition 2.2 (Competitive Ratio).
Let an online maximization problem with instance set be given and let be an online algorithm solving it. For any instance , denote by the gain that achieves on opt( computed offline. The competitive performance of on an instance is . For any , the algorithm is called strictly -competitive if it performs -competitively across all instances, that is, if . The infimal competitivity is called strict competitive ratio of . We can weaken the defining inequality above so that it only needs to hold asymptotically in the sense of . If this condition is met, we call nonstrictly -competitive.
Note that strict -competitivity implies nonstrict -competitivity but not vice versa, making it harder to prove lower bounds for nonstrict competitivity. For the knapsack problem, however, it makes sense to always analyze competitivity in the strict sense: On the one hand, we obtain a nonstrict lower bound from a strict one by scaling up the knapsack capacity and all item sizes in a hard instance set such that the smallest item is strictly larger than . If, on the other hand, scaling is impossible due to the problem being defined with a fixed knapsack capacity of , for example, then choosing shows any online algorithm is -competitive in the nonstrict sense.
3 Related Work
Knapsack is one of the 21 NP-complete decision problem in Karp’s famous list [19]. An algorithm based on dynamic programming solves both the proportional and the general version in pseudo-polynomial time; see Bellman [1, Section 1.4] for the general technique and Dantzig [8, p. 275] for a concrete description of its application to the knapsack problem. The pseudo-polynomial time algorithm can be adapted to the optimization version, yielding a fully polynomial-time approximation scheme [16]. In the following two subsections, we list the known results on the advice complexity of the proportional knapsack problem, first for the classical version and then for the variant allowing the removal of packed items.
3.1 Knapsack without Removability
Marchetti-Spaccamela and Vercellis were the first to consider the classical online version of the knapsack problem in 1995. They called it the knapsack problem to distinguish it from the fractional knapsack problem, which allows for packing items partially. They proved that both versions have an unbounded competitive ratio if items are allowed to have sizes different from their values [21, Thm. 2.1]. We denote the classical problem with neither fractional items nor removability by Knapand its proportional variant by PropKnap.
The concept of advice emerged much later. When it did, Knapquickly became one of the prime examples of a problem with an interesting advice complexity.
First, just a single advice bit brings with it a jump from non-competitivity to a -competitive algorithm [4, Thm. 4]. More advice bits do not help however, as long as the number stays below [4, Thm. 5]. Once this threshold is surpassed, logarithmic advice allows for a competitive ratio that is arbitrarily close to 1 [4, Thm. 6]. Achieving optimality, finally, requires at least advice bits [4, Thm. 3].
The situation for the general variant is simpler: Any algorithm reading less than advice bits has an unbounded competitive ratio, but advice suffices for a near-optimal solution [4, Thms. 11 and 12]. A schematic plot of the advice complexity behaviors just described can be found in Figure 1 in light gray.
3.2 Online Knapsack Variants
Iwama and Taketomi [17] proposed the online knapsack model with removability as it is examined in the present paper. They proved that the competitive ratio for the proportional variant of this problem, which we denote by PropRemKnap, is exactly the golden ratio. Iwama and Zhang later considered the problem with resource augmentation, that is, for online algorithms that may use a larger knapsack than the offline algorithm [18].
Later still, Han et al. [12] proved an upper bound of on the competitive ratio for a variant of PropRemKnap where the value of an item is not necessarily proportional to its size but not arbitrary either; instead, the value is given by a convex function known to the algorithm. They also proved the golden ratio to be optimal if has some further technical properties. Han et al. [10] considered online knapsack with removal costs, a variant of PropRemKnap where items can be removed, but not for free.
Noga and Sarbua [22] considered a knapsack variant, where it is possible to split each arriving item in two parts of not necessarily equal size, and combine this with resource augmentation. Han and Makino [14] considered another partially fractional variant of PropRemKnap where each item can be split a constant number of times at any time. Most importantly in our context, Han et al. [11] examined randomized algorithms for PropRemKnap, proving an upper bound of and a lower bound of on the expected competitivity. Cygan et al. [7] extended the study of randomization for PropRemKnap to a variant with multiple knapsacks. Recently, Böckenhauer et al. [2] have introduced a new model for the online proportional knapsack problem in which items can be stored outside of the knapsack until the instance ends after paying a reservation fee that is a fixed fraction of the item’s value.
4 Results for Proportional Removable Knapsack
In Section 4.1, we consider how much—or rather, how little—removability helps when trying to obtain an optimal solution. In Section 4.2, we prove upper and lower bounds on what is possible with a single advice bit. Finally, we prove in Section 4.3 that a constant amount of advice is sufficient to achieve a competitive ratio of , for an arbitrary , and a constant depending on . See Figure 1 for a rough representation of these results in dark gray.
4.1 Achieving Optimality
We begin by briefly considering PropKnap, the classical proportional knapsack problem without removability. Solving it optimally is trivial with advice bits: The algorithm reads one bit per item, telling it whether to accept or reject. LABEL:{thm:classic_prop_opt_lower_tight} proves this to be tight by lifting the best known lower bound from advice bits [4, Thm. 3] to advice bits.
Theorem 4.1.
Any algorithm for PropKnap reading less than advice bits is suboptimal.
Proof 4.2.
For every , we consider the instances that all begin with the same items, namely one for each of the sizes . The size of the final item is either or any . We remark that this hard instance family is almost identical to the one used by Böckenhauer et al. [4, Thm. 3] for proving the lower bound of advice bits; the only tiny modification is changing the item size for to . There are options for the final item, and each one requires an optimal algorithm to have packed another one of the possible subsets of the previous items: If the last item turns out to have size , for any given , then the knapsack can be filled completely if and only if exactly the items have been packed before it. And if the last item has size , then the algorithm needs to pack all items for optimality, leaving a gap of . Now, an advice string of length should already enable us to distinguish between the possible sizes of the last item, allowing the algorithm to select the optimal subset of the first items. An advice algorithm reading fewer than advice bits on instances of length inevitably packs the same subset of the first items for two different sizes of the last item, leading to a suboptimal performance for one of the two.
This is essentially what led to the previously known lower bound of advice bits for optimality. The key point to note now is that the algorithm has to read these advice bits, proved necessary for optimality on instances of length , before the last item is presented. Thus it is in fact reading advice bits while processing the first items of the instance, which—thanks to our modification—also constitute a complete instance on their own. Thus advice bits are consumed on an instance of length , concluding the proof.
Having determined PropKnap’s advice complexity for optimality, we now do the same for PropRemKnap, the variant with removability. It turns out that the option to remove items hardly helps at all in achieving optimality. We begin the upper bound, which is simple but instructive as to what is possible with removability.
Theorem 4.3.
There is an optimal algorithm for PropRemKnap reading advice bits.
Proof 4.4.
Consider an algorithm that packs the first item without reading any advice bits. For each subsequent item, it reads one advice bit, telling it whether the new item is part of a fixed optimal solution. If so, then the new item is packed; otherwise, it is rejected. The first item, which has been packed without advice, is kept in the knapsack as long as there is enough room for it. If the first item is part of the fixed optimal solution, then it will always fit in beside the other items being packed; otherwise, it will be discarded at some point. Thus the algorithm is able to reproduce the fixed optimal solution exactly.
Theorem 4.5.
Solving PropRemKnap optimally requires more than advice bits.
Proof 4.6.
Let any positive of the form for an odd integer be given. Now, we can choose an arbitrarily large odd integer such that is a power of two, namely an appropriate multiple of . Since is even and is odd, we know that is even and thus is an integer. We denote it by and note that . We consider a family of instances that are all identical, with exception of the final item. The capacity of the knapsack shall be . We could of course normalize this to by scaling down the capacity and all item sizes.
First, for each , an item of size is presented. Note that these items have a total size of . Moreover, for every , there is exactly one item subset of total size .
The instance then continues with more items, one of each size in
Finally, a single item of size is presented, where may be any subset of whose cardinality satisfies . There are such subsets and we have one instance for each possible choice. A straightforward tail bound, which we derive at the end of this proof, shows that we have , where is the binary entropy function. We also know that and therefore obtain
as a lower bound on the number of instances.
Consider the instance whose final item has size for any given . The knapsack of capacity can be filled completely with the items of this instance as follows: Pack the last item, all items of sizes in —which brings us to a total size of exactly —and finally the unique subset of the first items with a total size of . This is in fact the only way to fill the knapsack entirely for the following reason. There is exactly one selection of the items with non-integer sizes such that their fractional parts sum up to an integer—namely exactly —which is necessary to fill the knapsack of integer capacity completely. The remaining integer gap has to be filled by the remaining items with integer sizes, and we have already noted before that there is exactly one way to do this for every integer between and . The instances are all identical until the last item is presented. Therefore, any online algorithm must have packed exactly the right selection of items when the final one is presented to realize the optimal solution. The number of advice bits necessary to distinguish the possible instances and guarantee optimality is therefore
The following straightforward calculations—using the Taylor expansion for the logarithm and Stirling bounds—show that this can be bounded from below by for sufficiently large .
Using the Taylor expansion for the natural logarithm around , we have
for . Applying this to we can thus further bound the number of required advice from below by
Each of the described instances contains items. This is greater than the number of required advice bits by at most
For any fixed, positive , we have and thus the exponent growing to arbitrarily large negative numbers for increasing . This means that the difference between the number of items and the number of required advice bits asymptotically coincides with .
We have and thus for sufficiently large and thus . Hence more than advice bits are necessary for optimality on instances of length for an arbitrarily small positive .
It remains to prove the mentioned tail bound, for which we use the standard Stirling bounds [23], which—in a simple form—are .
We obtain
Since , we have . Using this and the binomial theorem twice, we obtain the following bound. | ||||
Since , we have and thus | ||||
Since and , we can continue as follows. | ||||
For any given, positive , we have . Choosing sufficiently large yields the desired tail bound: | ||||
This concludes the proof of the theorem.
4.2 A Single Advice Bit
The previous section covered the upper end of the advice spectrum, showing that, asymptotically, reading one advice bit for each item in the instance is necessary and sufficient for ensuring an optimal solution. We now turn to the other extreme and ask what can be done with the least nonzero amount of advice, one single bit for the entire instance.
First, we describe a very simple -competitive advice algorithm where a single advice bit indicates whether there is an optimal solution containing more than one item from the interval : If the answer is yes, the algorithm maintains the smallest item in this interval until a second item fits in, while ignoring all items outside of the interval. As soon as a second item fits, it is packed and all remaining items are rejected. If the answer is no, the algorithm maintains in the knapsack the largest item of size at least seen so far while packing all items smaller than as long as they fit. If the knapsack capacity is never exceeded, the solution is optimal. If the knapsack capacity is exceeded at some point, all packed items but possibly one are smaller than . Discard these items one by one, in arbitrary order, until we are within the capacity of the knapsack again. The remaining gap is at most .
Han et al. [11, Thm. 6] have presented a randomized algorithm that relies on a partition of the items into six size classes. It is rather involved and hard to analyze, yet yields an expected competitive ratio of . Because it uses only a single random bit, it provides an upper bound for our case of one advice bit as well. We undercut this bound with a more manageable -competitive algorithm that needs only five classes. We then complement this with a lower bound of .
Theorem 4.7.
There is a -competitive algorithm for PropRemKnap reading only one advice bit.
Proof 4.8.
We split the interval of possible sizes into subintervals at four points . We will call the items with sizes in one of these five intervals tiny, small, medium, big, and huge, respectively. Formally, we partition the items into the five classes
where , , , and .
We will call the small and medium items the little ones collectively and refer to the big and huge items as the large ones. Accordingly, we let and . See Figure 2 for an illustration of the subintervals and class names.
The oracle uses the one available advice bit to tell the algorithm which of the two strategies described below to apply. For the decision, the oracle picks an arbitrary optimal solution to the given instance. If contains a large item, the first strategy will be chosen, with one exception: If the instance contains no huge item but a little and a big item that fit into the knapsack together, then the first strategy is chosen only if a minimal big item appears in the instance before a minimal small item. In all other cases, the second strategy is implemented.
- Strategy One
-
If at any point a huge item appears, the algorithm packs it and keeps it until the end, discarding everything else.
Otherwise, the algorithm operates with two slots, a primary one and a secondary one. In the primary slot, it maintains the minimal big item and in the secondary slot it maintains the minimal little item. The primary slot takes precedence; that is, in case of a conflict where a new minimal item for one slot is presented that does not fit with the minimal item in the other slot, we discard the little item.
While maintaining the slot contents, tiny items are always packed greedily. If at any point a presented tiny item does not fit, the current contents of the knapsack are frozen and kept as they are until the instance has ended. The same happens after a step in which only tiny items have been discarded.
- Strategy Two
-
This strategy manages not only two but three slots, all of which maintain minimal items of some class. In order of precedence, the primary slot maintains two medium items, the secondary slot up to three small items, and the tertiary one big one. As an exception, if at any point a big item appears that can be packed alongside a currently packed small item by discarding everything else, then this is done and these two items are kept till the end. The tiny items are handled as before: They are packed greedily and if either a presented tiny item does not fit or only tiny items have been discarded in one step, then the current knapsack configuration is kept up to the very end.
We now need to carefully work through a case distinction according to the conditions listed in Table 1 and show that the algorithm’s competitivity is indeed bounded from above by .
Case | Strategy | Competitivity | Case Conditions | |||
A | One | |||||
B | One/Two | |||||
C | Two | |||||
D | Two | |||||
E | Two | |||||
F | Two |
Case A.
This case is trivial: If there are huge items in the instance, the first one will be packed and kept in the knapsack, yielding a competitive performance of or better.
Case B.
The case condition tells us that the optimal solution contains at least one big item. Since big items have a size above , it contains exactly one. Moreover, there is at most one medium item in the entire instance. We now consider two subcases.
Subcase B1: Assume first that the instance contains no pair of a little and a big item that can be packed at the same time. This means that the first strategy—which gives preference to big items over little ones—is operative. The algorithm will thus only discard a possibly packed little item when the first appearing big item appears to replace it. The strategy guarantees that one big item of size greater than is contained in the knapsack in the end. If there are no tiny items, both the online solution and the optimal solution contain exactly one big item and nothing else, implying a competitive performance of . For the case that there are tiny items, recall that they are always packed greedily. Moreover, if any tiny item does not fit or is dismissed in some step, the algorithm conserves the current state of the knapsack, guaranteeing a filling of at least . We may therefore assume that every tiny item is packed and kept in the online solution computed here. Whatever tiny items are contained in the optimal solution are thus in the online solution as well. If they have a total size , the competitive performance is thus bounded from above by .
Subcase B2: Assume that there are a little and a big item that can be packed alongside each other. Let be the first minimal little item and the first minimal big item. Clearly, and fit into the knapsack together. If the knapsack contains these two items in the end, the competitive performance is or better.
Subcase B2a: Assume that appears after . In this case, the first strategy is used. Since it maintains the smallest big item seen so far in the primary slot, it will have packed when is presented, allowing for to be packed alongside it.
Subcase B2b: Assume that appears before , letting the algorithm implement the second strategy. The chosen strategy maintains up to two minimal medium items in the primary slot and up to three minimal small items in its secondary slot. However, there is by the global assumption of case at most one medium item in the entire instance and a small item will always fit in beside a medium item because . Hence, overall, a minimal little item is maintained in the knapsack, meaning that is packed already when appears, allowing for a little and big item to be packed together according to the strategy’s stated exception.
Case C.
This simple case is covered by the second strategy. Maintaining two medium items in the slot with highest precedence guarantees a filled fraction of at least .
Case D.
This case is easy as well: The one medium item will be packed into the primary slot when presented, and at least one small item is packed into and stays in the secondary slot because any small item fits in beside any medium item. The total size of small and a medium item is at least , leading to a competitive performance of or better.
Case E.
Since there are no medium items in this case, the secondary slot will maintain up to three minimal small items. If there are three small items that fit together, they will eventually be packed, yielding a filled fraction of at least . Otherwise, two small items will be packed, or only one if and only if it is the only one. If there were no tiny items, we could in both cases bound the competitivity by , using the maximal and minimal possible size of a small item. However, repeating the argument of subcase B1, we may assume that all tiny items are packed and none discarded, otherwise the packing would freeze instantly with a filling of at least . If the tiny items have a total size of , our bound would therefore only improve to .
Case F.
This case is quite simple again. If there is a medium item, it is always packed and kept to the end. Beside this one potential medium item, there are only tiny ones, the minimization in the slot will therefore not affect the result adversely. If all items of the instance fit into the knapsack together, they are all packed and the solution is optimal. Otherwise, the greedy packing of tiny items leaves a gap of less than , ensuring a competitive factor of or better.
We now complement the upper bound of Theorem 4.7 with a lower bound of .
Theorem 4.9.
No algorithm for PropRemKnap reading only a single advice bit can have a better competitive ratio than .
Proof 4.10.
Let and choose a positive . Let an algorithm for PropRemKnap reading only a single advice bit be given. Consider the three instances , , and that all start with the same three items of sizes , , and , which is the end of instance but followed by a last item of size for and of size for .
optimal | second best | ratio | ||||||
: | ||||||||
: | ||||||||
: |
For each , the instance has a unique optimal solution; it contains and, except for , additionally . Table 2 shows the total size for each of these optimal solutions and the second best solution.
Because any two of these three items , , and sum up to over 1, the advice algorithm can keep at most one of them in the knapsack after the presentation of . Moreover, since only one advice bit is given and the three instances are indistinguishable until after the decision on the third item has been taken, there are two instances for which the same item, if any, is kept in the knapsack for the presentation of the potential fourth item. This implies that the algorithm is suboptimal for at least one instance. The second best solutions for , , and fill up a fraction , , and , respectively. Thus, the competitive ratio of cannot be better than the minimum of , , and . Since , this means the competitivity is at best for arbitrarily small .
Note again that an advice bit is at least as powerful as a random bit, hence Theorem 4.9 also improves the best known lower bound of for one random bit due to Han et al. [11, Thm. 8].
4.3 Near Optimality with Constant Advice
Having seen how much advice is necessary for optimality and what the effect of a single advice bit can be, we now address the entire range in between. For this, we prove the following generalization of Theorem 4.9.
Theorem 4.11.
Let an arbitrary integer be given. No algorithm for PropRemKnap reading at most advice bits can achieve a better competitive ratio than .
Proof 4.12.
We generalize the hard instance family from the proof of Theorem 4.9. Let an arbitrary integer be given and define as the positive root of , namely . Consider instances that all start with the same items of the following, decreasing sizes: first , then for every , and then for an arbitrary satisfying . The instance ends immediately after these common items, whereas the instances , for , presents one additional item of size as the final one. There is a unique optimal solution for each instance: For , it is to pack the first item of size . For with , it is to pack the item of size and the last one of size , which sum up to the optimal solution value . Since there are only advice bits available to handle the instances, at least two instances and with are processed with the same advice string and thus the same deterministic algorithm. Consider this algorithm and the moment after seeing and taking decisions on the first items. It is impossible for the algorithm to have more than one of these common items packed since the two smallest of them already have a combined size of . Now, if item is packed at the considered moment, the algorithm will perform suboptimally on instance . Analogously, if item is packed, the performance on instance is suboptimal.
Now if suffices to check that the best suboptimal solution has a filling of at most for , at most for , …, , and at most for . This leads to a performance ratio that is or at best, depending on the concrete algorithm, thus proving the theorem. See Table 3 for an overview of the hard instance family. The best and second best solutions to all instances and their associated performances are listed in Table 4.
: | None | |||||
: | ||||||
: |
We remark that Theorem 4.11 and its analogue for RemKnap instead of PropRemKnap, Theorem 5.7, improve upon the best known lower bounds implied by Han et al.’s results on the resource buffer model [13, Thms. 17 and 6]. In this model, the online algorithm may use a knapsack of some increased capacity , but only until the instance ends, at which point it has to choose from the reserved items a selection that fits a knapsack of capacity one. A resource buffer of some natural size allows us to simulate any algorithm using up to advice bits: We think of the resource buffer as split into knapsacks of capacity , allowing us to accommodate the items stored by the advice algorithm for every possible advice string simultaneously.
Instantiating Theorem 4.11 with , , and , for example, we obtain the lower bounds
and | |||||||||
for one, two, and three advice bits, respectively, while the lower bounds provided by Han et al. [13, Thm. 6] for a resource buffer of size are | |||||||||
and |
Clearly, the lower bound of Theorem 4.11 tends to for increasingly large but still constant advice.
With our most surprising result for the proportional knapsack problem, Theorem 4.15, we will prove that the true competitive ratio displays the same general behavior as the lower bound of Theorem 4.11: For any given , we can guarantee a competitive ratio of with a constant number of advice bits. It is of course also possible to derive more specific upper bounds for very few advice bits such as the following one.
Theorem 4.13.
There is a -competitive algorithm for PropRemKnap reading two advice bits.
Proof 4.14.
The algorithm operates in one of four modes, depending on the given advice.
We make the following case distinction that primarily depends on how many items falling into the size interval —we call them medium items—appear in the optimal solutions.
Strategy One.
This strategy is chosen if there is any item larger than or if there is an optimal solution containing either no or only one medium item. The algorithm maintains one maximal medium item while packing the smaller items greedily. As an exception, when an item larger than appears, it is packed and kept to the end, discarding everything else.
This procedure obviously produces -competitive solution if there is an item larger than . Otherwise, the knapsack will be filled optimally if all items fit into the knapsack together. In the remaining case, the greedy packing will leave a gap of at most because the algorithm will never displace a medium item in favor of a smaller one, thus removing only items smaller than .
Strategy Two.
This strategy can be chosen if there is an optimal solution containing at least three medium items or if the two minimal medium items in the instance have a combined size of or more. The algorithm maintains as long as possible the minimal three medium items from the interval among everything seen so far. If a third medium item does not fit at some point, the algorithm switches to maintaining only the two minimal medium items. This clearly yields a filling of at least .
Strategy Three.
This strategy works if there is an optimal solution containing two items from the size interval . It maintains two maximal such items, which is always possible, and packs the smaller items greedily. This either yields an optimal solution or one with a gap of at most .
Strategy Four.
This strategy is chosen in the remaining case. Specifically, we may now assume that every optimal solution to the given instance contains exactly two medium items, one of which has a size greater than .
In this case, the algorithm maintains on the one hand a minimal item and on the other hand a minimal item larger than . Clearly, this fills the knapsack to a total size of more than .
We now turn to our main result for the proportional knapsack problem, which complements Theorem 4.11 with an upper bound. Theorem 5.9 will generalize this result to the general version where an item’s size may differ from its value, albeit with a far more complicated proof. To make it as easily understandable as possible, we first present here the proof for the simple variant, which introduces the idea of slots that are reserved for items with certain properties. This will serve as a useful foundation for the proof of the general variant, which is also making use of such a slot system, although as merely one besides many more components.
Theorem 4.15.
For any , there is a strictly -competitive algorithm for PropRemKnap reading a constant number of advice bits.
Proof 4.16.
We describe such an algorithm called PropPack; see Algorithm 1 for a pseudo-code implementation. We begin by describing the advice communicated to PropPack with a constant number of bits, then explain how the algorithm operates on this advice, prove that it is correct and terminates, and finally analyze its competitive ratio.
Notions and Notation.
Without loss of generality, we assume that all items have size at most 1 and that . We define the constant .
Let an instance with items be given. Denote the items in the order of their appearance in the instance by and denote the size of item by . We divide the items into small and big ones, with serving as the dividing line: and . We further partition the big items into the subclasses . To alleviate the notation, we will often refer to as class and to as class . We also use this convention when writing to indicate the class to which item belongs: We have , with meaning that and meaning that .
The oracle chooses an arbitrary but fixed optimal solution . We denote the partition classes that are naturally induced by this solution by , , and for . Let be the number of big items in the optimal solution and denote them by in order of appearance.
Constant Advice.
The oracle communicates to the algorithm a tuple with the classes of the big items in the chosen optimal solution in order of appearance; that is, we have for each . We remark that this tuple needs to be encoded in a self-delimiting way. A constant number of bits suffices for this because is bounded by the constant for every and is bounded by the constant . The latter bound is an immediate consequence of the fact that and that any big item has a size larger than .
Algorithm Description.
The algorithm PropPack proceeds in phases as follows. In every phase, the algorithm opens a new virtual slot within the knapsack that can store exactly one item at a time; multiple items in succession are allowed, however. The slot opened in phase will accommodate items belonging to class exclusively; we say that items from this class match slot . Slots are never closed, thus there are exactly of them in the end. Small items are generally packed in a greedy manner and discarded one by one whenever necessary to pack a big item.
In the first phase, the algorithm rejects all big items until one of class appears. As soon as this is the case, said item is packed into the first slot, ending the first phase.
In the second phase, the algorithm opens the second slot to pack a matching item, that is, one of class . It waits for the first item from this class that fits into the knapsack alongside the item in the first slot. As soon as such an item appears, it is packed and the phase ends. In the meantime, whenever an item of class appears during the second round, the algorithm substitutes it for the one stored in the first slot if and only if this reduces the size of the stored item.
In general, phase begins with the opening of slot , which is reserved for items of class . The phase continues until an item appears that both matches the newly opened slot and fits in beside the items currently stored in the previously opened and filled slots without exceeding the capacity. Then this item is packed into the new slot, which ends the phase. During the entire phase, the algorithm maintains in all filled slots the smallest matching items seen so far: Whenever the algorithm is presented with a big item that either it belongs to a class other than or does not fit in alongside the items in the previously opened slots, then the new item replaces a largest item in the matching open slots, unless the new item itself is even larger.
The entire time, even after the last phase has terminated, small items are packed greedily and discarded one by one whenever this is necessary to make room for a big item according to the description above. Moreover, we may assume that, whenever a new item has been packed into the knapsack, the algorithm sorts the items in the matching open slots in increasing order. This sorting is not necessary for the algorithm to fulfill its duty, but it facilitates the proof by induction below.
Termination of All Phases.
We need to show that PropPack does in fact finish all phases; that is, all slots will be filled with a matching item without ever exceeding the knapsack capacity. Consider the big items of the optimal solution, which we denote by in their order of appearance. To ensure the termination of all phases, we prove by induction over that, after processing item , the first slots store items with a total size of or less.
We may start from as the trivial, if degenerate, base case. For the induction step, assume the hypothesis for and observe that no item in a slot is ever replaced by a larger one. Therefore, the items in the first slots still have a total size of at most when is presented.
There are now three possibilities. If slot has remained closed up to this point, it is now opened and filled with , which fits in because . Otherwise, slot is already storing an item: If said item is larger than , then replaces either this item or one that is at least as large. During the subsequent sorting, is then moved to slot or one of the slots from to , which may force some items from slots through into higher slots but never beyond slot . The third possibility is that slot contains an item of size at most already. We immediately obtain the induction claim for in all three cases.
Competitive Analysis.
We still denote by the optimal solution that served as the basis for the given advice, by the final output of the online algorithm PropPack (Algorithm 1), and the respective partition classes by , , and , , and .
Since PropPack opens one slot for each big item in the optimal solution and fills it with an item from the same subclass, as proved above, we have for every . Moreover, the sizes within a subclass vary by a factor of at most ; this means that we can bound both and from below by and from above by . We conclude .
Furthermore, since small items are packed greedily and only discarded one by one whenever necessary to make room for the big items, we will not lose much from their side either. If the presented small items have a total size of at most , none is ever discarded. In this case, we have and thus immediately . If small items are discarded, however, the worst case is the following type of instance: It starts with only small items of the largest possible size , some of which are then discarded to accommodate big items with sizes right at the upper limit for the classes indicated by the advice, leaving a gap of almost , follows up with slightly smaller big items that are in the optimal solution and would not have lead to any discarded small items, and finally presents big items at the lower end of the size span, replacing all previously packed big items.
Even in this worst case, the algorithm remains -competitive on the big items and detracting the largest possible loss of on the small items yields . By the definition of and and due to the simple fact that is at most , we have . This implies , as desired.
5 Results for General Removable Knapsack
First, we note that all lower bounds for the proportional removable knapsack problem carry over to the general removable knapsack problem, in particular Theorem 4.5.
Iwama and Zhang [18] have shown that the competitive ratio of RemKnap is unbounded without advice. This can be seen using an interactive instance that starts with an item and then presents items repeatedly, up to times, until one is packed, at which point the instance ends.
The following two theorems show RemKnap’s competitivity for one advice bit to be exactly .
The existence of a -competitive algorithm already follows from a result by Han et al. [11, Thm. 9], who proved the statement even for a single random bit instead of an advice bit. We prove Theorem 5.1 by describing a concrete advice algorithm.
Theorem 5.1.
There is a -competitive algorithm for RemKnap reading only a single advice bit.
Proof 5.2.
The single advice bit indicates whether the instance contains an item worth at least half of the optimal solution value. If so, the algorithm greedily packs the most valuable item. Otherwise, it packs in a yield-greedy manner while ignoring any items larger than . If some optimal solution contains some item larger than , then the rest of this solution is smaller than and worth at least half of the optimal solution value. The yield-greedy algorithm achieves at least this value: Either it packs all items up to size or, when having to discard such an item, leaves a gap smaller than while the rest is filled with the best possible yield.
We now provide the matching lower bound for Theorem 5.1.
Theorem 5.3.
No algorithm for RemKnap reading only a single advice bit can have a competitive ratio better than .
Proof 5.4.
Fix an arbitrary positive such that is an integer. We describe an adversarial instance family on which no algorithm with a single advice bit can achieve a competitive ratio better than .
The instance will present some subset of the following items:
The exact subset and order of presentation depends on the operating advice algorithm and will be explained below.
We begin by making some simple observations. The items decrease in both size and value. The smallest of them has still size , thus it is impossible to fit two of them into the knapsack together. The same is true for combining any item with any item , together the exceed the knapsack capacity. Finally, an item fits together with perfectly, but not with any of the items .
We arrange the items along the axes of a grid as shown in Figure 3. Every instance in the hard instance family can be represented by a directed path in this grid that starts at the top left corner, only moves down or right from there, and stops at the latest when reaching either the bottom or right border of the grid. Figure 3 shows one possible path.
We can read a given path as follows. All instances start by presenting the two items and corresponding to the corner . When a new coordinate along the -axis or -axis is reached, the corresponding item is presented. Thus, the path moving down means presenting the next item in the sequence , and analogously for moving to the right and the sequence . If the path ends at with and —that is, before reaching the grid’s bottom or right border—then the instance concludes with as an additional final item. If the path reaches the bottom or right end, the instance ends without such an additional item.
We now describe how the path is determined by the actions of the advice algorithm. Note that an algorithm with a single advice bit can be interpreted as two deterministic algorithms with the advice bit determining which algorithm is executed on any given instance. From with and , the path continues as follows.
- Case 1.
-
If both algorithms have discarded , then it goes to the right.
- Case 2.
-
If one algorithm has in its reserve and the other , the path continues downward.
- Case 3.
-
If one algorithm has in its reserve, but neither has kept , then the path stops.
We make two observations. First, at any point , the two algorithms may have in their reserve, but no other item from . This is because the path is moving right—and thus the instance presenting an item in this sequence—only after its predecessor has been discarded by both algorithms.
Second, when arriving at , one of the algorithms may still have in its reserve, but neither algorithm will have kept any of the previous items . This is because the path was able to move down to the current -coordinate only if one algorithm has had in its reserve and the other some item , which excludes any third item from .
We consider the three ways that a path representing an instance can end: at the right border, at the bottom edge, or anywhere else.
- Case 1.
-
If the path ends at the right border, the optimal solution consists of the entire sequence with total size and total value . The two deterministic algorithms, in contrast, have discarded all items in this optimal solution but possibly . Among and , which might have been presented, no two fit into a knapsack of capacity 1 together, thus the best feasible solution for the advice algorithm is taking the single most valuable item with a value of . The competitive performance of the algorithm is in this case.
- Case 2.
-
If the path reaches the bottom, this means that the last move was downward; thus one algorithm has kept in its reserve and the other . Therefore, only the three singleton solutions consisting of , , and , respectively, are attainable by the advice algorithm. Among these, the first option is the best with a value of . The optimum would have been to keep with a value of , however, resulting in a competitive performance of or worse.
- Case 3.
-
Finally, the path may stop at some point with and . In this case, both algorithms have discarded and, as observed in the beginning, all previously presented items except for and . Thus, when the final item is presented, the best option for the advice algorithm is the singleton solution with the item of value . The optimal solution, in contrast, can combine the two items and of complementing sizes and a total value of . The resulting competitive performance is .
Overall, the advice algorithm’s competitive ratio cannot be better than
which tends to for decreasing , thus proving the theorem.
Advice being more powerful than randomness, Theorem 5.3 also closes the remaining gap for barely random algorithms by lifting the previously best known lower bound by Han et al. [11, Thm. 12] from to .
The analysis of the hard instance presented in the proof of Theorem 5.3 could be adapted to the case of more than one advice bit. Two advice bits would mean that the oracle can provide to the algorithm one out of four advice strings instead of the two advice strings possible with one bit. We may also consider an intermediate advice algorithm limited to three advice strings, which corresponds to advice bits. Such an algorithm cannot achieve a competitive ratio better than since it is forced to use one of the three advice strings to keep the most valuable item , one to pack the items yield-greedily, and one to keep the with the value , resulting in a competitive ratio of .
This approach deteriorates too quickly, however. Adapting Theorem 4.11 to the case of PropRemKnap is the better choice; this results in Theorem 5.7, which already yields a better bound in the case of three advice strings, that is, for . For increased accessibility, we first provide an instantiation for the case of a single advice bit, namely .
Theorem 5.5.
No algorithm for RemKnap reading only a single advice bit can have a better competitive ratio than .
Proof 5.6.
The proof is similar to the one of Theorem 4.9 but takes advantage of the fact that the sizes and values of the items can be chosen independently. Let and let an algorithm for general removable knapsack reading only a single advice bit be given. Consider the three instances displayed in Table 5, which all start with the same three items.
optimal | suboptimal | ratio | ||||||
: | ||||||||
: | ||||||||
: |
For each , the instance has a unique optimal solution; it contains plus the last fourth item if it exists. Table 5 shows the total size for each of these optimal solutions and the second best solution.
Because the sizes of any two of these three items , , and sum up to over 1, the algorithm can have at most one of them in the knapsack after being offered . Moreover, since we have only one advice bit but three instances, there are two instances for which the algorithm has packed the same item right before the potential presentation of the fourth item. This implies that the algorithm is suboptimal for at least one instance, thus its competitive ratio cannot be better than .
Theorem 5.7.
Let an arbitrary integer be given. No algorithm for RemKnap reading at most advice bits can achieve a better competitive ratio than .
: | 0 | |||||
: | ||||||
: |
Optimal value | Best suboptimal value | Best suboptimal performance | |
: | |||
: | |||
: | |||
: | |||
: |
Proof 5.8.
Let an arbitrary integer be given and define as the unique positive solution of , namely . Consider instances that all start with the same items of the following, decreasing values: and for every . Note that . The sizes can be chosen arbitrarily satisfying .
The instance ends immediately after these common items, whereas the instance , for , presents a complement to item , namely an item of size and value as the final one. There is a unique optimal solution for each instance: For , it is to pack the first item, which has value . For with , it is to pack item and its complement, which sum up to the optimal solution value . Since there are only advice bits available to handle the instances, at least two instances and with are processed with the same advice string and thus by the same deterministic algorithm. Consider this algorithm and the moment after seeing and taking decisions on the first items. It is impossible for the algorithm to have more than one of these common items packed since all of these items are larger than . Now, if item is packed at the considered moment, the algorithm will perform suboptimally on instance . Analogously, if item is packed, the performance on instance is suboptimal.
Now if suffices to check that the best suboptimal solution has a value of at most for and at most for the other instances. This leads to a performance ratio of , thus proving the theorem. See Table 6 for an overview of the hard instance family. The best and second best solutions to all instances and their associated performances are listed in Table 7.
We point out again that Theorem 5.7 slightly improves over the lower bounds known from the resource buffer model by Han et al. [13, Thm. 6]. Specifically, we can choose , , and , for example, we obtain the lower bounds
and | |||||||||
for one, two, and three advice bits, respectively. The corresponding lower bounds by Han et al. for a resource buffer of size are | |||||||||
and |
We now move on to the core result of this paper, proving that a constant amount of advice bits is sufficient to reach a near-optimal competitive ratio not only for the proportional but even for the general removable knapsack problem. This will complete the picture of the global advice behavior of the online knapsack problem with removability outlined in Figure 1.
We first point out that algorithm PropPack (Algorithm 1) generally does not work on instances where the value of an item can vary independently of its size, as seen by the following counterexample: Assume that lies in the interior of some size class and choose an such that and are still in the same class. Present two items and . If the algorithm picks the first one, is presented as the last item; otherwise, the instance ends with the item . In both cases, the algorithm achieves a total value of , whereas the optimum is . The advice does not help us to distinguish the two cases, it only tells us that the optimal solution contains two items from the class. Clearly, we have to adapt the algorithm to take the value of the items into account somehow. A major obstacle is that the online algorithm has no bound on the values of appearing items, thus the algorithm has no way of reconstructing the constantly many value classes used by the oracle just from the parameter .
Moreover, the proof of Theorem 4.15 cannot be adapted for the general case in any simple way. Using only classes based on size, it is impossible for the algorithm to know, when maintaining an item in slot, how to balance minimizing the size against maximizing the value. On the one hand, if the size is not minimized, then the excess size may prevent other slots from being filled. On the other hand, not maximizing the values, the algorithm may incur an arbitrarily high loss because the potential values of items cannot be bounded. This is also the reason why simple value classes do not work either. The algorithm does not know the maximal value occurring in the instance until it has ended and can therefore not use it as a reference point, in contrast to the size classes that can be chosen relative to the known knapsack capacity.
A first step toward solving these issues is the definition of dynamic value classes that are anchored to both the value of the first item appearing in the instance and to the optimal solution value. The latter is of course also unknown to the algorithm until the instance ends. However, we are able to define our classes with some additional properties that enable our algorithm to compute at any point useful provisional bounds on the optimal solution value. These bounds will either turn out to be valid or the algorithm is able to notice that they are off just in time to adjust and take a fresh start before having lost too much due to bad decisions. The adversary may foil the algorithm over and over, forcing it to abandon its plans and adjust the bounds arbitrarily often.
To properly deal with these repeated resets, we develop a level system. One major challenge is to square the level system with some sort of slot system as used by the algorithm for the proportional case. We manage to do this by introducing the concept of a virtual algorithm, which has the special, even though only imagined, capability of kee** one item in a splitting slot and use arbitrary fractions of the item stored in it. We then describe an actual algorithm that tries to equal the idealized performance of the virtual algorithm without making use of the splitting slot. While it cannot quite achieve this, it will fare well enough in the end. Having one algorithm emulating another, we are going to prove the claimed competitivity in two stages, first for the virtual version and then for the actual algorithm.
This split analysis presents several further challenges, for example, a desynchronization of the current phase and the number of slots filled by the algorithm, which coincided in the proportional case. The necessary adaptations entail a number of further challenges, for example a judicious handling of the paltry items, which are worth almost nothing individually, yet may be too numerous to neglect. In fact, the algorithm will need to partition the items not only by their value but simultaneously by their size as well.
Overcoming these and a few other obstacles, we are able to prove our final theorem.
Theorem 5.9.
For any , there is a strictly -competitive algorithm for RemKnap reading a constant number of advice bits.
Proof 5.10.
Proving this theorem requires far more effort than what was necessary for its proportional counterpart Theorem 4.15, where an item’s value is always identical to its size. Having explained already why any straightforward adaption of the substantially simpler approach for the proportional variant is impossible, we now provide a high-level outline of the proof. Then, we introduce some notions and notation necessary to describe what advice the oracle is communicating to the algorithm, and show that encoding this advice is possible with a constant number of bits. Then, we describe the algorithm and how it is using the advice; see Algorithm 2 for an implementation in pseudo-code. Finally, we use two proofs by induction to show that the algorithm’s online output successfully maintains some properties, which help us to conclude the proof by bounding the competitive ratio.
Outline
As announced, we first provide a high-level outline of the workings of the advice algorithm.
The oracle chooses an arbitrary optimal solution and, based on its value , partitions the items of the instance into precious and paltry ones; the paltry ones are those worth less than for a suitable . The precious items are further split into finitely many classes such that the item values within any class are at most some factor apart from each other.
The advice will encode exactly the classes of the precious items from the optimal solution in their order of appearance; the goal is to ensure that the algorithm packs just as many precious items from each class as the optimal solution does, thus achieving a competitive factor of on these items. Assuming that the algorithm knows the exact value ranges of each class, it can achieve this using a system of slots, which will be filled with precious items in two stages: first just virtually—assuming the algorithm were able to do certain things that are in fact impossible—and then also actually at some point. Each virtual filling of a slot starts a new phase of the algorithm.
However, the algorithm knows only the target value but nothing about the size of the items belonging into each slot; it is necessary to prove that despite this, the algorithm is able to fill the slots in the right order without blocking important items yet to come.
And there is another problem: It is even impossible for the oracle to communicate to the algorithm the exact value range of each class with a constant amount of advice since there is no bound on the potential values occurring in an instance. Instead, the value ranges will be described in relation to the value of the first item of the instance, and merely modulo some constant factor. The algorithm will then operate under the assumption that the first item is a precious one, in which case all of the above will work out. Since the algorithm cannot know for sure which items are precious, it divides them into presumably precious and provenly paltry ones according to some computations based on the advice and the instance seen so far. If the algorithm’s assumption is mistaken, it is able to recognize this just in time by continually comparing the best solution realizable with the already presented items—whether they have been accepted or not—to a rather intricate estimate for the optimal solution value . Once the algorithm discovers its mistake, it resets with a revised set of assumptions on the value ranges; we say that the algorithm levels up. This is done such that the algorithm can go through arbitrarily many levels, resetting and taking a fresh start as often as necessary without incurring more than a negligible value loss.
The algorithm also needs to take care of the paltry items, which might constitute a considerable part of the optimal solution if there are sufficiently many of them. The algorithm is packing the paltry items in a somewhat inhibited greedy manner that optimizes the value-to-size ratio, which we also call yield. The volume taken up by the paltry items will be restricted sufficiently to guarantee that the precious items can always fill their slots, but not as severely as to lose too much value on the paltry items. The right volume restrictions in each phase of the algorithm are communicated via a constant amount of advice as well. Again, this cannot happen directly, since the right volume range might be infinitesimally small. Instead, the volume is controlled indirectly, via bounds not on some size but instead on the value that is provided by the paltry items packed before filling the current slot with a precious item.
Communicating the necessary volumes in this way is possible only up to some precision , and an overestimation could mean the loss of a crucial precious item. If we always round down, then this cannot happen, but the algorithm might reject some paltry item it should have kept for a selection of maximum yield. This is negligible if it happens only once, but we cannot tolerate taking such a loss in every phase, with every new volume bound. The solution is to analyze the situation using a special splitting slot, which can accommodate one paltry item at the time outside of the knapsack. We imagine the splitting slot lending us from the item stored in it any desired fraction at any time—just always the same fraction of the value and size. We refer to the item currently stored in the splitting slot as the split item. We will consider an algorithm that maintains a split item of highest yield after the remaining paltry items kept in the knapsack. This imaginary algorithm is an antecedent to our real advice algorithm, which builds on it but cannot actually split any items of course; we refer to the purely hypothetical precursor as the virtual version of our actual algorithm.
The actual algorithm will mimic the virtual version as closely as possible and deliver a result that is only marginally worse. Whenever the virtual version splits an item, the actual algorithm needs to decide whether to discard this item or store it completely. The challenge is to take the right decisions to allow for all slots to be filled in time and also avoid an undue accumulation of losses by passing on too many split items.
The advice helps the actual algorithm by indicating for every phase whether an item stored in the splitting slot by the virtual version is to be packed or discarded. This is done in such a way that in the end, the actual algorithm will have relinquished only the value of a single paltry item, namely the one kept in the splitting slot when the instance ends.
Packing entire items from the splitting slot comes with problems on its own; these paltry items might block for the actual algorithm some precious items that are packed by the virtual version. This problem is addressed by further advice to the algorithm on how to prioritize the packing of precious versus paltry items in each phase. This advice, telling the algorithm when to actualize a virtual packing of an item, is based on the solution that the virtual version would eventually produce if it existed. The virtual version does not depend on the actual algorithm and has no need for the part of the advice on actualization, which avoids any circular reasoning.
There are a few more technical issues to be dealt with, for example the special case that the precious items contribute only marginally to the value of the optimal solution. This undermines the estimates for the optimal solution value, is thus flagged by a dedicated advice bit , and handled by switching from the elaborate value-based limits that dampen the general yield-greedy strategy to a simpler size-sensitive strategy.
Notions and Notation
We make the same assumptions as in the proof of Theorem 4.15 for the proportional problem: The knapsack has capacity , all items have size at most , and . Again, we denote the items in the order of their appearance in the instance by . We write and for the size and value of item , respectively.
To make to proof more understandable, we use the four constants , , , and , which all depend only on the given parameter but are used in different roles. They need to satisfy several inequalities; a concrete list of possible choices is , , , and .
The oracle begins by computing an arbitrary optimal solution . In contrast to the proof for the proportional analogue of our theorem, not just the advice but also the constructed classes depend on and the instance as well. Specifically, the oracle uses the value of the first item in the instance and the optimal solution value to partition all items into the bi-infinite sequence of value classes
for every integer index , with being a constant for any parameter .
Claim 1.
These classes are constructed such that they simultaneously satisfy the following four properties, which are straightforward to verify and will prove crucial later on.
-
1.
Each class contains only items whose values lie within an interval spanning a factor of from the upper to the lower interval end.
-
2.
The value of the first item marks the upper end point of the value interval of the class containing this first item.
-
3.
The first item is contained in one of the classes .
-
4.
The index of the class whose interval contains the optimal solution value is a multiple of .
Proof 5.11.
For the first property, it we observe that the item value only occurs once in the entire definition of , namely within the first summand as a factor in the argument of the logarithm. Since , this term decreases by if is replaced by . Thus the values of items in any given class can span factor of up to but never more.
To verify the second property, we observe that is zero for but positive whenever and thus . Note that the logarithm base is smaller than .
The third property follows again due to the first summand vanishing for . This leaves the class index equal to , where is an integer taken modulo , meaning that we have and thus .
Finally, for the fourth and last property, it suffices to set and see that the minuend becomes identical to the first summand, except for being taken modulo , meaning that they combine to a multiple of .
For every , we define the modulo class , consisting of every th class. There are exactly distinct modulo classes, namely ; each corresponds to one of the possible values of the modulo term in the definition of . We could also have defined as , but using instead of will turn out to be more convenient later on.
Beside the modulo classes we define an infinite number of comboclasses. For every integer , comboclass comprises consecutive classes. This definition is again optimized for notational convenience in the remainder of this paper, which is also the reason for including into definition of the middle summand . For example, we can now reformulate the third and fourth property more succinctly as follows: Item is contained comboclass , and belongs to modulo class .
For any item , we write , , and to indicate the class, modulo class, and comboclass in which item lies. Thus, is the integer such that , analogously is the integer satisfying , and finally is the integer satisfying . Note that by their definitions these three terms satisfy the general relation for any item .
An item can be at most as valuable as the entire optimal solution. The comboclass that would contain such a potential item, namely the one with index , is called precious. The classes comprising the precious comboclass and all the items contained in it are called precious as well. The remaining items are called paltry. In the natural way, we denote the sets of precious and paltry items by and , respectively.
We now refer to Figure 4, which illustrates the value ranges of the classes, comboclasses, and modulo classes and shows which are considered paltry and precious, respectively. The notions of provenly paltry and presumably precious, which also appear in this figure, will only be defined during the discussion of the so-called level system further down.
Using Figure 4, it is also simple to verify the following. The highest class that could contain any paltry item is , and it is separated from , whose value range contains , by classes. Since the value range of each of these classes spans a factor of , it follows that any paltry item is worth less than , where the inequality holds by the definition of . This fact will be used later on.
We denote by the precious items appearing in the optimal solution in the order as they are presented during the given instance. These items partition the paltry items into subclasses, depending on their relative appearance time: For , we let denote the paltry items appearing after and before , where we use the auxiliary definitions and for two valueless items for notational convenience.
Finally, we partition the items— independently of the distinction between paltry and precious—into the big ones of size at least , denoted by , and the small ones below this threshold, denoted by .
Advice Content
In analogy to the proof of Theorem 4.15 for the proportional problem variant, where it is sufficient to define a finite number of instance-independent, size-based classes, we would like for the oracle to communicate through its advice the class of each precious item in the optimal solution in appearance order. This is impossible, however, since the number of classes is unbounded this time around. Instead, we restrict ourselves to conveying the information merely modulo the constant . We do so by encoding modulo classes—of which there are only finitely many—for all precious items into a tuple .
In addition, the advice tells the algorithm into which modulo class the first item of the instance is falling; that is, it encodes .
Furthermore, for every , the oracle encodes for some sufficiently small ; this is the fraction of the optimal solution value that is due to paltry items appearing in the instance after but before , rounded down to the nearest multiple of . We denote this fraction by .
There is also one special advice bit , telling the algorithm whether packing only paltry items yields a -competitive solution.
The advice described so far is everything needed for the virtual version of our algorithm to work. The actual algorithm makes use of the following additional advice, which depends on the online output of the virtual version: For every , the advice contains a tuple of numbers from . Here, the numbers are the indices of the slots used by the algorithm for storing precious items. The number is taken as the index of the splitting slot. The numbers of the tuple are determined by what the virtual algorithm does with the items appearing in phase . More precisely, it only matters what the algorithm does with those items that will be part of the eventual virtual solution , excluding the one item remaining in the splitting slot in the end. If there are no such items during phase , then the tuple is empty. Otherwise, consider the first such item of phase . It will be part of the eventual solution , meaning that must be packed by the virtual algorithm upon appearance. The first number of the tuple indicates the slot into which this item is stored, namely slot . The next number of the tuple is analogously determined by the next item that is packed during phase and a full part of the eventual virtual solution, and so on. In summary, tuple contains the indices of the slots filled during phase with items that will be a complete part of the eventual virtual solution, and the indices are sorted in the order these slots were filled with said items.
Constant Advice
We prove that a constant amount of advice suffices to encode the information just described.
We assume without loss of generality that the following, separately discussed pieces of information are combined into the advice string in such a way that they can be unambiguously retrieved. This is achieved by means of a suitable self-delimiting encoding that increases the advice length by at most a constant factor.
The number of precious items in the optimal solution, and thus also in the virtual solution, is bounded from above by the constant since every precious item is worth at least and the total value of packed precious items cannot exceed .
There are only constantly many modulo classes, namely ; a constant amount of advice therefore suffices to communicate the modulo classes of the precious items in the optimal solution and that of the first item of the instance.
For every , we can encode via ; this is the fraction to be approximated divided by and rounded down to the nearest integer. These integers are clearly bounded by the constant . Since both and are constants, this information is also encodable within a constant amount of advice.
Finally, there are the tuples , each containing at most numbers ranging from to . A number of advice bits cubic in , but still constant for any given parameter , is enough to store this information too.
Algorithm Description
A Single Special Switch.
As a first simple special case, we consider what the algorithm does when the bit is set to , meaning that packing only paltry items in a yield-greedy fashion would lead to a -competitive solution. In this case, the algorithm does not directly implement this strategy—being unsure what items are in fact paltry, it is in fact unable to do so—but instead runs a yield-greedy strategy on the small items, discarding any big item without consideration. When analyzing the algorithm later on, we will show that this still secures a solution of sufficient value.
For the remainder of this description, we assume that the switch is set to zero.
Computing the Classes.
Immediately after seeing the first item, the algorithm uses the advice-given information about the modulo class of this item and the fact that its value lies right at the upper end of the value interval of its class to reconstruct the precise value intervals of every class . This is possible thanks to the four properties of these value classes already proved above:
Once the exact value range covered by the class containing the first item is known to the algorithm, the first property can be used to achieve the same for all other classes. The remaining three properties help the algorithm retrieve all information about the value interval of the class of the first item. The second property fixes the upper end of this interval to . The third property tells us that is contained in one of the classes of comboclass . The fourth property determines which of these classes it is by fixing the modulo class of and thus also the one of , which is included in the advice given to the algorithm.
As a consequence, the algorithm is able to compute , , and for any item of the instance as soon as it appears. We emphasize that, nevertheless, it is still unable to tell for sure whether an item is precious or paltry as long as the instance has not ended. Instead, the algorithm partitions the items seen so far into presumably precious and provenly paltry ones. This partition may change over time and is based on the following level system.
The Level System.
At any time, there is exactly one comboclass considered presumably precious; all lower comboclasses are provenly paltry. The designation as presumably precious or provenly paltry is naturally inherited by the classes and items contained in a comboclass. For every integer , we say that the algorithm is at level if is the presumably precious comboclass at this moment. The algorithm starts at level , which means that the comboclass containing the first item of the instance is considered presumably precious in the beginning. While processing its input, the algorithm may level up many times, but the level is never decreasing: What has been recognized as presumably precious may become provenly paltry at a later point, but never the other way around. There are exactly two events that can trigger the raise to a new level.
-
1.
The first one is the appearance of an item with a value above the value range of the comboclass that is currently seen as presumably precious. In this case, the comboclass containing this new item becomes the presumably precious one.
-
2.
The algorithm might also be triggered into leveling up by the arrival of a provenly paltry item, but only under certain conditions. Namely, the algorithm is always kee** track of what the optimal solution value achievable with the items presented so far, including the rejected ones, would have been. This only hypothetically realizable value is continually compared against some upper estimate for the optimal solution value ; the exact estimate is explained and examined in the next subsection. As soon as the estimate for is exceeded by the hypothetically achievable solution value, the algorithm enters the next level: The presumably precious comboclass becomes provenly paltry and the comboclass immediately above it becomes the new presumably precious one.
We will explain the precise purpose for employing exactly these two triggers when analyzing the competitive ratio of the algorithm. Essentially, the first one protects precious items from being discarded due to procrastinated level changes, while the second trigger’s paramount duty is to prevent too many paltry items from being misjudged as precious, which can also lead to them being unduly discarded.
Each of the two triggers alone would already ensure that the algorithm eventually reaches a level such that the presumably precious comboclass is in fact the precious one. We call the level for which this happens the final level and refer to all previous ones as the lost levels for a reason that will become clear later on.
Estimating the Optimal Solution Value.
The upper estimate for mentioned before is
where is the index of the comboclass currently considered presumably precious by the algorithm. The modulo class index , the class index , and the rounded fractions of the optimal solution value contributed by paltry items from phase are all retrieved from the advice. When calculating the estimate above, the algorithm assumes to have reached its final level; that is, it operates under the assumption that the presumably precious comboclass is in fact the precious one. Under this assumption, is indeed a valid upper estimate for as we will show now.
We have and begin by analyzing the first of the two summands. It is the value contributed to the optimal solution by the precious items contained in it. The algorithm can use the information about the modulo classes of these items to place the value of each of them into an interval spanning a factor of . Specifically, we start with the already established general relation , apply it to , and use the assumption of the current comboclass being the precious one to obtain . Since lies at the upper endpoint of class , we can compute the upper end of the value range of class as precisely. Note that the given advice and the value of the first item are in tandem indeed sufficient to calculate this number. It is an upper bound on such that the true value cannot be smaller than a factor of it, provided that the algorithm’s assumption holds true. If the algorithm is mistaken, however—that is, if —then the estimate is far too low; namely, it would be exactly a factor of what it otherwise would have been. If the algorithm has not yet reached the final level, the estimate for is therefore at most a fraction of the true value. As mentioned before, the inequality holds by the definition of . All of the assertions above for any single precious item naturally carry over to the sum
In particular, the total value of all precious items in the fixed optimal solution —the first of the two summands to be examined—lies in the interval during the final level.
Using the advice information on the value of the paltry items in the optimal solution appearing during each phase —given as fractions of the optimal solution value, rounded down to the nearest multiple of —the algorithm can narrow down the second summand to for some factor , where we have used once more the bound , derived via the total value of all precious items. Together with the bounds found for the first summand in the previous paragraph we obtain the following two inequalities, in which the optimal solution value occurs three times:
From this we obtain for a lower bound of and the presumed upper bound , which is an actual upper bound only during the last level. The upper and lower bound lie a factor
apart. Note that this quotient no longer depends on . Furthermore,we may assume that . This is because otherwise the algorithm could attain a fraction of the optimal solution value by packing paltry items exclusively in an otherwise purely yield-greedy manner uninhibited by any value limit; this special case is covered by the dedicated advice bit , which, when set to , switches the restrictions applied to the algorithm’s yield-greedy approach from a value limit to a size limit, as already explained at the beginning of this proof. We can therefore use to obtain
and thus | ||||
where, for the last inequality, we used , which is satisfied by our choices of , , and . In other words: During the final level the algorithm’s estimate is indeed an upper bound on exceeding the real value by at most . The algorithm can thus derive from any hypothesized upper bound for an actual lower bound . We will put this insight to use when analyzing the competitive ratio of the algorithm.
The Slot System.
In the precious part of the knapsack, the algorithm uses a slot system to store presumably precious items. There are slots, each of which can accommodate one such item, and all of them are empty in the beginning. They will be filled one by one, each with exactly one item. The items in filled slots may also be exchanged at some point. In contrast to what happens in the simpler algorithm for the proportional version of the problem, slots might also be emptied again when the algorithm decides to level up. The second difference is that there are now two stages to filling a slot. Any slot first has to be filled virtually before this filling is actualized at some point. The precise meaning of these two notions is explained later on. The order in which the slots are filled virtually is determined by the modulo classes of the precious items in the optimal solution: Slot must be filled virtually after slots through and before the other slots. As soon as this condition is met, slot is filled virtually with the first matching item, that is, the first item from the same modulo class as . The order in which slots receive an actualized filling is encoded in the tuples given by the advice. A filling may be actualized long after or right when it has happened virtually, just never before that.
When exactly a slot is filled virtually, instead of just in which order, is described in the following paragraph; when exactly the fillings are actualized is explained after the discussion on packing the paltry part of the knapsack.
The Phase Progression.
We say that the algorithm is in phase if slot has been filled virtually but not yet slot . Since all precious items are discarded when the algorithm is leveling up, all slots are empty again at the start of a new level, implying that the algorithm’s phase is reset to as well. In general, the current phase ends as soon as the instance ends or presents a presumably precious item satisfying the following two conditions. On the one hand, it is from the same modulo class as —recall that we can compute for any given item and know from the advice. On the other hand, the virtual algorithm can fit it into the precious part of the knapsack beside the items already present in the other slots, even if just virtually, and the packed paltry items, including the currently used fraction of any split item. If both of these conditions are met, said item is virtually packed into slot . For any other presumably precious item , it is first checked whether there are matching slots—that is, slots reserved for items from modulo class —filled with items larger than . If this is the case, a largest of these items is evicted, either just virtually or actually, and item takes its place. Otherwise, the presumably precious item is discarded.
Packing the Paltry Part.
The paltry items in the instance are in principle packed in a yield-greedy manner, that is, optimizing the ratio of value to size on the paltry items. If there were no precious items, this would already guarantee a sufficient approximation to the optimal solution value; we would lose at most the value of a single paltry item. If there are precious items, however, then we need to restrict the reservation of paltry items such that they never block a crucial precious item from filling an empty slot. But too much restriction is bad as well; if we always favor the packing of precious items matching an empty slot over accruing paltry items, then we might discard too many paltry items; after all, it is impossible to give exact bounds on the sizes of the optimal precious items, and the paltry items can be infinitesimally small.
The right type of restriction keeps the total size of the reserved paltry items low enough to allow for filling the next empty slot when the right precious items appears but not more than a constant fraction below the optimal amount. Directly encoding the right volume bound into the advice is impossible, however, since the requisite precision grows indefinitely with decreasing item sizes. Instead, we can limit the value that we should be accumulating in the form of paltry items in each phase. This does not immediately bound the size occupied by these items—we have no knowledge about the necessary yield—but will always do so just in time to fill all regular slots with precious items.
The value goal for each phase is indicated with a precision of and always rounded down. Additionally, this value goal is indicated relative to , for which the algorithm has a lower bound that is too small by at most a factor of as seen above. Since there are at most phases, the value lost due to this rounding can be bounded by
which we can still tolerate, as shown by the competitive analysis in the end of this proof. However, the situation could be exacerbated by the fact that when discarding a single paltry item to get below the rounded value threshold, we could incur a loss of up to , the maximum value of a paltry item, instead of only in every phase. There are up to phases, so this could sum up to a total loss just shy of . In the following, we introduce what might be called a virtual version of our algorithm as a tool to circumvent this problem.
The Virtual Algorithm.
Beside the actual advice algorithm producing our online solution, we consider a virtual version of the algorithm that has one huge, if imaginary, advantage: It may use a so-called splitting slot. The splitting slot can store one paltry item at any point, and the virtual algorithm may then split off from the item currently stored there any desired fraction to be used in the packing of the knapsack. The fraction used of the split item is allowed to change at any moment. However, the algorithm must always take the same fraction for the value and the size of an item, meaning that the split-off part retains the yield of the full item.
In other words, the algorithm can, for an arbitrary positive , treat an item of size and value in the splitting slot as though it were an item of size and value, and the can be adjusted arbitrarily at any time.
This enables the virtual algorithm to hit the previously described target value precisely and persistently, once it could have exceeded it, by maintaining in the splitting slot a paltry item of highest yield after those actually kept outside the splitting slot, and always taking just the right fraction to stay at the value limit as long as possible. The unused fraction is assumed to neither take up any space nor contribute any value.
There are two ways for an item to be forced out of the splitting slot. If items of higher yield—or identical yield but smaller ones—and sufficient total value appear, the present split item will become useless to the virtual algorithm, which then discards it for good. If, however, there is a phase change accompanied by an increase of the value limit, then the algorithm may decide to retrieve the entire item from the splitting slot, pack it in the knapsack regularly, and store an item of lower yield—or identical yield but lower size—in the splitting slot instead.
Having described the behavior of the virtual version of the algorithm, which uses the imagined capabilities of the splitting slot, we now explain how the actual algorithm acts based on the decisions taken by the virtual version.
The Actual Algorithm.
The actual algorithm is essentially trying to trace every action of its virtual version. However, it is not allowed to split any items and thus faced with a binary decision whenever the virtual algorithm stores an item in the splitting slot: either pack said item as a whole or discard it completely. Both choices come with their own set of problems.
It is the simpler option for the algorithm to discard any split item, as it then can still imitate the virtual version in every other respect, by operating as though any fraction from the split item were available at any time. In particular, the precious items would be handled absolutely identically by both versions of the algorithm. However, if too many split items kept by the virtual algorithm are discarded, then their total value could accumulate to a substantial part the optimal solution value. Thus it will be necessary to store split items under certain circumstances.
This opens up the possibility for the second type of error, entailing even more serious consequences. If the actual algorithm packs an item in its entirety instead of only the fraction used by the virtual version, then there is less space left for precious items needed to fill up all slots in the end. The naïve approach of just following the virtual version in packing a precious item whenever feasible—that is, unless packed paltry items, including the used fraction of the split item, would need to be discarded—does not work here. This could entice the algorithm into filling a slot with a precious item much larger than what this slot will contain in the end, thus preventing the packing of rather large but still important paltry items into the splitting slot.
Instead, the algorithm uses the advice tuples to navigate the two issues in such a way that its final output is in fact identical to that of the virtual version, except for missing the one item remaining in the splitting slot at the end.
Specifically, the advice tuple is used in phase as follows. The algorithm does not pack any precious items or split items by default. Once the virtual algorithm packs an item into slot , however, the actual algorithm tries to follow suit. It might be unable to do so if it has stored items of a larger total size due to its inability to split items. If it can fill a new item into slot alongside with the virtual version, however, then from this moment on, the algorithm starts actually packing into slot whatever the virtual version packs into it; we say that slot is now actualized. After actualizing slot , the algorithm starts monitoring slot , which might already be filled virtually at this point, but is not yet filled actually. Whenever a new item—assume that it is precious for the moment—is stored into by the virtual algorithm, the actual algorithm observes if it could do the same. As soon as such an opportunity arises, it is taken, and slot is now also actualized. This continues until the tuple is exhausted, which means that no more slots will be actualized in this phase. If the advice tells the algorithm to actualize the splitting slot, which has the number , with a paltry item, this all works identically, with two exceptions: First, if the virtual algorithm updates an already actualized item in the splitting slot, then all slots that were actualized after the splitting slot in the current phase are virtualized again, meaning that the actual algorithm discards the items stored in them. And second, the splitting slot is reverted to be virtual at the beginning of each new phase. Nevertheless, an item already stored in the splitting slot at the beginning of a phase remains there until it is replaced by a future item.
We have now fully described our algorithm, whose pseudo-code is found in Algorithm 2. Note that both the value-restricted and the size-based yield-greedy procedure used for packing the paltry items are implemented by the function Greedy.
Turning now to the analysis of the algorithm, we will first show that the algorithm performs sufficiently in the special mode where items are filtered based on their size. Then we prove that the virtual version eventually fills all slots and always attains the value goal on the paltry items, resulting in a total value that surpasses our final goal with more than to spare. Finally, we prove that the actual algorithm can successfully re-create the solution by the virtual version up to potentially one single paltry item, which we can forego without problem due to the leeway afforded by the virtual version.
Success of Size-Based Strategy.
We first consider the rather simple case that the special bit is set to . The oracle does this if and only if a purely yield-greedy approach on the paltry items, ignoring all precious ones, is guaranteed to achieve a competitive ratio of on the given instance. However, as mentioned before, the algorithm does not know for sure which items will turn out to be paltry in the end; thus it is implementing a size-based strategy instead in this case, packing only small items and dismissing the big ones.
Since the big items all have size at least , at most of them fit into any feasible solution, in particular the -competitive solution that would have been produced by greedily packing only paltry items. Omitting from this solution, which contains only paltry items, the up to big items decreases its value by less than . This means that we now have a solution containing only small items, worth at least a fraction of the optimal solution value. Running a yield-greedy strategy on the small items either reproduces this solution perfectly or it leaves, as soon as a packed item is discarded, an unfilled gap smaller than . Since the yield is optimized for the filled part of the knapsack, this is a solution worth at least a fraction of the optimal solution value, which for our choices of and is greater than . We can therefore assume from now on.
Success of Virtual Version.
Assuming that the algorithm already starts in its final level—which is proved to be possible without loss of generality in its own section on leveling up—we show that the virtual version completes all phases and hits its value goal on the paltry items precisely in each phase. Recall that after reaching the final level, the notions of paltry and precious coincide with provenly paltry and presumably precious, respectively.
Denote by and the total value and size, respectively, of the items in optimal solution appearing after but before . Recall that the algorithm computes —where is given directly by the advice and is the current lower bound on —as a fairly accurate lower bound on . Denote this lower bound by , and denote by the proportional lower bound on , namely . The desired statement follows from a two-part claim by induction over , where we use once more our auxiliary definition of two imaginary items and .
Induction Claim.
-
1.
After the decision on item , the first slots are filled, whether just virtually or already actualized, with items of size at most .
-
2.
Consider the paltry items in the knapsack when is presented, including the used fraction of any split item. Among these, select items in a manner greedy for high yield and secondarily for low size—allowing for any items to be split, regardless of whether they are in the splitting slot—and stop only if the total value reaches . The value of this selection is in fact exactly and its size at most .
Base Case.
The base case is trivially true: Phase begins with the decision on the auxiliary item , which does not fit any of the slots, which thus all remain empty. The second part claim is empty as well due to .
Induction Step.
Let an arbitrary be given. We assume the claim for all as our induction hypothesis and use it to prove the statement for . By the first part of the hypothesis, the algorithm is at least in phase when the items between and are presented. Therefore, the value limit for packing paltry items is already or higher at the beginning of this period of the instance. The set of paltry items presented during this period contains a set of items, namely , with total size and size . A yield-greedy online packing choosing from these items with a value limit achieves, if splitting items arbitrarily is allowed, a selection with a value of exactly and—since the selection has the highest possible yield—size at most . We know from the second part of the hypothesis that at the beginning of the considered period the knapsack has already contained paltry items allowing for a selection of value and size at most . The combination of this selection with the previously described one has value and some size which is at most . Our algorithm will therefore also achieve at the end of the considered period a selection of this same value and some size that might be even lower—since it has to chance to use some items in of potentially greater yield—but never higher. This concludes the proof of the second part of the claim.
For the first part, it suffices to consider the case that the first slots do not yet contain items of size at most when item is presented. By the induction hypothesis, the first slots already contained items of size at most after the decision on . This remains true until the instance ends since items in a slot are only ever replaced by smaller ones. If slot is already filled when is presented, then the item in this slot either has size at most , or it is replaced by , both of which mean that the induction claim for is satisfied. Finally, if slot is still empty upon the presentation of , then we can combine the first part of our induction hypothesis and the already proven second part for to bound the total size of all packed items at this moment by
Since is a feasible solution, item will fill slot , which concludes the proof of the second part of the claim, the induction step from to , and thus the entire induction.
Success of Actual Algorithm
Having seen that the virtual version of the algorithm performs sufficiently well—the exact competitive analysis follows later on—we now prove that the actual algorithm successfully mimics this behavior in the following sense: Despite deviating from the virtual online solution by non-negligible values at some times, the actual algorithm produces a final output that is identical to that of the virtual solution , except for the omission of one single paltry item, namely the one remaining in the splitting slot when the instance ends. We will see that the actual algorithm, which uses exactly the same phases and value limits as the virtual version, can use the advice to actualize any item that is part of the eventual solution immediately when is appears. The first key toward this is the following observation. During any given phase, the value limit used by the algorithm remains fixed. Hence, any item that is split at any point during a given phase either remains in the splitting slot until the end of this phase or—if it leaves the splitting slot before the phase has ended—it is discarded in favor of items of greater yield or identical yield but larger size, as dictated by the yield-greedy approach for paltry items. This means that the paltry items remaining in the knapsack at the end of a phase, excluding the one in the splitting slot at this point, have never been in the splitting slot during the entire phase. By not actualizing the splitting slot, the algorithm will therefore not miss during this phase any paltry item from the eventual virtual solution but potentially the one item that is in the splitting slot at the end of the phase. Moreover, actualizing the splitting slot only upon appearance of this one item suffices to not miss any paltry item from in this phase. The algorithm can therefore focus on actualizing the precious items and paltry items that are in the splitting slot at the end of some phase—although it does not know beforehand which of the paltry items will turn out to be of this kind.
The second key, addressing this issue, is to actualize the slots in the right order, which is made possible by the advice. Denote by those items from the virtual solution , excluding the item remaining in the splitting slot in the end, that are either precious or have been in the splitting slot at the end of some phase, in the order as they appear during the instance. These are exactly the items that the algorithm might miss by not actualizing them. We inductively prove that the actual algorithm actualizes the items .
Induction Claim.
Immediately after the decision on , the algorithm has actualized the items .
Induction Basis.
Using once more the auxiliary definition of an imaginary item of zero value and size, the claim for is empty.
Induction Step.
Our induction hypothesis is that the items are already packed and actualized immediately after the decision on . These items will never be replaced by the actual algorithm because the virtual version does not do so either since they are part of its eventual solution .
The advice tells us into which slot the virtual algorithm will pack in the current phase. Whenever the virtual version packs an item into this slot, the algorithm will try to actualize it. We only need to prove this to be possible without exceeding the given capacity.
If the oracle advises the algorithm to not actualize any item in the splitting slot in the current phase, this is trivial: The actual algorithm never actualizes anything not also fully packed by the virtual version, which never exceeds the knapsack capacity.
The more difficult case is that the virtual algorithm puts into the splitting slot during this phase some paltry item that will be part of the eventual virtual solution in its entirety rather than just as a split item. In the moment when this item is put into the splitting slot, the remaining packed paltry items have a total size that will never be undercut during the rest of the instance. This is because the only way to decrease the total size of the packed paltry items is to discard some of them, which would be possible only if the item of lower priority in the splitting slot were discarded beforehand by the virtual algorithm, which it cannot do since is part of the eventual solution. This means that contains paltry items of some total size at least as large the size of paltry items packed when appears, plus the entire item , plus all the items . Thus the total size of is at least what the total size in the knapsack becomes for the actual algorithm when packing fully upon appearance, in addition to those the items from that have appeared earlier and those yet to appear. It might happen that the algorithm has actualized the slot for a precious item before it has appeared, which could mean that this slot contains an item larger than , which in turn could block the replacement of the item in the splitting slot by one that has higher yield, but is also larger. However, recall that in this case the algorithm just re-virtualizes the slots to be actualized after the splitting slot in the current phase, dismissing all precious items in them. Therefore, the algorithm can and will indeed always actualize upon appearance.
Competitive Analysis
We analyze the competitive ratios achieved on the precious items and the paltry items separately. During this, we assume that the algorithm starts in the final level and thus never discards previously packed items due to leveling up; this assumption is justified afterward.
We still denote by the optimal solution picked by the oracle to compute the advice, and let denote the final output of the online algorithm.
Precious Part.
It follows from the termination of all phases in the last level and the actualization of all slots that the precious part of the online solution contains exactly as many precious items in each value class as does. Each class spans a value interval whose lower and upper end spread a factor of exactly , thus we know that . The loss on the precious items is therefore at most a fraction of the optimal solution value.
Paltry Part.
For the paltry items, we have already bounded the lost value to a fraction of the optimal solution when discussing how the paltry part of the knapsack is packed using the splitting slot.
Leveling Up.
It remains to show that the potentially unbounded number of resets, which occur whenever the algorithm is leveling up, are only causing a negligible value loss.
The first trigger causing a level change was the appearance of an item worth more than the items considered presumably precious so far. This trigger ensures that the algorithm never mistreats a precious item as paltry since doing so could mean missing a precious item that should have filled a slot. If a precious item is not already recognized as such upon arrival, the algorithm immediately levels up to rectify this and pack the item if necessary.
The second trigger for leveling up was that the algorithm can construct, from the items seen so far—whether they have been accepted or not—a valid solution whose value exceeds the upper bound on the optimal solution value . The newest item is part of any such hypothetical solution—otherwise the level would have risen earlier—and when excluding it, the remaining possible solutions are all worth less than the current upper bound .
When a level change is occurring—independent of whether it was caused by the first or second trigger—this means that the estimate has in fact been far too low: It has been at most a fraction of what it is becoming now, as already noted in the section on notions and notation. Moreover, we have proved, when explaining how the optimal solution value is estimated, that we can derive from any upper bound a guaranteed lower bound .
Combining the three facts from the last two paragraphs, we see that the value of any solution that can be constructed from the items to be discarded with the level change is worth at most . If the final optimal solution contains any of these items, then omitting them means losing at most a fraction of the overall value, where the last inequality is satisfied for our choices of , , and . While we might incur such a loss of a factor bounded by with every new level change, the aggregate loss of the previous resets is fortunately also diminishing in relation to the estimate for with every update of this estimate to a higher value. Hence the total fractional value loss caused by the potentially unbounded number of resets of the algorithm can be bounded by . Deducting this fraction from the value of the final online solution, we are justified in assuming without loss of generality that the algorithm already starts at the final level.
Algorithm 2 implements all of this by resetting the input sequence to its initial state upon each level change, and then acting out what it would have done, had it been at the current level from the beginning. For all items encountered at past levels this is a mere simulation since all previously packed items are discarded during a reset. To allow for this simulation, the algorithm maintains a set of all items seen so far and writes them off as lost whenever the level changes. The lost items are remembered by storing during each reset the current as . This set is then omitted from the online output to keep to real.
Conclusion.
Combining the three types of potential losses discussed above—the one on the precious part, the one on the paltry part, and the one due to leveling up repeatedly—to a worst-case scenario, we are still left with at least a fraction of the optimal solution value, which is greater than , concluding the proof.
References
- [1] Richard Bellman. Dynamic Programming. Princeton University Press, Princeton, NJ, USA, 1957.
- [2] Hans-Joachim Böckenhauer, Elisabet Burjons, Juraj Hromkovič, Henri Lotze, and Peter Rossmanith. Online simple knapsack with reservation costs. In Markus Bläser and Benjamin Monmege, editors, 38th International Symposium on Theoretical Aspects of Computer Science, STACS 2021, March 16-19, 2021, Saarbrücken, Germany (Virtual Conference), volume 187 of LIPIcs, pages 16:1–16:18, 2021.
- [3] Hans-Joachim Böckenhauer, Dennis Komm, Rastislav Královič, Richard Královič, and Tobias Mömke. On the advice complexity of online problems. In ISAAC 2009, number 5878 in LNCS, pages 331–340, 2009.
- [4] Hans-Joachim Böckenhauer, Dennis Komm, Richard Královič, and Peter Rossmanith. The online knapsack problem: Advice and randomization. Theoretical Computer Science, 527:61–72, 2014.
- [5] Allan Borodin and Ran El-Yaniv. Online computation and competitive analysis. Cambridge University Press, 1998.
- [6] Joan Boyar, Lene M. Favrholdt, Christian Kudahl, Kim S. Larsen, and Jesper W. Mikkelsen. Online algorithms with advice: A survey. ACM Comput. Surv., 50(2):19:1–19:34, 2017.
- [7] Marek Cygan, Łukasz Jeż, and Jiří Sgall. Online knapsack revisited. Theory Comput. Syst., 58(1):153–190, 2016.
- [8] George B. Dantzig. Discrete-variable extremum problems. Operations Research, 5(2):266–277, 1957.
- [9] Yuval Emek, Pierre Fraigniaud, Amos Korman, and Adi Rosén. Online computation with advice. Theoretical Computer Science, 412(24):2642–2656, 2011.
- [10] Xin Han, Yasushi Kawase, and Kazuhisa Makino. Online unweighted knapsack problem with removal cost. Algorithmica, 70(1):76–91, 2014.
- [11] Xin Han, Yasushi Kawase, and Kazuhisa Makino. Randomized algorithms for online knapsack problems. Theoretical Computer Science, 562:395–405, 2015.
- [12] Xin Han, Yasushi Kawase, Kazuhisa Makino, and He Guo. Online removable knapsack problem under convex function. Theoretical Computer Science, 540:62–69, 2014.
- [13] Xin Han, Yasushi Kawase, Kazuhisa Makino, and Haruki Yokomaku. Online knapsack problems with a resource buffer. In Pinyan Lu and Guochuan Zhang, editors, 30th International Symposium on Algorithms and Computation, ISAAC 2019, December 8–11, 2019, Shanghai University of Finance and Economics, Shanghai, China, volume 149 of LIPIcs, pages 28:1–28:14. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 2019.
- [14] Xin Han and Kazuhisa Makino. Online removable knapsack with limited cuts. Theoretical Computer Science, 411(44-46):3956–3964, 2010.
- [15] Juraj Hromkovič, Rastislav Královič, and Richard Královič. Information complexity of online problems. In MFCS 2010, number 6281 in LNCS, pages 24–36. Springer, 2010.
- [16] Oscar H. Ibarra and Chul E. Kim. Fast approximation algorithms for the knapsack and sum of subset problems. Journal of the ACM, 22(4), 1975.
- [17] Kazuo Iwama and Shiro Taketomi. Removable online knapsack problems. In ICALP 2002, number 2380 in LNCS, pages 293–305. Springer, 2002.
- [18] Kazuo Iwama and Guochuan Zhang. Online knapsack with resource augmentation. Information Processing Letters, 110(22):1016–1020, 2010.
- [19] Richard M. Karp. Reducibility among combinatorial problems. In Complexity of computer computations, pages 85–103. Plenum, 1972.
- [20] Dennis Komm. An Introduction to Online Computation – Determinism, Randomization, Advice. Texts in Theoretical Computer Science. An EATCS Series. Springer, 2016.
- [21] Alberto Marchetti-Spaccamela and Carlo Vercellis. Stochastic on-line knapsack problems. Mathematical Programming, 68:73–104, 1995.
- [22] John Noga and Veerawan Sarbua. An online partially fractional knapsack problem. In 8th International Symposium on Parallel Architectures, Algorithms, and Networks, ISPAN 2005, December 7-9. 2005, Las Vegas, Nevada, USA, pages 108–112. IEEE Computer Society, 2005.
- [23] Herbert Ellis Robbins. A remark on Stirling’s formula. American Mathematical Monthly, 62:26–29, 1955.
- [24] Peter Rossmanith. On the advice complexity of online edge- and node-deletion problems. In Adventures Between Lower Bounds and Higher Altitudes – Essays Dedicated to Juraj Hromkovič on the Occasion of His 60th Birthday, number 11011 in LNCS, pages 449–462. Springer, 2018.