A Two-Phase Method for Solving Continuous Rank-One Quadratic Knapsack Problems
Abstract
In this paper, we propose a two-phase algorithm for solving continuous rank-one quadratic knapsack problems (R1QKP). In particular, we study the solution structure of the problem without the knapsack constraint. We propose an algorithm in this case. We then use the solution structure to propose an algorithm that finds an interval containing the optimal value of the Lagrangian dual of R1QKP. In the second phase, we solve the restricted Lagrangian dual problem using a traditional single-variable optimization method. We perform a computational test on random instances and compare our algorithm with the general solver CPLEX.
keywords:
Quadratic Knapsack Problem , Line-Sweep AlgorithmB[alph]
1 Introduction
The quadratic knapsack problem (QKP) deals with minimizing a quadratic function over one allocation constraint together with simple bounds on decision variables. Formally, this problem can be written as to
(1a) | ||||
(1b) | ||||
(1c) |
where is a symmetric matrix, and . QKP as a quadratic optimization problem is polynomially solvable when is positive definite matrix [12]. When is diagonal with strictly positive diagonal entries QKP can be viewed as a strictly convex separable optimization problem that has many applications (e.g. resource allocation [14, 13, 2] and multicommodity network flows [9]). The solution methods for solving this type of QKPs usually rely on the fact that the optimal solution of the Lagrangian dual subproblems can be explicitly obtained in terms of the Lagrange multiplier of (1b). Therefore the problem reduces to find a value for such that the solution of the corresponding Lagrangian subproblem is satisfied in equality constraint (1b). The resulting equation is solved by different methods. Helgason et. al [9] propose an algorithm for solving the equation based on searching breakpoints of the Lagrangian dual problem. Brucker [3] finds an bisection algorithm based on the properties of the Lagrangian dual function. Dai and Fletcher [5] propose a two-phase method; A bracketing phase that determines an interval containing the solution followed by the secant phase that approximates the solution within the promising interval. This method is modified by Comminetti et. al [4] with ignoring the bracketing phase and using a semi-smooth Newton method instead of the secant method. Liu and Yong-Jin [11] consider a special case of the strictly convex form of the problem. They find the solution structure of the subproblems and use it in a modified secant algorithm.
Robinson et. al [15] use the geometric interpretation of the problem and propose an algorithm that works in the primal space rather than the dual space. This algorithm iteratively fixes variables and terminates after at most iterations.
In a more general case, when is positive semidefinite in (1), Dussault et. al [7] propose an iterative algorithm in which a QKP with diagonal should be solved in each iteration. Paradalos et. al [12] suggest a potential reduction algorithm to solve this class of QKP. di Serafino et. al [6] propose a two-phase gradient projection that has acceptable numerical performance in comparison with similar gradient-based methods.
QKPs with positive definite are also solved by a gradient projection method [5], and an augmented-Lagrangian approach [8].
In this paper, we suppose is a rank one symmetric matrix, that is for some . Moreover, we assume that . Without loss of generality we assume that for each . By the following change of variables
problem (1) is reduced to
(2a) | ||||
(2b) | ||||
(2c) |
Sharkey et. al [16] study a class of nonseparable nonlinear knapsack problems in which one has to
(3) | ||||
where is an arbitrary real-valued function, and is given. They introduce an algorithm for solving (3) that runs in , where is the time required to solve a single-variable optimization problem for given . With and equals to the all-one vector, problem (2) is a special case of problem (3). That is, there exists an algorithm for solving problem (2).
In this paper, we propose a two-phase algorithm for problem (2). In section 2 we study the solution structure of the bounded version of the problem in which the equality constraint (2b) is omitted. We show that the bounded version could be solved in time. In section 3, in phase I, we use the solution structure of the bounded version to find an interval that may contain the optimal value of the Lagrangian dual function. This is done in time in the worst case. Then, we perform phase II, in which we explore the interval by a single-variable optimization method to find the optimal Lagrangian multiplier with desired precision. In section 4, we perform a computational test. In particular, we compare the algorithm with the general quadratic programming solver CPLEX.
2 Solution structure of the bounded version
In this section we consider the following bounded version of the problem
(4a) | ||||
(4b) |
We propose a characterization of the solution in the primal space. Note that most of algorithms for such problems use the so-called KKT conditions to study the solution structure. Without loss of generality, we assume that , and , . Given two vectors , we denote the set by . Finally, given vector we define for , and .
We begin with preliminary lemmas.
Lemma 2.1.
For define as
and as the all-zero vector, and, define as
Then the following assertions hold
-
1.
If is the smallest index in such that then .
-
2.
If for all then .
Proof.
(1) For we have
Thus
On the other hand, for we have
(5) | ||||
Now let . Then
Similarly, if , then we have .
We need the following result about two-dimensional version of problem (4).
Lemma 2.2.
Consider the following optimization problem
(6) | ||||
where and and are real constants. Define set where and . Then, problem (6) has no optimal solution outside of .
Proof.
If , then where . It is easy to see that with and is the optimal solution of the problem, and we have . Assume that . The feasible region of (6) is equal to where and . We show that there is no optimal solution in and . Indeed, we write the KKT optimality conditions as follows
(7) | |||
(8) | |||
(9) | |||
(10) | |||
(11) | |||
(12) | |||
(13) |
where and , are KKT multipliers corresponding to the bound constraints. If then from (9) and (10) we have . Substituting these values in (7) and (8) implies that which contradicts our assumption. On the other hand, if and , then we have . Now, (7) implies that . Thus . From (8) we have . Therefore, . This contradicts our assumption on s. That is, problem (6) has no optimal solution with . By similar argument one can conclude that (6) has no solution with . This completes the proof. ∎
Theorem 2.3.
Suppose and , and are defined as in Lemma 2.1. Then the following assertions hold
-
1.
If , then define as and . Also, define , as
where is the th column of the identity matrix of dimension . Then is the optimal value of the following optimization problem
(14) -
2.
If , then define . Also define . Then is the optimal value of the following optimization problem
-
3.
if for all , then define . Also define . Then is the optimal value of the following optimization problem
Proof.
(1) By Lemma 2.2 we can partition the optimal solution set as where and . We show that and . Indeed, we use a simple technique of single-variable calculus. Let , then , for some , where . Thus the problem reduces to . On the other hand, one can write
We have . Thus only if . Since and the optimal value is achieved at .
To prove , by the same argument as the previous paragraph, it suffices to solve single optimization problem , where . It is easy to see that if then . Since , by definition of , then is the optimal value of .
The following Corollary 2.4 states simple conditions under which the optimal solution of the problem in Theorem 2.3(1) is or .
Proof.
Theorem 2.3 solves a restricted version of problem (2). In the following theorem, we show that the solution of the restricted version is the solution of the original problem.
Theorem 2.5.
Proof.
For two vectors we have
(15) |
Let be a feasible solution of (4). If , then from the definition of we have , and the result follows from Theorem 2.3. Suppose . We show there exists a specially structured feasible solution that is better than . Indeed, let be such that
Define vector by
Then, clearly is feasible for (4) and
Moreover we have
(by monotonicity of ’s) | ||||
Therefor, (15) implies that , i.e. .
(1) Now, we consider three cases for index introduced in the definition of : , and . In the latter case, we have , so the assertion is true by Theorem 2.3, since
We show in both the other cases there is a point in the set better than , that is for some . By Lemma 2.1, and the result follows by Theorem 2.3.
First, let . Then we have
On the other hand, we have
Therefor
Thus .
Now, let . Then
On the other hand, we have
Thus
That is . Thus in both cases there exist a point , say, such that . Now, by Lemma 2.1, and the result follows by Theorem 2.3.
Proof of (2) Consider the possible values of at the beginning of the proof of part (1). Here, we just have . Now, similar argument for this case proves (2).
Proof of (3) Again consider the possible values of at the beginning of the proof of part (1). Similar argument with case with proves part (3).
∎
One can conclude the following result on the time needed to solve problem (4).
Theorem 2.6.
There exists an time algorithm for problem (4).
Proof.
Once the index is determined the solution can be determined in time. We need to sort vector , to compute vector , and to find index . That is, problem (4) can be solved in . ∎
3 The algorithm
Our algorithm consists of two phases: bounding the optimal solution, and, computing the optimal solution to the desired precision. The bounding phase is based on the Lagrangian dual of (2) and the solution structure of the bounded version described in section 2.
3.1 Lagrangian dual
Let be the Lagrange multiplier of equality constraint in (2). Then, the Lagrangian function is defined as
(16) | ||||
We have the following fact about the structure of the Lagrangian function .
Theorem 3.7.
Proof.
Now, one may conclude that if is fixed on an interval , then is a piecewise function that contains exactly pieces. However, the following simple example shows that this is not true.
Example 3.1.
Consider problem (2) with the following parameters
In Figure 1 we plot for . We distinct three cases in (Type A), (Type B) and (Type C) with three colors blue, red and green, respectively. As it can be seen in the figure, consists of pieces.

Inner optimization problem in (16) is a special case of problem (4), that can be solved by Theorem 2.5. In Theorem 2.5 it is assumed that coefficients of the linear term in the objective function is sorted in decreasing order. In problem (16), the order of coefficients of the linear term depends on . From now on, we denote by the coefficient of , i.e. . Moreover, we denote the line by . It is easy to see that, when becomes greater than the intersection of and , and change position in the ordered list of coefficients.
We use a modification of the well-known plane sweep algorithm to find the ordered intersection points of lines . Now, let , and are three consecutive intersection points, then because of the Lagrangian function is unimodal, the optimal Lagrange multiplier lies in the interval if and .
We modify the implementation of the line-sweep algorithm proposed in [1]. In this algorithm, a vertical line sweeps the plane from left to right. The status of the sweep line is the ordered sequence of lines that intersect it. The status initially contains all lines in the order of decreasing slope, that is the order of lines when they intersect with sweep line at . The status is updated when reaches an intersecting point. For example, suppose that the sequence of four lines , , , and appears in the status when reaches the intersection point of and . Then, and switch position and the intersection of lines and and the intersection of and are to be checked. The new detected intersection points are stored to proceed. The order of cost coefficient of the linear term in is unchanged between two consecutive intersection points.
If for some , then in the optimal solution of the subproblem. We introduce a set to store the non-vanished variables. To do so we add a dummy line . In each intersection of the dummy line and the other lines, the set should be updated. In fact, if intersect and , then we add to , otherwise, if , then it should be removed from . In other words, since we sweep the plane from left to right, if intersect and , then we add to . If intersect and then it means should be removed from . initially contains the set of all lines with a positive slope. With this modification, we guarantee that between two consecutive intersection points the set of zero-valued variables is unchanged. It should be noted here that lines with equal slopes are sorted based on increasing order of s. We summarize the algorithm in the following Algorithm 1. This algorithm is used as the first phase in the main algorithm.
true
false
Theorem 3.8.
Algorithm 1 runs in time.
Proof.
Initializing state array , line indices array and the queue in steps 3–7 needs time. In each iteration we perform two main operations: computing the value of for a new intersect point and updating . The order of and the vector can be updated from the previous intersection point in time. Finding needs , using binary search. On the other hand, insertion and deletion on the priority queue takes since one can implement the priority queue by a heap to store the intersection points. Therefore each iteration of the main loop needs time. Since there are intersection points, the algorithm runs in . ∎
Let and be the smallest and greatest intersection points of lines . The optimal solution of the Lagrangian problem may lie out of the interval . In this case, Algorithm 1 fails to find the optimal interval. So, we explore the outside of in a separate phase.
First consider the exploration of . Since the components of vector in Theorem 2.5 are linear functions in term of , then there exists such that the order of s does not change for . Indeed, a similar procedure for finding the smallest intersection of lines ’s can be used here to compute . Now, since is unimodal one can conclude that
(17) |
Similarly, for the values of greater than , one can find a threshold, say , such that
(18) |
We summarize the whole algorithm in Algorithm 2.
4 Computational Experiments
In this section, we compare the running time and the numerical accuracy of Algorithm 2 with the general convex quadratic programming solver, CPLEX. We implement Algorithm 2 with MATLAB R2019b. All runs are performed on a system with Core i7 GHz CPU and GB of RAM equipped with a bit Windows operating system. We solve single variables optimization problems (18), (17) and step 3 in Algorithm 2, using MATLAB built-in function fminbnd which is based on golden section search and parabolic interpolation.
Our testbed contains two types of randomly generated rank-one knapsack problems up to variables. In the first type, vectors and are integral and generated uniformly from the same interval. We denote this type by TypeI. In the second type (TypeII), vectors and are positive and negative randomly generated integral vectors, respectively. In Table 1 we summarize the parameter values for problem instances.
Type | \MLTypeI | |||||||
TypeII | \LL |
As a well-known general convex quadratic programming solver, we chose CPLEX (ver. 12.9) to compare with our results. Based on our numerical tests, we set the quadratic programming solver of CPLEX (qpmethod option) to barrier. The barrier convergence tolerance, convergetol is set to . After we complete our experimental tests, we found in [10] that the sparsity of the Hessian matrix influences the performance of CPLEX. To increase the performance, we reformulate our problem as
We denote the results corresponding to running CPLEX on the original problem and the above modification respectively by and .
Table 2 shows the average running time for runs of each algorithm/solver for each problem size. Dash sign, ’-’, denoted the algorithm/solver encounters out-of-memory status.
In all cases, Algorithm 2 outperforms . For instances up to , our algorithm and has same performance, whereas for larger instances, has smaller running time.
Our algorithm | \ML | TypeI | ||||||
---|---|---|---|---|---|---|---|---|
TypeII | ||||||||
TypeI | ||||||||
TypeII | ||||||||
TypeI | ||||||||
TypeII | ||||||||
TypeI | ||||||||
TypeII | ||||||||
TypeI | ||||||||
TypeII | ||||||||
TypeI | ||||||||
TypeII | ||||||||
TypeI | - | |||||||
TypeII | - | |||||||
TypeI | - | |||||||
TypeII | - | |||||||
TypeI | - | |||||||
TypeII | - | \ML |
5 Conclusions
In this paper, we proposed a two-phase algorithm for rank-one quadratic knapsack problems. To this end, we studied the solution structure of the problem when it has no resource constraint. Indeed, we proposed an algorithm to solve this problem. We then used the solution structure to propose an line-sweep algorithm that finds an interval that contains the optimal Lagrange multiplier. Then, the estimated optimal interval is explored for computing the optimal solution with the desired accuracy. Our computational tests showed that our algorithm has better performance than CPLEX when CPLEX is used to solve the original problem. After a reformulation of the problem, CPLEX outperforms our algorithm for instances with .
References
- [1] Mark de Berg, Otfried Cheong, Marc van Kreveld, and Mark Overmars, Computational geometry: Algorithms and Applications, Springer-Verlag TELOS, 2008.
- [2] Gabriel R Bitran and Arnoldo C Hax, Disaggregation and resource allocation using convex knapsack problems with bounded variables, Management Science 27 (1981), no. 4, 431–441.
- [3] Peter Brucker, An algorithm for quadratic knapsack problems, Operations Research Letters 3 (1984), no. 3, 163–166.
- [4] Roberto Cominetti, Walter F Mascarenhas, and Paulo JS Silva, A Newton’s method for the continuous quadratic knapsack problem, Mathematical Programming Computation 6 (2014), no. 2, 151–169.
- [5] Yu-Hong Dai and Roger Fletcher, New algorithms for singly linearly constrained quadratic programs subject to lower and upper bounds, Mathematical Programming 106 (2006), no. 3, 403–421.
- [6] Daniela di Serafino, Gerardo Toraldo, Marco Viola, and Jesse Barlow, A two-phase gradient method for quadratic programming problems with a single linear constraint and bounds on the variables, SIAM Journal on Optimization 28 (2018), no. 4, 2809–2838.
- [7] Jean-Pierre Dussault, Jacques A Ferland, and Bernard Lemaire, Convex quadratic programming with one constraint and bounded variables, Mathematical Programming 36 (1986), no. 1, 90–104.
- [8] Roger Fletcher, Augmented lagrangians, box constrained QP and extensions, IMA Journal of Numerical Analysis 37 (2017), no. 4, 1635–1656.
- [9] R Helgason, J Kennington, and H Lall, A polynomially bounded algorithm for a singly constrained quadratic program, Mathematical Programming 18 (1980), no. 1, 338–343.
- [10] IBM, Cplex performance tuning for quadratic programs, https://www.ibm.com/support/pages/node/397129?mhsrc=ibmsearch_a&mhq=CPLEXPerformanceTuningforQuadraticPrograms, June 2018, [Online; accessed 23-January-2022].
- [11] Meijiao Liu and Yong-Jin Liu, Fast algorithm for singly linearly constrained quadratic programs with box-like constraints, Computational Optimization and Applications 66 (2017), no. 2, 309–326.
- [12] Panos M Pardalos, Yinyu Ye, and Chi-Geun Han, Algorithms for the solution of quadratic knapsack problems, Linear Algebra and its Applications 152 (1991), 69–91.
- [13] Michael Patriksson, A survey on the continuous nonlinear resource allocation problem, European Journal of Operational Research 185 (2008), no. 1, 1–46.
- [14] Michael Patriksson and Christoffer Strömberg, Algorithms for the continuous nonlinear resource allocation problem—new implementations and numerical studies, European Journal of Operational Research 243 (2015), no. 3, 703–722.
- [15] AG Robinson, N Jiang, and CS Lerme, On the continuous quadratic knapsack problem, Mathematical programming 55 (1992), no. 1-3, 99–108.
- [16] Thomas C Sharkey, H Edwin Romeijn, and Joseph Geunes, A class of nonlinear nonseparable continuous knapsack and multiple-choice knapsack problems, Mathematical Programming 126 (2011), no. 1, 69–96.