A Dynamic Programming Heuristic for the Quadratic Knapsack Problem
Total Page:16
File Type:pdf, Size:1020Kb
This article was downloaded by: [148.88.244.227] On: 11 February 2014, At: 06:59 Publisher: Institute for Operations Research and the Management Sciences (INFORMS) INFORMS is located in Maryland, USA INFORMS Journal on Computing Publication details, including instructions for authors and subscription information: http://pubsonline.informs.org A Dynamic Programming Heuristic for the Quadratic Knapsack Problem Franklin Djeumou Fomeni, Adam N. Letchford To cite this article: Franklin Djeumou Fomeni, Adam N. Letchford (2014) A Dynamic Programming Heuristic for the Quadratic Knapsack Problem. INFORMS Journal on Computing 26(1):173-182. http://dx.doi.org/10.1287/ijoc.2013.0555 Full terms and conditions of use: http://pubsonline.informs.org/page/terms-and-conditions This article may be used only for the purposes of research, teaching, and/or private study. Commercial use or systematic downloading (by robots or other automatic processes) is prohibited without explicit Publisher approval. For more information, contact [email protected]. The Publisher does not warrant or guarantee the article’s accuracy, completeness, merchantability, fitness for a particular purpose, or non-infringement. Descriptions of, or references to, products or publications, or inclusion of an advertisement in this article, neither constitutes nor implies a guarantee, endorsement, or support of claims made of that product, publication, or service. Copyright © 2014, INFORMS Please scroll down for article—it is on subsequent pages INFORMS is the largest professional society in the world for professionals in the fields of operations research, management science, and analytics. For more information on INFORMS, its publications, membership, or meetings visit http://www.informs.org INFORMS Journal on Computing Vol. 26, No. 1, Winter 2014, pp. 173–182 ISSN 1091-9856 (print) ISSN 1526-5528 (online) http://dx.doi.org/10.1287/ijoc.2013.0555 © 2014 INFORMS A Dynamic Programming Heuristic for the Quadratic Knapsack Problem Franklin Djeumou Fomeni, Adam N. Letchford Department of Management Science, Lancaster University, Lancaster LA1 4YX, United Kingdom {[email protected], [email protected]} t is well known that the standard (linear) knapsack problem can be solved exactly by dynamic programming Iin O4nc5 time, where n is the number of items and c is the capacity of the knapsack. The quadratic knapsack problem, on the other hand, is NP-hard in the strong sense, which makes it unlikely that it can be solved in pseudo-polynomial time. We show, however, that the dynamic programming approach to the linear knapsack problem can be modified to yield a highly effective constructive heuristic for the quadratic version. In our experiments, the lower bounds obtained by our heuristic were consistently within a fraction of a percent of optimal. Moreover, the addition of a simple local search step enabled us to obtain the optimal solution of all instances considered. Key words: knapsack problems; integer programming; dynamic programming History: Accepted by Karen Aardal, Area Editor for Design and Analysis of Algorithms; received March 2012; revised September 2012, January 2013; accepted February 2013. Published online in Articles in Advance July 22, 2013. 1. Introduction wi D 1 for all i, one cannot even approximate the opti- The quadratic knapsack problem (QKP), introduced by mal profit within a constant factor in polynomial Gallo et al. (1980), is an optimisation problem of the time (e.g., Khot 2006). Even for this special case, the following form: best approximation factor obtained to date is O4n1=45 (Bhaskara et al. 2010). n n X X The QKP is a well-studied combinatorial optimisa- max qij xixj (1) iD1 jD1 tion problem with a variety of important applications, n for example in the location of satellites, airports, rail- X way stations, or freight terminals. A variety of bound- s.t. wixi ≤ c1 (2) iD1 ing procedures, heuristics, and exact algorithms are x 2 801 19n0 (3) available for it. For details, we refer the reader to Kellerer et al. (2004, Ch. 12), and the more recent sur- Here, n is the number of items, c is the (positive and vey by Pisinger (2007). One of the most effective exact integral) capacity of the knapsack, wi are the (posi- algorithms for the QKP is that of Caprara et al. (1999), tive and integral) weights of the items, and qij are the which is based on Lagrangian relaxation, subgradi- (nonnegative and integral) profits. For i D 11 0 0 0 1 n, the ent optimisation, and branch and bound. Recently, binary variable xi takes the value 1 if and only if this algorithm was made even more effective by the ith item is inserted into the knapsack. Pisinger et al. (2007), using several powerful reduc- 2 Note that, because xi D xi for all i, one can easily tion techniques. incorporate linear terms by adjusting the qii. Indeed, The purpose of this paper is to show that the DP the QKP reduces to the standard (linear) knapsack approach to the KP can be modified to yield an problem (KP) when qij D 0 for all i 6D j. In terms of effective heuristic for the QKP. In the basic form of computational complexity, however, the QKP is more our heuristic, one simply uses the same stages and Downloaded from informs.org by [148.88.244.227] on 11 February 2014, at 06:59 . For personal use only, all rights reserved. complex than the KP. Indeed, although the KP is NP- states as in the standard DP recursion for the KP, hard, as shown by Karp (1972), it is possible to solve but uses a quadratic objective in place of a linear it in O4nc5 time using dynamic programming (DP), objective. This heuristic already performs surprisingly as shown by Bellman (1957). The QKP, on the other well, but it can be significantly enhanced with lit- hand, is known to be NP-hard in the strong sense (see, tle additional effort. Specifically, we found that if the e.g., Caprara et al. 1999), which makes it unlikely that items are ordered appropriately, and ties are broken a pseudo-polynomial time algorithm exists. In fact, in an intelligent way, then one can consistently obtain there is evidence that, even in the special case where lower bounds that are within 0005% of optimality. 173 Fomeni and Letchford: A Dynamic Programming Heuristic for the Quadratic Knapsack Problem 174 INFORMS Journal on Computing 26(1), pp. 173–182, © 2014 INFORMS Moreover, when we applied a simple local search step of the first k items whose total weight is equal to r. to the solutions generated by the enhanced version of That is, let our heuristic, we obtained the optimal solution of all instances considered. f 4k1 r5 The paper is structured as follows: In §2 we review k k X X the relevant literature on the KP and QKP. In §3, the Dmax pixi2 wixi Dr1xi 280119 4i D110001k5 1 new heuristic is described, and it is shown how to iD1 iD1 implement it to use O4n2c5 time and O4nc5 memory where pi D qii. space. In §4 we present the abovementioned ordering If no such packing exists, then let f 4k1 r5 D −. and tie-breaking rules, and show that they consider- Also, by convention, let f 401 05 D 0. Now observe that ably enhance the performance of the heuristic. In §5 we present extensive computational results obtained 8 >max8f 4k − 11 r51 f 4k − 11 r − wk5 C pk9 with the enhanced version of our heuristic, along < f 4k1 r5 D if r ≥ wk1 (4) with ones obtained with the additional local search > :f 4k − 11 r5 otherwise. step. Finally, some concluding remarks are presented in §6. This is a classic dynamic programming recur- sive function, which indicates that the KP obeys 2. Literature Review the so-called “principle of optimality” of Bellman Because the literature on knapsack problems is vast, (1957). It enables us to compute the f 4k1 r5 using we do not attempt to cover it all here. Instead, we Algorithm 1. refer the reader to books by Kellerer et al. (2004), Algorithm 1 (The classical DP algorithm) Martello and Toth (1990), and the survey by Pisinger Initialise f 401 05 to 0 and f 4k1 r5 D − for all (2007). Nevertheless, there are certain key concepts other k1 r. from the literature that are vital to what follows for k D 11 0 0 0 1 n do and are therefore covered in the following four for r D 01 0 0 0 1 c do subsections. if f 4k − 11 r5 > f 4k1 r5 then Set f 4k1 r5 2D f 4k − 11 r5. 2.1. The Continuous Relaxation of the KP end if The continuous relaxation of the KP is defined as if r C w ≤ c and f 4k − 11 r5 C p > f 4k1 r C w 5 follows: k k k then n Set f 4k1 r C w 5 2D f 4k − 11 r5 C p . X T n k k max qiixi2 w x ≤ c1 x 2 601 17 0 end if iD1 end for Dantzig (1957) showed that this relaxation can be end for solved quickly, in O4n log n5 time, as follows: Output max0≤r≤c f 4n1 r5. 1. Temporarily set xi to 0 for all i. This algorithm clearly runs in O4nc5 time. Note that 2. Sort the items in nonincreasing order of profit-to- it outputs only the optimal profit. If you want the weight ratio qii=wi. optimal solution itself, you have to “trace back” the 3. Iteratively set variables to one in the given path from the optimal state to the initial state f 401 05.