Fully Dynamic Algorithms for Knapsack Problems with Polylogarithmic Update Time
Martin Böhm, Franziska Eberle, Nicole Megow, Lukas Nölke, Jens Schlöter, Bertrand Simon, Andreas Wiese
aa r X i v : . [ c s . D S ] J u l Fully Dynamic Algorithms for Knapsack Problems withPolylogarithmic Update Time
Martin B¨ohm ∗ Franziska Eberle ∗ Nicole Megow ∗ Lukas N¨olke ∗ Jens Schl¨oter ∗ Bertrand Simon ∗ Andreas Wiese † July 20, 2020
Abstract
Knapsack problems are among the most fundamental problems in optimization. In the M
ULTIPLE K NAPSACK problem, we are given multiple knapsacks with different capacities and items with valuesand sizes. The task is to find a subset of items of maximum total value that can be packed into theknapsacks without exceeding the capacities. We investigate this problem and special cases thereof in thecontext of dynamic algorithms and design data structures that efficiently maintain near-optimal knap-sack solutions for dynamically changing input. More precisely, we handle the arrival and departure ofindividual items or knapsacks during the execution of the algorithm with worst-case update time polylog-arithmic in the number of items. As the optimal and any approximate solution may change drastically,we only maintain implicit solutions and support certain queries in polylogarithmic time, such as thepacking of an item and the solution value.While dynamic algorithms are well-studied in the context of graph problems, there is hardly any workon packing problems and generally much less on non-graph problems. Given the theoretical interest inknapsack problems and their practical relevance, it is somewhat surprising that K
NAPSACK has not beenaddressed before in the context of dynamic algorithms and our work bridges this gap. ∗ University of Bremen, Germany. { martin.boehm,feberle,nmegow,noelke,jschloet,bsimon } @uni-bremen.de † Universidad de Chile, Chile. [email protected]
Introduction
Knapsack problems are among the most fundamental optimization problems, studied since the early days ofoptimization theory. In its most basic form, there is given a knapsack with capacity S ∈ N and a set of n items, where each item j ∈ [ n ] := { , , . . . , n } has a size s j ∈ N and a value v j ∈ N . The K NAPSACK problem asks for a subset of items, P ⊆ [ n ] , with maximal total value v ( P ) := P j ∈ P v j and with a totalsize s ( P ) := P j ∈ P s j that does not exceed the knapsack capacity S . In the more general M ULTIPLE K NAPSACK problem, we are given m knapsacks with capacities S i for i ∈ [ m ] . Here, the task is to select m disjoint subsets P , P , . . . , P m ⊆ [ n ] such that subset P i satisfies the capacity constraint s ( P i ) ≤ S i andthe total value of all subsets P i ∈ [ m ] v ( P i ) is maximized.The decision variant of M ULTIPLE K NAPSACK is strongly NP-complete, even for identical knapsackcapacities, as it is a special case of bin packing. The K
NAPSACK problem, on the other hand, is onlyweakly NP-complete in its decision variant – in fact, it is one of the 21 problems on Karp’s list of NP-complete problems [49] – and it admits pseudo-polynomial time algorithms [5]. The first published pseudo-polynomial time algorithm for K
NAPSACK from the 1950s has run time O ( n · S ) [5].As a consequence of these hardness results, each of the knapsack variants has been studied exten-sively over the years through the lens of approximation algorithms. Of particular interest are approximationschemes , families of polynomial-time algorithms that compute for each ε > a (1 − ε ) -approximate so-lution, i.e., a feasible solution with value within a factor of (1 − ε ) of the optimal solution value (see alsorelated work). The first approximation scheme for the K NAPSACK problem is due to Ibarra and Kim [38] andinitiated a long sequence of follow-up work, with the latest improvements appearing only recently [17, 47].M
ULTIPLE K NAPSACK is substantially harder and does not admit (1 − ε ) -approximate algorithms withrunning time polynomial in ε unless P = NP, even with two identical knapsacks [18]. However, someapproximations schemes with exponential dependency on ε are known [18, 50] as well as improved variantswhere the dependency on f (cid:0) ε (cid:1) for some function f is only multiplicative or additive [43, 45]. The currentlyfastest known algorithm has a runtime of O (log (1 /ε ) /ε ) + poly ( n ) [45]. All these algorithms are static inthe sense that the full instance is given to an algorithm and is then solved.The importance for theory and practice is reflected by the two books on knapsack problems [52, 61].Given the relevance of knapsack applications in practice and the ubiquitous dynamics of real-world in-stances, it is natural to ask for dynamic algorithms that adapt to small changes in the packing instance whilespending only little computation time. More precisely, during the execution of the algorithm, items andknapsacks arrive and depart and the algorithm needs to maintain an approximate knapsack solution withan update time polylogarithmic in the number of items in each step. A dynamic algorithm is then a datastructure that implements these updates efficiently and supports relevant query operations. To the best ofour knowledge, we are the first to analyze knapsack problems in the context of dynamic algorithms.Generally, dynamic algorithms constitute a vibrant research field in the context of graph problems. Referto surveys [15, 24, 34] for an overview on dynamic graph algorithms. Interestingly, only for a small numberof graph problems there are dynamic algorithms known with polylogarithmic update time, among themconnectivity problems [35, 37], the minimum spanning tree [37], and vertex cover [10, 12]. Recently, thiswas complemented by conditional lower bounds that are typically linear in the number of nodes or edges;see, e.g., [2]. Over the last few years, the generalization of dynamic vertex cover to dynamic set cover gainedinterest leading to near-optimal approximation algorithms with polylogarithmic update times [1, 9, 11, 30].For packing and, generally, for non-graph-related problems, dynamic algorithms with small update timeare much less studied. A notable exception is a result for bin packing that maintains a -approximativesolution with O (log n ) update time [40]. This lack of efficient dynamic algorithms is in stark contrast to theaforementioned intensive research on computationally efficient algorithms for knapsack problems.Besides the purely theoretical point of view, packing questions appear in many applications and efficientalgorithms for answering these questions are highly relevant in practice. One such example is estimating the1rofit of scheduling jobs onto several server hosting centers. Cloud providers need to adhere to certain Ser-vice Level Agreements while efficiently managing their resources. In recent years, it has become apparentthat the cost of powering large-scale computing infrastructures surpasses the hardware cost after only fewyears. Thus, the task of dynamically migrating workload as virtual machines between several computingclusters has evolved [6]. This allows the service provider to adapt the provided capacity, i.e., the currentlyrunning computing clusters, to the current demand. Situations of this flavor are addressed in [13, 21, 58].A framework for M ULTIPLE K NAPSACK with efficient update times can be viewed as a first-stagedecision tool: In real-time, it can be determined whether the customer in question should be allowed intothe system based on the cost of potentially powering and using additional servers. As the service providerhas to decide immediately which request she wants to accept, she needs to obtain the information fast , i.e.,sublinear in the number of requests already in the system.Given the theoretical interest in knapsack problems and their practical relevance, it is surprising thatK
NAPSACK has not been addressed in the context of dynamic algorithms. Our work bridges this gap initiat-ing the design of data structures and algorithms that efficiently maintain near-optimal knapsack solutions.
Our Contribution
In this paper, we present dynamic algorithms for maintaining approximate knapsack solutions for threeproblems of increasing complexity: K
NAPSACK , M
ULTIPLE K NAPSACK with identical knapsack sizes, andM
ULTIPLE K NAPSACK . Our algorithms are fully dynamic which means that in an update operation theycan handle both, the arrival or departure of an item and the arrival or departure of a knapsack. Further, weconsider the implicit solution or query model, in which an algorithm is not required to store the solutionexplicitly in memory such that the solution can be read in linear time at any given point of the execution.Instead, the algorithm may maintain the solution implicitly with the guarantee that a query about the packingcan be extracted in polylogarithmic time. Moreover, since K NAPSACK is already NP-hard even with fullknowledge of the instance, we aim at maintaining (1 − ε ) -approximate solutions.We give worst-case guarantees for update and query times that are polylogarithmic in n , the number ofitems currently in the input, and bounded by a function of ε > , the desired approximation accuracy. Forsome special cases, we can even ensure a polynomial dependency on ε . In others, we justify the exponentialdependency with NP-hardness results. Denote by v max the currently largest item value and by v an upperbound on v max that is know in advance. Let S max be the currently largest knapsack capacity. • For M
ULTIPLE K NAPSACK , we design a dynamic algorithm maintaining a (1 − ε ) -approximate solu-tion with update time (cid:0) ε log n log v (cid:1) O (1 /ε ) and query time O ( log nε ) for single items. (Theorem 6.1) • The exponential dependency on ε in the update time for M ULTIPLE K NAPSACK is indeed necessary,even for two identical knapsacks. We show that there is no (1 − ε ) -approximate dynamic algorithmwith update time (cid:0) ε log n (cid:1) O (1) , unless P = NP. (Theorem 3.3) • For K
NAPSACK , we give a (1 − ε ) -approximation algorithm with update time O (cid:0) log ( nv max ) ε (cid:1) + O ( ε log n log v ) and constant query times. (Theorem 4.1) • For M
ULTIPLE K NAPSACK with m identical knapsacks , we maintain a (1 − ε ) -approximate solutionwith update time (cid:0) ε log n log v max log S max (cid:1) O (1) and query time (cid:0) ε log n (cid:1) O (1) if m ≥ ε log n . Forsmall m , we get an exponential dependency on ε by extending the result for K NAPSACK .In each update step, we compute only implicit solutions and provide queries for the solution value, theknapsack of a queried item, or the complete solution. These queries are consistent between two update stepsand run efficiently, i.e., polynomial in log n and log v and with a dependence on ε and the output size. Weremark that it is not possible to maintain a solution with a non-trivial approximation guarantee explicitly2ith only polylogarithmic update time (even amortized) since it might be necessary to change Ω( n ) itemsper iteration, e.g., if a very large and very profitable item is inserted and removed in each iteration. Related Work
Since the first approximation scheme for K NAPSACK by Ibarra and Kim [38], running times have beenimproved steadily [17, 26, 27, 47, 51, 57, 68] with O ( n log ε + ( ε ) / ) by Jin [47] being the currently fastest.Recent work on conditional lower bounds [20, 56] implies that K NAPSACK does not admit an FPTAS withruntime O (( n + ε ) − δ ) , for any δ > , unless ( min, +) -convolution has a subquadratic algorithm [17, 64].A PTAS for M ULTIPLE K NAPSACK was first discovered by Chekuri and Khanna [18] and an EPTASdue to Jansen [43] is also known. The running time of the EPTAS is O (log(1 /ε ) /ε ) · poly ( n ) . Jansen laterpresented a second EPTAS [45] with an improved running time of O (log (1 /ε ) /ε ) + poly ( n ) . The mentionedalgorithms are all static and assume full knowledge about the instance for which a complete solution hasto be found. Hence, directly applying such an approximation scheme on each update is prohibitive as asingle item arrival can change a packing solution completely requiring a full recomputation with runningtime polynomial in the input size.At the heart of the two EPTASes [43, 45] lies a configuration integer linear program (ILP) for roundeditems and/or knapsacks of exponential size. Even though near-optimal solutions to the LP relaxations can befound and rounded in time O ( poly ( n )) , this is beyond the scope of the polylogarithmic update time we areinterested in. Additionally, the configuration ILPs still contain O ( n ) many constraints and variables which isyet another obstacle when aiming for dynamically maintaining approximate solutions with polylogarithmicrunning time. Hence, to sufficiently improve the running time, a more careful approach for rounding itemshas to be developed before similar configuration ILPs can be applied.The dynamic arrival and removal of items exhibits some similarity to knapsack models with incompleteinformation. Somewhat related to our work are models in which the set of items that has to be packed is notfully known. In the online knapsack problem [60] items arrive online one by one. When an item arrives,an algorithm must accept or reject it before the next item arrives, and this decision is irrevocable. The goalis to maintain a knapsack solution that has a value close to the optimal value achievable when all items areknown in advance. Contrary to our model, the available computational power is assumed to be unlimited(though many known algorithms run in polynomial time) as the key difficulty lies in making irrevocablepacking decisions under uncertainty. Various problem variants have been studied, e.g., online knapsackwith resource augmentation [42], the removable online knapsack problem [19, 31–33, 41], in which itemscan be discarded later, the online partially fractional knapsack problem [65], items arriving in a randomorder [3, 4], the stochastic online knapsack problem [53, 54, 60, 72], and online knapsack with advice [14].Other models that take into account uncertainty in the item set or in the available knapsack capacityinclude the stochastic knapsack problem [8, 23, 59] and various robust knapsack problems [16, 25, 62, 74].While some models allow for an adjustment of the solution after the realization of a scenario, the major focuslies on constructing a new packing of high value instead of the computational complexity of the update orthe data structures necessary to maintain (approximately) optimal packings.Finally, we mention two other seemingly related research streams towards more adaptive online modelswith a softened irrevocability requirement. Online optimization with recourse [29, 39, 63] or migration [46, 70, 71] allows to adapt previously taken decisions in a limited way. We are no aware of work onknapsack problems and, again, the goal is to bound the amount of change needed to maintain good onlinesolutions regardless of the computational effort. An approximation scheme is a family of polynomial-time algorithms computing a (1 − ε ) -approximation for every ε > .Based on the dependency on ε of the respective running time, we distinguish Polynomial Time Approximation Schemes (PTAS) with arbitrary dependency on ε , EPTAS where arbitrary functions f ( ε ) may only appear as a multiplicative factor, and FPTAS withpolynomial dependency on ε . Methodology and Roadmap
This section serves as a blueprint for our design of a dynamic algorithm for M
ULTIPLE K NAPSACK provid-ing a high-level overview over the key components and technical challenges. While the improved algorithmsfor some special cases have significance on their own, the used techniques further complement each otherand facilitate our main goal of handling arbitrary instances, which we discuss in Section 6.We accomplish this goal by partitioning the given knapsacks based on their respective capacity, creatingtwo subproblems of M
ULTIPLE K NAPSACK . This separation allows us to design algorithms that exploitthe structural properties specific to the respective problem. One subproblem consists of relatively few knap-sacks, but they are the largest of the instance. While the small number of these special knapsacks offers morealgorithmic freedom, this freedom is necessary since great care has to be taken when computing a solution.After all, there may be items of high value that only fit into special knapsacks. The second subproblem con-tains almost all of the remaining smaller knapsacks. The sheer number of these ordinary knapsacks resultsin an inverse problem, with the algorithmic handling of the numerous knapsacks being a major hurdle. Onthe upside, mistakes are forgiven more easily allowing us to even discard a small fraction of knapsacks en-tirely. Additionally, we create a third partition of knapsacks that lies in-between the two subproblems (w.r.t.knapsack capacity). It consists of knapsacks that contribute negligible value to an optimal solution. Thisproperty induces the precise partitioning and allows us to consider the knapsacks as empty extra knapsacks,which we use to place leftover items not packed in the subproblems.The major challenge with this divide-and-conquer approach is to decide which item is assigned to whichof the two subproblems. Clearly, for some – special – items this question is answered by their size as theyonly fit into special knapsacks, unlike the remaining – ordinary – items. In fact, for them the allocation is soproblematic that we resort to downright putting a number of high-value ordinary items into extra knapsacks.To handle the remainder, we guess the total size of ordinary items that are put into special knapsacks byan optimal solution. We then add a virtual knapsack – with capacity equal to this guess – to the ordinarysubproblem and solve it with the not yet packed ordinary items as input. The input for the special subproblemthen consists of all special items together with bundles of the ordinary items packed in the virtual knapsack.
Special Knapsacks:
The approach for the few ( m S ) special knapsacks can be divided itself into two partsthat consider high- and low-value items respectively. The corresponding partition is guessed so that thehigh-value items contain the m S ε most valuable items of an optimal solution, denoted by O PT , and the low-value items the remaining items of O PT . For the important high-value items, a good solution is paramount,so we employ an EPTAS for M ULTIPLE K NAPSACK . It is run on a low-cardinality set of high-value candi-date items together with m S ε placeholders of equal size that reserve space for low-value items. The valuesof placeholders are determined by filling them fractionally with the densest low-value items. We aim toreserve a total space equal to that of all low-value items in O PT , which we guess up to a factor of (1 + ε ) .Thanks to the partitioning, we can charge cut items to the high-value items in O PT . This yields an updatetime f (1 /ε ) ( mε log( nv max )) O (1) + O ( ε log v log n ) , with f quasi-linear, query time O (log m ε ) for individ-ual items and time O ( | P | ) to output the solution P for all or a single knapsack. See Appendix B for the fulldescription and analysis of this algorithm. Ordinary Knapsacks:
Having the extra knapsacks available for resource augmentation enables us toset up a configuration linear program (LP) for the ordinary knapsacks and place any fractional itemor configuration into the extra knapsacks. To solve the LP efficiently and achieve an update timeof (cid:0) ε log n (cid:1) O (1 /ε ) (log m log S max log v max ) O (1) we significantly decrease the number of ordinary itemswith a new, dynamic approach to linear grouping. Dynamic linear grouping clusters a (sub)set of items into so-called item types of roughly the same sizeand value in time (cid:0) ε log n (cid:1) O (1) . Traditionally, linear grouping is applied in bin packing problems whereany feasible solution contains all items [22]. This property is crucial since the cardinality of the groups4epends on the number of packed items. In knapsack problems, however, a feasible solution may consistof only a subset of items. We handle this uncertainty by simultaneously executing classical linear groupingfor O (log ε n ) many guesses of its cardinality and, thus, simulate the possible choices of an optimum.We call an item type small or big with respect to a particular knapsack if its size is at most or at least an ε -fraction of the knapsack’s capacity, respectively. Based on this, we partition ordinary knapsacks further intogroups such that the classification into small, big or “does not fit” is consistent among knapsacks of a givengroup. Note that these groups are not based on m and ε but dynamically depend on the current set of items.As the number of big items per knapsack is bounded, the LP explicitly assigns those via configurations toknapsacks while it assumes that small items can be packed fractionally and, thus, those are only assigned bynumber to the respective groups. This algorithm is described and analyzed in Appendix E.To highlight major algorithmic ideas and technical contributions, we present algorithms for the followingmore accessible special cases, which can – with some additional effort – be generalized to the subproblemsdiscussed above. Beyond that, they are of independent interest as they constitute relevant special cases ofM ULTIPLE K NAPSACK and allow for significant improvements in the running time.
Single Knapsack:
When the instance consists of only a single knapsack, the approach used for specialknapsacks allows for greatly improved update and query times. For K
NAPSACK , we can replace the EPTASby a faster FPTAS and, additionally, we need only a single placeholder item. The remaining steps areunchanged, yielding an update time of O (cid:0) log nv max ε (cid:1) + O ( ε log n log v ) . Moreover, the single placeholderenables us to compute its membership by comparing with a saved pivot element. Thus, we can access anyitem in constant time and de facto compute explicit solutions. We present these results in Section 4. Identical Knapsacks:
As a special case of the second subproblem, we consider M
ULTIPLE K NAPSACK with identical capacities, where an item is either big or small with respect to all knapsacks. As a con-sequence, (i) this exponentially decreases the number of constraints, and (ii) it suffices to reserve somecapacity of the knapsacks for packing the densest small items instead of computing their exact number bythe configuration LP. Still, the number of variables is prohibitively large. Hence, we would like to apply theEllipsoid method with an approximate separation oracle to the dual problem similar to [48, 67, 69]. How-ever, we cannot use their approaches directly due to two additional variables in the dual problem. Instead,we add an objective function constraint to the dual and carefully exploit the connection between feasible andinfeasible dual solutions to obtain a basic feasible solution for the primal. This enables us to approximatelysolve the LP and round a solution in time (cid:0) ε log n log v max log S max (cid:1) O (1) if m is sufficiently large. From the perspective of a data structure that implicitly maintains near-optimal solutions for M
ULTIPLE K NAPSACK , our algorithms support several different update and query operations. These allow for the inputto M
ULTIPLE K NAPSACK to be changed, which causes the computation of a new solution, or for (parts of)that solution to be output, respectively. The supported update operations are as follows. • Insert Item: inserts an item into the input • Remove Item j : removes item j from the input • Insert Knapsack: inserts a knapsack into the input • Remove Knapsack i : removes knapsack i from the inputThese compute a new solution which can be output, entirely or in parts, using the following query operations. • Query Item j : returns whether item j is packed in the current solution and if yes, additionally returnsthe knapsack containing it • Query Solution Value: returns the value of the current solution5
Query Entire Solution: returns all items in the current solution, together with the information inwhich knapsack each such item was packedIn particular, these queries are consistent in-between two update operations. Nevertheless, the answers toqueries are not independent of each other but depend on the precise queries as well as their order.To provide the above functionality, we require the use of additional auxiliary data structures and makea few basic assumptions which we now discuss. First, while the model imposes no time bounds on thecomputation of an initial solution, it can be easily seen that for all our algorithms such an initial solution canbe computed in time nearly linear in n and with additional dependencies on ε , v max , and v as in the respectivealgorithms. For simplicity, we assume that elementary operations such as addition, multiplication, andcomparison of two values can be handled in constant time. Clearly, this is not true as the parameters involvedcan be as large as v max and S max := max S i . However, as the number of elementary operations is bounded,their results do not grow arbitrarily large but are in fact bounded by a polynomial in log n , log m , S max ,and v max and some function of ε . Thus, we do not explicitly state the size of the involved numbers. Lastly,we make following standard assumptions on ε . By appropriately decreasing ε , we assume without loss ofgenerality that ε ∈ N . If m is sufficiently large, i.e., m ≥ ε , we also assume εm ∈ N . Rounding Values
A crucial ingredient to our algorithms is the partitioning of items into only few valueclasses V ℓ consisting of items j for which (1 + ε ) ℓ ≤ v j < (1 + ε ) ℓ +1 . Upon arrival of an item, we calculateits value class V ℓ j and store j together with v j , s j , and ℓ j in the appropriate data structures of the respectivealgorithm. We assume all items in V ℓ to have value (1 + ε ) ℓ and, abusing notation, use V ℓ to refer to boththe value class and the (rounded) value of its items. The following lemma justifies this assumption. Sincethis technique is rather standard, we only state the lemma without providing a formal proof. Lemma 3.1. (i) There are at most O ( log v max ε ) many value classes.(ii) For optimal solutions O PT and O PT ′ for the original and rounded instance respectively, wehave v ( O PT ′ ) ≥ (1 − ε ) · v ( O PT ) . Data Structures
The targeted running times do not allow for completely reading the instance in everyround but rather ask for carefully maintained data structures that allow us to quickly compute and storeimplicit solutions. For access to the input, we maintain an array that for each item stores the item’s size, valueand value class, and similarly for knapsacks. Mainly, however, our dynamic algorithms rely on maintainingsorted lists of up to n or m items or knapsacks respectively. For all sortings, break ties according to indices.As our goal is to design algorithms with poly-logarithmic update times, it is crucial that the data struc-tures enable accordingly efficient insertion, deletion and access times. Bayer and McCreight developed sucha data structure in 1972, the so-called B -trees that were later refined by Bayer to symmetric binary B -trees .In contrast to this early work, we additionally store in each node k information such as the total size, thetotal value, the total number of elements or the total capacity of the subtree rooted in k .As observed by Olivi´e [66] and by Tarjan [73], updating the original symmetric binary B -trees canbe done with a constant number of rotations. For our dynamic variant of B -trees, this implies that only aconstant number of internal nodes are involved in an update procedure. In particular, if a subtree is removedor appended to a certain node, only the values of this node and of his predecessors need to be updated. Thenumber of predecessors is bounded by the height of the tree which is logarithmic in the number of its leaves.Hence, the additional values stored in internal nodes can be maintained in time O (log n ) or O (log m ) .Storing the additional values such as total size of a subtree in its root allows us to compute prefixes or theprefix sum with respect to these values in time O (log n ′ ) as well. Prefix computation refers to finding themaximal prefix of the sorted list such that the elements belonging to the prefix have values whose sum isbounded by a given input. We return a prefix by outputting the index of its last element.6 emma 3.2.
There is a data structure maintaining a sorting of n ′ elements w.r.t. to key value. Moreover,(i) insertion, deletion, or search by key value or index of an element takes time O (log n ′ ) , and(ii) prefixes and prefix sums with respect to additionally stored values can be computed in time O (log n ′ ) . Hardness of Computation
To conclude this section, we provide a justification for the different runningtimes of our algorithms for M
ULTIPLE K NAPSACK depending on the number of knapsacks. It is known thatM
ULTIPLE K NAPSACK with m = 2 does not admit an FPTAS, unless P = NP [18]. For the dynamic setting,this implies that there is no dynamic algorithm with running time polynomial in log n and ε unless P = NP.We show that a (1 − ε ) -approximate dynamic algorithm for M ULTIPLE K NAPSACK with m < ε withupdate time polynomial in log n and ε would imply that -P ARTITION can be decided in polynomial time.The proof of following theorem is given in Appendix G.1. Note that this result can be extended to a largernumber of knapsacks by adding an appropriate number of sufficiently small knapsacks.
Theorem 3.3.
Unless P = NP , there is no fully dynamic algorithm for M ULTIPLE K NAPSACK that main-tains a (1 − ε ) -approximate solution in update time polynomial in log n and ε , for m < ε . The first problem we consider is K
NAPSACK . We show how to take advantage of dealing with only a singleknapsack when maintaining (1 − ε ) -approximate solutions. Utilizing an FPTAS to pack a low-cardinalityset of high-value candidates as well as a placeholder for low-value items, we obtain the following result. Theorem 4.1.
For ε > , there is a fully dynamic algorithm for K NAPSACK that maintains (1 − ε ) -approximate solutions with update time O (cid:0) log ( nv max ) ε (cid:1) + O ( ε log n log v ) . Furthermore, single items andthe solution value can be accessed in time O (1) . Definitions and Data Structures
Denote by O PT the item set of an optimal solution and by O PT ε the ε most valuable items of O PT . In both cases, break ties by picking smaller items. Denote by V ℓ max and V ℓ min the highest resp. lowest value (class) of an element in O PT ε and let n min := (cid:12)(cid:12) O PT ε ∩ V ℓ min (cid:12)(cid:12) ≤ ε . Further-more, denote by V L the value of the items in O PT \ O PT ε , rounded down to a power of (1 + ε ) .To efficiently run our algorithm we maintain several of the data structures from Section 3. We storethe items of each non-empty value class V ℓ (at most log ε v max ) in a data structure ordered by increasingsize. Second, for each possible value class V ℓ (at most log ε v ), we maintain a data structure ordered bydecreasing density that contains all items of value V ℓ or lower. In particular, we maintain such a data structureeven if V ℓ is empty since initialization is prohibitively expensive in terms of run time. Instead we constantlymaintain all data structures leading to the additive term in the update time of O (log n log ε v ) . We useadditional data structures to store our solution and support queries described in the proof of Lemma 4.2. Algorithm
The algorithm computes an implicit solution as follows.1)
Compute a set H ε of high-value candidates: Guess V ℓ max , V ℓ min and n min . If V ℓ min ≥ ε · V ℓ max ,define H ε to be the set containing the ε smallest items of each of the value classes V ℓ min +1 , . . . , V ℓ max ,plus the n min smallest items from V ℓ min . Otherwise, set H ε to be the union of the ε smallest items ofeach of the value classes with values in [ ε · V ℓ max , V ℓ max ] .2) Create a placeholder item B : Guess V L and consider the data structure of items with value atmost V ℓ min sorted by decreasing density. Remove the n min smallest items of V ℓ min until the nextupdate. For the remaining items, compute the minimal size of fractional items necessary to reach avalue V L . Then B is given by v B = V L and with s B equal to the size of those low-value items.7) Use an FPTAS:
On the instance I , consisting of H ε and the placeholder item B , run an FPTASparameterized by ε (we use the one by Jin [47]) to obtain a packing P .4) Implicit solution:
Among all guesses, keep the solution P with the highest value. Pack itemsfrom H ε as in P and, if B ∈ P , also pack the low-value items completely contained in B . Whileused candidates can be stored explicitly, low-value items are given only implicitly by saving the cor-rect guesses and computing membership in B on a query. Analysis.
The above algorithm attains an approximation ratio of (1 − ε ) · v ( O PT ) . One ε -fractionof v ( O PT ) is lost by using the FPTAS and additional one in each of the following three places. To obtain acandidate set H ε of constant cardinality, we restrict item values to [ ε · V ℓ max , V ℓ max ] . Since | O PT ε | = ε ,this removes items with a total value of at most ε · ε V ℓ max ≤ ε · O PT . Furthermore, due to guessing V L up to a power of (1 + ε ) , we get v B = V L ≥ (1 − ε ) · v ( O PT \ O PT ε ) . Finally, the item cut fractionally inStep 2) is charged to the ε items of O PT ε which have a larger value.The running time can be verified easily by multiplying the numbers of guesses for each value as wellas the running time of the FTPAS. The latter is O ( ε ) , since we designed H ε to contain only a constantnumber of items, namely O ( ε ) many. For a detailed analysis, see Appendix A. Queries
We show how to efficiently handle the different types of queries and state their runtime. • Single Item Query:
If the queried item is contained in H ε , its packing was saved explicitly. Other-wise, if B is packed, we save the last – i.e., least dense – item contained entirely in B . By comparingwith this item, membership in B can be decided in constant time on a query. • Solution Value Query:
While the algorithm works with rounded values, we may set up the datastructure of Section 3 to additionally store the actual values of items. We store the actual solutionvalue in the update step by adding the actual values of packed candidates and determining the actualvalue of items in B with a prefix computation. On query, we return the stored solution value. • Query Entire Solution:
Output the stored packing of candidates. If B was packed, iterate over itemsin B in the respective density-sorted data structure and output them. Lemma 4.2.
The query times of our algorithm are as follows.(i) Single item queries are answered in time O (1) .(ii) Solution value queries are answered in time O (1) .(iii) Queries of the entire solution P are answered in time O ( | P | ) . We describe our new dynamic approach to linear grouping for an item set J ′ ⊆ J where any feasible solutioncan pack at most n ′ items of J ′ . We consider J ′ instead of J because some of our dynamic algorithms onlyuse the dynamic linear grouping on a subset of items, e.g., big items. Theorem 5.1.
Given a set J ′ with | O PT ∩ J ′ | ≤ n ′ for all optimal solutions O PT , there is an algorithmwith running time O (cid:0) log n ′ ε (cid:1) that reduces the items in J ′ to item types T with |T | ≤ O (cid:0) log n ′ ε (cid:1) and en-sures v ( O PT T ) ≥ (1 − ε )(1 − ε )(1+ ε ) v ( O PT ) . Here, O PT T is the optimal solution attainable by packing itemtypes T instead of items in J ′ and using J \ J ′ without any changes. lgorithm In the following, we use the notation X ′ for a set X to refer to X ∩ J ′ while X ′′ refers to X \ J ′ .Recall that, upon arrival, item values of items in J are rounded to natural powers of (1 + ε ) to create thevalue classes V ℓ where each item j ∈ V ℓ is of value (1 + ε ) ℓ .1) Let ℓ max be the guess for the highest value class with V ′ ℓ ∩ O PT = ∅ and let ¯ ℓ := ℓ max − l log( n ′ /ε )log(1+ ε ) m .2) For each value class ¯ ℓ ≤ ℓ ≤ ℓ max and each guess n ℓ = (1 + ε ) l for ≤ l ≤ log ε n ′ dothe following: Consider the n ℓ elements of V ′ ℓ with the smallest size and determine the ε many(almost) equal-sized groups G ( n ℓ ) , . . . , G /ε ( n ℓ ) of ⌈ εn ℓ ⌉ or ⌊ εn ℓ ⌋ elements. If εn ℓ / ∈ N , ensurethat | G k ( n ℓ ) | ≤ | G k ′ ( n ℓ ) | ≤ | G k ( n ℓ ) | + 1 for k ≤ k ′ . If ε is not a natural power of (1 + ε ) , we alsocreate the groups G ( ε ) , . . . , G /ε ( ε ) where G k ( ε ) contains the k th smallest item in V ′ ℓ .Let G ( n ℓ ) , . . . , G /ε ( n ℓ ) be the corresponding groups sorted increasingly by the size of the items.Let j k ( n ℓ ) = max { j ∈ G k ( n ℓ ) } be the last index belonging to group G k ( n ℓ ) . After having deter-mined j k ( n ℓ ) for each possible value n ℓ (including ε ) and for each ≤ k ≤ ε , the size of each item j is rounded up to the size of the next large item j ′ where j ′ = j k ( n ℓ ) for some combination of k and n ℓ .3) Discard each item j with j ∈ V ′ ℓ for ℓ < ¯ ℓ . Analysis
Despite the new approach to apply linear grouping simultaneously to many possible values of n ℓ ,the analysis uses standard techniques. Thus, we only give a high-level overview of the proof here and referthe reader to Appendix C for the technical details. We start by observing that the loss in the objective functiondue to rounding item values to natural powers of (1 + ε ) is bounded by a factor of ε by Lemma 3.1. As ¯ ℓ is chosen such that n ′ items of value at most (1 + ε ) ¯ ℓ contribute less than an ε -fraction of O PT ′ , the loss inthe objective function by discarding items in value classes V ′ ℓ with ℓ < ¯ ℓ is bounded by a factor (1 − ε ) . Bytaking only (1 + ε ) ⌊ log ε n ℓ ⌋ items of V ′ ℓ instead of n ℓ , we lose at most a factor of ε . Observing that thegroups created by dynamic linear grouping are an actual refinement of the groups created by the classicallinear grouping for a fixed number of items, we pack our items as done in linear grouping: Not packingthe group with the largest items allows us to “shift” all rounded items of group G k ( n ℓ ) to the positions ofthe (not rounded) items in group G k +1 ( n ℓ ) at the expense of losing a factor of (1 − ε ) . Combining theseresults then shows the following lemma. Lemma 5.2.
Let O PT and O PT T be as defined above. Then, v ( O PT T ) ≥ (1 − ε )(1 − ε )(1+ ε ) v ( O PT ) . As T contains at most ε (cid:0)(cid:6) log n ′ /ε log(1+ ε ) (cid:7) + 1 (cid:1) many different value classes and using (cid:6) log n ′ log(1+ ε ) (cid:7) + 1 manydifferent values for n ℓ = | O PT ∩ V ′ ℓ | suffices as explained above, the next lemma follows. Lemma 5.3.
The algorithm reduces the number of item types to O ( log n ′ ε ) . The crucial ingredient for the refined dynamic linear grouping are the carefully calculated indices thatindicate the largest item in a group for a value n ℓ . These indices can be computed exactly once, dependingon the current value n ′ . Combining this observation with the bound in Lemma 5.3 and the access timesgiven in Lemma 3.2 is the main part of the proof of the next lemma. Lemma 5.4.
For a given guess ℓ max , the set T ( ℓ max ) can be determined in time O ( log n ′ ε ) .Proof of Theorem 5.1. Lemmas 3.1 and 5.2 bound the approximation ratio, Lemma 5.3 bounds the numberof item types, and Lemma 5.4 bounds the running time of the dynamic linear grouping approach.9 .2 A Dynamic Algorithm for Many Identical Knapsacks
In this section, we give a dynamic algorithm that achieves an approximation guarantee of (1 − ε ) for M UL - TIPLE K NAPSACK with identical knapsack sizes. The running time of the update operation is always poly-nomial in log n and ε . In this section, we assume m < n as otherwise assigning the items in some con-sistent order to the knapsacks is optimal. We focus on instances where m is large, i.e., m ≥ ε log n .For m ≤ ε log n , we use the algorithm for few knapsacks presented in Appendix B. Theorem 5.5.
Let U = max { Sm, nv max } . If m ≥ ε log n , there is a dynamic algorithm for the M UL - TIPLE K NAPSACK problem with m identical knapsacks with approximation factor (1 − ε ) and updatetime (cid:0) log Uε (cid:1) O (1) . Queries for single items and the solution value can be answered in time O (cid:0) log nε (cid:1) O (1) and O (1) , respectively. The whole solution P can be returned in time | P | (cid:0) log nε (cid:1) O (1) . Definitions and Data Structures
We partition the items into two sets, J B , the big items, and J S , the small items, with sizes s j ≥ εS and s j < εS , respectively. For an optimal solution O PT , define O PT B := O PT ∩ J B and O PT S := O PT ∩ J S .For this algorithm, we maintain three types of data structures: we store all items in one balanced binarytree in order of their arrivals, i.e., their indices. In this tree, we store the size s j and the value v j of eachitem j and additonally store the value class ℓ j for big items. Big items are also stored in one balanced binarytree per value class V ℓ sorted by non-decreasing size while all small items are sorted by non-decreasingdensity and stored in one tree. Overall, we have at most ε v max many data structures to maintain.Upon arrival of a new item, we insert it into the tree of all items and classify this item as big or smallaccording to s j ≥ εS i or s j < εS i . If the item is small, we insert it into the tree of small items. Otherwise,we determine its value class ℓ = ⌊ log ε v j ⌋ and insert it into the corresponding tree. Algorithm Linear grouping of big items:
Guess ℓ max , the index of the highest value class that belongs to O PT B and use dynamic linear grouping with J ′ = J B and n ′ = min { mε , n B } to obtain T , the set of itemtypes t with their multiplicities n t .2) Configurations:
Create all possible configurations of at most ε big items and store these configura-tions in C . For c ∈ C let v c and s c denote the total value respectively size of the items in c .3) Guessing the size of small items:
First guess v S as estimate of v ( O PT S ) . Let P be the maximalprefix of small items (sorted by decreasing density) with v ( P ) < v S . Define s S := s ( P ) .4) Configuration ILP:
Solve the following configuration ILP with variables y c for c ∈ C for the currentguesses ℓ max and s S . Here, y c counts how often a certain configuration c is used and n tc denotes thenumber of items of type t in configuration c . max X c ∈C y c v c subject to X c ∈C y c s c ≤ (1 − ε ) Sm − s S X c ∈C y c ≤ (1 − ε ) m X c ∈C y c n tc ≤ n t for all t ∈ T y c ∈ Z ≥ for all c ∈ C (P)10he first inequality ensures that the configurations chosen by the ILP fit into (1 − ε ) m knapsackswhile reserving sufficient space for the small items. The second constraint limits the total number ofconfigurations that are packed. The third inequality ensures that only available items are used.5) Obtaining an integral solution: As m is large, we cannot solve the ILP optimally but need to relaxthe integrality constraint and allow fractional solutions. Given such a fractional solution, we round thisfractional solution into an integral packing P B using at most εm additional knapsacks while ensuringthat v ( P B ) ≥ v LP , where v LP is the optimal solution value for the LP relaxation.6) Packing small items:
Consider the maximal prefix P of small items with v ( P ) < v S and let j be thedensest small item not in P . Pack j into one of the knapsacks kept empty by P B . Then, fractionallyfill up the (1 − ε ) m knapsacks used by P B and place any “cut” item into the εm additional knapsacksthat are still empty. We can guarantee that this packing is feasible. Analysis
The first step is to analyze the loss in the objective function value due to the linear grouping. Tothis end, set J ′ = J B and n ′ = min { mε , n } . Moreover, let O PT T be the optimal packing when using thecorresponding item types T obtained from applying dynamic linear rounding instead of the items in J B .Then, the next corollary immediately follows from Theorem 5.1. Corollary 5.6.
Let O PT and O PT T be defined as above. Then, v ( O PT T ) ≥ (1 − ε )(1 − ε )(1+ ε ) v ( O PT ) . In the next lemma, we show that there is a guess v S with the corresponding size s S such that v ∗ ILP + v S + v j for the optimal solution value v ∗ ILP of (P) is a good guess for the optimal solution v ( O PT T ) . Here, j is thedensest small item not contained in P while P is the maximal prefix of small items with v ( P ) < v S . Thehigh-level idea of the proof is to restrict an optimal solution O PT T to the (1 − ε ) m most valuable knapsacksand show that s S underestimates the size of small items in these (1 − ε ) m knapsacks. Transforming theseknapsacks into configurations then comprises a feasible solution for the configuration ILP. See Appendix D. Lemma 5.7.
Let v ∗ ILP and O PT T be defined as above. There are v S and s S with v ∗ ILP + v S ≥ − ε ε v ( O PT T ) . Moreover, for P and j as defined above, v ( P ) + v j ≥ v S . Next, we explain how to approximately solve the LP relaxation of the configuration ILP (P) and roundthe solution to an integral packing in slightly more knapsacks. As any basic feasible solution of (P) has atmost O (cid:0) |T | (cid:1) strictly positive variables, solving its dual problem with the Gr¨otschel-Lovasz-Schrijver [28]variant of the Ellipsoid method determines the relevant variables.The separation problem is a K NAPSACK problem, which we only solve approximately in time poly-nomial in log n and ε . This approximate separation oracle correctly detects infeasibility while a solutionthat is declared feasible may only be feasible for a closely related problem causing a multiplicative loss inthe objective function value of at most (1 − ε ) . We cannot use the approaches by Plotkin, Shmoys, andTardos [67] and Karmarkar and Karp [48] directly as our configuration ILP contains two extra constraintswhich correspond to additional variables in the dual and, thus, to two extra terms in the objective function.Instead, we add an objective function constraint to the dual and test for feasibility for a set of geometricallyincreasing guesses of the objective function value. Given the maximal guess for which the dual is infeasible,we use the variables corresponding to constraints added by the Ellipsoid method to solve the primal. Themultiplicative gap between the maximal infeasible and the minimal feasible such guess allows us to obtaina fractional solution with objective function value at least − ε ε . See Appendix D for the technical details. Lemma 5.8.
Let U = max { Sm, nv max } . Then, there is an algorithm that finds a feasible solution for theLP relaxation of (P) with value at least − ε ε v LP with running time bounded by (cid:16) log Uε (cid:17) O (1) . O ( |T | ) non-vanishing variables, the assumptions ε log n ≤ m and m < n imply ε log m ≤ m which inturn guarantees O ( |T | ) ≤ εm . Hence, the rounded solution uses at most (1 − ε ) m knapsacks and achievesa value of at least v LP ; see Appendix C.1. Lemma 5.9. If ε log n ≤ m , any feasible solution of the LP relaxation of (P) can be rounded to anintegral solution using at most (1 − ε ) m knapsacks with total value at least v LP . Next, we bound the value achieved by our algorithm in terms of the optimal solution.
Lemma 5.10.
Let P F be the solution returned by our algorithm and let O PT be a current optimal solution.It holds that v ( P F ) ≥ (1 − ε ) (1 − ε )(1 − ε )(1+ ε ) v ( O PT ) .Proof. The solution found by our algorithm achieves the maximal value over all combinations of v S , guessesof the value contributed by small items, and ℓ max , the highest value class of a big item. Thus, it sufficesto find a combination of v S and ℓ max such that P , the corresponding packing, is feasible and satisfies v ( P ) ≥ (1 − ε )(1 − ε )(1 − ε )(1+ ε ) v ( O PT ) .Let O PT B be the set of big items in O PT and let ℓ max := max { ℓ : V ℓ ∩ O PT B = ∅} . For this guess ℓ max ,let P S ∪ { j } be the set of small items of Lemma 5.7 such that v ∗ ILP + v ( P S ) + v j ≥ − ε ε v ( O PT T ) . ByLemma 5.9, there is a set of big items P B with a feasible packing into (1 − ε ) m knapsacks with total valueat least − ε ε v ILP . Packing j on its own and P S in a F IRST F IT manner, we extend this to a feasible packingof P B ∪ P S ∪ { j } into (1 + ε )(1 − ε ) m + 1 ≤ m knapsacks; see Lemma C.5. With Lemma 5.7, v ( P F ) ≥ v ( P ) ≥ − ε ε v ILP + v S + v j ≥ (1 − ε )(1 − ε )(1 + ε ) v ( O PT T ) , where O PT T is the most valuable packing after linear grouping. With Corollary 5.6 we get v ( P F ) ≥ (1 − ε ) (1 − ε )(1 − ε )(1 + ε ) v ( O PT ) . (1)The next lemma bounds the running time of our algorithm. The proof follows from the fact that the algo-rithm considers at most O (cid:16) log( nv max ) log v max ε (cid:17) many rounds, the running time for dynamic linear groupingbounded in Lemma 5.4, and the running time for solving the configuration ILP as described in Lemma 5.8. Lemma 5.11.
Let U := max { Sm, nv max } . The running time of our algorithm is bounded by (cid:16) log Uε (cid:17) O (1) . Queries
We show how to efficiently answer different queries and give their runtime. In contrast to theprevious section, for transforming an implicit solution into an explicit packing it does not suffice to knowwhether an item is packed or not but the query operation has to compute the knapsack where item j is packed.Since we do not explicitly store the packing of any item, we define and update pointers for small items andfor each item type that dictate the knapsacks where the corresponding items are packed. Therefore, to stayconsistent for the precise packing of a particular item between two update operations, we additionally cachequery answers for the current round in the data structure that store items.12 Single Item Query:
If the queried item is small, we check if it belongs to the prefix of densest itemsthat is part of our solution. In this case, the pointer for small items determines the knapsack. If thequeried item is big, we retrieve its item type and check if it belongs to smallest items of this type thatare packed by the implicit solution. In this case, the pointer for this item type dictates the knapsack. • Solution Value Query:
As the algorithm works with rounded values, after having found the currentsolution, we use prefix computation on the small items and on any value class of big items, to calculateand store the actual solution value. On query, we return the stored solution value. • Query Entire Solution:
We use prefix computation on the small items as well as on the value classesof the big items to determine the packed items. Then, we use the Single Item Query to determine theirrespective knapsacks.For a detailed analysis of the queries and the proof of the following lemma, see Appendix D.
Lemma 5.12.
The solution determined by the query algorithms is feasible and achieves the claimed totalvalue. The query times of our algorithm are as follows.(i) Single item queries can be answered in time O (cid:0) max (cid:8) log log nε , ε (cid:9)(cid:1) (ii) Solution value queries can be answered in time O (1) (iii) Queries of the entire solution P are answered in time O (cid:0) | P | max (cid:8) log log nε , ε (cid:9)(cid:1) .Proof of Theorem 5.5. In Lemma 5.10, we calculate the approximation ratio achieved by our algorithm. Forcalculating the update time and the time needed for answering queries, observe that |C ′ | depends on m .Then, Lemma 5.11 gives the desired bounds on the update time while Lemma 5.12 bounds the time neededfor answering a query. Lemma 5.12 also guarantees that the query answers are correct. ULTIPLE K NAPSACK
Having laid the groundwork with the previous two sections, we finally show how to maintain solutions forarbitrary instances of the M
ULTIPLE K NAPSACK problem, and give the main result of this paper. A detailedproof can be found in Appendix F.
Theorem 6.1.
For ε > , there exists a dynamic algorithm for M ULTIPLE K NAPSACK that maintainsan (1 − ε ) -approximate solution in update time (cid:0) ε log( nv max ) (cid:1) f (1 /ε ) + O ( ε log v log n ) , with f quasi-linear.Item queries are served in time O ( log nε ) and the whole solution P can be output in time O ( log nε | P | ) . As mentioned in Section 2, we obtain this result by partitioning the knapsacks into three sets, special,extra and ordinary knapsacks, and solving the respective subproblems. This has similarities to the approachin [43]; however, there it was sufficient to have only two groups of knapsacks. In Appendices B and Ewe show the following two theorems. They solve the special and ordinary subproblems by applying thealgorithmic techniques developed in Sections 4 and 5 respectively.
Theorem 6.2.
For ε > , there is a dynamic algorithm for M ULTIPLE K NAPSACK with m knapsacks thatachieves an approximation factor of (1 − ε ) with update time f (1 /ε ) ( mε log( nv max )) O (1) + O ( ε log v log n ) ,with f quasi-linear. Moreover, item queries are answered in time O (log m ε ) , solution value queries intime O (1) and queries of a single knapsack or the entire solution in time linear in the size of the output. Theorem 6.3.
There is a dynamic algorithm for M ULTIPLE K NAPSACK that, when given L = ( log nε ) O (1 /ε ) additional knapsacks as resource augmentation, achieves an approximation factor (1 − ε ) with updatetime (log n ) O (1 /ε ) (log S max log v max ) O (1) where S max := max { S i : i ∈ [ m ] } . Item queries are answeredin time O (cid:0) log nε (cid:1) and a solution P can be output in time O (cid:0) | P | log nε (cid:1) . efinitions and Data Structures. We assume that m > ( ε ) /ε · L . Otherwise, we apply Theorem 6.3.Consider ε groups of knapsacks with sizes Lε i for i ∈ { , , . . . , ε − } such that the first group ( i = 0 )consists of the L largest knapsacks, the second ( i = 1 ) of the Lε next largest, and so on. In O PT , one ofthese groups contains items with total value at most ε · O PT . Let k ∈ { , , . . . , ε − } be the index of sucha group and let L S := P k − i =0 Lε i . Based on k and L S , we partition the knapsacks into three groups thatincrease in knapsack capacity but decrease in cardinality. We refer to them as special , extra and ordinary knapsacks, with the special knapsacks being the L S largest ones. The extra knapsacks are the Lε k > L S ε + L next largest, and the ordinary knapsacks the remaining ones.Call an item ordinary if it fits into the largest ordinary knapsack and special otherwise. Denote by J O and J S the set of ordinary and special items respectively and by S O the total size, rounded down to a powerof (1 + ε ) , of ordinary items that O PT places in special knapsacks.Since we use the algorithms from Appendices B and E as subroutines, we require the maintenance ofthe corresponding data structures. This causes the additive term O ( ε log v log n ) in the update time. Algorithm. Dynamic linear grouping:
Compute O ( log nε ) item types as in Section 5.1 (using J ′ = J and n ′ = n ). Guess k and determine whether items of a certain type are ordinary or special.2) High-value ordinary items:
Place each of the L S ε most valuable ordinary items in an empty extraknapsack. On a tie choose the larger item. Denote the set of such items by J E .3) Virtual ordinary knapsack:
Guess S O and add a virtual knapsack with capacity S O to the ordinarysubproblem. In the LP (P) of Appendix E, that is used to solve the ordinary subproblem, only considervariables z g,t for this knapsack but no configurations.4) Solve ordinary instance:
Remove until the next update, from data structures used in the ordinarysubproblem, the set J E of items placed in extra knapsacks in Step 2). Solve the subproblem with thevirtual knapsack as in Appendix E and use extra knapsacks for resource augmentation. When roundingup variables, fill the O ( log nε ) rounded items from the virtual knapsack into extra knapsacks.5) Create bundles
Consider the items that remain on the virtual ordinary knapsack after rounding. Sortthem by type (e.g., first value, then size) and cut them fractionally to form L S ε bundles of equal size.Denote by B O this set of bundles and, for each bundle, remember how many items of each type areplaced entirely inside it. Place fractionally cut items into extra knapsacks. Consider each B ∈ B O asan item of size and value equal to the fractional size respectively value of items placed entirely in B .6) Solve special instance:
Temporarily insert the bundles in B O into the data structures used in thespecial subproblem. Solve this subproblem as detailed in Appendix B.7) Implicit solution:
Among all guesses, keep the solution P F with the highest value. Store items in J E and their placement explicitly. Revert the removal of J E from the ordinary data structures only duringthe next update. For the remaining items, the solutions are given as in the respective subproblem,see Appendices B and E with the exception of items packed in the virtual ordinary knapsack. Thesolution on these items is stored implicitly by deciding membership in a bundle on a query. Queries
For handling queries, we essentially use the same approach as in Appendices B and E for theordinary and special subproblem respectively. However, special care has to be taken with items in thevirtual knapsack. In the ordinary subproblem, we assume that items of a certain type which are packed inthe virtual knapsack are the first, i.e., smallest, of that type. We can therefore decide in constant time whetheror not an item is contained in the virtual knapsack and, if this is the case, fill it into the free space in special14napsacks reserved by bundles. We do this efficiently by using a first fit algorithm on the knapsacks withreserved space. Since items on extra knapsacks are stored explicitly, they can be accessed in constant time.Note that the number of special knapsacks is in ( log nε ) O (1 /ε ) , so the function g in Appendix B is in O (cid:0) ε (cid:1) . Lemma 6.4.
The query times of our algorithm are as follows.(i) Single item queries are answered in time O ( log nε ) .(ii) Solution value queries are answered in time O (1) .(iii) Queries of the entire solution P are answered in time O ( log nε | P | ) . We have presented a robust dynamic framework for K
NAPSACK and M
ULTIPLE K NAPSACK with itemand knapsack arrivals and departures and queries on solution size and item presence in the solution. Byhaving n items arrive one by one, any dynamic algorithm can be turned into a non-dynamic framework withincurring an additional linear term in the running time. Hence, the performance of any dynamic frameworkis subject to the same lower bounds as non-dynamic approximation schemes. Our results on K NAPSACK and M
ULTIPLE K NAPSACK with identical capacities are tight in the sense that their runtime is a form ofFPTAS (resp. EPTAS), matching the known results for the approximation algorithms.Clearly, further generalizing the results beyond M
ULTIPLE K NAPSACK remains an interesting openquestion. A straightforward generalization is d -dimensional K NAPSACK where each item comes with d dif-ferent sizes corresponding to d dimensions, each knapsack has d different capacities, and a feasible packingof a subset of items must meet the capacity constraint in each dimension. Using the reduction to the -dimensional setting developed by [22], allows us to generalize our results for K NAPSACK and M
ULTIPLE K NAPSACK with identical knapsacks to the d -dimensional setting at the loss of a factor d in the approxima-tion guarantee. A result by [55] shows that, unless W [1] = FPT, 2-dimensional knapsack does not admit adynamic algorithm maintaining a (1 − ε ) -approximation in worst-case update time f (cid:0) ε (cid:1) n O (1) . Designinga dynamic framework with a better guarantee than d remains open.We hope to foster further research within the dynamic algorithm framework for other packing, schedul-ing and, generally, non-graph problems. For bin packing and for scheduling to minimize the makespan onuniformly related machines, we notice that existing PTAS techniques from [48] and [36, 44] combined withrather straightforward data structures can be lifted to a fully dynamic framework for the respective problems.15 eferences [1] A. Abboud, R. Addanki, F. Grandoni, D. Panigrahi, and B. Saha. Dynamic set cover: improved algorithms andlower bounds. In STOC , pages 114–125. ACM, 2019.[2] A. Abboud and V. V. Williams. Popular conjectures imply strong lower bounds for dynamic problems. In
FOCS ,pages 434–443. IEEE Computer Society, 2014.[3] S. Albers, A. Khan, and L. Ladewig. Improved online algorithms for knapsack and GAP in the random ordermodel. In
APPROX-RANDOM , volume 145 of
LIPIcs , pages 22:1–22:23. Schloss Dagstuhl - Leibniz-Zentrumf¨ur Informatik, 2019.[4] M. Babaioff, N. Immorlica, D. Kempe, and R. Kleinberg. A knapsack secretary problem with applications. In
APPROX-RANDOM , volume 4627 of
Lecture Notes in Computer Science , pages 16–28. Springer, 2007.[5] R. Bellman.
Dynamic Programming . Princeton University Press, Princeton, NJ, USA, 1957.[6] A. Beloglazov and R. Buyya. Energy efficient allocation of virtual machines in cloud data centers. In
CCGRID ,pages 577–578. IEEE Computer Society, 2010.[7] D. Bertsimas and J. N. Tsitsiklis.
Introduction to linear organisation , volume 6 of
Athena scientific optimizationand computation series . Athena Scientific, 1997.[8] A. Bhalgat, A. Goel, and S. Khanna. Improved approximation results for stochastic knapsack problems. In
SODA , pages 1647–1665. SIAM, 2011.[9] S. Bhattacharya, M. Henzinger, and G. F. Italiano. Design of dynamic algorithms via primal-dual method. In
ICALP (1) , volume 9134 of
Lecture Notes in Computer Science , pages 206–218. Springer, 2015.[10] S. Bhattacharya, M. Henzinger, and D. Nanongkai. Fully dynamic approximate maximum matching and mini-mum vertex cover in O (log3 n ) worst case update time. In SODA , pages 470–489. SIAM, 2017.[11] S. Bhattacharya, M. Henzinger, and D. Nanongkai. A new deterministic algorithm for dynamic set cover. In
FOCS , pages 406–423. IEEE Computer Society, 2019.[12] S. Bhattacharya and J. Kulkarni. Deterministically maintaining a (2 + ε )-approximate minimum vertex cover ino(1/ ε ) amortized update time. In SODA , pages 1872–1885. SIAM, 2019.[13] N. Bobroff, A. Kochut, and K. A. Beaty. Dynamic placement of virtual machines for managing SLA violations.In
Integrated Network Management , pages 119–128. IEEE, 2007.[14] H. B¨ockenhauer, D. Komm, R. Kr´alovic, and P. Rossmanith. The online knapsack problem: Advice and ran-domization.
Theor. Comput. Sci. , 527:61–72, 2014.[15] N. Boria and V. T. Paschos. A survey on combinatorial optimization in dynamic environments.
RAIRO - Opera-tions Research , 45(3):241–294, 2011.[16] C. B¨using, A. M. C. A. Koster, and M. Kutschka. Recoverable robust knapsacks: the discrete scenario case.
Optim. Lett. , 5(3):379–392, 2011.[17] T. M. Chan. Approximation schemes for 0-1 knapsack. In
SOSA@SODA , volume 61 of
OASICS , pages 5:1–5:12.Schloss Dagstuhl - Leibniz-Zentrum f¨ur Informatik, 2018.[18] C. Chekuri and S. Khanna. A polynomial time approximation scheme for the multiple knapsack problem.
SIAMJ. Comput. , 35(3):713–728, 2005.[19] M. Cygan, Ł. Je˙z, and J. Sgall. Online knapsack revisited.
Theory Comput. Syst. , 58(1):153–190, 2016.[20] M. Cygan, M. Mucha, K. Wegrzycki, and M. Wlodarczyk. On problems equivalent to (min, +)-convolution.
ACM Trans. Algorithms , 15(1):14:1–14:25, 2019.[21] K. Daudjee, S. Kamali, and A. L´opez-Ortiz. On the online fault-tolerant server consolidation problem. In
SPAA ,pages 12–21. ACM, 2014.
22] W. F. de la Vega and G. S. Lueker. Bin packing can be solved within 1+epsilon in linear time.
Combinatorica ,1(4):349–355, 1981.[23] B. C. Dean, M. X. Goemans, and J. Vondr´ak. Approximating the stochastic knapsack problem: The benefit ofadaptivity.
Math. Oper. Res. , 33(4):945–964, 2008.[24] C. Demetrescu, D. Eppstein, Z. Galil, and G. F. Italiano.
Dynamic Graph Algorithms , page 9. Chapman &Hall/CRC, 2 edition, 2010.[25] Y. Disser, M. Klimm, N. Megow, and S. Stiller. Packing a knapsack of unknown capacity.
SIAM J. Discret.Math. , 31(3):1477–1497, 2017.[26] G. Gens and E. Levner. Computational complexity of approximation algorithms for combinatorial problems. In
MFCS , volume 74 of
Lecture Notes in Computer Science , pages 292–300. Springer, 1979.[27] G. Gens and E. Levner. Fast approximation algorithms for knapsack type problems. In
Optimization Techniques ,pages 185–194. Springer, 1980.[28] M. Gr¨otschel, L. Lov´asz, and A. Schrijver. The ellipsoid method and its consequences in combinatorial opti-mization.
Combinatorica , 1(2):169–197, 1981.[29] A. Gu, A. Gupta, and A. Kumar. The power of deferral: Maintaining a constant-competitive steiner tree online.
SIAM J. Comput. , 45(1):1–28, 2016.[30] A. Gupta, R. Krishnaswamy, A. Kumar, and D. Panigrahi. Online and dynamic algorithms for set cover. In
STOC , pages 537–550. ACM, 2017.[31] X. Han, Y. Kawase, and K. Makino. Randomized algorithms for removable online knapsack problems. In
FAW-AAIM , volume 7924 of
Lecture Notes in Computer Science , pages 60–71. Springer, 2013.[32] X. Han, Y. Kawase, K. Makino, and H. Guo. Online removable knapsack problem under convex function.
Theor.Comput. Sci. , 540:62–69, 2014.[33] X. Han and K. Makino. Online removable knapsack with limited cuts.
Theor. Comput. Sci. , 411(44-46):3956–3964, 2010.[34] M. Henzinger. The state of the art in dynamic graph algorithms. In
SOFSEM , volume 10706 of
Lecture Notes inComputer Science , pages 40–44. Springer, 2018.[35] M. R. Henzinger and V. King. Randomized fully dynamic graph algorithms with polylogarithmic time peroperation.
J. ACM , 46(4):502–516, 1999.[36] D. S. Hochbaum and D. B. Shmoys. Using dual approximation algorithms for scheduling problems theoreticaland practical results.
J. ACM , 34(1):144–162, 1987.[37] J. Holm, K. de Lichtenberg, and M. Thorup. Poly-logarithmic deterministic fully-dynamic algorithms for con-nectivity, minimum spanning tree, 2-edge, and biconnectivity.
J. ACM , 48(4):723–760, 2001.[38] O. H. Ibarra and C. E. Kim. Fast approximation algorithms for the knapsack and sum of subset problems.
J.ACM , 22(4):463–468, 1975.[39] M. Imase and B. M. Waxman. Dynamic steiner tree problem.
SIAM J. Discret. Math. , 4(3):369–384, 1991.[40] Z. Ivkovic and E. L. Lloyd. Fully dynamic algorithms for bin packing: Being (mostly) myopic helps.
SIAM J.Comput. , 28(2):574–611, 1998.[41] K. Iwama and S. Taketomi. Removable online knapsack problems. In
ICALP , volume 2380 of
Lecture Notes inComputer Science , pages 293–305. Springer, 2002.[42] K. Iwama and G. Zhang. Online knapsack with resource augmentation.
Inf. Process. Lett. , 110(22):1016–1020,2010.[43] K. Jansen. Parameterized approximation scheme for the multiple knapsack problem.
SIAM J. Comput. ,39(4):1392–1412, 2009.
44] K. Jansen. An EPTAS for scheduling jobs on uniform processors: Using an MILP relaxation with a constantnumber of integral variables.
SIAM J. Discrete Math. , 24(2):457–485, 2010.[45] K. Jansen. A fast approximation scheme for the multiple knapsack problem. In
SOFSEM , volume 7147 of
Lecture Notes in Computer Science , pages 313–324. Springer, 2012.[46] K. Jansen and K. Klein. A robust AFPTAS for online bin packing with polynomial migration.
SIAM J. Discret.Math. , 33(4):2062–2091, 2019.[47] C. Jin. An improved FPTAS for 0-1 knapsack. In
ICALP , volume 132 of
LIPIcs , pages 76:1–76:14. SchlossDagstuhl - Leibniz-Zentrum f¨ur Informatik, 2019.[48] N. Karmarkar and R. M. Karp. An efficient approximation scheme for the one-dimensional bin-packing problem.In
FOCS , pages 312–320. IEEE Computer Society, 1982.[49] R. M. Karp. Reducibility among combinatorial problems. In
Complexity of Computer Computations , The IBMResearch Symposia Series, pages 85–103. Plenum Press, New York, 1972.[50] H. Kellerer. A polynomial time approximation scheme for the multiple knapsack problem. In
RANDOM-APPROX , volume 1671 of
Lecture Notes in Computer Science , pages 51–62. Springer, 1999.[51] H. Kellerer and U. Pferschy. Improved dynamic programming in connection with an FPTAS for the knapsackproblem.
J. Comb. Optim. , 8(1):5–11, 2004.[52] H. Kellerer, U. Pferschy, and D. Pisinger.
Knapsack problems . Springer, 2004.[53] A. J. Kleywegt and J. D. Papastavrou. The dynamic and stochastic knapsack problem.
Oper. Res. , 46(1):17–35,1998.[54] A. J. Kleywegt and J. D. Papastavrou. The dynamic and stochastic knapsack problem with random sized items.
Oper. Res. , 49(1):26–41, 2001.[55] A. Kulik and H. Shachnai. There is no EPTAS for two-dimensional knapsack.
Inf. Process. Lett. , 110(16):707–710, 2010.[56] M. K¨unnemann, R. Paturi, and S. Schneider. On the fine-grained complexity of one-dimensional dynamic pro-gramming. In
ICALP , volume 80 of
LIPIcs , pages 21:1–21:15. Schloss Dagstuhl - Leibniz-Zentrum f¨ur Infor-matik, 2017.[57] E. L. Lawler. Fast approximation algorithms for knapsack problems.
Math. Oper. Res. , 4(4):339–356, 1979.[58] Y. Li, X. Tang, and W. Cai. On dynamic bin packing for resource allocation in the cloud. In
SPAA , pages 2–11.ACM, 2014.[59] W. Ma. Improvements and generalizations of stochastic knapsack and markovian bandits approximation algo-rithms.
Math. Oper. Res. , 43(3):789–812, 2018.[60] A. Marchetti-Spaccamela and C. Vercellis. Stochastic on-line knapsack problems.
Math. Program. , 68:73–104,1995.[61] S. Martello and P. Toth. Lower bounds and reduction procedures for the bin packing problem.
Discret. Appl.Math. , 28(1):59–70, 1990.[62] N. Megow and J. Mestre. Instance-sensitive robustness guarantees for sequencing with unknown packing andcovering constraints. In
ITCS , pages 495–504. ACM, 2013.[63] N. Megow, M. Skutella, J. Verschae, and A. Wiese. The power of recourse for online MST and TSP.
SIAM J.Comput. , 45(3):859–880, 2016.[64] M. Mucha, K. Wegrzycki, and M. Wlodarczyk. A subquadratic approximation scheme for partition. In
SODA ,pages 70–88. SIAM, 2019.[65] J. Noga and V. Sarbua. An online partially fractional knapsack problem. In
ISPAN , pages 108–112. IEEEComputer Society, 2005.
66] H. J. Olivi´e. A new class of balanced search trees: Half balanced binary search trees.
RAIRO Theor. InformaticsAppl. , 16(1):51–71, 1982.[67] S. A. Plotkin, D. B. Shmoys, and ´E. Tardos. Fast approximation algorithms for fractional packing and coveringproblems.
Math. Oper. Res. , 20(2):257–301, 1995.[68] D. Rhee. Faster fully polynomial approximation schemes for knapsack problems. Master’s thesis, MassachusettsInstitute of Technology, 2015.[69] T. Rothvoß. The entropy rounding method in approximation algorithms. In
SODA , pages 356–372. SIAM, 2012.[70] P. Sanders, N. Sivadasan, and M. Skutella. Online scheduling with bounded migration.
Math. Oper. Res. ,34(2):481–498, 2009.[71] M. Skutella and J. Verschae. Robust polynomial-time approximation schemes for parallel machine schedulingwith job arrivals and departures.
Math. Oper. Res. , 41(3):991–1021, 2016.[72] R. V. Slyke and Y. Young. Finite horizon stochastic knapsacks with applications to yield management.
Oper.Res. , 48(1):155–172, 2000.[73] R. E. Tarjan. Updating a balanced search tree in O(1) rotations.
Inf. Process. Lett. , 16(5):253–257, 1983.[74] G. Yu. On the max-min 0-1 knapsack problem with robust optimization applications.
Oper. Res. , 44(2):407–415,1996. ppendicesA Proofs for Single Knapsack In this section we give the detailed analysis of our algorithm for K
NAPSACK in Section 4. We consider theiteration in which the guesses V ℓ max , V ℓ min , n min and V L are correct and show that the obtained solution hasa value of at least (1 − ε ) · v ( O PT ) .Let P be the set of solutions respecting: (i) packed items not in H ε have a value of at most V ℓ min butare not part of the n min smallest items of the value class V ℓ min , and (ii) the total value of these items liesin [ V L , (1 + ε ) V L ] . Denote by O PT the solution of highest value in P . Lemma A.1.
Consider O PT defined as above. Then, v ( O PT ) ≥ (1 − ε ) · v ( O PT ) .Proof. Let O PT ∗ be the packing obtained from O PT by removing all items belonging to O PT ε whose valueis strictly smaller than ε V ℓ max . Since O PT ε consists of ε many items, the total value of removed items isat most ε · ε V ℓ max ≤ ε · O PT . We show that O PT ∗ ∈ P .Consider an item j in O PT ε of value v j ≥ ε V ℓ max . If v j = V ℓ min , then j ∈ H ε by definition of n min and O PT ε , specifically, due to the tie-breaking rules. Assume now that v j > V ℓ min and j / ∈ H ε . Recallthat H ε contains the ε smallest items of value v j , and | O PT ε | = ε . Thus, there exists an item of value v j ,smaller than j , which belongs to H ε but not to O PT ε . Exchanging j for this item contradicts the definitionof O PT . Therefore, j ∈ H ε and Condition (i) is satisfied. Condition (ii) follows directly from the definitionof V L , and therefore O PT ∗ ∈ P , concluding the proof. Lemma A.2.
Let O PT be the optimal solution of the instance I on which the FPTAS is run at Step 3).Then, v ( O PT ) ≥ (1 − ε ) · v ( O PT ) .Proof. Consider the fractional solution O PT ∗ for I that is obtained from O PT as follows. Place itemsfrom H ε as in O PT and additionally place the placeholder item B . Denote by J L the set of items packedby O PT that are not in H ε , i.e., the low-value items. By definition of B , we have v B = V L ≥ (1 − ε ) v ( J L ) . Further, since B consists of the densest low-value items, it must be the case, that s B ≤ s ( J L ) .Therefore, O PT ∗ is a feasible solution for I and the statement follows. Lemma A.3.
For the solution P F of the algorithm, we have v ( P F ) ≥ (1 − ε ) · v ( O PT ) .Proof. The solution P FPTAS returned by the FPTAS in Step 3) has a value of at least (1 − ε ) · v ( O PT ) . Thesolution P F is obtained from P FPTAS by replacing the placeholder with the corresponding low-value items,except possibly the fractional item j . Since there are ε items in O PT that are of higher value than j , namelythe ones in O PT ε , this implies v ( P F ) ≥ v ( P FPTAS ) − ε · v ( O PT ) . Using Lemmas A.1 and A.2, we obtain: v ( P F ) ≥ v ( P FPTAS ) − ε · v ( O PT ) ≥ (1 − ε ) · v ( O PT ) − ε · v ( O PT ) ≥ (1 − ε ) · v ( O PT ) − ε · v ( O PT ) ≥ (1 − ε ) · v ( O PT ) . Lemma A.4.
The algorithm has update time O (cid:0) ε · log n · log( n · v max ) · log v max (cid:1) . roof. In the first step, guessing V ℓ max and V ℓ min , and therefore enumerating over all possible values, leadsto O ( ε · log v max ) many iterations. Guessing n min adds an additional factor of ε .In the second step, again guessing V L adds a factor to the runtime, specifically O ( ε log( n · v max )) .Temporarily removing the n min ≤ ε elements from the data structure costs a total of O ( ε log n ) , as doesadding back removed items from a previous iteration. Computing the size of B can be done by querying theprefix of value just above V L in time O (log n ) , see Section 3.For Step 3) note that the set H ε spans value classes ranging from ε · V ℓ max or higher to V ℓ max . As valuesare rounded to powers of (1 + ε ) , we consider at most log ε ε many. Hence, H ε is composed of O ( ε ) items and the FPTAS runs in time O (cid:0)(cid:0) ε / ε / + ε (cid:1) / Ω( √ log(1 /ε )) (cid:1) = O ( ε ) .Recall, that we need to maintain one data structure for every existing and one for each possible valueclass, that is, O ( ε log v ) many data structures in total. Maintenance of these, i.e., insertion or deletion of anitem, takes time O ( ε log v log n ) in total. B Few Different Knapsacks
It is not very difficult to extend the approach from Section 4 to the case of multiple but few knapsacks. Whiletheoretically applicable for any number of knapsacks, the runtime is reasonable when m = ( ε log n ) O ε (1) .The main difference to Section 4 comes from the fact that to reserve space for low-value items, a singleplaceholder is no longer sufficient. Instead, we utilize several smaller placeholders. And since guessing thesize of low-value items for every knapsack would lead to a runtime exponential in m , we instead employ asufficiently large number of placeholder items, namely mε many.This leads to additional changes as there are more fractionally cut items, i.e., one per placeholder. To beable to charge them as before in Lemma A.3, we now consider the mε most profitable items in O PT . This inturn leads to a larger candidate set of size mε . Furthermore, since we consider multiple knapsacks, we needto utilize an EPTAS instead of an FPTAS. Besides these changes, the algorithm remains unchanged. Theorem 6.2.
For ε > , there is a dynamic algorithm for M ULTIPLE K NAPSACK with m knapsacks thatachieves an approximation factor of (1 − ε ) with update time f (1 /ε ) ( mε log( nv max )) O (1) + O ( ε log v log n ) ,with f quasi-linear. Moreover, item queries are answered in time O (log m ε ) , solution value queries intime O (1) and queries of a single knapsack or the entire solution in time linear in the size of the output. Definitions and Data Structures
Let O PT be the set of items used in an optimal solution and O PT mε theset containing the mε most valuable items of O PT ; in both cases, break all ties by picking smaller-size items.Further, denote by V ℓ max and V ℓ min the highest and lowest value (class) of an element in O PT mε respectivelyand by n min the number of elements of O PT mε with value V ℓ min . Let V L be the total value of the itemsin O PT \ O PT mε , rounded down to a power of (1 + ε ) . The data structures used are identical to those ofSection 4. Algorithm Compute high-value candidates H mε : Guess the three values V ℓ max , V ℓ min and n min . If V ℓ min · m ≥ ε · V ℓ max , then define H mε to be the set that contains the mε smallest items of each of the valueclasses V ℓ min +1 , . . . , V ℓ max , plus the n min smallest items from V ℓ min .Otherwise, we set H mε to be the union of the mε smallest items of each of the value classes with valuesin [ ε m · V ℓ max , V ℓ max ] .2) Create bundles of low-value items as placeholders:
Guess the value V L and consider the datastructure containing all the items of value at most V ℓ min sorted by decreasing density. Remove from21t (temporarily) the n min smallest items of value V ℓ min . Insert them back into the data structure rightbefore the next full update. From the remaining items, compute the size of fractional items necessaryto reach a value of V L . That is, sum the sizes of the densest items until the total value exceeds V L and, if necessary, cut the last item fractionally. Cut this range of items again fractionally to obtainbundles B , B , . . . , B mε of equal size εm · V L . The value of a bundle is determined by the fractionalvalue of the contained items.3) Use an EPTAS:
Consider the instance I consisting of the items in H mε and the placeholder bun-dles B , B , . . . , B mε . Run the EPTAS designed by Jansen [43, 45], parameterized by ε , to obtain apacking P for this instance.4) Implicit Solution:
Among all guesses, keep the feasible solution P with the highest value. Then,for any knapsack, place into the knapsack items from H mε as in P and, if B k is placed in P on thisknapsack, also place the low-value items that constitute B k , except possibly items cut fractionally.While used candidates can be stored explicitly, low-value items are given only implicitly by savingthe correct guesses and recomputing B k on a query. Analysis.
The analysis is almost identical with that of Section 4 with only slight changes to accommodatethe alterations described above. For completeness, we give the full proofs. We consider the iteration inwhich all guesses ( V ℓ max , V ℓ min , n min , V L ) are correct, and show that the obtained solution has a value of atleast (1 − ε ) · v ( O PT ) . To this end, we consider intermediate results to analyze the impact of each step.Let P be the set of solutions respecting: (i) items not in H mε have a value of at most V ℓ min but arenot part of the n min smallest items of the value class V ℓ min , and (ii) the total value of these items liesin [ V L ; (1 + ε ) V L ] . Denote by O PT the solution of highest value in P . Lemma B.1.
Consider O PT defined as above. Then, v ( O PT ) ≥ (1 − ε ) · v ( O PT ) .Proof. Let O PT ∗ be the packing obtained from O PT by removing all items belonging to O PT mε whose valueis strictly smaller than ε m · V max . Since O PT mε consists of mε many items, the total value of removed itemsis at most mε · ε m · V max ≤ ε · O PT . We show that O PT ∗ ∈ P .Consider an item j in O PT mε of value v j ≥ ε m · V max . If v j = V ℓ min , then j ∈ H mε by definitionof n min and O PT mε ; specifically, due to the tie-breaking rules. Assume now that v j > V ℓ min and j / ∈ H mε .Recall that H mε contains the mε smallest items of value v j , and | O PT mε | = mε . Thus, there exists an item ofvalue v j , smaller than j , which belongs to H mε but not to O PT mε . Exchanging j for this item contradicts thedefinition of O PT . Therefore, j ∈ H mε and Condition (i) is satisfied. Condition (ii) follows directly fromthe definition of V L , and therefore O PT ∗ ∈ P , concluding the proof. Lemma B.2.
Let O PT be the optimal solution of the instance I on which the EPTAS is run at Step 3).Then, v ( O PT ) ≥ (1 − ε ) · v ( O PT ) .Proof. Consider the fractional solution O PT ∗ for I that is obtained from O PT as follows. First, place itemsfrom H mε as in O PT . Next, consider the placeholder bundles B , B , . . . , B mε in any order, and place themfractionally into the remaining space. That is, place remaining bundles in the first non-full knapsack. If abundle does not fit, fill the current knapsack with a fraction of the bundle and place the remaining fractionin the next non-full knapsack using the same process. Finally, discard the fractionally cut bundles.Denote by J L the set of items packed by O PT that are not in H mε , i.e., the low-value items. Since thebundles consists of the densest low-value items, it must be the case, that P mk =1 s ( B k ) ≤ s ( J L ) . There-fore, O PT ∗ is a feasible solution for I and the statement follows.By definition of the bundles, we have P mk =1 v ( B k ) = V L ≥ (1 − ε ) v ( J L ) . Further, since thereare mε bundles of equal value and at most m of them are cut fractionally and discarded, we concludethat v ( O PT ∗ ) ≥ (1 − ε ) · v ( O PT ) . 22 emma B.3. For the solution P F of the algorithm, we have v ( P F ) ≥ (1 − ε ) · v ( O PT ) .Proof. The solution P EPTAS returned by the EPTAS in Step 3) has a value of at least (1 − ε ) · v ( O PT ) .The solution P F is obtained from P EPTAS by replacing the placeholder bundles with the correspondinglow-value items with the exception of fractionally cut ones, of which there are at most mε many. Since thereare mε items in O PT that are of higher value than these items, namely the ones in O PT mε , this implies v ( P F ) ≥ v ( P EPTAS ) − ε · v ( O PT ) . Using Lemmas B.1 and B.2, we obtain: v ( P F ) ≥ v ( P EPTAS ) − ε · v ( O PT ) ≥ (1 − ε ) · v ( O PT ) − ε · v ( O PT ) ≥ (1 − ε ) · (1 − ε ) · v ( O PT ) − ε · v ( O PT ) ≥ (1 − ε ) · (1 − ε ) − ε ) · v ( O PT ) ≥ (1 − ε ) · v ( O PT ) , where the second to last equation follows from Bernoulli’s inequality. Lemma B.4.
The algorithm has an update time of O ( ε · log ( ε )) · ( mε log( nv max )) O (1) + O ( ε log v log n ) .Proof. In the first step, guessing V ℓ max and V ℓ min leads to O ( ε log v max ) many iterations. Guessing n min adds an additional factor of mε . In the second step, guessing V L leads to O ( ε log( nv max )) many additionaliterations, so the factor due to guessing is O ( mε log v max log( nv max )) Temporarily removing the n min ≤ mε elements from the data structure costs a total of O ( mε log n ) , asdoes adding back removed items from a previous iteration. Computing the size of the bundles can be doneby querying the prefixes of value just above V L , so in time O (log n ) . Computing the cut items of the bundlestakes time mε log n .The set H mε spans value classes ranging from V ℓ max to a value at least ε m · V ℓ max . As the value classescorrespond to powers of (1 + ε ) , this means we consider at most log ε mε many. Since each of themcontains at most mε items, H mε contains O ( m ε ) items in total. Thus, in the third step, the EPTAS, used on O ( m ε ) many items, runs in time O ( ε · log ( ε )) + ( mε ) O (1) . Together, this gives the desired update time.Recall, that we need to maintain one data structure for every existing and one for each possible valueclass, that is, O ( ε log v ) many data structures in total. Maintaining these takes time O ( ε log v log n ) . Queries
We show how to efficiently handle the different types of queries and state their runtime. • Single Item Query:
If the queried item is contained in H mε , its packing was saved explicitly. Forlow-value items, we save the first and last element entirely inside a bundle and on query of an itemdecide its membership in a bundle by comparing its density with those pivot elements. • Solution Value Query:
While the algorithm works with rounded values, we may set up the datastructure of Section 3 to additionally store the actual values of items and enable prefix computationon the actual values. We can compute and store the actual solution value after an update by summingthe actual values of packed candidates and determining the actual value of items in B using prefixcomputations while subtracting the values of discarded fractional bundles and items. On query, wereturn the stored solution value. • Single Knapsack Query:
Output the saved packing of all candidates packed in the knapsack. Then,in the respective density sorted data structure, iterate over items in bundles that were packed in thequeried knapsack and output them. As above, this is possible since the first and last item of a bundlewere saved during the update step. 23
Query Entire Solution:
Output saved packing of all candidates and iterate over items in packedbundles in the respective density sorted data structure as above.
Lemma B.5.
The query times of our algorithm are as follows.(i) Single item queries are answered in time O (log m ε ) .(ii) Solution value queries are answered in time O (1) .(iii) Queries of a single knapsack P K are answered in time O ( | P K | ) .(iv) Queries of the entire solution P are answered in time O ( | P | ) .Proof. (i): Since the packing of candidates is stored explicitly, each of the packed candidates can be outputin time O (1) . The part of the solution corresponding to low-value items is stored implicitly, by saving thecorrect guesses and the first and last items of each bundle. The latter are stored in a tree sorted by density firstand item index second, as in the data structure that was used to compute the bundles. Also save a pointer toand from the respective adjoining bundles of these items. This preparation is done during an update. Whena low-value item is queried, use these pivot items to determine whether it is contained in packed bundles andif so in which it lies. This takes time O (log m ε ) .(ii): The computations for this query are done during an update of the instance, with the update clearlydominating the runtime. Thus, on a query, the answer can be given in constant time.(iii): As in (i), the packing of candidates in P K can be output in time O (1) . For low-value items wecreate, during an update, pointers from bundles to the first, i.e., densest, item contained in them. On a query,we then simply consider each bundle in P K and iterate over the density sorted data structure used to findand output all items of the bundle.(iv): We use the approach from (iii) on all knapsacks. C Proofs for Dynamic Linear Grouping
In this section, we give the technical details of the analysis of the dynamic linear grouping approach devel-oped in Section 5.1. We start by analysing the approximation ratio, i.e., by formally proving Lemma 5.2.We restate it here for convenience.Recall that O PT is the optimal solution and O PT T is the optimal solutionattainable by packing item types T instead of items in J ′ and using J \ J ′ without any changes. Lemma 5.2.
Let O PT and O PT T be as defined above. Then, v ( O PT T ) ≥ (1 − ε )(1 − ε )(1+ ε ) v ( O PT ) . The loss in the objective function due to rounding item values to natural powers of (1 + ε ) is bounded bya factor of (1 − ε ) by Lemma 3.1. As already pointed out, the analysis of the approximation ratio consistsof three steps. In Lemma C.1 we show that the loss in the objective function value when restricting theitems in J ′ to the value classes with ¯ ℓ ≤ ℓ ≤ ℓ max is bounded by a factor of (1 − ε ) . If an optimal solutioncontains n ℓ items of V ′ ℓ , it is feasible to pack the n ℓ smallest such items. Then, Lemma C.2 shows that wedo not need n ℓ exactly but it suffices to guess n ℓ up to a factor of (1 + ε ) . Finally, in Lemma C.3, we arguethat using the introduced dynamic linear grouping approach costs at most a factor (1 − ε ) . In Lemma 5.3,we show that the number of item types within one value class is reduced to O ( log n ′ ε ) . In Lemma 5.4, webound the running time of the algorithm.Let P be the set of solutions that (i) may use all items in J ′′ and (ii) uses items in J ′ only of the valueclasses V ℓ with ¯ ℓ ≤ ℓ ≤ ℓ max . Let O PT be an optimal solution in P . The following lemma bounds thevalue of O PT in terms of O PT . Lemma C.1.
Let O PT be defined as above. Then, v ( O PT ) ≥ (1 − ε ) v ( O PT ) . roof. Given ℓ max , it follows that v ( O PT ) ≥ (1 + ε ) ℓ max . As n ′ is an upper bound on the cardinality ofO PT ′ , the items in the value classes with l < ¯ ℓ contribute at most n ′ − items to O PT ′ while the value of oneitem is bounded by (1 + ε ) ¯ ℓ . Thus, the total value of items in V , . . . , V ¯ ℓ contributing to O PT ′ is bounded by n ′ (1 + ε ) ¯ ℓ = n ′ (1 + ε ) ℓ max − (cid:24) log n ′ /ε log(1+ ε ) (cid:25) ≤ n ′ (1 + ε ) ℓ max − log( n ′ /ε )log(1+ ε ) = n ′ (1 + ε ) ℓ max (1 + ε ) − log ε ( n ′ /ε ) = n ′ (1 + ε ) ℓ max εn ′ ≤ ε (1 + ε ) ℓ max ≤ εv ( O PT ) . Let J be the items in O PT ′ restricted to the value classes with ¯ ℓ ≤ ℓ ≤ ℓ max . Clearly, J and O PT ′′ canbe feasibly packed. Hence, v ( O PT ) ≥ v ( J ) + v ( O PT ′′ ) ≥ v ( O PT ′ ) − εv ( O PT ) + v ( O PT ′′ ) ≥ (1 − ε ) v ( O PT ) . From now on, we only consider packings in P , i.e., we restrict to the value classes V ℓ with ¯ ℓ ≤ l ≤ ℓ max for the items in J ′ . Let V ℓ be a value class contributing to O PT ′ . As explained above, knowing n ℓ = | V ℓ ∩ O PT ′ | would be sufficient to determine the items of V ′ ℓ contributing to O PT , i.e., to determine V ′ ℓ ∩ O PT .In the following lemma we show that we can additionally assume that n ℓ = (1 + ε ) k ℓ for some k ℓ ∈ N .To this end, let P contain all the packings in P where the number of big items of each value class V ℓ is anatural power of (1 + ε ) . Let O PT be an optimal packing in P . Lemma C.2.
Let O PT be as defined above. Then, v ( O PT ) ≥ ε ) v ( O PT ) .Proof. Consider O PT , the optimal packing in P . We set O PT ′ := O PT ∩ J ′ and O PT ′′ := O PT \ J ′ = O PT ∩ J ′′ . We construct a feasible packing in P that achieves the desired value of ε ) v ( O PT ) .Let J be the subset of O PT ′ where each value class V ′ ℓ is restricted to the smallest (1 + ε ) ⌊ log ε n ℓ ⌋ items in V ′ ℓ if V ℓ ∩ O PT ′ = ∅ .Fix one value class V ℓ with V ℓ ∩ O PT ′ = ∅ . Restricting to the first (1 + ε ) ⌊ log ε n ℓ ⌋ items in V ℓ ∩ O PT ′ implies v ( V ℓ ∩ J ) = (1 + ε ) ⌊ log ε n ℓ ⌋ (1 + ε ) ℓ ≥
11 + ε (1 + ε ) log ε n ℓ (1 + ε ) ℓ = 11 + ε (1 + ε ) ℓ n ℓ = 11 + ε v ( V ℓ ∩ O PT ′ ) . Clearly, J ∪ O PT ′′ is a feasible packing in P . Observe that v ( O PT ′ ) = P ℓ max ℓ =¯ ℓ v ( V ℓ ∩ O PT ′ ) . Hence, v ( O PT ) ≥ v ( J ) + v ( O PT ′′ ) ≥
11 + ε v ( O PT ′ ) + v ( O PT ′′ ) ≥
11 + ε v ( O PT ) . P . This means, we restrict the items in J ′ to valueclasses V ′ ℓ with ¯ ℓ ≤ ℓ ≤ ℓ max and assume that n ℓ = (1 + ε ) k ℓ for n ℓ ∈ N or n ℓ = 0 . Even with n ℓ being of the form (1 + ε ) k ℓ , guessing the exponent for each value class V ′ ℓ independently is intractable intime polynomial in log n and ε . To resolve this, the dynamic linear grouping creates groups that take intoaccount all possible guesses of n ℓ . This rounding is done for each value class individually and results initem types T ℓ for the set V ′ ℓ . Let P T be the set of all feasible packings of items in T ℓ for ¯ ℓ ≤ ℓ ≤ ℓ max and any subset of items in J ′′ . That is, instead of the original items in J ′ the packings in P T pack thecorresponding item types. Note that packings in P T are not forced to pack natural powers of (1 + ε ) manyitems per value class. Let O PT T be the optimal solution in P T . The next lemma shows that v ( O PT T ) is atmost a factor (1 − ε ) less than v ( O PT ) , the optimal solution in P . Lemma C.3.
Let O PT be defined as above. Then, v ( O PT T ) ≥ (1 − ε ) v ( O PT ) .Proof. We construct a feasible packing J in P T based on the optimal packing O PT . Let O PT ′ := J ′ ∩ O PT and O PT ′′ := J ′′ ∩ O PT . We let J ′′ := O PT ′′ be the items of J ′′ in our new packing J . Theseitems will be packed exactly where they are packed in O PT . For items in J ′ , we consider each valueclass V ℓ ∩ O PT ′ individually and carefully construct the set J ,l , the items of V ′ ℓ contributing to J . Then,we show that the items in J ℓ, can be packed into the knapsacks where the items in V ℓ ∩ O PT ′ are placedwhile ensuring that v ( J ℓ, ) ≥ (1 − ε ) v ( V ℓ ∩ O PT ′ ) .If V ℓ ∩ O PT ′ = ∅ , we set J ℓ, = ∅ . Then, both requirements are trivially satisfied. Consider the casewhere | V ′ ℓ ∩ O PT ′ | ≤ ε . Then, we set J ℓ, := V ′ ℓ ∩ O PT ′ . Clearly, v ( J ℓ, ) ≥ (1 − ε ) v ( V ℓ ∩ O PT ′ ) .For packing J ℓ, , we observe that T ℓ actually contains the smallest ε items as item types. Hence, theirsizes are not affected by the rounding procedure and whenever O PT packs one of these items, we can packthe same item into the same knapsack.Let ℓ be a value class with n ℓ := | V ′ ℓ ∩ O PT ′ | > ε . Let G ( n ℓ ) , . . . , G /ε ( n ℓ ) be the correspond-ing ε groups of ⌊ εn ℓ ⌋ or ⌈ εn ℓ ⌉ many items created by the (traditional) linear grouping for n ℓ . Weset J ℓ, = G ( n ℓ ) ∪ . . . ∪ G /ε − ( n ℓ ) . As v ( G /ε ( n ℓ )) = ⌈ εn ℓ ⌉ (1 + ε ) ℓ ≤ εn ℓ (1 + ε ) ℓ = 2 εv ℓ, ,we have v ( J ℓ, ) ≥ (1 − ε ) v ( V ′ ℓ ∩ O PT ′ ) . For packing these items, we observe that the item typescreated by our algorithm are a refinement of G ( n ℓ ) , . . . , G /ε ( n ℓ ) . As the dynamic linear grouping en-sures | G /ε ( n ℓ ) | ≥ | G /ε − ( n ℓ ) | ≥ . . . ≥ | G ( n ℓ ) | and that the item sizes are increasing in the group index,we can pack the items of group G k ( n ℓ ) where O PT packs the items of group G k +1 ( n ℓ ) for ≤ k < ε .We conclude v ( O PT T ) ≥ v ( J ) + v ( O PT ′′ ) ≥ (1 − ε ) v ( O PT ′ ) + v ( O PT ′′ ) ≥ (1 − ε ) v ( O PT ) . Next, we formally prove the bound on the running time, i.e., Lemma 5.4.
Lemma 5.4.
For a given guess ℓ max , the set T ( ℓ max ) can be determined in time O ( log n ′ ε ) .Proof. Remember that n ′ is an upper bound on the number of items in J ′ in any feasible solution. Observethat the boundaries of the linear grouping created by the algorithm per value class are actually independentof the value class and only refer to some k th item in class V ℓ . Hence, the algorithm first computes thedifferent indices needed in this round. We denote the set of these indices by I ′ = { j , . . . } sorted in anincreasing manner. There are at most ⌊ log ε n ′ ⌋ many possibilities for n ℓ . Thus, the algorithm needs tocompute at most ε (log ε n ′ + 1) many different indices. This means that these indices can be computedand stored in time O ( log n ′ ε ) while each index is bounded by n .Given the guess ℓ max and ¯ ℓ , fix a value class V ℓ with ¯ ℓ ≤ l ≤ ℓ max . We want to bound the time thealgorithm needs to transform the big items in V ℓ into the modified item set T ℓ . We will ensure that the26ynamic algorithms in the following sections maintain a balanced binary search for each value class V ℓ thatstores the items in J ′ sorted by increasing size. Hence, the sizes of the items corresponding to J ′ can beaccessed in time O ( log n ′ ε ) . These sizes correspond to the item size s t for an item type t ∈ T ℓ . Given an itemtype t ∈ T ℓ , n t = j t − j t − , which can again be pre-computed independently of the value class. Thus, T ℓ can be computed in time O ( log n ′ ε ) .As there are O ( log n ′ ε ) many value classes that need to be considered for a given guess ℓ max , calculatingthe set T ( ℓ max ) needs O ( log n ′ ε ) many computation steps. C.1 Integrally Packing Fractional Solutions
One of the main ingredients to the dynamic algorithms in this section is a configuration ILP. As solvinggeneral ILPs is NP-hard, in a first step, we relax the integrality constraints and accept fractional solutionsbefore rounding the obtained solution to an integral one. The first lemma of this section describes howto obtain an integral solution with slightly more knapsacks given a fractional solution to a certain class ofpacking ILPs. Even after rounding, the configuration ILPs only take care of integrally packing big items,i.e., items with s j ≥ εS i . Therefore, the second lemma focuses on packing small items integrally given anintegral packing of big items that reserves enough space for packing these items fractionally using resourceaugmentation.We consider a packing problem of items into a given set of knapsacks K with capacities S k and multi-plicities m k . The objective is to maximize the total value without violating any capacity constraint. Eachitem j has a certain type t , i.e., value v j = v t and size s j = s t , and in total there are n t items of type t . Itemscan either be packed as single items or as part of configurations. A configuration c has value v c = P j ∈ c v j and size s c = P j ∈ c s j . Then, the set E represents the items and the configurations that we are allowed touse for packing. Without loss of generality, we assume that for each element e ∈ E there exists at least oneknapsack i where this element can be stored.Let ≤ β ≤ and s ≥ . Intuitively, later we will choose β = 1 − O ( ε ) since we will leave an O ( ǫ ) -fraction of the knapsacks unused. Consider the packing ILP for the above described problem withvariables z e,k that may additionally contain constraints of the form X e ∈ E,k ∈ K ′ s e z e,k ≤ β X k ∈ K ′ m k S k − s and X e ∈ E,k ∈ K ′ z e,k ≤ β X k ∈ K ′ m k , i.e., the elements assigned to a subset of knapsacks K ′ do not violate the total capacity of a β -fraction of theknapsacks in K ′ while reserving a space of size s and use at most a β -fraction of the available knapsacks.The configuration ILPs used for multiple identical knapsacks and multiple different knapsacks with resourceaugmentation fall into this class of problems.Let v ( z ) be the value attained by a certain solution z and let n ( z ) be the number of non-zero variablesof z . The high-level idea of the proof of the following lemma is to round down each non-zero variable z e,k and pack the corresponding elements as described by z e,k . For packing enough value, we additionally placeone extra element e into the knapsacks given by resource augmentation for each variable z e,k that wassubjected to rounding.More precisely, for each element e and each knapsack type k , let ¯ z ′ e,k := ⌊ z e,k ⌋ and ¯ z ′′ e,k := ⌈ z e,k − ¯ z ′ e,k ⌉ .Note that ¯ z ′ + ¯ z ′′ may require more items of a certain type than are available. Hence, for each item type t that is now packed more than n t times, we reduce the number of t in ¯ z ′ + ¯ z ′′ by either adapting the chosenconfigurations if t is packed in a configuration or by decreasing the variables of type z t,k if items of type t are packed as single items in knapsacks of type k . Let z ′ and z ′′ denote the solution obtained by thistransformation. For some elements e , z ′ e,k + z ′′ e,k may now pack more or less elements than z e,k due to thejust described reduction of items. 27 emma C.4. Any fractional solution z to the above described packing ILP can be rounded to an integralsolution with value at least v ( z ) using at most n ( z ) additional knapsacks.Proof. Consider a particular item type t . If ¯ z ′ + ¯ z ′′ packs at most n t items of this type, then the valueachieved by z for this particular item type is upper bounded by the value achieved by z ′ + z ′′ . If an item typewas subjected to the modification, then z ′ + z ′′ packs exactly n t items of this type while z packs at most n t items. This implies that v ( z ′ + z ′′ ) ≥ v ( z ) .It remains to show how to pack ¯ z ′ + ¯ z ′′ (and, thus, z ′ + z ′′ ) into the knapsacks defined by K andpotentially n ( z ) additional knapsack. Clearly, ¯ z ′ can be packed exactly as z was packed. If z e,k = 0 for e ∈ E and k ∈ K , then ¯ z ′ e,r = 0 . Hence, the number of non-zero entries in ¯ z ′′ is bounded by n ( z ) .Consider one element e ∈ E and a knapsack type k with ¯ z ′′ e,k = 1 and let k ′ be a knapsack where e fits.Pack e into k ′ .As reducing the number of packed items of a certain type only decreases the size of the correspondingconfiguration or only decreases the number of individually packed elements, z ′ + z ′′ can be packed exactlyas described for ¯ z ′ + ¯ z ′′ . Then, we need at most n ( z ) extra knapsacks to pack z ′′ which concludes theproof.After having successfully rounded an ILP solution, we explain how to pack small items, i.e., itemswith s j < εS i , using resource augmentation given an integral packing of big items. More precisely, let K be a set of knapsacks and let J ′ S ⊂ J S be a subset of items that are small with respect to any knapsack in K .Let J ′ B ⊂ J B be a set of big items admitting an integral packing into m = | K | knapsacks that preserves aspace of at least s ( J ′ S ) in these m knapsacks. We develop a procedure to extend this packing to an integralpacking of all items J ′ B ∪ J ′ S in (1 + ε ) m knapsacks where the εm additional knapsacks can be chosen tohave the smallest capacity of knapsacks in K .We use a packing approach similar to N EXT F IT for the problem B IN P ACKING . That is, consider anarbitrary order of the small items and an arbitrary order of the knapsacks filled with big items. If the currentsmall item j still fits into the currently open knapsack, we place it there and decrease the remaining capacityaccordingly. If it does not fit anymore, we pack this item as “cut” item into the next empty slot of the εm additional knapsacks, close the current knapsack and open the next one for packing small items. Lemma C.5.
Let K , J ′ S , and J ′ B be as defined above. The procedure described above feasibly packs allitems J ′ B ∪ J ′ S in (1 + ε ) m knapsacks where the εm additional knapsacks can be chosen to have the smallestcapacity of knapsacks in K .Proof. Clearly, the packing created by the procedure is integral and feasible. It remains to bound the numberof additional knapsacks. Observe that each item that we packed into the resource augmentation while anoriginal knapsack was still available, implied the closing of the current knapsack and the opening of a newone. Hence, for each original knapsack at most one small item was placed into the additional knapsacks.Thus, at most m small items are packed into the additional knapsacks. As at least ε items fit into oneadditional knapsack, we only need εm extra knapsacks for such items. We complete the proof by showingthat all items in J ′ S are indeed packed. Assume that there is a small item j left after all knapsacks, originaland opened extra knapsacks, were closed while packing small items. As a knapsack is only closed if thecurrent small item does not fit anymore, this implies that the volume of all items that are packed so far havea total volume at least as large as the total capacity of knapsacks in K . Hence, the total volume of all itemsin J ′ B ∪ J ′ S is strictly larger than the total capacity of knapsacks in K as j is left unpacked after all knapsackshave been closed. This contradicts the assumption imposed on J ′ B and on J ′ S .28 Proofs for Identical Knapsacks
In this section we give the technical details of some of the lemmas used in Section 5.2. We start by provingLemma 5.7. Recall that v ∗ ILP refers to an optimal, integral solution to ILP (P) and that O PT T is an optimalsolution to the current instance when packing item types T instead of the big items J B . Further, P is themaximal prefix of small items (ordered by non-decreasing density) with v ( P ) < v S and j is the densestsmall item not in P . Lemma 5.7.
Let v ∗ ILP and O PT T be defined as above. There are v S and s S with v ∗ ILP + v S ≥ − ε ε v ( O PT T ) . Moreover, for P and j as defined above, v ( P ) + v j ≥ v S .Proof. Let O PT B, T := O PT T ∩ J B and O PT S, T := O PT T ∩ J S . We construct again a candidate set J ILP of items that are feasible for (P) and obtain a value of at least (1 − ε ) v ( O PT B, T ) . To this end, takethe optimal packing for the items in O PT T and consider the (1 − ε ) m most valuable knapsacks in thispacking. Let J B, T and J S, T consist of the big and small, respectively, items in these knapsacks. Then, v ( J B, T ) + v ( J S, T ) ≥ (1 − ε ) v ( O PT T ) .Create the variable values y c corresponding to the number of times configuration c is used by the itemsin J B, T . As J B, T ∪ J S, T can be feasibly packed into (1 − ε ) m knapsacks, we have X c ∈C y c ≤ (1 − ε ) m and X c ∈C y c s c + s ( J S, ) ≤ (1 − ε ) Sm.
As we guess the value of the small items in the dynamic algorithm up to factors of (1 + ε ) there willbe one guess v S satisfying v S ≤ v ( J S, T ) ≤ (1 + ε ) v S . Let P be the maximal prefix of small itemswith v ( P ) < v S and let j be the densest small item not in P . Then, v ( P ) + v j ≥ v S ≥ ε v ( J S, T ) .As P contains the densest small items, this implies s S := s ( P ) ≤ s ( J S, T ) . Thus, X c ∈C y c s c ≤ (1 − ε ) Sm − s ( J S, T ) ≤ (1 − ε ) Sm − s S . Hence, the just created y c are feasible for the ILP with the guess s S and v ∗ ILP + v ( P ) + v j ≥ v ( J B, T ) + 11 + ε v ( J S, T ) ≥ (1 − ε ) (cid:18) v ( O PT B, T ) + 11 + ε v ( O PT S, T ) (cid:19) ≥ − ε ε v ( O PT T ) . Proof of Lemma 5.8
In this part, we provide the full proof of our approach to solving the LP relaxation ofthe configuration ILP when m satisfies ε log n ≤ m . In the following, we abuse notation and also referto the LP relaxation of (P) by (P): 29 ax X c ∈C y c v c subject to X c ∈C y c s c ≤ (1 − ε ) Sm − s S X c ∈C y c ≤ (1 − ε ) m X c ∈C y c n tc ≤ n t for all t ∈ T ( l max ) y c ∈ ≥ for all c ∈ C (P)Let γ and β be the dual variables of the capacity constraint and the number of knapsacks constraint,respectively. We set T := T ( ℓ max ) for simplicity. Let α t for t ∈ T be the dual variables of the constraintensuring that only n t items of type t are packed. Then, the dual is given by the following linear program. min (1 − ε ) mβ + ((1 − ε ) Sm − s S ) γ + X t ∈T n t α t subject to β + s c γ + X t ∈ T α t n tc ≥ v c for all c ∈ C α t ≥ for all t ∈ T β, γ ≥ . (D)As discussed above, for applying the Ellipsoid method we need to solve the separation problem effi-ciently. The separation problem decides if the current solution ( α ∗ , β ∗ , γ ∗ ) is feasible or finds a violatedconstraint. As verifying the first constraint of (D) corresponds to solving a K NAPSACK problem, we do notexpect to optimally solve the separation problem in time polynomial in log n and ε . Instead, we apply adynamic program (DP) for the single knapsack problem after restricting the item set further and roundingthe item values as follows.Let ¯ v t := v t − α ∗ t − γ ∗ s t for t ∈ T . If there exists an item type with ¯ v t > β ∗ , we return the configurationusing only this item. Otherwise, we define ˜ v t := (cid:4) ¯ v t ε β ∗ (cid:5) · ε β ∗ . By running the dynamic program for theK NAPSACK problem on the item set T with multiplicities min { ε , n t } and values ˜ v t , we obtain a solution x ∗ where x ∗ t indicates how often item type t is packed. If P t ∈T x ∗ t ˜ v t > β ∗ , we return the configuration definedby x ∗ as separating hyperplane. Otherwise, we return DECLARED FEASIBLE for the current solution.The next lemma shows that this algorithm approximately solves the separation problem by either cor-rectly declaring infeasibility or by finding a solution that is almost feasible for (D). The slight infeasibilityfor the dual problem translates to a slight decrease in the optimal objective function value of the primalproblem. In the proof we use that x ∗ is optimal for the rounded values ˜ v t to show that ( α ∗ , β ∗ , γ ∗ ) is almostfeasible if P t ∈T x ∗ t ˜ v t ≤ β ∗ . Noticing that ¯ v t ≥ ˜ v t then concludes the proof. Lemma D.1.
Given ( α ∗ , β ∗ , γ ∗ ) , there is an algorithm with running time O (cid:16) log nε (cid:17) which either finds aconfiguration c ∈ C such that β ∗ + s c γ ∗ + P t ∈T α ∗ t n tc < v c or guarantees that β ∗ + s c γ ∗ + P t ∈T α ∗ t n tc ≥ (1 − ε ) v c holds for all c ∈ C .Proof. Fix a configuration c and recall that s c = P t ∈T n tc s t and v c = P t ∈T n tc v t . Then, checking β ∗ + s c γ ∗ + P t ∈T α ∗ t n tc ≥ v c for all configurations c ∈ C is equivalent to showing max c ∈C P t ∈T ( v t − α ∗ t − γ ∗ s t ) n tc ≤ β ∗ . This problem translates to solving the following ILP and comparing its objective function30alue to β ∗ . max X t ∈T ( v t − α ∗ t − γ ∗ s t ) x t s.t. X t ∈T s t x t ≤ Sx t ≤ n t for all t ∈ T x t ∈ Z ≥ (S)This ILP is itself a (single) K NAPSACK problem. Hence, the solution x ∗ found by the algorithm is indeedfeasible for (S).We start by bounding the running time of the algorithm. Recall that, for each t ∈ T , ¯ v t := v t − α ∗ t − γ ∗ s t and ˜ v t := (cid:4) ¯ v t ε β ∗ (cid:5) · ε β ∗ . Observe that T only contains big items. Hence, it suffices to consider min { n t , ε } items per value class in the DP. It can be checked in time O ( log nε ) , if ¯ v t ≤ β ∗ is violated for one t ∈ T .Otherwise, ˜ v t ≤ ¯ v t and ¯ v t − ˜ v t ≤ ε β ∗ hold. Thus, the running time of the DP is bounded by O (cid:16) |T | ε (cid:17) = O (cid:16) log nε (cid:17) [38].It remains to show that the solution x ∗ either defines a configuration with β ∗ + s c γ ∗ + P t ∈T α ∗ t n tc < v c or ensures that β ∗ + s c γ ∗ + P t ∈T α ∗ t n tc ≥ (1 − ε ) v c holds for all c ∈ C . If P t ∈T x ∗ t ˜ v t > β ∗ , it holds X t ∈T x ∗ t ¯ v t ≥ X t ∈T x ∗ t ˜ v t > β ∗ and, thus, x ∗ defines a separating hyperplane.Suppose now that P t ∈T x ∗ t ˜ v t ≤ β ∗ . We assume for the sake of contradiction that there is a configuration c ′ , defined by packing x t items of type t , such that X t ∈T x t (cid:0) (1 − ε ) v t − α ∗ t − γ ∗ s t (cid:1) > β ∗ . As T contains only big item types, we have that P t ∈T x t ≤ ε . This implies that there exists at least oneitem type t ′ in T with x t ′ ≥ and (1 − ε ) v t ′ − α ∗ t ′ − γ ∗ s t ′ ≥ εβ ∗ . Moreover, ¯ v t = v t − α ∗ t − γ ∗ s t ≥ (1 − ε ) v t − α ∗ t − γ ∗ s t holds for all item types t ∈ T . This implies for t ′ that ¯ v t ′ ≥ εβ ∗ . Hence, X t ∈T x t ¯ v t ≥ εx t ′ ¯ v t ′ + X t ∈T x t (cid:0) (1 − ε ) v t − α ∗ t − γ ∗ s t (cid:1) > εv t ′ + β ∗ ≥ (1 + ε ) β ∗ . By definition of ˜ v , we have ¯ v t − ˜ v T ≤ ε β ∗ and P t ∈T x t (¯ v t − ˜ v t ) ≤ ε β ∗ . This implies X t ∈T x t ˜ v t = X t ∈T x t ˜ v t + X t ∈T x t (¯ v t − ˜ v t ) > (1 + ε ) β ∗ − ε β ∗ ≥ β ∗ , where the last inequality follows from ε ≤ . By construction of the DP, x ∗ is the optimal solution for thevalues ˜ v and achieves a total value less than or equal to β ∗ . Hence, β ∗ ≥ X t ∈T x ∗ t ˜ v t ≥ X t ∈T x t ˜ v t > β ∗ ; a contradiction. 31e now present the proof of Lemma 5.8, which we restate for convenience. Lemma 5.8.
Let U = max { Sm, nv max } . Then, there is an algorithm that finds a feasible solution for theLP relaxation of (P) with value at least − ε ε v LP with running time bounded by (cid:16) log Uε (cid:17) O (1) .Proof. As discussed above, the high-level idea is to solve (D), the dual of (P), with the Ellipsoid method andto consider only the variables corresponding to constraints added by the Ellipsoid method for solving (P).As (S) is part of the separation problem for (D), there is no efficient way to exactly solve the separationproblem unless P = NP. Lemma D.1 provides us with a way to approximately solve the separation problem.As an approximately feasible solution for (D) cannot be directly used to determine the important variablesin (P), we add an upper bound r on the objective function as a constraint to (D) and search for the largest r such that the Ellipsoid method returns infeasible. This implies that r is an upper bound on the objectivefunction of (D) which in turn guarantees a lower bound on the objective function value of (P) by weakduality.Of course, testing all possible values for r is intractable and we restrict the possible choices for r .Observe that v LP ∈ [ v max , nv max ] where v LP is the optimal value of (P). Thus, for all ⌈ log ε v max ⌉ ≤ k ≤⌊ log ε ( nv max ) ⌋ , we use r = (1 + ε ) k as upper bound on the objective function. That is, we test if (D)extended by the objective function constraint (1 − ε ) mβ + ((1 − ε ) Sm − s S ) γ + P t ∈T n t α t ≤ r isdeclared feasible by the Ellipsoid method with the approximate separation oracle for (S). We refer to thefeasibility problem by (D r ).For a given solution ( α ∗ , β ∗ , γ ∗ ) of (D r ) the separation problem asks for one of the two: either theaffirmation that the point is feasible or a separating hyperplane that separates the point from any feasiblepoint. It can be checked in time O ( |T | ) ≤ O (cid:0)(cid:0) log nε (cid:1) (cid:1) that α ∗ t , β ∗ , and γ ∗ are non-negative. In case of anegative answer, the corresponding non-negativity constraint is a feasible separating hyperplane. Similarly,the objective function constraint (1 − ε ) β + (1 − ε )( Sm − s k ) γ + P t ∈T n t α t ≤ r can be checked intime O ( |T | ) where the numbers are bounded by log U and added as a new inequality if necessary. In casethe non-negativity and objective function constraints are not violated, the separation problem is given bythe knapsack problem in (S). The algorithm in Lemma D.1 either outputs a configuration that yields a validseparating hyperplane or declares ( α ∗ , β ∗ , γ ∗ ) feasible. That is β ∗ + s c γ ∗ + P t ∈T α ∗ t n tc ≥ (1 − ε ) v c holdsfor all c ∈ C . This implies that ( α ∗ , β ∗ , γ ∗ ) is feasible for the following LP. (Note that we changed the righthand side of the constraints when compared to (D).) min (1 − ε ) β + ((1 − ε ) Sm − s S ) γ + X t ∈T n t α t s.t. β + s c γ + X t ∈T α t n tc ≥ (1 − ε ) v c for all c ∈ C α t ≥ for all t ∈ T β, γ ≥ (D (1 − ε ) )Let r ∗ be minimal such that (D r ) is declared feasible for r = r ∗ . Let v (1 − ε ) D denote the optimal solutionvalue of (D (1 − ε ) ). As ( α ∗ , β ∗ , γ ∗ ) is feasible and has an objective value of at most r ∗ , it follows v (1 − ε ) D ≤ r ∗ .32et v (1 − ε ) denote the optimal solution value of its dual, i.e., of the following LP. max X c ∈C y c (1 − ε ) v c subject to X c ∈C y c s c ≤ (1 − ε ) Sm − s S X c ∈C y c ≤ (1 − ε ) m X c ∈C y c n tc ≤ n t for all t ∈ T ( l max ) y c ∈ Z ≥ for all c ∈ C . (P (1 − ε ) )Then, y = 0 is feasible for (P (1 − ε ) ) and by weak duality, we have v (1 − ε ) = v (1 − ε ) D ≤ r ∗ . Note that (P) and (P (1 − ε ) ) have the same feasible region and their objective functions only differ by thefactor (1 − ε ) . This implies that v LP = v (1 − ε ) − ε ≤ r ∗ − ε . (2)Because of the relation between v LP and r ∗ it suffices to find a feasible solution for (P) with objectivefunction value close to r ∗ in order to prove the lemma.To this end, let C r be the configurations that correspond to the inequalities added by the Ellipsoid methodwhile solving (D r ) for r = r ∗ ε . Consider the problems (P) and (D) restricted to the variables y c for c ∈ C r and to the constraints for c ∈ C r , respectively, and denote these restricted LPs by (P ′ ) and (D ′ ). Let v ′ and v ′ D be their respective optimal values.It holds that v ′ D > r as the Ellipsoid method also returns infeasibility for (D ′ ) when run on (D ′ ) extendedby the objective function constraint for r . As y = 0 is feasible for (P ′ ) and α = 0 , β = max c ∈C r v c ,and γ = 0 are feasible for (D ′ ), their objective function values coincide, i.e., v ′ = v ′ D > r . Since (P ′ ) onlyhas few variables, an optimal solution for (P ′ ) can be found fast. Clearly, this solution is also feasible for (P)and achieves an objective function value v ′ > r ∗ ε ≥ − ε ε v LP where we used Equation (2) for the last inequality.It remains to show that the Ellipsoid method can be applied to the setting presented here and that therunning time of the just described algorithm is indeed bounded by a polynomial in log n , ε , and log U . Asthe details are rather technical and contain no new insights, we refer to Appendix D.Recall that U is an upper bound on the absolute values of the denominators and numerators ap-pearing in (D), i.e., on Sm and nv max . Observe that by Lemma D.1, the separation oracle runs intime O (cid:16) log nε + log nε log S log m (cid:17) ; the additive term is due to checking non-negativity and the objec-tive function constraint as first step of the separation problem. The number of iterations of the Ellipsoidmethod will be bounded by a polynomial in log U and ˜ n ∈ O (cid:16) log nε (cid:17) . Here, ˜ n is an upper bound on thenumber of variables in the problems (D r ) (and (D (1 − ε ) )).The feasible region of (D r ) is a subset of the feasible region of (D (1 − ε ) ), even when the objective functionconstraint is added to the latter LP. The Ellipsoid method usually is applied to full-dimensional, boundedpolytopes that guarantee two bounds: (i) if the polytope is non-empty, then its volume is at least v and (ii)the polytope is contained in a ball of volume at most V . As shown in Chapter 8 of [7], these assumption33an also be ensured and the parameters v and V can be chosen as polynomial functions of ˜ n and U . As wecannot check feasibility of (D r ) directly, we choose the parameters v and V described in Chapter 8 of [7] forthe problem (D (1 − ε ) ) extended by the objective function constraint for r . Then, after N = O (˜ n log( V /v )) iterations, the modified Ellipsoid method either finds a feasible solution to (D (1 − ε ) ) with objective functionvalue at most r or correctly declares (D r ) infeasible. Chapter 8 of [7] shows that the number of iterations N satisfies N = O (˜ n log(˜ nU )) and that the overall running time is polynomially bounded in ˜ n and log U .Hence, (P ′ ), the problem (P) restricted to the constraints added by the Ellipsoid method, has at most N variables and, thus, any polynomial time algorithm for linear programs can be applied to (P ′ ) to obtain anoptimal solution. Answering Queries
The remainder of this section is concerned with proving the results stated for answer-ing queries. For convenience, we restate the corresponding lemmas.Note that, throughout the course of the dynamic algorithm, we only implicitly store solutions. In theremainder of this section we explain how to answer the queries stated in Section 3 and bound the runningtimes of the corresponding algorithms. We refer to the time frame between two updates as a round andintroduce a counter τ that is increased after each update and denotes the current round. As our answersto queries have to stay consistent within a round, we cache existing query answers by aditionally storing around t ( j ) and a knapsack k ( j ) for each item in the search tree for items where t ( j ) stores the last round inwhich item j has been queried and k ( j ) points to the knapsack of j in round t ( j ) . If j was NOT SELECTED in t ( j ) , we store this with k ( j ) = 0 . Storing t ( j ) is necessary since resetting the cached query answers aftereach update takes too much running time.Let ¯ y c , c ∈ C , be the packing for the big items in terms of the variables of the configuration ILP. Duringthe run of the algorithm the set C ′ := { c ∈ C : ¯ y c ≥ } was constructed. We assume that this set is orderedin some way and stored in one list. In the following we use the position of c ∈ C ′ in that list as the index of c . For assigning ¯ y c distinct knapsacks to configuration c ∈ C ′ we use the ordering of the configurations andmap the knapsacks P c − c ′ =1 ¯ y c + 1 , . . . , P cc ′ =1 ¯ y c ′ to configuration c .For small items, we store all items in a balanced binary search tree sorted by decreasing density.Let , . . . , j ⋆ be the items selected by the implicit solution as guess for the size of small items in the currentsolution. Item j ⋆ + 1 is packed into its own knapsack. Any item j ≤ j ⋆ is either packed regularly into theempty space of a knapsack with a configuration or it is packed into a knapsack designated for packing “cut”small items. Therefore, we maintain two pointers: κ r points to the next knapsack where a small item issupposed to go if it is packed regularly and κ c points to the position where the next cut small item is packed.To determine if an item is packed regularly or as cut item, we store in ρ the remaining capacity of κ r .For each type t of big items, we maintain a pointer κ t to the knapsack where the next queried item oftype t is supposed to be packed. Moreover, the counter η t stores how many slots κ t still has for items oftype t . Let ¯ n t denote the number of items of type t belonging to solution ¯ y . We will only pack the first ¯ n t items of type t . Answering Item Queries. Check cache.
Let τ be the current round and let j be the queried item. If t ( j ) = τ , return k ( j ) .2) Answer queries for non-cached items.
Set t ( j ) = τ . If s j ≤ εS , item j is small. Otherwise, j isbig. Small items. If j > j ⋆ + 1 , return NOT SELECTED and set k ( j ) = 0 .If j = j ⋆ + 1 , return k ( j ) = m .Otherwise, determine if j is packed regularly or as cut item: If s j ≤ ρ , return k ( j ) = κ r and update ρ accordingly. Otherwise, return k ( j ) = κ c . Increase κ c to the next position for fractional items.34ncrease κ r by one and update ρ accordingly to reflect the empty space in κ r . Big items.
Determine the value class V ℓ of j . If ℓ < ℓ min , return NOT SELECTED . Otherwise,determine the item type t of j by retracing the steps of the dynamic linear grouping.If j is not among the first ¯ n t items of type t , return NOT SELECTED and set k ( j ) = 0 .Otherwise, return k ( j ) = κ t and decrease η t by one. If η t = 0 , increase κ t to the next knapsack fortype t and update η t accordingly. If no such knapsack exists, set κ t = 0 . Answering the Solution Value Query. Value of small items.
Calculate v S = P j ⋆ +1 j =1 v j with prefix computation.2) Value of big items.
For each item type t , calculate v B,t the value of the first ¯ n t items of type t usingprefix computation.3) Value.
Return v S + P t ∈T v B,t . Answering the Solution Query. Small items.
Query each item j = 1 , . . . j ⋆ + 1 and return the solution.2) Big items.
For each type t ∈ T , query the first ¯ n t items and return the solution.We prove the parts of the following lemmas individually. Lemma 5.12.
The solution determined by the query algorithms is feasible and achieves the claimed totalvalue. The query times of our algorithm are as follows.(i) Single item queries can be answered in time O (cid:0) max (cid:8) log log nε , ε (cid:9)(cid:1) (ii) Solution value queries can be answered in time O (1) (iii) Queries of the entire solution P are answered in time O (cid:0) | P | max (cid:8) log log nε , ε (cid:9)(cid:1) . Lemma D.2.
The solution determined by the query algorithms is feasible and achieves the claimed totalvalue.Proof.
By construction of t ( j ) and k ( j ) , the answers to queries happening between two consecutive updatesare consistent.For small items, observe that , . . . , j ⋆ + 1 are the densest small items in the current instance.By Lemma C.5, the packing obtained by our algorithms is feasible for these items. In Lemma 5.10 weargue that these items contribute enough value to our solution.For big items, the algorithms correctly pack the first ¯ n t items of type t . A knapsack with configura-tion c ∈ C ′ correctly obtains n c,t items of type t . Moreover, each configuration c ∈ C ′ gets assigned ¯ y c knapsacks. Hence, the algorithms pack exactly the number of big items as dictated by the implicit solu-tion ¯ y . Lemma D.3.
The data structures for big items can be generated in time O (cid:0) |C ′ | ε (cid:1) . Queries for big items canbe answered in time O (cid:0) log log nε (cid:1) .Proof. We assume that C ′ is already stored in some list. We start by formally mapping knapsacks to config-urations. To this end, we create a list α where α c = P c − c ′ =1 ¯ y c is the first knapsack with configuration c ∈ C ′ .Using α c = α c − + ¯ y c − , we can compute these values in constant time while the appearing numbers arebounded by m . Hence, by iterating once through C ′ , this list can be generated in O ( |C ′ | ) . By definition, thecreated lists are already ordered by increasing α c . 35e start by recomputing the indices needed for the dynamic linear grouping approach. For each valueclass V ℓ with ¯ ℓ ≤ ℓ ≤ max , we access the items corresponding to the boundaries of the item types T ℓ in order to obtain the item types T ℓ . By construction, these types are already ordered by non-decreasingsize s t . By Lemma 5.4, these item types can be computed in time O (cid:0) log nε (cid:1) and stored in one list T ℓ pervalue class V ℓ .For maintaining and updating the pointer κ t , we generate a list C t of all configurations c ∈ C ′ with n c,t ≥ . By iterating through each c ∈ C ′ , we can add c to the list of t if n c,t ≥ . We additionally store n c,t and α c in the list C t . While iterating through the configurations, we additionally compute ¯ n t = P c ∈C ′ ¯ y c n c,t and store ¯ n t in the same list as the item types T ℓ . Note that since the list of C ′ by definition is ordered byindices, the created lists C t are also sorted by indices. For each item type, we point κ t to the first knapsackof the first added configuration c and set η t = n c,t . If the list of an item type remains empty, we set κ t = 0 .Since each configuration contains at most ε item types, the lists C t can be generated in time O ( |C ′ | ε ) .Now consider a queried big item j . In time O (log n ) we can decide whether j has already been queriedin the current round. If not, let V ℓ be the value class of j , which was computed upon arrival of j . If ℓ < ¯ ℓ , j does not belong to the current solution and no data structures need to be updated. Otherwise, the type of j is determined by accessing the item types T ℓ in time O (log log nε ) . Once t is determined, ¯ n t can be added tothe left boundary of type t in order to determine if j is packed or not. If j belongs to the current solution,pointer κ t dictates the answer to the query.In order to update κ t and η t , we extract c , the current configuration of knapsack κ t in time O (log |C ′ | ) bybinary search over the list α . If κ t + 1 < α c +1 , κ t is increased by one and η t = n c,t in constant time. If not,the next configuration c ′ containing t can be found with binary search over the list C t in time O (log |C ′ | ) . Ifno such configuration is found, we set κ t = 0 . Otherwise, we set κ t = α c ′ and η t = n c,t . Overall, queries forbig items can be answered in time O (cid:0) max { log |C ′ | , log log nε } (cid:1) . Observing that |C ′ | ∈ O ( T ) = O (cid:0) log nε (cid:1) completes the proof. Lemma D.4.
The above mentioned data structures for small items can be generated in time O ( log nε ) .Queries for small items can be answered in time O (cid:0) max (cid:8) log log nε , ε (cid:9)(cid:1) .Proof. We initialize κ r = 1 and ρ = S − s where s is the total size of the configuration assigned to thefirst knapsack. For packing cut items, we use the pointer κ c to the current knapsack for “cut” items while η f stores the remaining slots of small items. We initalize these values with κ c = (1 − ε ) m − εm +1 and η c = ε .These initializations can be computed in time O (log |C ′ | ) (for accessing s ) while the numbers are boundedby S and m .Now consider a queried small item j . In time O (log n ) we can decide whether j has already beenqueried in the current round. In constant time, we can decide whether j > j ⋆ + 1 . If j > j ⋆ , the answeris NOT SELECTED . If j = j ⋆ + 1 , we return m . Both answers can be determined in constant time withnumbers bounded by m . If j ≤ j ⋆ , the algorithm only needs to decide if j is packed into κ r or κ c , whichcan be done in constant time. Finally, κ r , κ c as well as ρ and η c need to be updated. While κ c , κ r and η c can be updated in constant time, we need to compute the configuration c and remaining capacity S − s c of knapsack κ r if the pointer is increased. By using binary search over the list α , the configuration can bedetermined in time O (log |C ′ | ) . Once the configuration is known, ρ can be calculated in time O (cid:0) ε (cid:1) withnumbers bounded by S . Overall, queries for small items can be answered in time O (cid:0) max (cid:8) log |C ′ | , ε (cid:9)(cid:1) .Using that |C ′ | ∈ O ( |T | ) = O (cid:0) log nε (cid:1) concludes the proof. Lemma D.5.
A query for the solution value can be answered in time O (cid:0) log nε (cid:1) . roof. The value achieved by the small items, v S can be computed with on prefix computation of thefirst j ⋆ + 1 items in the density-sorted tree for small items in time O (log n ) by Lemma 3.2.For computing the value of a big item, we consider each value class V ℓ with ¯ ℓ ≤ ℓ ≤ ℓ max individually.There are at most O (cid:0) log nε (cid:1) many values classes by Lemma C.1. For one value class, in time O (cid:0) log nε (cid:1) ,iterate through the item types t . For each item type, we can access the total value of the first ¯ n t items intime O (log n ) by Lemma 3.2.Combining these two bounds gives the running time claimed in the lemma. Lemma D.6.
A query for the complete solution can be answered intime O (cid:0) | P | log nε max { log |C ′ | , log log nε } (cid:1) where P is our solution.Proof. The small items belonging to a solution can be accessed in time O (( j ⋆ + 1) log n ) by Lemma 3.2.Lemma D.4 then ensures that their knapsacks can be determined in time O (cid:0) max (cid:8) log |C ′ | , ε (cid:9)(cid:1) .For big items, we consider again at most O (cid:0) log nε (cid:1) many value classes individually. In time O (cid:0) log nε (cid:1) , weaccess the boundaries of the corresponding item types. In time O (¯ n t log n ) we can access the ¯ n t items oftype t belonging to our solutions by Lemma 3.2. Lemma D.3 ensures that their knapsacks can be determinedin time O (cid:0) max { log |C ′ | , log log nε } (cid:1) In total, this bounds the running time by O (cid:0) | P | log nε max { log |C ′ | , log log nε } (cid:1) . E Knapsacks with Resource Augmentation
In this section, we consider instances for M
ULTIPLE K NAPSACK with many knapsacks and arbitrary capac-ities. We show how to efficiently maintain a (1 − ε ) -approximation when given L = ( log nε ) O ( ε ) additionalknapsacks that have the same capacity as a largest knapsack in the input instance. The algorithm will againsolve the LP relaxation of a configuration ILP and round the obtained solution to an integral packing. How-ever, in contrast to the problem for identical knapsacks, not every configuration fits into every knapsack andwe therefore cannot just reserve a fraction of knapsacks in order to pack the rounded configurations sincethe knapsack capacities might not suffice. For this reason, we employ resource augmentation in the case ofarbitrary knapsack capacities. While we may pack items into the additional knapsacks, an optimal solutionis not allowed to use them. Again, we assume that item values are rounded to powers of (1 + ε ) whichresults in value classes V ℓ of items with value v j = (1 + ε ) ℓ . We prove the following theorem. Theorem 6.3.
There is a dynamic algorithm for M ULTIPLE K NAPSACK that, when given L = ( log nε ) O (1 /ε ) additional knapsacks as resource augmentation, achieves an approximation factor (1 − ε ) with updatetime (log n ) O (1 /ε ) (log S max log v max ) O (1) where S max := max { S i : i ∈ [ m ] } . Item queries are answeredin time O (cid:0) log nε (cid:1) and a solution P can be output in time O (cid:0) | P | log nε (cid:1) . Overview.
We use dynamic linear grouping as developed in Section 5.1 in order to reduce the number ofdifferent item types to O ( log nε ) . Given the set of item types T , we decide whether a given item type is smallor big with respect to a certain knapsack. Recall that an item j is called small with respect to a knapsackwith capacity S i if s j < εS i and big otherwise.Using the item types, we group knapsacks of similar capacity in a way such that within a group anygiven item type is either small for all knapsacks in the group or it is big for all knapsacks in the group. Wedenote by G the set of all such groups. As there are O ( log nε ) item types, we have at most O ( log nε ) groups.Within one group, we give an explicit packing of the big items into slightly less knapsacks than belongingto the group by solving a configuration ILP. For packing the small items, we use Lemma C.5. That is, wegreedily fill up knapsacks with small items and pack any “cut” small item into the knapsacks that were left37mpty by the configuration ILP. However, since items classify as big in one knapsack group and as small inanother group, instead of guessing the size of small items per knapsack group, we incorporate them into theconfiguration LP by reserving sufficient space for the small items in each group. Data structures
In this section, we maintain three different types of data structures: one tree for storingevery item j together with its size s j , its value v j , and its value class ℓ j sorted by non-decreasing time ofarrival. We additionally store the knapsacks sorted in non-increasing capacity in one separate tree as well.For each value class V ℓ , we additionally maintain one balanced binary tree for sorting the items with ℓ j = ℓ in order of non-decreasing size. Algorithm Linear grouping of big items:
Guess ℓ max , the index of the highest value class that belongs to O PT and use dynamic linear grouping with J ′ = J and n ′ = n to obtain T , the set of item types t withtheir multiplicities n t .2) Knapsack Grouping:
Consider the knapsacks sorted increasingly by their capacity and determine foreach item size for which knapsacks a corresponding item would be big or small. This yields a set G of O ( log nε ) many knapsack groups. Denote by F g the set of all item types that are small with respect togroup g , and by S g the total capacity of all knapsacks in group g . Let m g be the number of knapsacksin group g and let G (1 /ε ) be the groups in G with m g ≥ ε . For each g ∈ G (1 /ε ) , define S g,ε as the totalcapacity of the smallest εm g many knapsacks in g . Similar to the ILP for identical knapsacks, the ILPreserves some knapsacks to pack small “cut” items. We distinguish between G (1 /ε ) and G \ G (1 /ε ) torestrict only large enough groups g , i.e, g ∈ G (1 /ε ) , to the (1 − ε ) m g most valuable knapsacks of g .3) Configurations:
For each group g ∈ G , create all possible configurations consisting of at most ε items which are big with respect to knapsacks in g . This amounts to O (( log nε ) /ε ) configurationsper group. Order the configurations decreasingly by size and denote the set of such configurationsby C g = { c g, , c g, . . . c g,k g } . Let m g,ℓ be the total number of knapsacks in group g in which wecould possibly place configuration c g,ℓ . Further, denote by n c,t the number of items of type t inconfiguration c , and by s c and v c the size and value of c respectively.4) Configuration ILP:
Solve the following configuration ILP with variables y c and z g,t . Here, y c countshow often a certain configuration c is used, and z g,t counts how many items of type t are packed inknapsacks of group g if type t is small with respect to g . Note that by the above definition of C g , we38ay have duplicates of the same configuration for several groups. max X g ∈G X c ∈C g y c v c + X g ∈G X t ∈F g z g,t v t s.t. ℓ X h =1 y c g,h ≤ m g,ℓ for all g ∈ G , ℓ ∈ [ k g ] X c ∈C g y c ≤ (1 − ε ) m g for all g ∈ G (1 /ε ) X c ∈C g y c s c g,h + X t ∈F g z g,t s t ≤ S g for all g ∈ G \ G (1 /ε ) X c ∈C g y c s c g,h + X t ∈F g z g,t s t ≤ S g − S g,ε for all g ∈ G (1 /ε ) X g ∈G X c ∈C g y c n c,t + X g ∈G : t ∈F g z g,t ≤ n t for all t ∈ T y c ∈ Z ≥ for all g ∈ G , c ∈ C g z g,t ∈ Z ≥ for all t ∈ T , g ∈ G z g,t = 0 for all t ∈ T , g ∈ G : t / ∈ F g (P)The first inequality ensures that the configurations chosen by the ILP actually fit into the knapsacksof the respective group while the second inequality ensures that an ε -fraction of knapsacks in G /ε remains empty for packing small “cut” items. The third and fourth inequality guarantee that thetotal volume of large and small items together fits within the designated total capacity of each group.Finally, the fifth inequality makes sure that only available items are used by the ILP.5) Obtaining an integral solution:
After relaxing the above ILP and allowing fractional solutions, weare able to solve it efficiently. Let O PT LP be an optimal (fractional) solution to (P) with objectivefunction value v LP . With Lemma C.4 we obtain an integral solution that uses the additional knapsacksgiven by the resource augmentation with value at least v LP . Let P F denote this final solution.6) Packing small items:
Observe that small item types t ∈ F g are only packed fractionally by P F .Lemma C.5 provides us with a way to pack the small items integrally. Analysis
We start again by showing that the loss in the objective function value due to the linear groupingof items is bounded by a facor of at most (1 − ε )(1 − ε )(1+ ε ) . To this end, let O PT be an optimal solution tothe current, non-rounded instance and let J be the set of items with values already rounded to powers of (1 + ε ) . By setting J ′ = J , we apply Lemma 3.1 and Lemmas C.1 to C.3 to obtain the following corollary.Here, O PT T is the optimal solution for the instance specified by the item types T with multiplicities n t . Corollary E.1.
Let O PT and O PT T be defined as above. Then, v ( O PT T ) ≥ (1 − ε )(1 − ε )1+ ε v ( O PT ) . We have thus justified the restriction to item types in T instead of packing the actual items. In the nexttwo lemmas, we show that (P) is a linear programming formulation of the D YNAMIC M ULTIPLE K NAPSACK problem on the item set T and that we can obtain a feasible integral packing (using resource augmentation)if we have a fractional solution (without resource augmentation) to (P). Let v LP be the optimal objectivefunction value of the LP relaxation of (P).Similar to the proof of Lemma 5.7 we restrict a given optimal solution O PT T to the (1 − ε ) m g mostvaluable knapsacks if m g ≥ ε and otherwise we do not restrict the knapsacks at all. Lemma E.2.
It holds that v LP ≥ (1 − ε ) v ( O PT T ) . roof. We show the statement by explicitly stating a solution ( y, z ) that is feasible for (P) and achieves anobjective function value of at least (1 − ε ) v ( O PT T ) .Consider a feasible optimal packing O PT T for item types. The construction of ( y, z ) considers eachgroup g ∈ G . If g / ∈ G (1 /ε ) , let y c count how often a configuration c ∈ C g is used in O PT T . Moreover,let z g,t denote how often an item that is small with respect to g is used in O PT T . By construction, thefirst and the third constraint of (P) are satisfied. The solution ( y, z ) restricted to group g achieves the samesolution value as O PT T restricted to the same knapsacks.If g ∈ G (1 /ε ) , i.e., if there are at least ε knapsacks in group g , consider the ⌊ (1 − ε ) m g ⌋ most valuableknapsacks in group g packed by O PT T . Define y c to count how often O PT T uses configuration c ∈ C c in thisreduced knapsack set and let z g,t denote how often O PT T uses item type t ∈ F g in these knapsacks. Clearly,this solution satisfies the first constraint of (P). By construction, P c ∈C g y c ≤ ⌊ (1 − ε ) m g ⌋ ≤ (1 − ε ) m g and,hence, the second constraint of the ILP is also satisfied. Cleary, the ⌊ (1 − ε ) m g ⌋ most valuable knapsackscan be packed into the ⌊ (1 − ε ) m g ⌋ largest knapsacks in g , which implies the feasibility for the fourthconstraint of the ILP. Observe that ⌊ (1 − ε ) m g ⌋ ≥ (1 − ε ) m g − ≥ (1 − ε ) m g . Thus, the value of thecorresponding packing is at least a (1 − ε ) fraction of the value that O PT T obtains with group g .As ( y, z ) uses no more items of a certain item type than O PT T does, the last constraint of the ILP is alsosatisfied. Hence, ( y, z ) is feasible and v LP ≥ X g ∈G ( X c ∈C g y c v c + X t ∈F g z g,t v t ) ≥ (1 − ε ) v ( O PT T ) . The next corollary shows how to round any fractional solution of (P) to an integral solution (possibly)using additional knapsacks given by resource augmentation. It follows immediately from Lemma C.4.
Corollary E.3.
Any feasible solution ( y, z ) of the LP relaxation of (P) with objective function value v canbe rounded to an integral solution using at most L extra knapsacks with total value at least v . In the next lemma, we bound the value obtained by our algorithm in terms of O PT , the optimal solutionfor a given input. Let P F be the solution returned by our algorithm. Lemma E.4.
Let P F be defined as above. Then, v ( P F ) ≥ (1 − ε ) (1 − ε )(1+ ε ) v ( O PT ) .Proof. Observe that our algorithm outputs the solution P ∗ F with the maximum value over all guesses of ℓ max ,the highest value class in O PT . Hence, we give a guess ℓ max and a corresponding solution P that satis-fies v ( P ) ≥ (1 − ε ) (1 − ε )(1+ ε ) v ( O PT ) .Fix an optimal solution O PT and let ℓ max := max { l : V ℓ ∩ O PT = ∅} and set ¯ ℓ := ℓ max − l log( n/ε )log(1+ ε ) m .Then, ℓ max is considered in some round of the algorithm. Hence, let v ILP be the optimal solution to theconfiguration ILP (P) and let v LP be the solution value of its LP relaxation. Corollary E.3 provides a wayto round the corresponding LP solution ( y, z ) to an integral solution (¯ y, ¯ z ) using at most L extra knapsackswith objective function value at least v LP ≥ v ILP . The construction of (¯ y, ¯ z ) guarantees that only small itemsin the original knapsacks might be packed fractionally.Consider one particular group g . Lemma C.5 shows how to pack the fractional small items selectedby (¯ z g ) into εm g extra knapsacks. If m g < ε , we use one extra knapsack per group to store the frac-tional items. If m g ≥ ε , g ∈ G (1 /ε ) which implies that the configuration ILP (and its relaxation) alreadyreserved ⌈ εm g ⌉ knapsacks of this group for packing small items. Hence, P is feasible. By Corollary E.1and Lemma E.2 we have that v ( P F ) ≥ v ( P ) ≥ (1 − ε ) (1 − ε )(1 + ε ) v ( O PT ) . Lemma E.5.
The update time of the dynamic algorithm is boundedby (cid:0) ε log n (cid:1) O (1 /ε ) (log m log S max log v max ) O (1) .Proof. By assumption, upon arrival, the value of each item is rounded to natural powers of (1 + ε ) . Thealgorithm starts with guessing ℓ max the highest value class to be considered in the current iteration. Thereare log v max many guesses possible where v max is the highest value appearing in the current instance.By Lemma 5.4, the harmonic rounding of all items has at most O (cid:16) log nε (cid:17) iterations. The size of theappearing numbers is bounded by O (log max { S max , v } ) , where S max := max S i is the maximal capacityof the given knapsacks.Let the knapsacks be sorted by increasing capacity and stored in a binary balanced search tree as de-fined in Lemma 3.2. Then, the index of the smallest knapsack i with S i ≥ S or the largest knapsackwith S i ≤ S can be determined in time O (log m ) , where S is a given number. Thus, the knapsack groupsdepending on the item types can be determined in time O (log m log nε ) as the number of item types isbounded by O ( log nε ) . The number of big items per knapsack is bounded by ε and, hence, the number ofconfigurations is bounded by O (cid:16) log nε (cid:0) log nε (cid:1) ε (cid:17) .The number of variables in the considered configuration ILP is bounded by N = O (cid:16) log nε (cid:0)(cid:0) log nε (cid:1) ε + log nε (cid:1)(cid:17) = O (cid:0) log /ε nε /ε (cid:1) . Hence, there is a polynomial function g ( N, log S max , log v max ) that bounds therunning time of finding an optimal solution to the LP relaxation of the configuration ILP. Clearly, setting upand rounding the fractional solution is dominated by solving the LP.Combining everything, we can bound the running time of the algorithm by (cid:0) ε log n (cid:1) O (1 /ε ) (log m log S max log v max ) O (1) .In similar time, we can store y and z , the obtained solutions to the configuration LP. Let y ′ and z ′ be thevariables obtained by (possibly) rounding down y and z and let y ′′ and z ′′ be the variables assigned to theresource augmentation by Lemma C.4. Clearly, obtaining these variables is dominated by solving the LPrelaxation of the configuration ILP. Answering Queries
Since we only store implicit solutions, it remains to show how to answer the cor-responding queries. In order to determine the relevant parameters of a particular item, we assume that allitems are stored in one balanced binary search tree that allows us to access one item in time O (log n ) byLemma 3.2. We additionally assume that this balanced binary search tree also stores the value class of anitem. We use again the round parameter t ( j ) and the corresponding knapsack k ( j ) to cache given answersin order to stay consistent between two updates. If j was NOT SELECTED in round t ( j ) , we represent thisby k ( j ) = 0 . We assume that these two parameters are stored in the same binary search tree that also storesthe items and, thus, can be accessed in time O (1) .We now design an algorithm for non-cached items. The high-level idea is identical to the algorithmdeveloped in Section 5.2. As the knapsacks have different capacities in this section, the size class of an itemdepends on the particular knapsack group, i.e., an item can be big with respect to one knapsack and smallwith respect to another. Thus, the distinction between small and big items is not possible anymore and needsto be handled carefully. Table 1 gives an overview over the parameters and counters used to answer queriesbetween two updates.We assume that the knapsacks are sorted by decreasing capacity and stored in one binary search treetogether with S i , the capacity of the knapsacks. The knapsacks given by the resource augmentation are41tored in three different lists R ( y ) , R ( z ) , and R ( ε ) indicating whether they are needed due to rounding y or z ,or because m g < ε . The knapsack groups are stored in the list G sorted by decreasing capacity. For eachgroup, we additionally store m g , the number of knapsacks in group g .Let y ′ , y ′′ , z ′ , and z ′′ be the implicit solution of the algorithm. Here ∗ ′ refers to packing configurations oritems into the original knapsacks while ∗ ′′ refers to the knapsacks given by resource augmentation. Let C ′ g bethe set of configurations c with y ′ c,g + y ′′ c,g ≥ ordered in decreasing size s c and stored in one list per group.In the following, we use the position of a configuration c ∈ C ′ g in that list as the index of c . For mappingthe configurations to knapsacks we assign the knapsacks P g − g ′ =1 m g ′ + 1 , . . . , P gg ′ =1 m g ′ − + P cc ′ =1 y c toconfiguration c .For each item type t , we maintain a pointer γ t to the group where the next queried item of type t issupposed to go. If t is big with respect to γ t , we use again the pointer κ t to refer to the particular knapsackwhere the next item of type t goes while η t stores how many slots κ t still has for items of type t . Because ofresource augmentation, κ t may point to a knapsack in R ( y ) , the additional knapsacks for rounding y .If t is small with respect to γ t , we use group pointers κ rγ t and κ cγ t to refer to the knapsack for packingitems regularly or to the position for packing cut items. If m g < ε , than R ε ( g ) is used for packing cutitems. As the number of items of type t assigned to group g as small items is determined by z ′ g,t + z ′′ g,t , weadditionally use the counter η t , initialized with z ′ γ t ,t + z ′′ γ t ,t , to reflect how many slots group γ t still has foritems of type t . As before, ρ g refers to the remaining space for small items in the knapsack κ rg . Because ofresource augmentation, both knapsack pointers may point to a knapsack given by resource augmentation. Answering Item Queries. Check cache.
Let τ be the current round and let j be the queried item. If t ( j ) = τ , return k ( j ) .2) Answer queries for non-cached items.
Set t ( j ) = τ and determine t , the type of j . Let γ be thegroup of t . If γ = 0 , return NOT SELECTED . Decide if j is small or big with respect to the group γ . Small items. If η t = z ′′ γ,t , determine if j goes to the resource augmentation R ( z ) :If z ′′ γ,t = 1 , set k ( j ) to the knapsack in R ( z ) reserved for z ′′ γ,t and increase γ t to the next group fortype t . If no such group exists, set γ t = 0 . Otherwise, update η t and possibly κ t accordingly.If z ′′ γ,t = 0 , increase γ t to the next group for type t and go to Step 2. If no such group exists,set γ t = 0 , k ( j ) = 0 , and return NOT SELECTED .Otherwise, determine if j is packed regularly or as a cut item. If s t ≤ ρ γ , return k ( j ) = κ rγ anddecrease ρ γ accordingly. Otherwise, return k ( j ) = κ cγ and increase κ cγ to the next position for “cut”items in group γ . Big items. If γ t = 0 , return NOT SELECTED and set k ( j ) = 0 . Otherwise, return k ( j ) = κ t anddecrease η t by one. If this implies η t = 0 , let c be the configuration of κ t .If κ t ∈ R ( y ) , let c ′ be the next configuration for type t in group γ and update κ t and η t accordingly. Ifno such configuration exists, increase γ t to the next group for type t and update κ t and η t accordingly.If no such group exists, set γ t = 0 .If κ t belongs to the original knapsacks and is the last knapsack assigned to configuration c , check ifthere is resource augmentation for configuration c . In this case, point κ t to the knapsack reserved forrounding y ′′ c,γ . Otherwise, let c ′ be the next configuration for type t in group γ and update κ t and η t accordingly. If no such configuration exists, increase γ t to the next group for type t and update κ t and η t accordingly. If no such group exists, set γ t = 0 .Otherwise, increase κ t by one and update η t accordingly.42 able 1: Counters and parameters used during querying items.
Counter/Pointer Meaning C ′ g Configurations that are used by group gα c,g First knapsack with configuration c in group gR ( y ) c,g Knapsack in R y used for group g and configuration cR ( z ) g,t Knapsack in R z used for group g and type t G t Knapsack groups where items of type t are packed γ t Current knapsack group where items of type t are packed κ rg Current knapsack in g for packing small items regularly κ cg Current knapsack in g (or in R ε ) for packing cut small items ρ rg Remaining capacity in κ rg for packing small items η rf Remaining number of slots for small items in κ rf C g,t List of configurations c ∈ C ′ g with n c,t ≥ κ t Current knapsack for packing items of a big type tη t Remaining number of slots for items of type t in κ t or in γ t depending on the size of t with respect to γ t . Answering the Solution Value Query. Value per item type.
For each item type t , calculate v t , the total value of the first ¯ n t items with prefixcomputation.2) Value.
Return P t ∈T v t . Answering the Solution Query. • For each item type t , query the first ¯ n t items and return these items with their knapsacks. Lemma E.6.
The query algorithms return a feasible and consistent solution obtaining the total value givenby the implicit solution.Proof.
By construction of k ( j ) and t ( j ) , the solution returned by the query algorithm is consistent betweenupdates.Observe that y ′ and z ′ is a feasible solution to the configuration ILP (P). Hence, showing that thealgorithm does not assign more than y ′ c,g times configuration c and not more than z ′ g,t items of type t togroup g is sufficient for having a feasible packing of the corresponding elements into the ⌊ (1 − ε ) m g ⌋ largest knapsacks if m g ≥ ε or into the m g knapsacks of group g if m g < ε .If the item type t is small with respect to the group g , then at most z ′ g,t items of type t are packed ingroup g . Then, Lemma C.5 ensures that all small items assigned to group g fit in the regular and the “cut”-items knapsack. Moreover, the treatment of η t = z ′′ g,t guarantees that the value obtained by small itemspacked in g and its additional knapsacks is as claimed by the implicit solution.If t is big with respect to group g , then the construction of κ t and η t ensure that exactly P c ∈C ′ g ( y ′ c + y ′′ c ) n c,t items of type t are packed in group g and in R ( y ) . Hence, the total value achieved is as given by theimplicit solution.The next lemmas are concerned with the running time of the algorithms used for answering queries.Table 1 summarizes the counters and pointers used in the proof. Lemma E.7.
The above mentioned data structures can be generated in O (cid:16) log nε log /ε nε /ε (cid:17) many iterations.Queries for a particular item can be answered in O (cid:16) log nε (cid:17) many steps. roof. We start by retracing the steps of the dynamic linear grouping in order to obtain the set T of itemtypes. We store the types T ℓ of one value class in one list, sorted by non-decreasing size. By Lemma 5.4,the set T can be determined in time O ( log nε ) .We first argue about the generation of the data structures and the initialization of the various pointersand counters. We start again by generating a list α g for each group g where α c,g stores the first (original)knapsack of configuration c ∈ C ′ g . Then, α c,g = α c − ,g + y ′ c − ,g + 1 where α ,g = 0 . Then, we set R ( z ) g,t = P g − g ′ =1 P t ∈T z ′′ g,t and R ( y ) c,g = P g − g ′ =1 P t ∈C ′ g y ′′ g,t , where R ( z ) g,t corresponds to the resource augmentationneeded because of rounding z g,t and R ( y ) c,g corresponds to the resource augmentation caused by rounding y c,g .Then, these lists can be generated by iterating through the list C ′ g for each group g in time O ( P g ∈G |C g | ) = O ( log nε log /ε nε ε/ ) .For maintaining and updating the pointer γ t , we generate the list G t that contains all groups g whereitems of type t are packed in the implicit solution. By iterating through the groups once more and check-ing P c ∈C ′ g ( y ′ c,g + y ′′ c,g ) n t,c ≥ or z ′ t,g + z ′′ g,t ≥ , we can add the corresponding groups g to G t . Then, γ t points to the head of the list. Note that the appearing numbers are bounded by O ( |C g | n ) . While iterat-ing through the groups, we also calculate ¯ n t = P g ∈G (cid:0) P c ∈C ′ g ( y ′ c,g + y ′′ c,g ) + z ′ t,g + z ′′ t,g (cid:1) and store thecorresponding value together with the item type. The lists G t can be generated in O ( |T | P g ∈G |C g | ) = O (cid:16) log nε log /ε nε /ε (cid:17) many iterations.For maintaining and updating the pointer κ t we create the list C g,t storing all configurations c ∈ C ′ g where t is packed as big item. While iterating through the groups and creating G t , also checking y ′ c,g + y ′′ c,g ≥ for each configuration allows us to add c to the list C g,t where we also store n c,t . Initially, we point κ t tothe head of the first group g where t is packed as big item. If c is the corresponding configuration, we startwith η t = n c,t . Then, the time needed for this is bounded by O ( |T | P g ∈G |C g | ) = O (cid:16) log nε log /ε nε /ε (cid:17) .The pointer κ rg is initialized with κ rg = P g − g ′ =1 m g + 1 . By using binary search on the list C ′ g , we get s ,the total size of configuration 1 assigned to κ rg , and binary search over the knapsacks allows us to obtain S κ rg ,the capacity of knapsack κ rg . Then, ρ g = S κ rg − s can be initialized in time O ( P g ∈G (log( |C ′ g | ) + log m ) = O (cid:16) log nε (cid:0) log log nε + log m (cid:1)(cid:17) .If m g ≥ ε , we set κ cg = P g − g ′ m g + ⌊ (1 − ε ) m g ⌋ + 1 while m g < ε implies that κ cg points to theresource augmentation R ( ε ) , i.e., κ cg = R ( ε ) g = |{ g ′ ≤ g : m g ′ < ε }| . The time needed for initializingis O ( |C ′ g | ) while the numbers are bounded by m and |C ′ g | . In order to determine the position of the next cutitem, we also maintain η g , initialized with η cg = ε , that counts how many slots are still left in knapsack κ cg .Now consider the query for an item j . In time O (log n ) we can decide if j has already been queried inthe current round. Upon arrival of j , we calculated its value class V ℓ . By retracing the steps of the lineargrouping, the boundaries of value class V ℓ can then be determined in time O ( log nε ) . By binary search, theitem type of j can then be determined in time O (log log nε ) . Once the item type is determined, we checkif j belongs to the first ¯ n t items of this type. If not, then NOT SELECTED is returned. Otherwise, thepointer γ t answers the question in which group item j is packed. The pointer γ t is updated at most once before determining k ( j ) . Hence, the case distinction on the relative size of type t is invoked at most twice.If j is small, the knapsack k ( j ) can be determined in constant time by nested case distinction and havingthe correct pointer (either κ rγ t or κ cγ t ) dictate the answer. Returning the answer then takes time O (log m ) .In order to bound the update time of the data structures, it suffices to consider the case where j is packedas a cut item since this implies the most updates. The capacity of the new knapsack κ rγ t can be determinedin O (log m ) by binary search over the knapsack list while the configuration c of the new knapsack κ rγ t andits total size are determined by binary search over the list α γ t in time O (cid:16) log |C ′ γ t | (cid:17) = O (cid:16) log(log( n ) /ε ) ε (cid:17) .44hen, ρ γ t = S κ rγt − s c can be computed with constantly many operations while the appearing numbersare bounded by O ( S max ) . If η cγ t = 0 after packing j in κ cγ t , we increase the knapsack pointer by one andupdate η cγ t = ε .If j is big, the pointer κ γ t dictates the answer which can be returned in time O (log m ) . For bound-ing the running time of the possibly necessary update operations, observe that η t is updated in constanttime with values bounded by n . If η t = 0 after the update, the knapsack pointer κ t needs to be up-dated as well. The most time consuming update operations are finding a new configuration c ′ and possi-bly even a new group g ′ . Finding c ′ ∈ C γ t ,t can be done by binary search through the list C γ t ,t in time O (cid:16) log |C ′ γ t ,t | (cid:17) = O (cid:16) log(log( n ) /ε ) ε (cid:17) . To update κ t and η t , we extract the configuration c ′ from the list α γ t and n c,t from the list C ′ γ t ,t in O (cid:16) log |C ′ γ t | (cid:17) = O (cid:16) log(log( n ) /ε ) ε (cid:17) by binary search with values bounded by m and n respectively. If the algorithm needs to update γ t as well, this can be done by binary search on thelist G t in time O (log |G t | ) = O (cid:16) log (cid:0) log( n ) ε (cid:1)(cid:17) .In both cases, the running time of answering the query and possibly updating data structures is boundedby the running time of the linear grouping step, i.e., by O ( log nε ) . Lemma E.8.
A query for the solution value can be answered in time O (1) .Proof. For calculating the value of the current solution, we need to calculate v t , the total value of the first ¯ n t items. We do this by iterating through the value classes once and per value class, we iterate once throughthe list T ℓ to access the number ¯ n t . Then, we use prefix computation twice in order to access the total valueof the first ¯ n t items of type t . Lemma 3.2 bounds this time by O (log n ) . By Lemma 5.3, the number of itemtypes is bounded by O (cid:0) log nε (cid:1) . Combining these two values bounds the total running time by O (cid:0) log nε (cid:1) .As this time is clearly dominated by obtaining the implicit solution in the first place, we precalculate thesolution value when computing the implicit solution value and store it to return it in O (1) . Lemma E.9.
A query for the complete solution can be answered in time O (cid:0) | P | log nε (cid:1) where P is the currentsolution.Proof. For returning the complete solution, we iterate once through the value classes and for each valueclass, we iterate through the list T ℓ to access the number ¯ n t . Then, we use prefix computation on index foraccessing the corresponding ¯ n t items of type t . We access and query each item individually. Lemma E.7bounds the running time of these queries by O (cid:0) log nε (cid:1) while Lemma 3.2 bounds the running time for access-ing item j . Lemma 5.3 bounds the number of item types. In total, the running time is bounded by O (cid:0) | P | log ε (cid:1) where P is the current solution. Proof of main result
Proof of Theorem 6.3.
In Lemma E.4, we bound the approximation ratio achieved by our algorithm.Lemma E.5 gives the desired bound on the update time. Lemmas E.7 to E.9 additionally bound the timeneeded for answering a query.
F M
ULTIPLE K NAPSACK
Analysis.
We consider the iteration in which all the guesses, V ℓ max , k and S O are correct. Let P be the setof solutions on the ordinary knapsacks (without the additional virtual knapsack) and the special knapsackssuch that the total size of ordinary items placed in special knapsacks lies in the range [ S O , (1 + ε ) S O ] .45enote by O PT a solution of highest value in P . Altering O PT by deleting the extra knapsacks gives asolution in P of value at least (1 − ε ) · v ( O PT ) . This holds since for correct guesses the yellow knapsacksby definition contribute at most an ε -fraction to O PT . Further, the correctness of the guessed S O implies thatthe altered O PT is indeed a packing in P . Observation F.1.
For O PT defined as above, we have v ( O PT ) ≥ (1 − ε ) · v ( O PT ) . Lemma F.2.
Consider an optimal solution O PT O to the ordinary subproblem, i.e., exclude items in J E butinclude the virtual knapsack. Then v ( O PT O ) ≥ v ( O PT ,O ) − ε · v ( O PT ) , where we use the shorthand O PT ,O := ( O PT ∩ J O ) \ J E .Proof. Consider the ordinary items in O PT that are not in J E . Leave items on ordinary knapsacks in theircurrent position and place ordinary items on special knapsacks into the virtual ordinary knapsack. The latteris possible with the exception of possibly an ε -fraction of the items (with respect to size) due to S O beingrounded down. Deleting the least dense items until the remainder fits into the virtual knapsack causes a lossof at most an ε -fraction of the value of O PT plus an additional ordinary item j O . This item j O contributesat most an ε -fraction to O PT as its value is not larger than that of the least valuable element in J E which hasa value of less than εv ( O PT ) . Lemma F.3.
Let P F be the final solution the algorithm computes. Then v ( P F ) ≥ (1 − ε ) v ( O PT ) .Proof. Consider P O , the solution of the ordinary subproblem returned by the algorithm of Appendix E(including virtual knapsack and resource augmentation). We know that v ( P O ) ≥ (1 − ε ) · v ( O PT O ) ≥ v ( O PT ,O ) − ε · v ( O PT ) by Theorem 6.3 and Lemma F.2.Let O PT S := O PT ∩ J S , and P := P O ∪ O PT S ∪ J E . Then, O PT = O PT ,O ∪ ( O PT ∩ J E ) ∪ ( O PT ∩ J S ) implies v ( O PT ) = v ( O PT ,O ) + v ( O PT ∩ J E ) + v ( O PT ∩ J S ) ≤ v ( P O ) + 3 εv ( O PT ) + v ( J E ) + v ( O PT S ) ≤ v ( P ) + 3 εv ( O PT ) . With Observation F.1 we then obtain v ( P ) ≥ v ( O PT ) − εv ( O PT ) .We now modify P to obtain a solution P that lacks the virtual ordinary knapsack and deals withbundles instead. Build L S ε equal-sized bundles from P O as in Step 5). Place these bundles fractionallyon the remaining space of the special knapsacks that is left after O PT S is packed. This space is sufficientby definition of S O and P . Arrange the bundles such that the lowest-value ones are placed fractionallyand removing them from the solution incurs a loss of at most εv ( O PT ) . Further, remove the items placedfractionally among bundles. Since there are at most L S ε of these with value smaller than the L S ε items in J E ,this incurs a loss of at most εv ( O PT ) .Therefore, v ( P ) ≥ v ( P ) − εv ( O PT ) . Moreover, the portion of P on special knapsacks is a valid so-lution for the request sent to the special subproblem. Therefore, using Theorem 6.2, the overall solution P F satisfies v ( P F ) ≥ (1 − ε ) v ( O PT ) . Lemma F.4.
The algorithm has update time (cid:0) ε log( nv max ) (cid:1) f (1 /ε ) + O ( ε log v log n ) , where f is a quasi-linear function.Proof. Guessing k adds a factor of ε to the update time. Placing the L S ε most valuable ordinary itemson extra knapsacks and removing them from data structures takes time O ( L S ε log n ) which is within thetime bound. The same holds for the updates of the ordinary and special data structures and for solving thesubproblems with the algorithms of Appendices B and E.46utting the items placed in the virtual ordinary knapsack info L S ε equal-sized bundles can be archivedefficiently as follows. Compute the total size of these items, using the number of items used for each of the O ( log nε ) item types and deduce the size of a bundle. Sort the item types, e.g., by value then size, and theniteratively pack items of the same type by computing how many items of this type fit in the next non-emptybundle. This takes time O ( log nε · L S ε ) which is sufficient.Additionally, the maintenance of data structures is dominated in runtime by that of the subproblems.These takes time O ( ε log v log n ) and cause the additive factor. G Proof of Theorem 3.3
G.1 Hardness of Approximation
The following theorems provides a justification why our algorithms for multiple knapsacks have differentrunning times depending on the number of knapsacks. As Chekuri and Khanna [18] observed, M
ULTIPLE K NAPSACK with m = 2 does not admit an FPTAS unless P = NP.
Theorem G.1 (Proposition 2.1 in [18]) . If M ULTIPLE K NAPSACK with two identical knapsacks has anFPTAS, then P ARTITION can be solved in polynomial time. Hence there is no FPTAS for M ULTIPLE K NAP - SACK even with m = 2 , unless P = NP . In the fully dynamic setting, this implies that there is no dynamic algorithm with running time polyno-mial in log n and ε unless P = NP. There, we are able to extend this result to the case where n + m ≤ ε . Theorem 3.3.
Unless P = NP , there is no fully dynamic algorithm for M ULTIPLE K NAPSACK that main-tains a (1 − ε ) -approximate solution in update time polynomial in log n and ε , for m < ε .Proof. Consider the strongly NP-hard problem 3-P
ARTITION where there are m items with sizes a j ∈ N such that P mj =1 a j = mA . The task is to decide whether there exists a partition S mi =1 J i = [3 m ] suchthat | J i | = 3 and P j ∈ J i a j = A for ≤ i ≤ m .Consider the following instance for D YNAMIC M ULTIPLE K NAPSACK : There are m knapsackswith S = A and m many items. Each item corresponds to a 3-P ARTITION item with s j = a j and v j = 1 for ≤ j ≤ m . Observe that the 3-P ARTITION instance is a Y ES -instance if and only if the optimalsolution to the K NAPSACK problem contains m items.If D YNAMIC M ULTIPLE K NAPSACK admits a dynamic algorithm with approximation guarantee atleast (1 − ε ) and running time polynomial in ε and log n where m < ε , such an algorithm is able tooptimally solve the K NAPSACK instance reduced from 3-P
ARTITION . Thus, such an algorithm decides3-P
ARTITION in polynomial time which is not possible, unless P ==