Misplaced Pages

Quadratic knapsack problem

Article snapshot taken from Wikipedia with creative commons attribution-sharealike license. Give it a read and then ask your questions in the chat. We can research this topic together.

The quadratic knapsack problem (QKP), first introduced in 19th century, 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. The 0-1 quadratic knapsack problem is a variation of the knapsack problem, combining the features of the 0-1 knapsack problem and the quadratic knapsack problem.

Definition

Specifically, the 0–1 quadratic knapsack problem has the following form:

maximize  { i = 1 n p i x i + i = 1 n j = 1 , i j n P i j x i x j : x X , x  binary } {\displaystyle {\text{maximize }}\left\{\sum _{i=1}^{n}p_{i}x_{i}+\sum _{i=1}^{n}\sum _{j=1,i\neq j}^{n}P_{ij}x_{i}x_{j}:x\in X,x{\text{ binary}}\right\}}
subject to  X { x { 0 , 1 } n : i = 1 n w i x i W ; x i { 0 , 1 }  for  i = 1 , , n } . {\displaystyle {\text{subject to }}X\equiv \left\{x\in \{0,1\}^{n}:\sum _{i=1}^{n}w_{i}x_{i}\leq W;x_{i}\in \{0,1\}{\text{ for }}i=1,\ldots ,n\right\}.}

Here the binary variable xi represents whether item i is included in the knapsack, p i {\displaystyle p_{i}} is the profit earned by selecting item i and P i j {\displaystyle P_{ij}} is the profit achieved if both item i and j are added.

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.

Application

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. Applications of QKP in the field of computer science is more common after the early days: compiler design problem, clique problem, very large scale integration (VLSI) design. Additionally, pricing problems appear to be an application of QKP as described by Johnson et al.

Computational complexity

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. 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.

Solving

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, 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.

Brute force

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:

// Input:
//     Profits (stored in array p)
//     Quadratic profits (stored in matrix P)
//     Weights (stored in array w)
//     Number of items (n)
//     Knapsack capacity (W)
int max = 0
for all subset S do
    int value, weight = 0
    for i from 0 to S.size-1 do:
        value = value + p
        weight = weight + w
            for j from i+1 to S.size-1 do: 
                value = value + P
    if weight <= W then:
        if value > max then:    
            max = value

Given n items, there will be at most 2 n {\displaystyle 2^{n}} subsets and for each legal candidate set, the running time of computing the values earned is O ( n 2 ) {\displaystyle O(n^{2})} . Thus, the efficiency class of brute-force algorithm is ( 2 n n 2 ) = λ ( 2 n ) {\displaystyle (2^{n}n^{2})=\lambda (2^{n})} , being exponential.

Linearization

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.

Standard linearization

The first one is the standard linearization strategy, as shown below:

LP1: maximize
i = 1 n p i x i + i = 1 n ( j = 1 , i < j n ( P i j + P j i ) z i j ) . {\displaystyle \sum _{i=1}^{n}p_{i}x_{i}+\sum _{i=1}^{n}\left(\sum _{j=1,i<j}^{n}(P_{ij}+P_{ji})z_{ij}\right).}
subject to
z i j x i {\displaystyle z_{ij}\leq x_{i}} for all ( i , j ) , i < j {\displaystyle (i,j),i<j}
z i j x j {\displaystyle z_{ij}\leq x_{j}} for all ( i , j ) , i < j {\displaystyle (i,j),i<j}
x i + x j 1 z i j {\displaystyle x_{i}+x_{j}-1\leq z_{ij}} for all ( i , j ) , i < j {\displaystyle (i,j),i<j}
z i j 0 {\displaystyle z_{ij}\geq 0} for all ( i , j ) , i < j {\displaystyle (i,j),i<j}
x X , x {\displaystyle x\in X,x} binary

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.

Glover's linearization

The second reformulation, which is more concise, is called Glover's linearization. The Glover formulation is shown below, where Li and Ui are lower and upper bounds on j = 1 , i j n P i j x j {\displaystyle \sum _{j=1,i\neq j}^{n}P_{ij}x_{j}} , respectively:

LP2: maximize
i = 1 n p i x i + i = 1 n z i {\displaystyle \sum _{i=1}^{n}p_{i}x_{i}+\sum _{i=1}^{n}z_{i}}
subject to
L i x i z i U i x i {\displaystyle L_{i}x_{i}\leq z_{i}\leq U_{i}x_{i}} for i = 1 , , n {\displaystyle i=1,\ldots ,n}
j = 1 , i j n P i j x j U i ( 1 x i ) z i j = 1 , i j n P i j x j L i ( 1 x i ) {\displaystyle \sum _{j=1,i\neq j}^{n}P_{ij}x_{j}-U_{i}(1-x_{i})\leq z_{i}\leq \sum _{j=1,i\neq j}^{n}P_{ij}x_{j}-L_{i}(1-x_{i})} for i = 1 , , n {\displaystyle i=1,\ldots ,n}
x X , x {\displaystyle x\in X,x} binary

In the formulation LP2, we have replaced the expression j = 1 , i j n P i j x i x j {\displaystyle \sum _{j=1,i\neq j}^{n}P_{ij}x_{i}x_{j}} with a continuous variable zi. Similarly, we can use standard solvers to solve the linearized problem. Note that Glover's linearization only includes n {\displaystyle n} auxiliary variables with 2 n {\displaystyle 2n} constraints while standard linearization requires ( n 2 ) {\displaystyle {n \choose 2}} auxiliary variables and 3 ( n 2 ) {\displaystyle 3{n \choose 2}} constraints to achieve linearity.

Convex quadratic reformulation

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 u , v S {\displaystyle \forall u,v\in S} , λ u + ( 1 λ ) v S {\displaystyle \lambda u+(1-\lambda )v\in S} where λ [ 0 , 1 ] {\displaystyle \lambda \in } . That is to say, any point between two points in the set must also be an element of the set. A function f is concave if f [ λ u + ( 1 λ ) v ] λ f ( u ) + ( 1 λ ) f ( v ) {\displaystyle f\leq \lambda f(u)+(1-\lambda )f(v)} . A function f is convex if f [ λ u + ( 1 λ ) v ] λ f ( u ) + ( 1 λ ) f ( v ) {\displaystyle f\geq \lambda f(u)+(1-\lambda )f(v)} . Informally, a function is concave if the line segment connecting two points on the graph lies above or on the graph, while a function is convex if below or on the graph. Thus, by rewriting the objective function into an equivalent convex function, we can reformulate the program to be convex, which can be solved using optimization packages.

The objective function can be written as c T x + x T C x {\displaystyle c^{T}x+x^{T}Cx} using linear algebra notation. We need to make P a positive semi-definite matrix in order to reformulate a convex function. In this case, we modify the objective function to be p T x + x T P x + i = 1 n ( j = 1 , j i n | P i j | ) ( x i 2 x i ) {\displaystyle p^{T}x+x^{T}Px+\sum _{i=1}^{n}\left(\sum _{j=1,j\neq i}^{n}|P_{ij}|\right)(x_{i}^{2}-x_{i})} by applying results from linear algebra, where P is a diagonally dominant matrix and thus a positive semi-definite. This reformulation can be solved using a standard commercial mixed-integer quadratic package.

Greedy heuristic algorithm

George Dantzig 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, p i + i j n P i j {\displaystyle p_{i}+\sum _{i\neq j}^{n}P_{ij}} , and sort the items in decreasing order of the potential value per unit of weight, ( p i + i j n P i j ) / w i {\displaystyle (p_{i}+\sum _{i\neq j}^{n}P_{ij})/w_{i}} . Then select the items with the maximal value-weight ratio into the knapsack until there is no space for more, which forms the initial solution. Starting with the initial solution, the improvement is conducted by pairwise exchange. For each item in the solution set, identify the items not in the set where swapping results in an improving objective. Select the pair with maximal improvement and swap. There are also possibilities that removing one from the set or adding one to the set will produce the greatest contribution. Repeat until there is no improving swapping. The complexity class of this algorithm is O ( 2 n ) {\displaystyle O(2^{n})} since for the worst case every possible combination of items will be identified.

Quadknap

Quadknap is an exact branch-and-bound algorithm proposed by Caprara et al., 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.

Dynamic programming heuristic

While dynamic programming can generate optimal solutions to knapsack problems, dynamic programming approaches for QKP 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.

Dynamic programming algorithm

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 W {\displaystyle w\leq W} , define f ( m , w ) {\displaystyle f(m,w)} to be the value of the most profitable packing of the first m items found with a total weight of w. That is, let

f ( m , w ) = max { i = 1 m p i x i + i = 1 m j = 1 , i j m P i j x i x j : i = 1 m w i = w , 1 i m } . {\displaystyle f(m,w)=\max \left\{\sum _{i=1}^{m}p_{i}x_{i}+\sum _{i=1}^{m}\sum _{j=1,i\neq j}^{m}P_{ij}x_{i}x_{j}:\sum _{i=1}^{m}w_{i}=w,1\leq i\leq m\right\}.}

Then, f ( m , w ) {\displaystyle f(m,w)} is the solution to the problem. Note that by dynamic programming, the solution to a problem arises from the solution to its smaller sub-problems. In this particular case, start with the first item and try to find a better packing by considering adding items with an expected weight of 𝑤. If the weight of the item to be added exceeds 𝑤, then f ( m , w ) {\displaystyle f(m,w)} is the same with f ( m 1 , w ) {\displaystyle f(m-1,w)} . Given that the item has a smaller weight compared with the desired weight, f ( m , w ) {\displaystyle f(m,w)} is either the same as f ( m 1 , w ) {\displaystyle f(m-1,w)} if adding makes no contribution, or the same as the solution for a knapsack with smaller capacity, specifically one with the capacity reduced by the weight of that chosen item, plus the value of one correct item, i.e. f ( m 1 , w w m ) + p m + i = 1 m 1 P i m x i {\displaystyle f(m-1,w-w_{m})+p_{m}+\sum _{i=1}^{m-1}P_{im}x_{i}} . To conclude, we have that

f ( m , w ) = { max f ( m 1 , w ) , f ( m 1 , w w m ) + p m + i = 1 m 1 P i m x i if  w m w f ( m 1 , w ) otherwise {\displaystyle f(m,w)={\begin{cases}\max f(m-1,w),f(m-1,w-w_{m})+p_{m}+\sum _{i=1}^{m-1}P_{im}x_{i}&{\text{if }}w_{m}\leq w\\f(m-1,w)&{\text{otherwise}}\end{cases}}}

Note on efficiency class: Clearly the running time of this algorithm is O ( W n 2 ) {\displaystyle O(Wn^{2})} , based on the nested loop and the computation of the profit of new packing. This does not contradict the fact the QKP is NP-hard since W is not polynomial in the length of the input.

Revised dynamic programming algorithm

Note that the previous algorithm requires O ( W n 2 ) {\displaystyle O(Wn^{2})} space for storing the current packing of items for all m,w, which may not be able to handle large-size problems. In fact, this can be easily improved by dropping the index m from f ( m , w ) {\displaystyle f(m,w)} since all the computations depend only on the results from the preceding stage.

Redefine f ( w ) {\displaystyle f(w)} to be the current value of the most profitable packing found by the heuristic. That is,

f ( w ) = max { i = 1 m p i x i + i = 1 m j = 1 , i j m P i j x i x j : i = 1 m w i = w , m n } . {\displaystyle f(w)=\max \left\{\sum _{i=1}^{m}p_{i}x_{i}+\sum _{i=1}^{m}\sum _{j=1,i\neq j}^{m}P_{ij}x_{i}x_{j}:\sum _{i=1}^{m}w_{i}=w,m\leq n\right\}.}

Accordingly, by dynamic programming we have that

f ( m ) = { max f ( w ) , f ( w w m ) + p m + i = 1 m 1 P i m x i if  w m w , f ( w ) otherwise. {\displaystyle f(m)={\begin{cases}\max f(w),f(w-w_{m})+p_{m}+\sum _{i=1}^{m-1}P_{im}x_{i}&{\text{if }}w_{m}\leq w,\\f(w)&{\text{otherwise.}}\end{cases}}}

Note this revised algorithm still runs in O ( W n 2 ) {\displaystyle O(Wn^{2})} while only taking up O ( W n ) {\displaystyle O(Wn)} memory compared to the previous O ( W n 2 ) {\displaystyle O(Wn^{2})} .

Related research topics

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 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 , 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 . 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.

See also

Notes

  1. C., Witzgall (1975). "Mathematical methods of site selection for Electronic Message Systems (EMS)". NBS Internal Report. 76: 18321. Bibcode:1975STIN...7618321W. doi:10.6028/nbs.ir.75-737.
  2. Gallo, G.; Hammer, P.L.; Simeone, B. (1980). "Quadratic knapsack problems". Combinatorial Optimization I. Mathematical Programming Studies. Vol. 12. Springer. pp. 132–149. doi:10.1007/bfb0120892. ISBN 978-3-642-00801-6.
  3. Rhys, J.M.W. (1970). "A Selection Problem of Shared Fixed Costs and Network Flows". Management Science. 17 (3): 200–207. doi:10.1287/mnsc.17.3.200.
  4. Helmberg, C.; Rendl, F.; Weismantel, R. (1996). "Quadratic knapsack relaxations using cutting planes and semidefinite programming". Integer Programming and Combinatorial Optimization. Lecture Notes in Computer Science. Vol. 1084. Springer. pp. 175–189. doi:10.1007/3-540-61310-2_14. ISBN 978-3-540-61310-7.
  5. Dijkhuizen, G.; Faigle, U. (1993). "A cutting-plane approach to the edge-weighted maximal clique problem". European Journal of Operational Research. 69 (1): 121–130. doi:10.1016/0377-2217(93)90097-7.
  6. Park, Kyungchul; Lee, Kyungsik; Park, Sungsoo (1996). "An extended formulation approach to the edge-weighted maximal clique problem". European Journal of Operational Research. 95 (3): 671–682. doi:10.1016/0377-2217(95)00299-5.
  7. Ferreira, C.E.; Martin, A.; Souza, C.C.De; Weismantel, R.; Wolsey, L.A. (1996). "Formulations and valid inequalities for the node capacitated graph partitioning problem". Mathematical Programming. 74 (3): 247–266. doi:10.1007/bf02592198. S2CID 37819561.
  8. Johnson, Ellis L.; Mehrotra, Anuj; Nemhauser, George L. (1993). "Min-cut clustering". Mathematical Programming. 62 (1–3): 133–151. doi:10.1007/bf01585164. S2CID 39694326.
  9. Garey, Michael R.; Johnson, David S. (1979). Computers and intractibility: A guide to the theory of NP completeness. New York: Freeman and Co.
  10. Adams, Warren P.; Sherali, Hanif D. (1986). "A Tight Linearization and an Algorithm for Zero-One Quadratic Programming Problems". Management Science. 32 (10): 1274–1290. doi:10.1287/mnsc.32.10.1274.
  11. Adams, Warren P.; Forrester, Richard J.; Glover, Fred W. (2004). "Comparisons and enhancement strategies for linearizing mixed 0-1 quadratic programs". Discrete Optimization. 1 (2): 99–120. doi:10.1016/j.disopt.2004.03.006.
  12. Adams, Warren P.; Forrester, Richard J. (2005). "A simple recipe for concise mixed 0-1 linearizations". Operations Research Letters. 33 (1): 55–61. doi:10.1016/j.orl.2004.05.001.
  13. Adams, Warren P.; Forrester, Richard J. (2007). "Linear forms of nonlinear expressions: New insights on old ideas". Operations Research Letters. 35 (4): 510–518. doi:10.1016/j.orl.2006.08.008.
  14. Glover, Fred; Woolsey, Eugene (1974). "Technical Note—Converting the 0-1 Polynomial Programming Problem to a 0-1 Linear Program". Operations Research. 22 (1): 180–182. doi:10.1287/opre.22.1.180.
  15. Glover, Fred (1975). "Improved Linear Integer Programming Formulations of Nonlinear Integer Problems". Management Science. 22 (4): 455–460. doi:10.1287/mnsc.22.4.455. S2CID 17004334.
  16. Glover, Fred; Woolsey, Eugene (1973). "Further Reduction of Zero-One Polynomial Programming Problems to Zero-One linear Programming Problems". Operations Research. 21 (1): 156–161. doi:10.1287/opre.21.1.156.
  17. Bliek, Christian; Bonami, Pierre; Lodi, Andrea (2014). "Solving Mixed-Integer Quadratic Programming problems with IBM-CPLEX: a progress report" (PDF). Proceedings of the Twenty-Sixth RAMP Symposium, Hosei University, Tokyo, October 16-17, 2014.
  18. Dantzig, George B. (1957). "Discrete-Variable Extremum Problems". Operations Research. 5 (2): 266–288. doi:10.1016/j.disopt.2004.03.006.
  19. Caprara, Alberto; Pisinger, David; Toth, Paolo (1999). "Exact Solution of the Quadratic Knapsack Problem". INFORMS Journal on Computing. 11 (2): 125–137. CiteSeerX 10.1.1.22.2818. doi:10.1287/ijoc.11.2.125.
  20. "Quadknap". Retrieved 2016-12-03.
  21. Fomeni, Franklin Djeumou; Letchford, Adam N. (2014). "A Dynamic Programming Heuristic for the Quadratic Knapsack Problem" (PDF). INFORMS Journal on Computing. 26 (1): 173–182. doi:10.1287/ijoc.2013.0555. S2CID 15570245.
  22. Forrester, Richard J.; Adams, Warren P.; Hadavas, Paul T. (2009). "Concise RLT forms of binary programs: A computational study of the quadratic knapsack problem". Naval Research Logistics. 57: 1–12. doi:10.1002/nav.20364. S2CID 121015443.

External links

Categories: