Approximating the product knapsack problem

We consider the product knapsack problem, which is the variant of the classical 0-1 knapsack problem where the objective consists of maximizing the product of the profits of the selected items. These profits are allowed to be positive or negative. We present the first fully polynomial-time approximation scheme for the product knapsack problem, which is known to be weakly NP-hard. Moreover, we analyze the approximation quality achieved by a natural extension of the classical knapsack greedy procedure to the product knapsack problem.

approximation scheme (FPTAS) and can be solved exactly in pseudopolynomial time by dynamic programming (cf. [3]).
The product knapsack problem (PKP) is a new addition to the knapsack family. It has recently been introduced in [1] and is formally defined as follows:

Definition 1 (Product knapsack problem (PKP))
INSTANCE: Items j ∈ N := {1, . . . , n} with weights w j ∈ Z and profits p j ∈ Z, and a positive knapsack capacity C ∈ N + . TASK: Find a subset S ⊆ N with j∈S w j ≤ C such that j∈S p j is maximized.
The solution S = ∅ is always feasible and is assumed to yield an objective value of zero. Note that the assumption that the knapsack capacity as well as all weights and profits are integers is without loss of generality. Indeed, any instance with rational input data can be transformed into an equivalent instance with integer input data in polynomial time by multiplying all numbers by their lowest common denominator.
D'Ambrosio et al. [1] list several application scenarios for PKP, in particular in the area of computational social choice, and also provide pointers to literature on other nonlinear knapsack problems. Furthermore, two different ILP formulations for PKP are presented and compared from both a theoretical and a computational perspective. In addition, D'Ambrosio et al. [1] develop an algorithm performing dynamic programming by weights with pseudopolynomial running time O(nC). A computational study exhibits the strengths and weaknesses of the dynamic program and the ILP approaches for determining exact solutions of PKP depending on the characteristics of the test instances.
Concerning the complexity of PKP, a short proof of weak NP-hardness is given as a side remark in [1]. This proof, however, uses a reduction from KP and requires an exponential blow-up of the profits of the given instance of KP (by putting them into the exponent of 2). Since KP is only weakly NP-hard, this does not prove the desired hardness result. However, a valid NP-hardness proof for PKP has recently been provided in [2], which shows that the problem is weakly NP-hard even when all profits are required to be positive.
Note that this proof requires concepts of advanced calculus. As a possibly useful alternative, we provide a simpler proof using only elementary operations in an extended version of this paper, which is available as a technical report [5].

Our contribution
In this paper, we provide an FPTAS for PKP based on dynamic programming by profits. Since PKP is weakly NP-hard, an FPTAS is the best approximation result possible for the problem unless P = NP. Moreover, the construction of an FPTAS deserves attention since standard greedy-type algorithms do not yield a constant approximation ratio for PKP. We demonstrate this in Sect. 4 by providing a tight analysis of the greedy algorithm obtained by extending the classical greedy procedure for KP to PKP in the natural way.
We do not report computational experiments on the FPTAS or the greedy algorithm. The presented pseudocode descriptions are provided in order to illustrate the algorithms and allow a rigorous analysis of the obtained approximation ratios, but are not optimized for practical efficiency.

Preliminaries
In contrast to KP, both the item weights w j and the item profits p j are allowed to be negative in PKP. However, one can exclude certain weight-profit combinations that yield "useless" items, which leads to the following assumption used throughout the paper:

Assumption 1 Any instance of PKP satisfies:
(a) Any single item fits into the knapsack, i.e., w j ≤ C for all j ∈ N . (b) All profits are nonzero, i.e., p j ∈ Z \ {0} for all j ∈ N . (c) For each item j ∈ N with negative profit p j < 0, there exists another item j ∈ N \ { j} with negative profit p j < 0 such that w j + w j ≤ C. (d) All weights are nonnegative, i.e., w j ∈ N 0 for all j ∈ N . (e) All items with weight zero have negative profit, i.e., p j < 0 if w j = 0.
We note that Assumption 1 imposes no loss of generality and can easily be checked in polynomial time. Indeed, items j ∈ N violating (a), (b), or (c) can never be part of any feasible solution with positive objective value and may, thus, be removed from the instance. The nonnegativity of the weights w j demanded in (d) has been shown to impose no loss of generality in [1]. For (e), we note that items j with w j = 0 can always be assumed to be packed if their profit is positive (but items j with w j = 0 and negative profit remain part of the optimization).
Using Assumption 1 (b), the item set N can be partitioned into N + := { j ∈ N | p j ≥ 1} and N − := { j ∈ N | p j ≤ −1}. For convenience, we define p max := max j∈N | p j |, p + max := max j∈N + p j , and p − max := max j∈N − | p j |. Throughout the paper, we denote an optimal solution set for a given instance of PKP by S * and the optimal objective value by z * . Note that we must always have z * ≥ 1 since packing any item from N + or any feasible pair of items from N − yields an objective value of at least 1.

Definition 2
For 0 < α ≤ 1, an algorithm A that computes a feasible solution set S ⊆ N with j∈S p j ≥ α · z * in polynomial time for every instance of PKP is called an α-approximation algorithm for PKP. The value α is then called the approximation ratio of A.
A polynomial-time approximation scheme (PTAS) for PKP is a family of algorithms (A ε ) ε>0 such that, for each ε > 0, the algorithm A ε is a (1 − ε)-approximation algorithm for PKP. A PTAS (A ε ) ε>0 for PKP is called a fully polynomial-time approximation scheme (FPTAS) if the running time of A ε is additionally polynomial in 1 ε .
Throughout the paper, log(x) always refers to the base 2 logarithm of x and ln(x) refers to the natural logarithm of x.

A fully polynomial-time approximation scheme
We now derive a fully polynomial-time approximation scheme (FPTAS) for PKP based on dynamic programming.
The most common approach for the exact solution of knapsack-type problems in pseudo-polynomial time applies dynamic programming by weights. This means that, for every capacity value d = 0, 1, . . . , C, the largest profit value reachable by a feasible solution is determined, which yields a running time polynomial in C (see [3,Sec. 2.3]). However, for obtaining fully polynomial-time approximation schemes, one usually performs dynamic programming by profits. In this case, for every profit value p up to some upper bound U on the objective function value, the smallest weight required for a feasible solution with profit p is sought, which leads to a running time polynomial in U (see [3,Lemma 2.3.2]). Then, the profit space is simplified in some way, e.g., by scaling (cf. [3, Sec. 2.6]), such that the running time of the dynamic program becomes polynomial and the incurred loss of accuracy remains bounded. D'Ambrosio et al. [1] provide an algorithm solving PKP with dynamic programming by weights, where each entry of the dynamic programming array contains the objective value of a subproblem. However, exchanging the roles of profits and weights (as it is done, e.g., for KP, see [3, Sec. 2.3]), would require a dynamic programming array of length O( p n max ), which is exponential and does not permit a suitable scaling procedure. An obvious way out of this dilemma would be the application of the logarithm to the profits. In fact, such an approach is suggested as a side remark in [1,Sec. 3] for dynamic programming by weights (without commenting on the details of the rounding process). For dynamic programming by profits, however, the profit values must be mapped to integers as indices of the dynamic programming array and there seems to be no way to preserve optimality in such a process. It should also be noted that applying any kapproximation algorithm for KP to the instance resulting from logarithmization would only yield a (1/z * ) 1/k -approximation for PKP. Thus, constant-factor approximations for PKP require different approaches.
We now construct a scaled profit space that actually yields a (1 − ε)-approximation for PKP. Our scaling construction is based on a parameter K > 0 depending on ε, which will be defined later. For every item j, we define an integer scaled profit value in the logarithmized space asp Since | p j | ≥ 1, we havep j ≥ 0, and we obtainp j = 0 if and only if | p j | = 1.
Note that an item j with p j = −1 andp j = 0 might still be useful for changing the sign of the solution of PKP. Analogous to p max , we definep max := log( p max ) K . Ruling out trivial instances, we can assume without loss of generality that p max ≥ 2, so log( p max ) ≥ 1.
Regarding the computability of the scaled profitsp j , we observe that their definition involves logarithms log(| p j |), which cannot be computed exactly in polynomial time.
However, these logarithms only appear in expressions that are rounded to integers, so we do not have to compute these values exactly.
We define the following dynamic programming arrays for profit valuesp = 0, 1, . . . , n ·p max : Note that the empty set has even cardinality. For convenience, we set the minimum over the empty set equal to +∞. The computation of these arrays can be done by the following recursion, which is related to Algorithm DP PKP in [1, Fig. 1]: If p j ≥ 1, then: The obvious initialization is given by W + 0 (0) := 0 and setting all other entries (including the hypothetical ones withp < 0) to +∞.
The approximate solution set S A is represented by the array entry with max{p | W + n (p) ≤ C}. It follows by construction that S A maximizes the total profit in the associated instance of KP with scaled profitsp j among all subsets of N that fulfill the weight restriction and contain an even number of items from N − . In the following, we show that, by choosing the set S A yields a (1 − ε)-approximation for PKP and can be computed in polynomial time via the above dynamic programming procedure. To this end, we use the following two lemmas: Proof The statement follows since, for any x ∈ (0, 1), we have Lemma 2 Any optimal solution set S * for PKP satisfies j∈S * log(| p j |) ≥ log( p max ).
Proof Let j max ∈ N denote an item with | p j max | = p max . If p j max > 0, then the set { j max }, which is feasible for PKP by Assumption 1 (a), has objective value p max . If p j max < 0, Assumption 1 (c) implies that there exists another item j = j max with p j < 0 such that { j max , j } is feasible for PKP, and this set has objective value p j · p j max ≥ p max since p j ≤ −1 by Assumption 1 (b). Thus, in both cases, the optimality of S * for PKP implies that

Proposition 1 The running time for computing S A is in O( n 4 ε log( p max )), which is polynomial in 1/ε and encoding length of the input of PKP.
Proof Clearly, for each of the n items, one has to pass through the whole length of the two dynamic programming arrays. Therefore, the total running time is in

Proposition 2 The set S A yields a (1 − ε)-approximation for PKP.
Proof The proof consists of two parts. First, we analyze the effect of scaling by K and rounding down in (1) by showing that S A yields an objective value close to the value of an optimal solution set S * for PKP in the associated instance of KP with profits log(| p j |). The argumentation closely follows the standard FPTAS for KP (see [3, Sec. 2.6]): To obtain the second inequality in (3), we exploited the optimality of S A for the KP instance with profitsp j . We now set Then, using the definition of K in (2) and that ε ≤ − log(1 − ε) for ε ∈ (0, 1), we obtain and using that j∈S * log(| p j |) ≥ log( p max ) by Lemma 2, the chain of inequalities in (3)-(4) yields that In the second part of the proof, we simply raise two to the power of both sides of this inequality, i.e., 2 j∈S A log(| p j |) ≥ 2 j∈S * log(| p j |) Here, the right inequality in (6) is derived from the trivial bound z * ≤ ( p max ) n , and the second equality in (7) from the definition of ε in (5). Recalling that S A contains an even number of items from N − , the claim follows.
Propositions 1 and 2 immediately yield the following theorem: Theorem 1 There exists an FPTAS with running time in O( n 4 ε log( p max )) for PKP. We conclude this section with an example illustrating how the FPTAS works.
Example 1 Consider the instance of PKP given by the n = 5 items with profits and weights as shown in Table 1 and a knapsack capacity of C := 9. We choose ε = 0.025 so that K = ε n 2 = 0.001.
For this instance, the FPTAS finds the optimal solution set S * = {3, 5} during the computation of W + 5 (10001), which is given as follows: Here, W + 4 (10001) = +∞ since a scaled profit of 10001 cannot be obtained by any subset S ⊆ {1, 2, 3, 4} containing an even number of items from N − , and W − 4 (10001) = 5 since a scaled profit of 10001 is reachable by the subset S = {3} ⊆ {1, 2, 3, 4} that contains an odd number of items from N − . Thus, the solution set corresponding to the array entry W + 5 (10001) is {3, 5} = S * , and sincep = 10001 is indeed the highest value ofp for which W + 5 (p) ≤ C = 9, this is also the set S A returned by the FPTAS.

A greedy-type algorithm
For KP, the classical greedy procedure is probably one of the most obvious first attempts for anybody confronted with the problem. Hence, it is interesting to evaluate the performance of a variant of this greedy procedure also for PKP.
It is known that, for obtaining a bounded approximation ratio for KP in the classical greedy procedure, one has to take into account also the item with largest profit as a singleton solution (cf. [3, Sec. 2.1]). Extending this requirement to the negative profits allowed in PKP, we additionally determine, among all items with negative profits, a feasible pair of items with largest profit product. Moreover, if the greedy solution contains an odd number of items from N − , we simply remove the negative-profit item whose profit has the smallest absolute value. This leads to the following natural greedy algorithm for PKP, which we refer to as Product Greedy: S :=S 8: end if 9: Let { j 1 , j 2 } ⊆ N − be a pair of items with w j 1 + w j 2 ≤ C maximizing the profit product p j 1 · p j 2 over all such pairs. 10: Let j + max := argmax{ p j | j ∈ N + } be an item with largest positive profit. 11: return the best among the three solutions S, { j 1 , j 2 }, and { j + max }.
We note that, since log(| p j |)/w j = log | p j | 1/w j and the logarithm is a strictly increasing function, the sorting and renumbering of the items in step 1 of Product Greedy can equivalently be done by sorting the items in nonincreasing order of | p j | 1/w j , which means that the values log(| p j |)/w j do not have to be computed in the algorithm.
Let j + max := argmax{ p j | j ∈ N + } denote an item with largest positive profit (i.e., with p j + max = p + max ) as in Product Greedy. Similarly, we let j − max := argmax{| p j | | j ∈ N − } denote an item with smallest negative profit (i.e., with − p j − max = p − max ). Then, by Assumption 1 (c), there exists another item in N − that can be packed into the knapsack together with j − max . This implies that the profits of the items j − and j 1 , j 2 considered in Product Greedy satisfy In the following analysis, we denote the objective value obtained by Product Greedy by z H .

Proof
The algorithm clearly runs in polynomial time. In order to analyze its approximation ratio, let s ∈ N be the split item, i.e., the first item in the given order that cannot be packed into the knapsack anymore during the greedy procedure performed in step 2. Similar to the analysis of the greedy procedure for KP, the analysis concentrates on the split solution, i.e., the set of itemsS = { j ∈ N | j ≤ s − 1} produced in step 2 of Product Greedy. We distinguish two cases depending on the number of items with negative profits inS and, for each of the two cases, two subcases depending on the sign of the profit p s of the split item s: Case 1: |S ∩ N − | is even. In this case, the solution S =S is considered when choosing the best solution in step 11. Consider the sign of the split item's profit. If p s > 0, then Obviously, we also have log(z H ) + log( p + max ) ≥ s j=1 log(| p j |).
Similarly, if p s < 0, then where the third inequality follows from (8). Moreover, we have log(z H )+log( p − max ) ≥ s j=1 log(| p j |). Case 2: |S ∩ N − | is odd. In this case, the solution S =S \ { j − } is considered when choosing the best solution in step 11. If p s > 0, we obtain Moreover, we have log(z H ) + 2 log( p − max ) ≥ s j=1 log(| p j |). Summarizing all four cases, we always have 3 · log(z H ) ≥ s j=1 log(| p j |). Then, since s j=1 log(| p j |) is an upper bound on the optimal objective value of the LP relaxation of the associated instance of KP with profits log(| p j |) (see, e.g., [3]), in the article's Creative Commons licence, unless indicated otherwise in a credit line to the material. If material is not included in the article's Creative Commons licence and your intended use is not permitted by statutory regulation or exceeds the permitted use, you will need to obtain permission directly from the copyright holder. To view a copy of this licence, visit http://creativecommons.org/licenses/by/4.0/.