1 Introduction

In many selection problems, one is given a set N of items and is asked to determine a subset of items \(S \subseteq N\) that maximizes a profit function f(S) under some operational constraints. The most common problem in this family is the well-known Knapsack Problem (KP), in which each item j has associated a weight \(w_j\) (\(\forall j \in N\)) and the capacity constraint imposes that the total weight of the selected items does not exceed a given positive threshold C. In addition, each item j has associated a profit \(p_j\) (\(\forall j \in N\)) and the objective function asks to maximize the sum of the profits of the selected items, i.e., \(f(S) = \sum _{j \in S} p_j\).

The KP can be modeled by the following Integer Linear Program (ILP) formulation:

$$\begin{aligned} \max \left\{ \sum _{j \in N} p_j \, x_j: \sum _{j \in N} w_j x_j \le C, x_j \in \{0,1\}, j \in N \right\} , \end{aligned}$$

where each variable \(x_j\) takes value 1 if and only if item j is inserted in the knapsack. The KP is NP-hard, although in practice fairly large instances can be solved to optimality within low running time. We note that one can assume, without loss of generality, that profits and weights of all items are positive. The reader is referred to [14, 16] for comprehensive surveys on applications and variants of this problem.

Different profit functions f(S) have been studied in the literature but, surprisingly, the natural variant which considers the product of the item profits has not received much attention yet. Considering generic profits, i.e., the case in which each \(p_j\) can take either a positive or a negative value, the profit function studied in this paper is the following:

$$\begin{aligned} f(S) = \prod _{j \in S} p_j. \end{aligned}$$
(1)

More precisely, (1) describes a profit function f(S) that assigns to each feasible set of items S the product of the profits of the items in S. We can now formally define the problem considered in this manuscript, i.e., the Product Knapsack problem (PKP), as follows:

  1. (PKP)

    input: A set \(N = \{1, \ldots , n\}\) of items, the j-th item having a weight \(w_j\)

    and a profit \(p_j\), and a single knapsack with positive capacity C.

    objective: Determine a subset of items \(S \subseteq N\) such that \(\sum _{j \in S} w_j \le C\) and

    \(\prod _{j \in S} p_j\) is maximized.

As usual in knapsack problems, we assume that the weight of each item \(j \in N\) is not larger than the capacity C; indeed, any item k with \(w_k > C\) can be removed from consideration as it cannot be inserted in any feasible solution. In the following we will denote by \(N^{+} = \{j \in N: p_j > 0\}\) and \(N^{-} = \{j \in N: p_j < 0\}\) the sets of items with positive and negative profits, respectively. Without loss of generality, we can assume that all profits are different from zero; indeed, including in the solution an item with null profit would yield a null profit, that we can obtain also by taking no items. Moreover, we note that, without loss of generality, also items with profit in (0, 1] can be excluded. Indeed, the only situation in which an optimal solution contains an item, say k, with \(p_k \in (0,1]\) is the case in which all items have profit in (0, 1] and k is the item with largest profit in N (the only item in the solution).

To the best of our knowledge this is the first paper that specifically addresses the Product Knapsack Problem (PKP); for this reason, we first study the computational complexity of the problem, and then propose effective exact methods to solve it.

Preprocessing of items with negative weights. In the following, we will further assume that all items have a non-negative weight. We now show that this assumption can be done without loss of generality. In particular, we will show that for any instance, say \(I=(n, p, w, C)\), in which some items have negative weights, we can define an equivalent instance, say \(\widetilde{I}= (\widetilde{n}, \widetilde{p}, \widetilde{w}, \widetilde{C})\), with only non-negative weights, whose optimal solution allows to recover the optimal solution of the former instance. Our transformation is based on the following trivial observation:

Observation 1

An optimal solution to PKP must include an even number of items \(j \in N^{-}\).

Let us assume that items are sorted by non-decreasing weights, i.e., all items with negative weight (if any) precede items with non-negative weight. Let \(\bar{n}\) and \(\hat{n}\) denote the number of items with negative weight and the number of items that have both negative weight and profit, respectively. For simplicity, we assume that \(\hat{n}\) is even; later, we will show how to modify the transformation in case \(\hat{n}\) is odd.

Given an instance I with \(\bar{n}>0\), define a new instance \(\widetilde{I}\) as follows: \(\widetilde{n}= n\), \(\widetilde{C}= C - \sum _{j \le \bar{n}} w_j\), and

$$\begin{aligned} \widetilde{w}_j = \left\{ \begin{array}{ll} -w_j &{} \quad \text {if }j \le \bar{n}\\ w_j &{} \quad \text {otherwise,} \end{array} \right. \qquad \qquad \tilde{p}_j = \left\{ \begin{array}{ll} \frac{1}{p_j} &{} \quad \text {if }j \le \bar{n}\\ p_j &{} \quad \text {otherwise.} \end{array} \right. \end{aligned}$$

The transformation above allows us to state the following result:

Proposition 1

Let \(\widetilde{S}^*\) be an optimal solution for instance \(\widetilde{I}\). Then, an optimal solution \(S^*\) for instance I can be computed as follows:

$$\begin{aligned} S^* = \{j \in \widetilde{S}^*: j > \bar{n}\} \cup \{j \notin \widetilde{S}^*: j \le \bar{n}\}. \end{aligned}$$

Proof

First, we show that \(S^*\) is a feasible solution. Indeed, we have

$$\begin{aligned} \sum _{j \in S^*} w_j= & {} \sum _{\begin{array}{c} j \in \widetilde{S}^* \\ j> \bar{n} \end{array}} w_j + \sum _{\begin{array}{c} j \notin \widetilde{S}^* \\ j \le \bar{n} \end{array}} w_j = \sum _{\begin{array}{c} j \in \widetilde{S}^* \\ j > \bar{n} \end{array}} \widetilde{w}_j + \sum _{\begin{array}{c} j \notin \widetilde{S}^* \\ j \le \bar{n} \end{array}} w_j - \sum _{\begin{array}{c} j \in \widetilde{S}^* \\ j \le \bar{n} \end{array}} { w_j} + \sum _{\begin{array}{c} j \in \widetilde{S}^* \\ j \le \bar{n} \end{array}} w_j = \sum _{j \in \widetilde{S}^*} \widetilde{w}_j\nonumber \\&+ \sum _{j \le \bar{n}} w_j \le C \end{aligned}$$

where the last inequality derives from feasibility of solution \(\widetilde{S}^*\) with respect to capacity \(\widetilde{C}\).

Let us denote by z and \(\widetilde{z}\) the optimal solution values of instances I and \(\widetilde{I}\), respectively. We have

$$\begin{aligned} z= & {} \prod _{j \in S^*} p_j = \prod _{\begin{array}{c} j \in \widetilde{S}^* \\ j> \bar{n} \end{array}} p_j \prod _{\begin{array}{c} j \notin \widetilde{S}^* \\ j \le \bar{n} \end{array}} p_j = \prod _{\begin{array}{c} j \in \widetilde{S}^* \\ j> \bar{n} \end{array}} p_j \prod _{\begin{array}{c} j \notin \widetilde{S}^* \\ j \le \bar{n} \end{array}} p_j \prod _{\begin{array}{c} j \in \widetilde{S}^* \\ j \le \bar{n} \end{array}} p_j \prod _{\begin{array}{c} j \in \widetilde{S}^* \\ j \le \bar{n} \end{array}} \frac{1}{p_j} \\= & {} \prod _{\begin{array}{c} j \in \widetilde{S}^* \\ j > \bar{n} \end{array}} \widetilde{p}_j \prod _{j \le \bar{n}} p_j \prod _{\begin{array}{c} j \in \widetilde{S}^* \\ j \le \bar{n} \end{array}} \widetilde{p}_j = \prod _{j \in \widetilde{S}^*} \widetilde{p}_j \prod _{j \le \bar{n}} p_j = \left( \prod _{j \le \bar{n}} p_j\right) \widetilde{z}. \end{aligned}$$

Since \(\hat{n}\) is even, \(\widetilde{z}\) is multiplied by a positive constant and, accordingly, the values of the two solutions are proportional to each other. This implies that an optimal solution of the first problem corresponds to an optimal solution of the second one, and vice-versa.

We conclude the proof showing the transformation in case \(\hat{n}\) is odd. In this case, we define an additional item with index \(\widetilde{n}= n+1\), profit \(\widetilde{p}_{\widetilde{n}} = -\,M\), and weight \(\widetilde{w}_{\widetilde{n}} = 0\), where M is a large (positive) number. It is easy to see that, in this case, any optimal solution includes both item \(\widetilde{n}\) and an odd number of items from set \(N^{-}\). As to the solution values, we have

$$\begin{aligned} \prod _{j \in S^*} p_j = -\frac{1}{M} \prod _{j \in \widetilde{S}^*} \widetilde{p}_j \prod _{j \le \bar{n}} p_j = \left( -\frac{1}{M} \prod _{j \le \bar{n}} p_j\right) \widetilde{z}\end{aligned}$$

which concludes the proof. \(\square \)

Thus, we may assume, without loss of generality, that all weights are positive. In addition, we will assume that all input data are integer numbers; fractions, if any, can be handled by multiplying through a proper factor.

Other nonlinear variants of the Knapsack Problem. Different variants of the nonlinear knapsack problem have been considered in the literature. For example, [9] proposed heuristics for the general mixed integer nonlinear knapsack problem when the objective function is separable. Another relevant variant is the Quadratic Knapsack Problem (QKP). Given an item set S, the QKP profit function reads as

$$\begin{aligned} f(S) = \sum _{j \in S} p_j + \sum _{i \in S} \sum _{j \in S, i < j } a_{ij} \end{aligned}$$
(2)

and considers the pairwise interaction between couples of items. Observe that in this case the \(a_{ij}\) coefficients can take also negative values; thus, the maximum profit item set may be nonmaximal with respect to inclusion, which is a main difference with respect to KP.

QKP has been introduced in the eighties, see [11], and models many real-world applications. Though its simple definition, it is one of the most challenging optimization problems arising in practice, and it attracted a large amount of research. A survey on heuristics, reduction techniques, branch-and-bound algorithms, and approximation results is given in [18], where some QKP applications are also mentioned. The interested reader is referred to [7, 14, 19] for further reading on the topic.

A further generalization of KP arises when considering the profit for item sets with cardinality larger than two. In this case, one is given a family T that contains all item sets with non-zero profit, and the profit for a given item set \(S \in T\) is defined as

$$\begin{aligned} f(S) = \sum _{S' \subseteq S} g(S') \end{aligned}$$
(3)

where \(g(S')\) denotes the (possibly, negative) profit associated with each item set \(S' \in T\). The profit of an item set S defined by (3) takes into account also the contribution of each proper subset \(S' \subset S\).

There are, however, many applications in which the profit of an item set does not involve included subsets, i.e., f(S) does not explicitly depend on the profit \(f(S')\) of all subsets \(S' \subset S\). The resulting class of problems has been addressed in the Computational Social Choice literature, in the context of preference aggregation, voting theory, and ranking systems among others (see, e.g., [8]). We refer the interested reader to the seminal work of [5] where the paradox of multiple elections is studied. For example, consider a situation in which one has to select a number of members for a committee subject to a budget constraint, and the quality of the committee is related to both individual “scores” of the members, and to interrelations between subsets of members. It may happen that two members have high individual scores, but show some incompatibility that produces a negative impact on the quality of the committee, and the same situation may involve a larger number of members of the committee. This kind of situations have been introduced and studied in [23]. Thus, an optimal committee can be determined by taking into account the mutual scores of all subsets of candidate members that may reduce the total quality of the solution found. Similarly, the model above can be used in Multiagents Systems where the interest of some individual agents is conflicting with that of the overall system (see, [12]).

More in general, PKP can be used to model situations in which items are partitioned into two subsets, and a hard constraint imposes that the solution must include an even number of items from one subset. In this case, maximizing the product of the profits of the selected items is a proxy for guiding the solution to include an even number of items from that subset. In the context of Computational Social Choice, PKP models the special case of selection of committee members built starting from two groups of people, i.e., candidates that have to be taken in pairs and the others.

PKP also models a category of knapsack problems where one has to select among two different categories of items, say, “small” and “large” ones. Consider for example a special knapsack divided into compartments, where each compartment can accommodate either a large item or two small ones. Moreover, there are side constraints (e.g., stability when shipping fragile objects) imposing that in a feasible solution each compartment has to be either empty or full. This problem can be modelled as a PKP by assigning a negative profit to the small items while the knapsack constraint limits the total weight.

The Product Knapsack Problem considered in this paper is a special case of the KP with objective function (3). To the best of our knowledge, this is the first paper on this specific nonlinear variant of the KP, whereas a large amount of research has been devoted to 0–1 polynomial optimization. In particular, the most effective approaches either transform the problem at hand into a quadratic one (see, e.g., [6, 20]), or linearize each monomial in the objective function by adding new variables and constraints (see, e.g., [3, 17, 22]).

Paper contribution. In Sect. 2 we introduce possible integer nonlinear and linear programming formulations for PKP; for each integer linear formulation, we discuss how to solve the associated linear programming relaxation and the quality of the corresponding upper bound. In Sect. 3, we give an alternative approach based on a dynamic programming algorithm, and discuss about the complexity of PKP. A computational analysis on the presented models and algorithms on a large set of instances derived from the literature is given in Sect. 4. Finally, Sect. 5 draws some conclusions.

2 Mathematical formulations

In this section we first present a simple mixed integer nonlinear formulation of PKP. Then, we present a reduction of PKP to KP that can be applied under some hypotheses. Finally, we remove these hypotheses and consider the general version of PKP for which we introduce two alternative ILP formulations and study the associated linear programming relaxations.

2.1 Mixed integer nonlinear formulation

We introduce two variables for each item \(j \in N\): a binary variable \(x_j\), which takes value 1 if item j is selected and 0 otherwise, and a continuous variable \(y_j\), which takes value \(p_j\) if item j is selected and 1 otherwise. Then, a mathematical (MINLP) model for PKP can be obtained as follows:

$$\begin{aligned} \max&\prod _{j \in N} y_j&\end{aligned}$$
(4)
$$\begin{aligned}&\sum _{j \in N} w_j x_j \le C&\end{aligned}$$
(5)
$$\begin{aligned}&y_j = 1 + (p_j - 1) x_j&j \in N \end{aligned}$$
(6)
$$\begin{aligned}&x_j \in \{0,1\}&j \in N. \end{aligned}$$
(7)

Objective function (4) maximizes the product of y variables. Constraints (6) define the correct value of each variable \(y_j\) (\(\forall j \in N\)): if \(x_j = 1\), variable \(y_j\) takes value \(p_j\) and item j contributes to the objective function with its profit. If instead \(x_j = 0\) then we have \(y_j = 1\), i.e., item j gives no contribution to the solution profit. Observe that some entries in the objective function (4) can take negative values, hence y variables cannot be bounded to non-negative values. The model has 2n variables (half binary, half continuous) and \(n+1\) linear constraints. The objective function is highly nonlinear as it includes the product of the y variables.

2.2 Reduction to KP

We present here a reduction of PKP to KP that is valid only in case all profits are positive, i.e., \(p_j > 0 \quad \forall j \in N\).

Indeed, observe that in this case we have that each \(y_j\) is strictly positive \(\forall j \in N\). Thus, we can apply the \(\log \) operator to objective function (4) and exploit the fact that \(\log \, \prod _{j \in N} y_j = \sum _{j \in N} \log y_j\). This allows us to reformulate MINLP as a separable problem. Observing that \(\log y_j\) is zero if \(x_j=0\), and is equal to \(\log p_j\) otherwise, we can project the y variables out, and obtain the following reformulation

$$\begin{aligned} \max \left\{ \sum _{j \in N} (\log p_j) \, x_j: \sum _{j \in N} w_j x_j \le C, x_j \in \{0,1\}, j \in N \right\} , \end{aligned}$$

that is a standard KP in which each item j has a profit equal to \(\log p_j\).

2.3 First ILP formulation

In this section, we present an ILP formulation for the case \(N^{-} \not = \emptyset \). The ILP model is obtained by explicitly modeling Observation 1 by means of linear constraints, so as to avoid the distinction between items with positive and negative profit. In particular, considering the absolute values of the profits, one can apply the reduction to KP described in the previous section.

More in details, we introduce an additional variable

$$\begin{aligned} \alpha = \text{ Number } \text{ of } \text{ pair } \text{ of } \text{ items } j \in N^{-} \text{ that } \text{ are } \text{ selected } \end{aligned}$$

that is bounded to assume integer values, and obtain the following (ILP1) model:

$$\begin{aligned} \max&\sum _{j \in N} (\log |p_j|) \, x_j&\end{aligned}$$
(8)
$$\begin{aligned}&\sum _{j \in N} w_j x_j \le C&\end{aligned}$$
(9)
$$\begin{aligned}&\sum _{j \in N^{-}} x_j = 2 \alpha&\end{aligned}$$
(10)
$$\begin{aligned}&x_j \in \{0,1\}&j \in N \end{aligned}$$
(11)
$$\begin{aligned}&\alpha \in \mathbb {Z}_+.&\end{aligned}$$
(12)

In the model above, the left-hand-side of constraint (10) counts the number of items with negative profit that are selected. Since variable \(\alpha \) is integer, the effect of this constraint is to impose this number to be even, which makes the resulting solution value positive, i.e., it allows us to have the absolute value of the profits in the objective function.

Let us denote by LP1 the Linear Programming (LP) relaxation of ILP1, obtained by replacing (11) and (12) by \(0 \le x_j \le 1\)   \(\forall j \in N\) and \(\alpha \ge 0\), respectively.

Proposition 2

An optimal solution to LP1 can be computed in linear time.

Proof

Dropping integrality requirement on \(\alpha \) makes constraint (10) immaterial. The remaining problem is the LP relaxation of KP, that can be solved in O(n) time finding the critical item in linear time (see [1]) and applying Dantzig’s algorithm [10]. Given an optimal solution to the LP relaxation of KP, the optimal value for variable \(\alpha \) can be computed a posteriori using (10). \(\square \)

2.4 Second ILP formulation

An alternative ILP formulation for PKP can be obtained by modelling Observation 1 in a different way. Let us define the set \(J = \{(i,j): i \in N^{-}, j \in N^{-}, i < j\}\) containing all distinct pairs (ij) of items that have negative profit, and introduce a binary variable \(z_j\) for each item \(j \in N^{+}\) which takes value 1 if item j is selected and 0 otherwise. In addition, for each pair \((i,j) \in J\), we introduce a binary variable \(\beta _{ij}\) which takes value 1 if both items i and j are selected (and 0 otherwise). Then, a second (ILP2) model for PKP is as follows:

$$\begin{aligned} \max&\sum _{j \in N^{+}} (\log p_j) \, z_j + \sum _{(i,j) \in J} (\log p_i p_j) \, \beta _{ij} \end{aligned}$$
(13)
$$\begin{aligned}&\sum _{j \in N^{+}} w_j z_j + \sum _{(i,j) \in J} (w_i + w_j) \, \beta _{ij} \le C&\end{aligned}$$
(14)
$$\begin{aligned}&{\sum _{i: (i,k) \in J} \beta _{ik}+\sum _{i: (k,i) \in J} \beta _{ki} } \le 1&k \in N^{-} \end{aligned}$$
(15)
$$\begin{aligned}&z_j \in \{0,1\}&j \in N^{+} \end{aligned}$$
(16)
$$\begin{aligned}&\beta _{ij} \in \{0,1\}&(i,j) \in J. \end{aligned}$$
(17)

Variables \(\beta \) are used to model the fact that items in \(N^{-}\) must be selected in pairs in any optimal solution; hence, each variable \(\beta _{ij}\) counts the profit (and weight) of simultaneously packing items i and j. Given that, we can remove the distinction between items with positive and negative profit and apply the reduction given in Sect. 2.2 to define objective function (13). Finally, constraints (15) impose that each item \(k \in N^{-}\) is paired with at most another item \(i \in N^{-}\).

2.5 Comparison between the two ILP models

Observe that the number of variables of model ILP2 is \(|N^{+}| + |N^{-}|(|N^{-}|-\,1)/2\), i.e., it is quadratic in the number of items with negative profits—as opposed to model ILP1 that has a linear size independently of the number of positive and negative items. Furthermore, the first model is smaller also in terms of number of constraints, 2 versus 1 + \(|N^{-}|\). However, the following observation shows that model ILP2 dominates model ILP1 in terms of LP relaxation. As before, let us denote by LP2 the Linear Programming (LP) relaxation of ILP2, obtained by replacing (16) and (17) by \(0 \le z_j \le 1\)   \(\forall j \in N\) and \(0 \le \beta _{ij} \le 1\)   \(\forall (i,j) \in J\), respectively. In addition, let opt(LP1) and opt(LP2) denote the upper bounds produced by relaxations LP1 and LP2, respectively.

Proposition 3

LP2 dominates LP1. Moreover, the ratio \(\frac{opt(LP1)}{opt(LP2)}\) can be arbitrarily large.

Proof

We will show that any feasible solution \((z^*, \beta ^*)\) of LP2 can be converted into a feasible solution \(x^*\) to LP1 that has the same objective function value, and that the opposite is not always possible.

Let \((z^*, \beta ^*)\) be a feasible solution to LP2, and define a solution \(x^*\) as follows

(18)

First, observe that upper bounds on the z variables and constraints (15) ensure that no item is taken more than once. The total weight of the selected items is

$$\begin{aligned} \sum _{k \in N} w_k x^*_k= & {} \sum _{k \in N^{+}} w_k z^*_k + \sum _{k \in N^{-}} w_k \left( \sum _{i: (i,k) \in J} \beta ^*_{ik} +\sum _{i: (k,i) \in J} \beta ^*_{ki} \right) = \sum _{k \in N^{+}} w_k z^*_k\\&+ \sum _{(i,k) \in J} (w_i + w_k) \beta ^*_{ik} \end{aligned}$$

i.e., solution \(x^*\) is feasible by definition. Similarly, plugging \(x^*\) into (8), the solution profit is

$$\begin{aligned} \sum _{k \in N} (\log |p_k|) \, x^*_k= & {} \sum _{k \in N^{+}} (\log |p_k|) z^*_k + \sum _{k \in N^{-}} (\log |p_k|) \left( \sum _{i: (i,k) \in J} \beta ^*_{ik} + \sum _{i: (k,i) \in J} \beta ^*_{ki}\right) \nonumber \\= & {} \sum _{k \in N^{+}} (\log p_k) z^*_k + \sum _{(i,k) \in J} (\log p_i p_k) \beta ^*_{ik} \end{aligned}$$

that is the same profit given by (13).

Consider now the following instance with \(n=3\), profits \(p=(-\,2M, -\frac{1}{M},2)\), weights \(w=(1, 1, 1)\) and capacity \(C=2\), where M is a sufficiently large number. An optimal solution to LP1 is \(x_1 = 1\), \(x_2 = 0\), \(x_3 = 1\) and \(\alpha =1/2\), and has value \(\log 2M + \log 2\), while an optimal solution of LP2 is \(z_3 = 1\) and \(\beta _{1,2}= 1/2\) and has value \(3/2 \log 2\). Thus, the ratio \(\frac{opt(LP1)}{opt(LP2)}\) is arbitrarily large for sufficiently large M. \(\square \)

Though LP2 theoretically dominates LP1 (see Proposition 3), Proposition 4 hereinafter shows that instances for which \(opt(LP2) < opt(LP1)\) are very rare in practice, in particular when the number of items with negative profit is large.

Proposition 4

Let \(x^*\) be an optimal solution of LP1 and \(\bar{N}^{-} = \{j~|~j \in {N}^{-} \text{ and } x^*_j > 0 \}\). If \(|\bar{N}^{-}|\ge 3\), then \(opt(LP1)=opt(LP2)\).

Proof

Using Proposition 3, we have only to show that opt(LP2) cannot be smaller than opt(LP1). To this aim, we construct a solution \((z^*, \beta ^*)\) that is feasible for LP2 and has the same value as solution \(x^*\). Assume w.l.o.g. that N is sorted with items with negative profit first, i.e., \({N}^{-} = \{1,\dots ,|{N}^{-}|\}\) and \({N}^{+} = \{|{N}^{-}|+1,\dots ,|N|\}\). Assume also that the negative-profit items and positive-profit items are sorted separately by non-increasing non-increasing \(\frac{\log |p_j|}{w_j}\) values. Let \(s=|\bar{N}^{-}|\), \(t=s-1\), \(u=s-2\) and assume that s is odd. As observed in the proof of Proposition 2, the optimal solution of LP1 has the same structure as that of the continuous relaxation of the knapsack problem, i.e., all items \(j \in {N}^{-}: j < s\) (including t and u) have \(x^*_j = 1\). Define the following solution:

$$\begin{aligned} z^*_j= & {} x^*_j \quad \text{ for } \text{ each } \text{ item } \quad j \in N^{+}\\ \beta ^*_{j,j+1}= & {} 1 \quad \text{ for } \quad j=1,3,5,\dots ,s-4\\ \beta ^*_{ut}= & {} 1-\dfrac{x^*_{s}}{2}; \quad \beta ^*_{us} = \dfrac{x^*_{s}}{2}; \quad \beta ^*_{ts} = \dfrac{x^*_{s}}{2}, \end{aligned}$$

and all the remaining \(\beta \) variables are set to zero. It is easy to check that solution \((z^*, \beta ^*)\) is feasible for LP2 and its value is

$$\begin{aligned}&\sum _{j \in N^{+}}w_j z^*_j + \sum _{\begin{array}{c} j=1 \\ j \text { odd} \end{array}}^{s-4}\log (p_j p_{j+1}) \beta ^*_{j,j+1} + \log (p_u p_t)\beta ^*_{ut}\\&\qquad + \log (p_u p_s)\beta ^*_{us} + \log (p_t p_s)\beta ^*_{ts}\\&\quad =\sum _{j \in N^{+}}w_j x^*_j + \sum _{\begin{array}{c} j=1 \\ j \text { odd} \end{array}}^{s-4}(\log (p_j)x^*_j + \log (p_{j+1}) x^*_{j+1}) + \log (p_u p_t)\left( 1-\dfrac{x^*_{s}}{2}\right) \\&\qquad + \log (p_u p_s)\dfrac{x^*_{s}}{2} + \log (p_t p_s)\dfrac{x^*_{s}}{2} \\&\quad =\sum _{j \in N^{+}}w_j x^*_j + \sum _{\begin{array}{c} j=1 \\ j \text { odd} \end{array}}^{s-4}(\log (p_j)x^*_j + \log (p_{j+1}) x^*_{j+1}) +\log (p_s)x^*_{s}\\&\qquad +\log (p_t)x^*_{t} +\log (p_u)x^*_{u}. \end{aligned}$$

Similarly, if s is even, let \(v=s-3\) and define the following solution

$$\begin{aligned} z^*_j= & {} x^*_j \quad \text{ for } \text{ each } \text{ item } \quad j \in N^{+}\\ \beta ^*_{j,j+1}= & {} 1, \quad j=1,3,5,\dots ,s-5;\\ \beta ^*_{ts}= & {} x^*_{s}; \beta ^*_{ut} = \dfrac{1-x^*_{s}}{2};\quad \beta ^*_{vt} = \dfrac{1-x^*_{s}}{2};\quad \beta ^*_{vu} = \dfrac{1+x^*_{s}}{2}. \end{aligned}$$

In this case too, all the remaining \(\beta \) variables are set to zero. The value of this solution is

$$\begin{aligned}&\sum _{j \in N^{+}}w_j z^*_j + \sum _{\begin{array}{c} j=1 \\ j \text { odd} \end{array}}^{s-5}\log (p_j p_{j+1}) \beta ^*_{j,j+1} + \log (p_t p_s)\beta ^*_{ts} + \log (p_u p_t)\beta ^*_{ut}\\&\qquad + \log (p_v p_t)\beta ^*_{vt} + \log (p_v p_u)\beta ^*_{vu}\\&\quad =\sum _{j \in N^{+}}w_j x^*_j + \sum _{\begin{array}{c} j=1 \\ j \text { odd} \end{array}}^{s-5}(\log (p_j)x^*_j +log(p_{j+1}) x^*_{j+1}) + \log (p_t p_s)x^*_{s}\\&\qquad +\log (p_u p_t)\dfrac{1-x^*_{s}}{2} + \log (p_v p_t)\dfrac{1-x^*_{s}}{2} + \log (p_v p_u)\dfrac{1+x^*_{s}}{2} \\&\quad =\sum _{j \in N^{+}}w_j x^*_j + \sum _{\begin{array}{c} j=1 \\ j \text { odd} \end{array}}^{s-5}(\log (p_j)x^*_j +log(p_{j+1}) x^*_{j+1}) +\log (p_s)x^*_{s} +\log (p_t)x^*_{t}\\&\qquad +\log (p_u)x^*_{u} +\log (p_v)x^*_{v}. \end{aligned}$$

Thus, the solution has the same profit as \(x^*\), which concludes the proof. \(\square \)

A similar argument shows that \(opt(LP1)=opt(LP2)\) holds also in case \(|\bar{N}^{-}|=2\) provided that \(x^*_{j} = 1~\forall j \in N^{-}\), i.e., the optimal solution of LP1 fully packs exactly two items with negative profit. Therefore, it is very unlikely to generate instances which do not satisfy the requirements of Proposition 4.

We conclude this section by observing that model ILP2 can be viewed as a 0-1 Knapsack Problem with Conflict Graph (KGC) with \(|N^+|+|J|\) items. Objective function (13) and constraints (14), (16), and (17) can be rewritten as a standard KP, while (15) are the conflict constraints, see [24]. The conflict constraints can be represented via a conflict graph, with one node for each item in the knapsack and one edge for each couple of items that can not be taken together in a feasible solution.

The results presented in [4] show that, from a computational point of view, the density (i.e., the ratio between the number of edges and the the cardinality of the edge set of the complete graph having the same number of vertices) of the associated conflict graph can impact the performances of the solution method used to solve one instance of KGC. In our case, the density of the conflict graph can be computed with a closed formula that depends only on \(|N^+|\) and \(|N^-|\). The conflict graph contains \(|N^+|+|J| = |N^{+}| + \dfrac{|N^{-}|(|N^{-}|-\,1)}{2}\) nodes. Since there are \(|N^{-}|\) constraints (15), each involving \(|N^{-}|-\,1\) variables, it is easy to see that the total number of edges is \(\dfrac{|N^{-}| (|N^{-}|-1)(|N^{-}|-2)}{2}\). As \(|N^{+}| = O(n)\) and \(|N^{-}| = O(n)\), the overall density of the graph is O(1 / n), i.e, the resulting conflict graph is sparse for sufficiently large instances. It has been computationally proved in [4, 21] that, for sparse graphs, the direct use of an ILP solver is the most efficient way to solve KGC, whereas more efficient combinatorial methods exist for dense graphs.

3 Dynamic Programming and computational complexity

Dynamic Programming (DP) was introduced by Bellman [2]. Subsequently, several authors proposed DP algorithms for KP (see for example [13] or [15]). In this section we first present a dynamic programming for PKP and then we determine the computational complexity of the problem.

Our DP algorithm (called \(DP_\mathtt{PKP}\)) is composed by n steps. At each step j, the algorithm computes, for each capacity value \(s=0,\dots ,C\), both the most positive and the most negative PKP objective function values that can be obtained using the first j items with a capacity equal to s. All these values can be stored into two matrices \(f_j[s]\) and \(g_j[s]\), and can be computed using the following recursive formulas:

$$\begin{aligned} f_j[s]= & {} \left\{ \begin{array}{ll} \max \{ f_{j-1}[s], p_j \cdot f_{j-1}[s-w_j], p_j \cdot g_{j-1}[s-w_j] \} &{} \quad \text{ if } s \ge w_j; \\ f_{j-1}[s]&{} \quad \text{ otherwise } \end{array} \right. \qquad \end{aligned}$$
(19)
$$\begin{aligned} g_j[s]= & {} \left\{ \begin{array}{ll} \min \{ g_{j-1}[s], p_j \cdot g_{j-1}[s-w_j], p_j \cdot f_{j-1}[s-w_j] \} &{} \quad \text{ if } s \ge w_j; \\ g_{j-1}[s]&{} \quad \text{ otherwise } \end{array} \right. \end{aligned}$$
(20)

with the initialization \(f_0[s] = 1\) and \(g_0[s] = 1\), \(\forall s = 0,\dots ,C\). The optimal PKP solution value is finally given by \(f_n[C]\).

Proposition 5

\(DP_\mathtt{PKP}\) computes an optimal solution value of PKP in O(nC) time.

Proof

The time complexity is obvious, as O(nC) entries have to be computed, each requiring O(1) time. We now prove that the algorithm computes an optimal solution by induction. Assume that \(f_{j-1}\) and \(g_{j-1}\) have been correctly computed for each capacity value s; consider now a capacity value s and evaluate the possible update of the associated \(f_j\) entry—the proof is identical for what concerns the \(g_j\) entry. If \(s < w_j\) then item j cannot be inserted in any feasible solution, hence no update can take place. Otherwise, either the new item is not packed in the partial solution, keeping \(f_j[s]\) unchanged, or item j is selected. In this latter case, if \(p_j > 0\) the new value of \(f_{j}[s]\) is obtained multiplying \(p_j\) by the most positive objective function value obtained with a partial capacity decreased by \(w_j\), i.e., \(p_j \cdot f_{j-1}[s-w_j]\). If instead \(p_j < 0\), a maximum profit solution that packs item j is obtained multiplying \(p_j\) by the most negative objective function value obtained with a partial capacity decreased by \(w_j\), i.e., \(p_j \cdot g_{j-1}[s-w_j]\). In both cases, the update is implemented only in case it is profitable. \(\square \)

To illustrate the algorithm, Table 1 reports matrices f and g for the following numerical example: \(n=4\) (four items), profits \(p=(5,-\,3,-\,4,2)\), weights \(w=(2,1, 1, 1)\) and capacity \(C=3\). Entry \(f_4[3]\) provides the optimal solution value equal to 24.

Table 1 States of algorithm \(DP_\mathtt{PKP}\) for the example instance of four objects and capacity \(C=3\)

A possible implementation of the algorithm is given in Fig. 1. In this scheme, instead of storing two \(n \cdot (C+1)\) matrices for the f and g entries, we use two \(C+1\) vectors. For each item j, these vectors are scanned according to decreasing values of the available capacity s, possibly updating the associated entries. This implementation allows to reduce the memory requirement of the algorithm, yielding some improvements from a computational viewpoint.

Fig. 1
figure 1

Dynamic programming algorithm \(DP_\mathtt{PKP}\)

Finally, it is important to remark that an equivalent version of Algorithm \(DP_\mathtt{PKP}\) can be obtained by storing in f and g the logarithm of the (absolute values of the) products showed in equations (19) and (20). This a crucial step for the practical applicability of the algorithm (see, Sect. 4).

Proposition 6

PKP is weakly NP-hard.

Proof

Given the dynamic programming algorithm above, PKP cannot be strongly NP-hard. We now show that any instance I of KP can be polynomially transformed into an instance \(I'\) of PKP that has the same solution. Let \(I=(n, C, p, w)\) be a KP instance, and define \(I'\) as follows: \(n'=n\), \(C'=C\), \(p'_j = \log ^{-1} p_j\) and \(w'_j = w_j\)   \(\forall j\). Indeed, all profits in \(I'\) are positive and we can apply the reduction introduced in Sect. 2.2, which produces an optimal solution to a KP instance with profits \(\log p'_j = \log \, \log ^{-1} p_j = p_j\), i.e., the same profits as in instance I. \(\square \)

4 Computational experiments

The primary goal of this computational study is to compare the performances of the ILP models discussed in Sect. 2 with the Dynamic Programming algorithm (\(DP_\mathtt{PKP}\)) described in Sect. 3. A second goal of this section is to determine the size of the instances that can be solved to proven optimality within short computing time.

All the experiments have been performed on a computer with a 3.40 Ghz 8-core Intel Core i7-3770 processor and 16Gb RAM, running a 64 bits Linux operating system. All the codes were compiled with g++ (version 4.8.4) using -O3 as optimization option. We have tested the ILP formulations using Cplex 12.6.0, in single-thread mode. All Cplex parameters are at their default values except the optimality tolerances which have been set to 0 to allow a meaningful comparison with the solutions produced by the DP algorithm.

Instances: The PKP is a new problem and, accordingly, no benchmark instances are available in the literature. Nevertheless, since a PKP instance can be easily obtained from a KP instance by introducing items with negative profits, we create a PKP benchmark starting from nine classes of KP instances of the literature. The KP item profits and weights are obtained using the random generator proposed in [15] (available at http://www.diku.dk/~pisinger/codes.html) with the following features, where u.r. stands for “uniformly random integer”:

  1. 1.

    Uncorrelated: \(w_{j}\) u.r. in \([1,{\overline{R}}]\), \(p_{j}\) u.r. in \([1,{\overline{R}}]\).

  2. 2.

    Weakly correlated: \(w_{j}\) u.r. in \([1,{\overline{R}}]\), \(p_{j}\) u.r. in \([\max \{1, w_j-{\overline{R}}/10\},w_j+{\overline{R}}/10]\).

  3. 3.

    Strongly correlated: \(w_{j}\) u.r. in \([1,{\overline{R}}]\), \(p_{j} = w_{j} + {\overline{R}}/10\).

  4. 4.

    Inverse strongly correlated: \(p_{j}\) u.r. in \([1,{\overline{R}}]\), \(w_{j} = p_{j} + {\overline{R}}/10\).

  5. 5.

    Almost strongly correlated: \(w_{j}\) u.r. in \([1,{\overline{R}}]\), \(p_{j}\) u.r. in \([w_{j} + {\overline{R}}/10 - {\overline{R}}/500, w_{j} + {\overline{R}}/10 + {\overline{R}}/500]\).

  6. 6.

    Subset-sum: \(w_{j}\) u.r. in \([1,{\overline{R}}]\), \(p_{j} = w_{j}\).

  7. 7.

    Even-odd subset-sum: \(w_j\) even value u.r. in \([1,{\overline{R}}]\), \(p_{j} = w_{j}\), C odd.

  8. 8.

    Even-odd strongly correlated: \(w_j\) even value u.r. in \([1,{\overline{R}}]\), \(p_{j} = w_{j} + {\overline{R}}/10\), C odd.

  9. 9.

    Uncorrelated with similar weights: \(w_{j}\) u.r. in \([100\,{\overline{R}},100\,{\overline{R}} + {\overline{R}}/10]\), \(p_{j}\) u.r. in \([1,{\overline{R}}]\).

For a given class, a given number of items n, and a specific value of \({\overline{R}}\), the capacity C is defined as a percentage of the total item weight (\(W = \sum _{j=1}^n w_j\)) as follows: \(C= \lfloor \bar{c} \cdot W \rfloor \). where \(\bar{c}\) is another instance-generator parameter. Moreover, C is increased by 1, if even, for classes 7 and 8. Given a KP instance, we define a PKP problem using an additional parameter \(\bar{m}\), that represents the percentage of items with negative profit. In particular, we set \(\bar{n} = \lfloor \bar{m} \cdot n\rfloor \) and change the sign of the profit for \(\bar{n}\) randomly selected items.

Our test bed is divided in two sets. The first set (called set A) consists of instances of small size obtained using the following set of instance-generator parameters: \({\overline{R}} = 1000\); \(n \in \{50, 100,500,1000\}\); \(\bar{c}=0.5\); and \(\bar{m} \in \{0.66, 0.50, 0.25\}\). For each combination of these parameters, one problem is generated for each of the 9 aforementioned classes, thus producing a test bed with 108 instances. The second set (called set B) consists of instances of larger size, and is obtained using the following set of instance-generator parameters: \({\overline{R}} \in \{100,1000,10000\}\); \(n \in \{500, 1000,2000\}\); \(\bar{c} \in \{0.1,0.2,0.3,0.4,0.5,0.6\}\); and \(\bar{m} \in \{0.66, 0.50, 0.25\}\). In this case too, one problem is generated for each combination of the parameters and for each class of KP instances, yielding a benchmark with 1458 problems. Set A is used to compare the performances of the two ILP models, while set B is used to compare the best-performing ILP model against the DP algorithm.

The test bed has been thought to measure the impact on the computational performances of the principal features of a PKP instance, i.e., the instance class, the number of items n, the capacity C, and the percentage of negative-profit items \(\bar{m}\). It is worth mentioning that items in class 9 have, on average, weights that are 2 orders of magnitude larger than in the other classes. Since C is defined as a percentage of the sum of all item weights, and the time complexity of DP is O(nC), these instances are specifically designed to be hard for the DP algorithm. Similarly, increasing the value of \({\overline{R}}\) produces instances with larger W and, hence, harder for the DP algorithm. Preliminary computational experiments showed that the direct application of MINLP solvers to model (4)–(7) is not a viable way for solving these sets of instances. In most of the cases, the optimal solution includes many items, which makes the product of the associated profits (i.e., the objective function value) too large for being stored in the memory of a computer. For this reason, we do not present results for this approach. All the instances considered in our computational analysis are available at the following address: http://or.dei.unibo.it/library/product-knapsack-problem.

Comparison between ILP models. We now compare the computational performances of ILP1 and ILP2, i.e., the models presented in Sects. 2.3 and 2.4, on the instances of set A.

Table 2 Computational comparison between ILP1 and ILP2 for instances set A

Table 2 is horizontally divided in three parts according to the 3 values taken by \(\bar{m}\), i.e., the percentage of items with negative profit. Each line is associated with instances having the same number n of items, and each entry reports the aggregated results concerning 9 instances, one for each class. For both ILP1 and ILP2, we report the average CPU time (in seconds) required by Cplex to solve the model (\(t_{ILP}\)) and to solve its linear programming relaxation (\(t_{LP}\)). We also report the average number of explored nodes in the Branch-and-Cut tree and the size of the model in terms of number of variables (vars) and constraints (cons). In all tests, a time limit of 600 seconds is imposed. For model ILP2, some of the instances are not solved to proven optimality within the time limit; thus, we also report the number of unsolved instances (column T.L.). The average CPU time and number of nodes are computed considering only instances solved within the time limit. As already observed, ILP2 requires \(|N^{+}| + |N^{-}|(|N^{-}|-1)/2\) binary variables, i.e., the size of the formulation grows quadratically with respect to the number of items and may became large in practice, which yields to computationally demanding models. In particular, ILP2 behaves poorly on average on this set of instances, and is unable to solve any instance with \(n=1000\) items within 10 minutes of CPU time. In addition, ILP2 is not capable of solving several instances with \(n\le 500\). On the contrary, ILP1 is able to solve all the instances in a fraction of a second. For this reason, we decided to exclude ILP2 in the following analysis.

It is worth mentioning that, though LP2 is theoretically stronger than LP1, the two models always provide the same upper bound for the instances in set A. Strict dominance applies only for instances with specific characteristics (see Sect. 2.5) and it never happens in our test bed. For this reason, in Table 2 we report only one LP gap for both models (computed as \(\hbox {gap}=100 \cdot \frac{opt(LP)-opt}{opt(LP)}\) where opt(LP) is the optimal solution value of the linear programming relaxation, and opt is the optimal solution value).

Moreover, thanks to an additional set of preliminary experiments, we noticed that LP2 is stronger in practice only for instances where the percentage of items with negative profit \(\bar{m}\) is very small, namely for \(\bar{m} < 0.1\).

Finally, we observe that the LP gap decreases when the number of items increases. This is not surprising as, given a solution of LP1, one can derive a feasible integer solution by removing at most two items, namely the critical item (if any) and possibly one item with negative profit. As the gap is related to the contribution of at most two items, its percentage value decreases when feasible solutions include many items (as in the case in which n is large), similar to what happens to the LP relaxation of the knapsack problem. In addition, we note that the number of nodes explored by ILP2 is always several orders of magnitudes larger than the same figure for ILP1.

Since the solution of LP2 requires considerably more time than LP1, a future line of research could be devoted to the development of a branch-and-price algorithm, generating binary variables on the fly, to reduce the overall CPU time of the associated relaxation.

Table 3 Computational comparison between ILP1 and the DP algorithm for instance set B
Table 4 Computational comparison between ILP1 and the DP algorithm for instances with \({\overline{R}}=100\) and different capacity percentages

Comparison between ILP1 and algorithm \(DP_\mathtt{PKP}\). Tables 3 and 4 report the average CPU times required by algorithm \(DP_\mathtt{PKP}\) and by Cplex for model ILP1 in order to solve to proven optimality the instances of set B. A time limit of 600 seconds is imposed for each run; as for Table 2, we report the number of instances that are not solved to proven optimality (columns T.L.). Table 3 is divided in 9 blocks, one for each class of instances. Each block is horizontally divided in three parts according to the 3 values of \({\overline{R}}\), and each line is associated with instances that share the same number n of items. Each entry reports the average CPU time of the instances solved out of 18 instances, i.e., grouping together the different values of the parameters \({\bar{c}}\) and \(\bar{m}\). The results show that algorithm \(DP_\mathtt{PKP}\) is able to solve to proven optimality all the instances of the first 8 classes, but fails on some problems of class 9. The CPU time of the DP algorithm is directly proportional to the value \({\overline{R}}\) and n, which is not surprising as its computational complexity is O(nC). On the other hand, the computational performance of ILP1 is less predictable, i.e., for many classes of instances there are several problems for which ILP1 hits the time limit. Nevertheless for instances of classes 1 and 9, ILP1 dominates algorithm \(DP_\mathtt{PKP}\). For the instances with \({\overline{R}}=100\) and classes from 2 to 8 the DP algorithm almost always outperforms ILP1. The instances of classes 3 and 8 are the most difficult ones for ILP1, with 6 and 5 unsolved instances, respectively.

Table 4 reports additional results aimed at evaluating the effect of the capacity C on the computational performances of ILP1 and algorithm \(DP_\mathtt{PKP}\). Since the value of the capacity depends on two parameters, \({\overline{R}}\) and \(\bar{c}\), we decided to include in this analysis only instances with the same value of \({\overline{R}}\), namely \({\overline{R}}=100\), and to report results for different values of \(\bar{c}\). Each line of the table is associated with a class of problems, thus entries report aggregated results for the 9 instances obtained with different combinations of parameters n and \(\bar{m}\). We report the results associated with instances that have \(\bar{c} \in \{0.2, 0.4, 0.6, 0.8\}\), i.e., some problems of the instance set B plus some additional instances with \(\bar{c}=0.8\). As for the previous tables, we report the average computing time and, for ILP1, the number of instances that could not be solved to proven optimality within the 600-second time limit. These results clearly show that increasing the capacity produces harder instances for algorithm \(DP_\mathtt{PKP}\), for which the associated CPU time grows almost linearly with parameter \(\bar{c}\). Indeed, while the performances of algorithm \(DP_\mathtt{PKP}\) are strongly dependent on \({\overline{R}}\) and n, the behaviour of ILP1 is less predictable: out of the 22 instances that are not solved to optimality within the time limit, 4 involve 500 items only. In addition, we notice that classes 3 and 8 are the most challenging for ILP1. As to algorithm \(DP_\mathtt{PKP}\), classes from 1 to 8 are equally hard while, as expected, instances of class 9 are instead much harder.

5 Conclusions

In this article we study the PKP which is a variant of the Knapsack Problem in which the objective function optimizes the product of the profits of the selected items. The PKP is particularly interesting in the context of Computation Social Choice since it is a step in the direction of measuring the interaction among the members of a committee. We have demonstrated the computational complexity of the PKP and proposed different linear and nonlinear mathematical formulations. We have introduced a Dynamic Programming algorithm with a pseudo polynomial computational complexity. Finally, an extensive analysis on a large set of instances with diverse characteristics has computationally demonstrated that the Integer Linear Programming model ILP1 and the new DP algorithm proposed are the best performing exact approaches for the PKP.

With this manuscript we hope to stimulate the research in the boundaries of Optimization and Computation Social Choice. An interesting line of research in this direction would be the analysis of others objective functions which take into consideration different kinds of interrelation between the selected members of a committee.