The quadratic knapsack problem (QKP), first introduced in 19th century,[1] is an extension of knapsack problem that allows for quadratic terms in the objective function: Given a set of items, each with a weight, a value, and an extra profit that can be earned if two items are selected, determine the number of items to include in a collection without exceeding capacity of the knapsack, so as to maximize the overall profit. Usually, quadratic knapsack problems come with a restriction on the number of copies of each kind of item: either 0, or 1. This special type of QKP forms the 0-1 quadratic knapsack problem, which was first discussed by Gallo et al.[2] The 0-1 quadratic knapsack problem is a variation of knapsack problems, combining the features of unbounded knapsack problem, 0-1 knapsack problem and quadratic knapsack problem.
Specifically, the 0–1 quadratic knapsack problem has the following form:
maximize
n | |
\left\{\sum | |
i=1 |
pixi+
n | |
\sum | |
j=1,i ≠ j |
Pijxixj:x\inX,xbinary\right\}
subjecttoX\equiv\left\{x\in\{0,1\}n:
n | |
\sum | |
i=1 |
wixi\leqW;xi\in\{0,1\}fori=1,\ldots,n\right\}.
Here the binary variable xi represents whether item i is included in the knapsack,
pi
Pij
Informally, the problem is to maximize the sum of the values of the items in the knapsack so that the sum of the weights is less than or equal to the knapsack's capacity.
As one might expect, QKP has a wide range of applications including telecommunication, transportation network, computer science and economics. In fact, Witzgall first discussed QKP when selecting sites for satellite stations in order to maximize the global traffic with respect to a budget constraint. Similar model applies to problems like considering the location of airports, railway stations, or freight handling terminals.[3] Applications of QKP in the field of computer science is more common after the early days: compiler design problem,[4] clique problem,[5] [6] very large scale integration (VLSI) design.[7] Additionally, pricing problems appear to be an application of QKP as described by Johnson et al.[8]
In general, the decision version of the knapsack problem (Can a value of at least V be achieved under a restriction of a certain capacity W?) is NP-complete.[9] Thus, a given solution can be verified to in polynomial time while no algorithm can identify a solution efficiently.
The optimization knapsack problem is NP-hard and there is no known algorithm that can solve the problem in polynomial time.
As a particular variation of the knapsack problem, the 0-1 quadratic knapsack problem is also NP-hard.
While no available efficient algorithm exists in the literature, there is a pseudo-polynomial time based on dynamic programming and other heuristic algorithms that can always generate “good” solutions.
While the knapsack problem is one of the most commonly solved operation research (OR) problems, there are limited efficient algorithms that can solve 0-1 quadratic knapsack problems. Available algorithms include but are not limited to brute force, linearization,[10] and convex reformulation. Just like other NP-hard problems, it is usually enough to find a workable solution even if it is not necessarily optimal. Heuristic algorithms based on greedy algorithm, dynamic programming can give a relatively “good” solution to the 0-1 QKP efficiently.
The brute-force algorithm to solve this problem is to identify all possible subsets of the items without exceeding the capacity and select the one with the optimal value. The pseudo-code is provided as follows:
int max = 0for all subset S do int value, weight = 0 for i from 0 to S.size-1 do: value = value + p[i] weight = weight + w[i] for j from i+1 to S.size-1 do: value = value + P[i][j] if weight <= W then: if value > max then: max = value
Given n items, there will be at most
2n
O(n2)
(2nn2)=λ(2n)
Problems of such form are difficult to solve directly using standard solvers and thus people try to reformulate it as a linear program using auxiliary variables and constraints so that the problem can be readily solved using commercial packages. Two well-known linearization approaches for the 0-1 QKP are the standard linearization and Glover’s linearization.[11] [12] [13]
The first one is the standard linearization strategy, as shown below:
LP1: maximize
n | |
\sum | |
i=1 |
pixi+
n | |
\sum | |
i=1 |
n | |
\left(\sum | |
j=1,i<j |
(Pij+Pji)zij\right).
subject to
zij\leqxi
(i,j),i<j
zij\leqxj
(i,j),i<j
xi+xj-1\leqzij
(i,j),i<j
zij\geq0
(i,j),i<j
x\inX,x
In the formulation LP1, we have replaced the xixj term with a continuous variable zij. This reformulates the QKP into a knapsack problem, which we can then solve optimally using standard solvers.
The second reformulation, which is more concise, is called Glover’s linearization.[14] [15] [16] The Glover formulation is shown below, where Li and Ui are lower and upper bounds on
n | |
\sum | |
j=1,i ≠ j |
Pijxj
LP2: maximize
n | |
\sum | |
i=1 |
pixi+
nz | |
\sum | |
i |
subject to
Lixi\leqzi\leqUixi
i=1,\ldots,n
nP | |
\sum | |
ij |
xj-Ui(1-xi)\leqzi\leq
nP | |
\sum | |
ij |
xj-Li(1-xi)
i=1,\ldots,n
x\inX,x
In the formulation LP2, we have replaced the expression
n | |
\sum | |
j=1,i ≠ j |
Pijxixj
n
2n
{n\choose2}
3{n\choose2}
Note that nonlinear programs are hard to solve due to the possibility of being stuck at a local maximum. However, when the program is convex, any local maximum is the global maximum. A convex program is to maximize a concave function or minimize a convex function on a convex set. A set S is convex if
\forallu,v\inS
λu+(1-λ)v\inS
λ\in[0,1]
f[λu+(1-λ)v]\leqλf(u)+(1-λ)f(v)
f[λu+(1-λ)v]\geqλf(u)+(1-λ)f(v)
The objective function can be written as
cTx+xTCx
pTx+x
n | |
i=1 |
n|P | |
\left(\sum | |
ij |
2-x | |
|\right)(x | |
i) |
George Dantzig[18] proposed a greedy approximation algorithm to unbounded knapsack problem which can also be used to solve the 0-1 QKP. The algorithm consists of two phrases: identify an initial solution and improve it.
First compute for each item, the total objective contribution realizable by selecting it,
pi+\sum
n | |
i ≠ j |
Pij
(pi+\sum
nP | |
ij |
)/wi
O(2n)
Quadknap is an exact branch-and-bound algorithm proposed by Caprara et al.,[19] where upper bounds are computed by considering a Lagrangian relaxation which approximate a difficult problem by a simpler problem and penalizes violations of constraints using Lagrange multiplier to impost a cost on violations. Quadknap releases the integer requirement when computing the upper bounds. Suboptimal Lagrangian multipliers are derived from sub-gradient optimization and provide a convenient reformulation of the problem. This algorithm is quite efficient since Lagrangian multipliers are stable, and suitable data structures are adopted to compute a tight upper bound in linear expected time in the number of variables. This algorithm was reported to generate exact solutions of instances with up to 400 binary variables, i.e., significantly larger than those solvable by other approaches. The code was written in C and is available online.[20]
While dynamic programming can generate optimal solutions to knapsack problems, dynamic programming approaches for QKP[21] can only yield a relatively good quality solution, which can serve as a lower bound to the optimal objectives. While it runs in pseudo-polynomial time, it has a large memory requirement.
For simplicity, assume all weights are non-negative. The objective is to maximize total value subject to the constraint: that the total weight is less than or equal to W. Then for each
w\leqW
f(m,w)
m | |
f(m,w)=max\left\{\sum | |
i=1 |
pixi+
m | |
\sum | |
j=1,i ≠ j |
Pijxixj:
m | |
\sum | |
i=1 |
wi=w,1\leqi\leqm\right\}.
Then,
f(m,w)
f(m,w)
f(m-1,w)
f(m,w)
f(m-1,w)
f(m-1,w-wm)+pm+\sum
m-1 | |
i=1 |
Pimxi
f(m,w)= \begin{cases} maxf(m-1,w),f(m-1,w-wm)+pm+\sum
m-1 | |
i=1 |
Pimxi&ifwm\leqw\\ f(m-1,w)&otherwise \end{cases}
Note on efficiency class: Clearly the running time of this algorithm is
O(Wn2)
Note that the previous algorithm requires
O(Wn2)
f(m,w)
Redefine
f(w)
m | |
f(w)=max\left\{\sum | |
i=1 |
pixi+
m | |
\sum | |
i=1 |
m | |
\sum | |
j=1,i ≠ j |
Pijxixj:
m | |
\sum | |
i=1 |
wi=w,m\leqn\right\}.
f(m)= \begin{cases} maxf(w),f(w-wm)+pm+\sum
m-1 | |
i=1 |
Pimxi&ifwm\leqw,\\ f(w)&otherwise.\end{cases}
Note this revised algorithm still runs in
O(Wn2)
O(Wn)
O(Wn2)
Researchers have studied 0-1 quadratic knapsack problems for decades. One focus is to find effective algorithms or effective heuristics, especially those with an outstanding performance solving real world problems. The relationship between the decision version and the optimization version of the 0-1 QKP should not be ignored when working with either one. On one hand, if the decision problem can be solved in polynomial time, then one can find the optimal solution by applying this algorithm iteratively. On the other hand, if there exists an algorithm that can solve the optimization problem efficiently, then it can be utilized in solving the decision problem by comparing the input with the optimal value.
Another theme in literature is to identify what are the "hard" problems. Researchers who study the 0-1 QKP often perform computational studies[22] to show the superiority of their strategies. Such studies can also be conducted to assess the performance of different solution methods. For the 0-1 QKP, those computational studies often rely on randomly generated data, introduced by Gallo et al. Essentially every computational study of the 0-1 QKP utilizes data that is randomly generated as follows. The weights are integers taken from a uniform distribution over the interval [1, 50], and the capacity constraints is an integer taken from a uniform distribution between 50 and the sum of item weights. The objective coefficients, i.e. the values are randomly chosen from [1,100]. It has been observed that generating instances of this form yields problems with highly variable and unpredictable difficulty. Therefore, the computational studies presented in the literature may be unsound. Thus some researches aim to develop a methodology to generate instances of the 0-1 QKP with a predictable and consistent level of difficulty.