Abstract
Knapsack problem (KP) is a representative combinatorial optimization problem that aims to maximize the total profit by selecting a subset of items under given constraints on the total weights. In this study, we analyze a generalized version of KP, which is termed the generalized multidimensional knapsack problem (GMDKP). As opposed to the basic KP, GMDKP allows multiple choices per item type under multiple weight constraints. Although several efficient algorithms are known and the properties of their solutions have been examined to a significant extent for basic KPs, there is a paucity of known algorithms and studies on the solution properties of GMDKP. To gain insight into the problem, we assess the typical achievable limit of the total profit for a random ensemble of GMDKP using the replica method. Our findings are summarized as follows: (1) when the profits of item types are normally distributed, the total profit grows in the leading order with respect to the number of item types as the maximum number of choices per item type xmax increases while it depends on xmax only in a sub-leading order if the profits are constant among the item types. (2) A greedy-type heuristic can find a nearly optimal solution whose total profit is lower than the optimal value only by a sub-leading order with a low computational cost. (3) The sub-leading difference from the optimal total profit can be improved by a heuristic algorithm based on the cavity method. Extensive numerical experiments support these findings.
Export citation and abstract BibTeX RIS
Original content from this work may be used under the terms of the Creative Commons Attribution 4.0 licence. Any further distribution of this work must maintain attribution to the author(s) and the title of the work, journal citation and DOI.
1. Introduction
Combinatorial optimization is a popular topic related to numerous research fields. It is deeply connected to computer science and the theory of algorithms, and it is frequently applied to real-world problems in the field of operations research. The knapsack problem (KP) is a major combinatorial optimization problem such as the traveling salesman problem and the minimum spanning tree problem [1]. There are many variants of KP, but all of them aim to maximize the total profit by selecting a subset of items as long as they do not violate the given constraints for total weights. KP has been extensively examined for a long time because of its wide applicability. Its application includes resource allocation problems [2], cutting or packing stock problems [3], and capital budgeting problems [4, 5].
The basic and most well-known version of KP, which we refer to as 0–1 one-dimensional KP (0–1 1DKP), is defined as follows: suppose that there are N item types. Each item type i, 1 ⩽ i ⩽ N, has two characteristic quantities vi ∈ (0, ∞) and wi ∈ (0, ∞), where vi stands for a profit that an item of type i possesses while wi means a weight of the item. The 0–1 1DKP aims to find a way to select items to put in a knapsack such that the total profit is maximized under the constraint that each item type can be selected at most only once, and the total weight does not exceed the capacity of the knapsack. The problem is mathematically formulated as follows:
where U and denote the total profit and total weight, respectively. Variables xi denote the number of item types i to be placed in the knapsack, and C denotes the capacity of the knapsack.
We herein address the generalized multidimensional knapsack problem (GMDKP) by extending 0–1 1DKP in the following two directions:
- (a)Introduction of multiple constraints on total weights as for μ ∈ {1, ..., K}, which is termed as multi-dimensionalization [6].
- (b)Relaxation of the maximum number up to which each item type can be chosen [6]. This implies that we allow each item type i to be selected up to times. The 0–1 1DKP corresponds to the case of .
Specifically, GMDKP is expressed as follows:
Two issues are worth discussing here. The first issue is related to the theoretically achievable limit of the total profit of the GMDKP, which offers a baseline for examining the performance of search algorithms. Korutcheva et al [7] considered a multidimensional version and analyzed the typical properties of solutions under a random set up while maintaining . We term this version the multidimensional knapsack problem (MDKP). Later, Inoue [8] examined MDKP by relaxing non-negative integers xi to spherically constrained real numbers. However, no such typical case performance analyses have been obtained for GMDKP.
The second issue concerns the algorithm for finding the solution of GMDKP. Even in the basic case, KPs are known to belong to the class of NP-hard [9]. A significant amount of effort has been made to overcome the computational hardness, which can be classified into two directions. The first direction involves searching for exact solutions. It has been empirically shown that methods based on dynamic programming [10] and the branch-and-bound method [11] can find exact solutions very efficiently for many instances of 0–1 1DKP. However, such methods are not applicable to GMDKP. Therefore, for the extended KPs, we should resort to the second direction, which aims to efficiently search good approximate solutions. In this direction, it is experimentally shown that a greedy-type heuristic algorithm can find fairly good approximate solutions for randomly generated GMDKPs [12]. However, its possibilities and limitations have not been theoretically clarified yet.
In view of the current situation, we analyze a random ensemble of GMDKP using the replica method to clarify the typically achievable limit of the total profit. The result of the analysis indicates that when the profits of item types are normally distributed, the total profit grows in the leading order with respect to the number of item types as the maximum number of choices per item type xmax increases while it depends on xmax only in a sub-leading order if the profits are constant among the item types. Besides, it also implies that a nearly optimal solution whose total profit is lower than the optimal value only by a sub-leading order can be found by the aforementioned greedy-type algorithm with a low computational cost. However, further improving the total cost in the sub-leading order is still non-trivial. For accomplishing this, we develop a heuristic algorithm based on the cavity method. Extensive numerical experiments support the analytical results and the usefulness of the developed algorithm.
The remainder of this paper is organized as follows. In the next section, we introduce a random ensemble of GMDKP, which is analyzed. In section 3, we theoretically examine the typically achievable limit of the total profit for the introduced problem ensemble. In section 4, we numerically validate the results obtained in section 3. We also develop a heuristic algorithm for the sub-leading order improvement. The final section is devoted to discussion and future prospects.
2. Problem setup
To examine the typical properties of GMDKP, we consider an ensemble that is characterized by the following simplified conditions:
- Fix to a constant xmax for ∀i ∈ {1, ..., N}.
- Cμ ≡ CN for ∀μ ∈ {1, ..., K}, where C > 0 is a proportional constant.
- vi (∀i ∈ {1, ..., N}) are independently distributed from an identical Gaussian distribution , where 0 σV ≪ V.
- wμi (∀i ∈ {1, ..., N}, ∀μ ∈ {1, ..., K}) are independently distributed from another identical Gaussian distribution , where 0 < σW ≪ W.
A distinctive feature of the KP is the positivity of the profit (vi ) and weight (wμi ) parameters. The current simplifying setup incorporates this feature with a small number of parameters although possible correlations among the parameters that may exist in realistic problems are ignored.
3. Statistical mechanics analysis on the optimal solution
We compute the typical value of the achievable U in the limit of N, K → ∞ by maintaining their ratio K/N = α ∈ [0, ∞). In the following, we use N → ∞ as a shorthand notation of this scaling limit to avoid cumbersome expression. Hence, we first transform the total weights to appropriate expressions under the assumption that the solution is placed in the vicinity of the boundaries of the weight constraints [7], which means that the total number of chosen items satisfies
Inserting wμi = W + ξμi , where , into the definitions of total weights, this yields the following decomposition with respect to the total weights.
where
M controls the difference of the total number of chosen items from its leading term NC/W in the scale of . These expressions indicate that the total weights are constant in the leading order of O(N) and vary in the next order of based on the choice of . Handling as a Hamiltonian, where , we compute the partition function with the inverse temperature β > 0 as
where Θ(x) = 1 (x ⩾ 0) and 0 (x ⩽ 0), and Tr x denote the summation with respect to all possible choices of .
Zβ ( ξ , η , M) varies randomly depending on the realization of ξ = (ξμi ) and η = (ηi ), and it is supposed to scale exponentially with respect to N. This implies that its typical behavior can be examined by assessing the average of its logarithm (free entropy). This naturally leads to the use of the replica method. More specifically, for , we compute the moment , where denotes the average operation with respect to ξ and η , as a function of n and continue the obtained functional expression to . Subsequently, we evaluate the average free entropy per item type using the identity
After some calculations (details are provided in appendix
where extrX {...} denotes the operation of the extremization of ... with respect to X, and
The typical value of the maximum total profit (per item type) is assessed as
In the following, we describe the results obtained by the above computation for and , separately, as they are considerably different between the two cases.
Case of .
In the limit of β → ∞, the variables in (4) scale so as to satisfy χ = β(Q − q) ∼ O(1), , , . Using the new variables, the extremum condition is expressed as
where
The solution determined by these offers the maximum per item type total profit as
and entropy (per item type) as
However, we must keep in mind that the solution is obtained under the RS ansatz, which may not be valid for β → ∞. The stability analysis against the perturbation that breaks the replica symmetry [13] indicates that the RS solution is locally unstable if
is satisfied. Equation (6) means that x* varies discontinuously by unity at certain values of z, which leads to [14]. These conclude that (7) is satisfied, which indicates that the RS solution is invalid, as long as M is finite. As the replica symmetry breaking (RSB) implies that finding the lowest energy (the optimal profit) solution is challenging due to ragged energy landscapes, this also suggests that designing the way of optimally packing items in the knapsack is computationally difficult.
Meanwhile, (7) also implies that the validity of the RS solution is recovered for M → −∞ as holds. In addition, as E, F → 0 holds, we can obtain an analytical expression of the RS solution in this limit as
which yields
where A is the solution of H(A) = C/(xmax W).
Equation (8) corresponds to the solution obtained by choosing NC/W + o(N) items from the item types of higher vi values, which we term the 'greedy packing'. This bounds the leading order term of U from above by since choosing O(N) items further on top of the NC/W + o(N) items typically breaks some of the weight constraints. On the other hand, the upper bound is easily achieved by choosing by the greedy packing. This is because the largest value of the fluctuation terms uμ (μ = 1, ..., αN) in (2) scales typically as , and therefore, all the weight constraints are typically satisfied if we set a sufficient size 'margin' by reducing the total number of chosen items from NC/W by without changing the leading O(N) term of U.
In summary, we obtain the following results:
- The optimal total profit grows with xmax in the leading term of O(N).
- Finding the truly optimal solution would be computationally difficult.
- However, achieving the total profit that is lower than the optimal value only by would be easy by employing the greedy packing.
Case of .
Unlike the case of , the variables in (4) remain O(1) even in the limit of β → ∞. This is because the constraint for the total number of chosen items (1) makes β irrelevant to the extremum condition of (4). More precisely, expressing , the extremum of (4) is characterized by
independently of β, where
The resultant solution yields the per item type total profit for N → ∞ as
which, unlike the case of , does not vary with xmax. The solution also offers the per item type entropy as
which does not depend on β.
Figure 1 shows S versus M for several values of α for xmax = 1, which indicates that for all the value of α, S becomes positive for M below a certain critical values of Mopt(α) at which S vanishes. Such behavior is also the case for xmax ⩾ 2. Figure 2 plots Mopt(α) versus xmax. This indicates that Mopt(α) increases with xmax, but almost saturates for xmax ≳ 10. The local stability of the RS solution would be broken if
were satisfied. However, (12) does not hold for M < Mopt(α) indicating that the RS solution is valid.
Download figure:
Standard image High-resolution imageTo summarise, we reach the following conclusions:
- The optimal total profit does not depend on xmax in the leading term of O(N).
- Solutions are highly degenerated up to the sub-leading term of of the total profit. This has also been pointed out for the case of xmax = 1 in [7]. For M < Mopt(α), exponentially many solutions achieve the value of total profit . The solutions vanish at M = Mopt(α), which indicates that the optimal total profit is provided as
- The total profit is improved monotonically in the term of by increasing xmax, but almost saturates for xmax greater than a moderate value.
4. Search algorithms
4.1. Achieving leading order optimality by greedy packing
The results in the previous section imply that the greedy packing can find a nearly optimal solution with a low computational cost. For confirming this, we carried out numerical experiments using OR-Tools by Google [15] and PECHγ by Akçay et al [12].
OR-Tools provides an exact algorithm that can efficiently find the exact solutions for problems of moderate sizes. However, the necessary computational cost still grows exponentially with respect to N in the worst case. Therefore, its use is practically limited to N of several tens. Additionally, it is applicable only for 0–1 MDKP. On the other hand, PECHγ is a greedy-type heuristic in which the greediness is controlled by a parameter γ ∈ (0, 1]. By setting γ = 1, in each iteration, it chooses at most xmax items from the remainders so as to maximize the increase of the total profit until a certain weight constraint is violated. This realizes the greedy packing.
Figure 3 plots the achieved per item type total profit versus the number of item types N for a case of . As mentioned in section 3, the largest value uμ (μ = 1, ..., αN) in the weight constraints (2) scales as O((N log N)1/2). This implies that for finite N, the difference of the per item type total profit achieved by PECH1.0 from of (9) is proportional to N−1/2(log N)1/2 in the leading order. On the other hand, such dependence for the exact solution obtained by OR-tools is nontrivial, but we speculate that the leading order is O(N−1/2). This is because we should be able to construct physically valid replica solutions at least in a certain range of finite M by taking RSB into account, which means that the total number of chosen items can grow from NC/W − O((N log N)1/2) to NC/W − O(N1/2) by optimizing the choice of items. Values extrapolated from experimental data to N → ∞ assuming the abovementioned scaling forms exhibit considerably good agreement with theoretical prediction (9) in view of the corrections by terms of o(N−1/2(log N)1/2).
Download figure:
Standard image High-resolution imageThe results for are plotted in figure 4. We employed the scaling forms of O(N−1/2(log N)1/2) and O(N−1/2) for PECH1.0 and OR-tools, respectively, as in the case of . The employment of O(N−1/2) for OR-tools is more reasonable than that for as the finiteness of M for the optimal solution is supported by the stability of the RS solution. Meanwhile, as shown in figure 2, Mopt, which corresponds to the prefactor of the term of O(N−1/2) in of the exact solution, almost vanishes for the examined parameter setting. We, therefore, determined the value of for OR-Tools by the extrapolation under the assumption of taking into account the contribution of the higher order term of O(N−1). This as well as the extrapolation for PECH1.0 again results in significantly good accordance with the replica prediction. However, unlike the case of , the achieved per item type total profit depends little on xmax.
Download figure:
Standard image High-resolution image4.2. Performance improvement in sub-leading order by cavity method
The greedy packing implemented by PECH1.0 achieves the leading order optimality with an O(N) computational cost. However, for finite N, the achieved total profit is still lower than the truly optimal profit by O((N log N)1/2). We here develop a method for reducing the gap using the cavity method [16].
For this purpose, we consider the 'canonical distribution' of x = (xi ), , i = 1, ..., N that satisfy all the weight constraints given by as
and evaluate the marginal distributions , where β > 0 is a parameter for controlling the emphasis on the total profit. Ξ is a normalization constant. Then, we find item type i* that maximizes the probability of being non-zero , put one item of i* in the knapsack, and reduce by one as . We also subtracted the upper bounds of weight Cμ as . We repeat these procedures as long as the weight constraints are satisfied. After the final repetition, the items in the knapsack constitute an approximate solution. We refer to this procedure as 'marginal-probability-based greedy strategy' (MPGS). The pseudo-code for the procedure is summarized in algorithm 1.
Algorithm 1. MPGS.
Input: |
Output: xi (i = 1, ..., N) |
xi := 0 (i = 1, ..., N) |
i* := 0 |
while Cμ ⩾ 0, ∀μ and do |
Evaluate with algorithm 2 or 3 |
i* ←argmaxi pi (xi ≠ 0|D) |
if or then |
break |
else |
for μ = 1 to K do |
Unfortunately, it is computationally difficult to conduct this greedy search because the computational cost for assessing the marginal distributions from the joint distribution grows exponentially with respect to N. We employed the cavity method to resolve this problem. To perform this, we depict the joint distribution by a factor graph (figure 5) and recursively update messages defined on the edges between the factor and variable nodes as
by following the recipe of belief propagation (BP), which provides efficient algorithms for finding the solution of the cavity method [16]. After determining the messages, the marginal distribution is approximately assessed as follows:
where cμ→i , ci→μ , and ci are normalization constants.
Download figure:
Standard image High-resolution imageThe exact performance of the BP algorithm is still computationally infeasible as the computational cost for evaluating (15) grows exponentially with respect to N. This problem is solved by the Gaussian approximation employed in the approximate message passing technique [17, 18]. More precisely, utilizing the central limit theorem, we consider ∑j≠i wμj xj in (15) as a Gaussian random variable, which is characterized by mean Δμ→i = ∑j≠i wμj mj→μ and variance , where mj→μ and χj→μ denote mean and variance of , respectively. Hence, it is possible to analytically evaluate (15) as follows:
This reduces BP of (15) and (16) for updating equations with respect to 4NK variables, mi→μ
, χi→μ
, Δμ→i
, and Vμ→i
, which are defined as edges in the factor graph. The BP algorithm is reduced as described above, and it is summarized with the pseudo-code in algorithm 2. The computational cost can be further reduced by expressing the BP algorithm to that for variables defined for nodes, which is sometimes referred to as generalized approximate message passing (GAMP) [17, 19, 20]. Its derivation and the pseudo code (algorithm 3) are provided in appendix
Algorithm 2. BP.
Input: | |
Output: | |
while messages not converged do | |
Δμ := 0, Vμ := 0 (μ = 1, ..., K) | |
for i = 1 to N do | ▹Pre-calculation |
for μ = 1 to K do | |
Δμ ← Δμ + wμi mi→μ | |
for xi = 0 to do | |
for i = 1 to N do | |
for μ = 1 to K do | |
Δμ→i := Δμ − wμi mi→μ | |
for xi = 0 to do | |
Normalize | |
for i = 1 to N do | |
for xi = 0 to do | |
Normalize |
Three issues are noteworthy. The first issue is with respect to the necessary cost of computation. Given that it is necessary to assess summations over μ = 1, ..., K and i = 1, ..., N for each of i = 1, ..., N and μ = 1, ..., K, respectively, the computational cost of this algorithm is O(NK) per update, where is assumed as O(1). Furthermore, we should repeat the computation until convergence with respect to each choice of one item, which implies that the cost of finding an approximate solution increases with respect to O(NKT), where T denotes the number of selected items, as long as the number of iterations necessary for the convergence is O(1) per choice. Although this may not be low-cost, it is still feasible in many practical situations. At the selection of the next item, starting with the convergent solution for the last choice, which is termed as 'warm start', is effective for suppressing the number of iterations. In addition, as the leading order optimality is achieved by the greedy packing, we can limit the employment of MPGS to the 'final stage' of the solution search. For instance, after obtaining a solution by PECH1.0, it would be reasonable to improve the solution by redoing the last 10% search by MPGS. In such cases, the practical system size is reduced considerably, for which the computational cost would not be a big problem.
The second is about the setting of β. The larger values emphasize the greediness of the solution search; the larger β prefers item types of the larger vi . However, too large β prevents BP from converging due to the occurrence of RSB unless vi is constant among the item types. Hence, we have to tune the value of β. In the experiments shown below, we set β = 2–10, for which BP converged.
The final issue is related to the validity of the current approximate treatment. The developed algorithm yields the exact results under appropriate conditions, as N → ∞, if wμi 's are provided as independent random variables sampled from a distribution with zero mean and finite variance [20, 21]. Unfortunately, they are biased to positive numbers in KPs, including GMDKP, which does not guarantee the accuracy of the obtained solutions. Nevertheless, the cavity/BP framework provides another advantage in terms of technical ease for computing marginal distributions. The naive mean field method (nMFM) [22] and Markov chain Monte Carlo (MCMC) are representative alternatives for assessing marginals. However, nMFM cannot be directly employed for (14) because diverges to −∞ for x that do not satisfy the weight constraints. Additionally, MCMC in systems such as (14), hardly converge as they are in frozen states at any temperature [23]. Hence, they offer a rational reason for selecting the cavity/BP framework as the basis of the approximate search algorithm. Replacing BP with expectation propagation (EP) [24, 25], which can somewhat incorporate the correlations among wμi 's, can be another option. However, EP requires a higher computational cost of per update than BP, which limits its employment to relatively small systems.
Figure 6 compares the rescaled difference of the achieved total profit among OR-tools, PECH1.0, and MPGS (based on BP) for N = 80 and xmax = 1 under the setting of figure 3 that corresponds to . Data of OR-Tools is plotted only for α = 0.1 as obtaining data for lager α is difficult due to the limitation of computational resources. Although the total profit of MPGS is considered lower than that of OR tools, it is larger than that of PECH1.0 at all of the examined values of α. A similar tendency is also observed for (figure 7). Meanwhile, error bars of MPGS for are considerably larger than those for , which may be due to the influence of RSB. This implies that the total profit for cases could be further improved by generalizing BP so as to take RSB into account [26, 27].
Download figure:
Standard image High-resolution imageDownload figure:
Standard image High-resolution image5. Summary
In summary, we analyzed a random ensemble of GMDKP, which is a generalized version of the KP. The KP is a representative NP-hard optimization problem. Using the replica method, we assessed the achievable limit of the total profit under multiple weight constraints for typical samples of the ensemble. Our analysis showed that despite the NP-hardness, one can achieve a nearly optimal total profit that accords with the truly optimal value in the leading order with respect to the number of item types N with an O(N) computational cost. Several earlier studies report that KPs may be among the 'easiest' NP-hard problems [28–31]. Although the studies argue not the approximation accuracy but the computational cost for finding the exact solution, our analysis may offer a useful clue for understanding the 'easiness' of solving KPs.
We also developed a heuristic algorithm to improve the total profit in the sub-leading order by the cavity method. Extensive numerical experiments showed that the developed algorithm outperforms other existing algorithms.
In this study, we assumed that the weight and profit parameters of GMDKP were independently provided from certain distributions. However, these parameters can show some correlations in realistic problems. Hence, examining the property of solutions for such cases is an important future task.
Acknowledgments
Useful comments from anonymous referees are appreciated. This study was partially supported by JSPS KAKENHI Grant Nos. 21K21310 (TT), 17H00764 (YK), and JST CREST Grant No. JPMJCR1912 (YK).
Data availability statement
No new data were created or analysed in this study.
Appendix A.: Details of replica calculation
where represents the summation with respect to all possible choices of . By introducing the RS assumption
we have
The last term can be computed as follows:
Finally, we have
Appendix B.: GAMP
GAMP provides the following update equations for node variables as follows:
for i = 1, ..., N, and
for μ = 1, ..., K, where . After obtaining these variables, the marginal distributions are assessed as . This update rule is summarized in algorithm 3.
Algorithm 3. GAMP.
Input: |
Output: |
while not converged do |
for i = 1 to N do |
for μ = 1 to K do |
for i = 1 to N do |
for xi = 0 to do |
Normalize |
Its derivation is as follows. We employ Taylor's expansion of up to the second order of handling as a small number, which leads to the following expression.
where and .
This provides the mean and variance of as
and those of , mi , and χi , as
where , , , and The small size of validates handling ai→μ ≃ ai and χi→μ ≃ χi for i = 1, ..., N and μ = 1, ..., K. This yields for μ = 1, ..., K, and i = 1, ..., N. Similarly, as the difference between Δμ→i and is relatively small, . Furthermore, we expand mi→μ as and provide
where . Additionally, Taylor's expansion, yields
The aforementioned expressions provide the update equations for the node variables.