Next Article in Journal
Bi-Squashing S2,2-Designs into (K4e)-Designs
Previous Article in Journal
Fractional Neutral Integro-Differential Equations with Nonlocal Initial Conditions
Previous Article in Special Issue
Communication-Efficient Zeroth-Order Adaptive Optimization for Federated Learning
 
 
Font Type:
Arial Georgia Verdana
Font Size:
Aa Aa Aa
Line Spacing:
Column Width:
Background:
Article

An Improved Unbounded-DP Algorithm for the Unbounded Knapsack Problem with Bounded Coefficients

School of Mathematical Sciences, Xiamen University, Xiamen 361005, China
Mathematics 2024, 12(12), 1878; https://doi.org/10.3390/math12121878
Submission received: 9 May 2024 / Revised: 10 June 2024 / Accepted: 14 June 2024 / Published: 16 June 2024
(This article belongs to the Special Issue Analysis and Application of Optimization Algorithms)

Abstract

:
Benchmark instances for the unbounded knapsack problem are typically generated according to specific criteria within a given constant range R, and these instances can be referred to as the unbounded knapsack problem with bounded coefficients (UKPB). In order to increase the difficulty of solving these instances, the knapsack capacity C is usually set to a very large value. While current efficient algorithms primarily center on the Fast Fourier Transform (FFT) and (min,+)-convolution method, there is a simpler method worth considering. In this paper, based on the basic Unbounded-DP algorithm, we utilize a recent branch and bound (B&B) result and basic theory of linear Diophantine equation, and propose an improved Unbounded-DP algorithm with time complexity of O ( R 4 ) and space complexity of O ( R 3 ) . Additionally, the algorithm can also solve the All-capacities unbounded knapsack problem within the complexity O ( R 4 + C ) . In particular, the proof techniques required by the algorithm are primarily covered in the first-year mathematics curriculum, which is convenient for subsequent researchers to grasp.

1. Introduction

Definition 1
([1,2,3,4,5]). Given a multiset N consisting of n item types and a total of n items, where all items of the j-th type have the same profit p j , weight w j , and p j , w j N + . Each type can be selected unlimited times. The goal of the unbounded knapsack problem (UKP) is to find an optimal multisubset (i.e., a set that allows multiple copies of the same element) of the multiset N such that its total profit is maximized without exceeding the knapsack capacity C. The problem can be formulated as follows.
max   f ( X ) = j = 1 n p j x j
s . t . j = 1 n w j x j C ,
x j N .
The variable x j denotes the frequency with which the j-th type is selected. The UKP is akin to the 0–1 knapsack problem (0–1 KP), sharing the same objective and capacity constraints. A key distinction of the UKP is that the j-th type can be selected an unlimited number of times, as detailed in Equation (3). Specifically, without loss of generality, we arrange items in descending order of their profit density ratio, i.e., p 1 / w 1 p 2 / w 2 p n / w n .
The UKP is not only a variant of the 0–1 KP, it is also a special form of integer linear programming when the constraint number is only 1 (i.e., m = 1 ). As such, it is an NP -hard problem [6,7,8,9,10,11]. NP -hard problems have widespread applications in cryptology [12], commercial decision-making, and industrial manufacturing, leading to significant economic value. A well-known example of the UKP is the change-making problem, also referred to as the coin-changing problem. It involves determining how a cashier can minimize the number of coins used when providing change to a customer, considering an unlimited supply of coins for each denomination [13]. Therefore, efficient and exact algorithms have attracted the attention of numerous researchers. Unfortunately, the research progress on efficient algorithms is slow due to limitations in mathematical tools [14,15]. Currently, there is no exact polynomial-time algorithm to solve the UKP, except for dynamic programming (DP), which can provide an exact solution in pseudo-polynomial time complexity [16,17].
Although there are currently no efficient algorithms to solve general NP -hard problems exactly, taking into consideration practical application context, extensive research has been conducted on improving algorithms in the following three directions. The first direction is based on methods such as linear relaxation within the framework of the branch and bound algorithm (B&B) [18]. By improving the Dantzig bound [19] and later the cutting plane method [9,20,21], it aims to solve as many decision variables as possible in polynomial time complexity, reducing the number of exhaustive subproblems and enhancing the algorithm’s solving speed. The selection of upper bounds is typically within a time complexity of O ( n 2 ) , such as in [22,23,24,25]. The second direction utilizes mathematical tools, including number theory, to enhance the speed of basic dynamic programming (BDP) and reduce the pseudo-polynomial time complexity, such as in [26,27,28,29]. The third direction involves adding as few and as general constraints as possible to transform NP -hard problems into P , such as utilizing specific data features [30,31,32,33,34] or fixing the number of variables [35,36,37,38,39].
To demonstrate the performance of improved algorithms, researchers typically test them on benchmark instances of varying scales, which are generated according to specific criteria. Given a positive integer R, it raises an intriguing question of whether an instance with parameters ranging from 1 to R can be solved in polynomial time. Taking the UKP as an example, if the profit p j and weight w j of each type in an instance are positive integers that do not exceed R, the number of possible decisions is limited to at most R 2 . To incorporate bounded coefficients, the unbounded knapsack problem with bounded coefficients (UKPB) introduces the following constraints to the UKP model:
p j , w j R .
Dynamic programming can solve the 0–1 KP exactly within the polynomial time complexity O ( n 2 R ) when inequality (4) holds for any capacity constraint C. Whereas, for any capacity constraint C in the UKPB, the input length can be expressed as log 2 C . The BDP solves the UKPB exactly in complexity O ( n C ) , while basic B&B solves it in time complexity O ( j = 1 n C w j ) . Clearly, when C is a sufficiently large number, neither BDP nor basic B&B can solve the UKPB exactly within polynomial time complexity. It is important to note that the polynomial-solvable algorithm is not straightforward in its design and implementation. However, by fixing the number of variables, a polynomially solvable algorithm for integer linear programming, and therefore also for the UKPB, was presented in the famous paper by Lenstra [2,38], with the proof technique derived from the geometry of numbers.
Since the coefficients of UKPB are bounded, when the time complexity of an algorithm depends solely on R and n , the algorithm will still have a polynomial time complexity. As a result, many researchers have conducted a series of studies on algorithms, in terms of R or n , by Fast Fourier Transform (FFT) and the (min, +)-convolution method [13,29,40,41,42,43,44]. Although Chan and He [13] proposed an algorithm that can solve the UKPB and AUKP in complexity O ( R 2 log R ) and O ( R 2 log R + C ) , respectively, the algorithm cannot provide the optimal solution but optimal objective value. Due to the hardness of the solving method, it is worth expecting simpler and more efficient algorithms.

1.1. Our Results

In this paper, we propose an exact and simple pseudo-polynomial time complexity algorithm for the UKPB. The time and space complexities of the algorithm are O ( R 4 ) and O ( R 3 ) , respectively, where R is an upper bound of coefficients. These complexities do not change with the capacity of the knapsack C. In particular, since R is a given integer, the time and space complexities of the algorithm are both O ( 1 ) . Therefore, the algorithm is a constant time complexity algorithm. Moreover, the algorithm can also be used to solve the All-capacities unbounded knapsack problem (AUKP) in complexity O ( R 4 + C ) . Compared with the results of Chan and He [13], our algorithm can provide not only an optimal objective value but also the optimal solution.
Furthermore, the method primarily employs fundamental mathematical concepts that are typically included in the first-year mathematics curriculum, such as Elementary Number Theory and Data Structure. The proof tools employed are straightforward, ensuring subsequent researchers can easily grasp and build upon them.

1.2. Sketch of Proof Techniques

Our method first obtains the break type b and residual capacity r using the common greedy algorithm [2,5]. Then, the types in the set N are divided into two disjoint subsets, N 1 and N 2 , where the profit density of types in N 1 and N 2 are equal to and less than the break type, respectively. That is, N 1 = { j | p j / w j = p 1 / w 1 } and N 2 = { j | p j / w j < p 1 / w 1 } . Finally, through linear relaxation, we obtain an upper bound for the problem.
For the types in N 2 , we employ a recent B&B theoretical result by Dey et al. [45], derived from analyzing the performance of the B&B in solving random integer linear programming problems, and obtain an upper bound on the number of times a type in N 2 can be selected. In other words, for the j-th type in N 2 , if a solution has x j > R 2 , then the solution cannot be optimal. Consequently, types in N 2 can be exactly solved with a space complexity of O ( R 3 ) and a time complexity of O ( R 4 ) using the unbounded-DP method [2].
For the types in N 1 , we first utilize the unbounded-DP to solve the subproblem with a capacity of 2 R 2 + 2 R . When the knapsack capacity C exceeds R 2 + 2 R , we transform the problem of finding the optimal type selection into a linear Diophantine equation (LDE) [46,47,48,49,50,51,52]. Since R is bounded, the LDE of N 1 is defined over the finitely generated field [53]. We employ the Euclidean algorithm to compute the greatest common divisor of the types of weights in N 1 , denoted as gcd ( W 1 ) , which can be computed with a time complexity of O ( n log R ) . Subsequently, we apply Bézout’s theorem and classical results of Frobenius numbers [52,54,55,56] to obtain an optimal solution for the problem.
For the AUKP, like the single-capacity UKPB, we first use the unbounded-DP algorithm to solve the subproblem with a capacity of R 3 + 2 R 2 + 2 R in time complexity O ( R 4 ) . When the knapsack capacity C exceeds R 3 + 2 R 2 + 2 R , we solve the problem recursively by the above algorithm in complexity O ( R 4 + C ) .

1.3. Organization of the Paper

The rest of this paper is organized as follows: Section 2 provides an overview of the preliminary tools required for the subsequent proofs. The main theoretical results and their proofs are presented in Section 3. Section 4 applied the algorithm to solve the AUKP. In Section 5, we summarize the paper.

2. Preliminary

2.1. Dynamic Programming

For NP -hard problems that satisfy the Bellman Optimality Principle, dynamic programming (DP) has been an important method for solving them. BDP, which typically takes the time and space complexity respectively of both O ( n C ) , yields the optimal solution to the UKP, denoted by Y  [2]. Let DP ( j , k ) represent the optimal solution for selecting the first j items under the constraint of a given knapsack capacity of k. Clearly, DP ( n , C ) is the optimal solution to the original problem and can be obtained through the following recursive equation
DP ( j , k ) = DP ( j 1 , k ) , if k < w j , max { DP ( j 1 , k ) , DP ( j 1 , k w j ) + p j } , if k w j .
BDP requires n arrays of size C for a given capacity constraint. As the capacity increases, the storage cost increases significantly. With the development of data structures, an unbounded dynamic programming (unbounded-DP) approach based on linked list storage and addressing unbounded constraints has been proposed in [2]. Although the time complexity remains unchanged, the space complexity of the unbounded-DP can be reduced to O ( n + C ) , which is a significant improvement. The pseudo-code for the unbounded-DP is presented as follows.
The unbounded-DP algorithm first initializes a recursive array DP of length C + 1 and a types selection array T. Next, the algorithm employs a recursive method similar to BDP to obtain the array DP (Algorithm 1, lines 2–5). Clearly, the objective function value is f ( Y ) = DP ( C + 1 ) . Finally, the optimal solution Y is obtained from the array T (Algorithm 1, lines 7–8).
Algorithm 1 Unbounded-DP
Require:  n , W , P , C
Ensure:  Y
1:
DP = zeros ( 1 , C + 1 )
2:
T = DP
3:
for  j = 1 : n  do
4:
    for  k = w j + 1 : C + 1  do
5:
        if  DP ( k w j ) + p j > DP ( k )  then
6:
                DP ( k ) = DP ( k w j ) + p j , T ( k ) = j
7:
        end if
8:
    end for
9:
end for
10:
t = C + 1 , Y = zeros ( 1 , n )
11:
while  t > 1  do
12:
     k = T ( t ) , y k = y k + 1 , t = t w k
13:
end while
It is worth noting that for the UKP, even state-of-the-art dynamic programming algorithms such as EDUK have a time complexity of O ( n C )  [2,5,57]. Furthermore, the most special case of the UKP, where all types have the same profit density, is known as the unbounded subset sum problem (USSP). Unfortunately, both for the UKP and USSP, the time and space complexity of state-of-the-art dynamic programming algorithms include at least one term of C [2,5,28,29]. In particular, Pisinger proposed an encoding method for USSP that achieves exact solutions with a time complexity of n C log C and a space complexity of C log C [58]. Clearly, these methods are still not polynomial-time algorithms for UKPB.

2.2. Branch and Bound

B&B, proposed by Ailsa and Alison [18], is often more efficient for solving linear integer programs with a larger knapsack capacity, and it is widely used for solving the 0–1 KP and its variants [2]. Given an instance of the UKP, B&B embeds all possible solutions in a search tree. Each level of the search tree represents a decision variable, and the j-th level of the search tree has C w j nodes. The entire search tree contains a total of j = 1 n C w j nodes. Faced with an exponential number of solutions, B&B first introduces a lower bound for the original problem commonly obtained from a greedy algorithm or heuristic algorithm as v ̲ ( P ) . Then, the algorithm fixes a decision variable with a value of α where α N and generates a subproblem. Through linear relaxation, the subproblem is transformed into a convex problem [59], and its optimal solution is quickly obtained in the O ( n ) time complexity, denoted as v ¯ ( P | x j = α ) . Clearly, if v ¯ ( P | x j = α ) < v ̲ ( P ) , then we can conclude that y i α and prune the branch in the search tree. While B&B can quickly solve general instances, it still requires an exhaustive search of the exponential number of feasible solutions for certain special structured instances [2].
During the process of solving subproblems, the computation method of the upper bound, first proposed by Dantzig [19], is undoubtedly essential. For the UKP, a well-known upper bound can be expressed as follows:
U = C w 1 p 1 + r p 2 w 2
where r is the residual capacity and
r : = C C / w 1 w 1 .
By utilizing the upper bound, we can obtain the following results in the 0–1 KP.
Theorem 1
([22]). For the j-th item, if
p j r w j p b w b > 0 ,
we can conclude that y j = 0 , where Y denotes the optimal solution.
Recently, Dey et al. [45] proposed that, for a fixed number of constraints, B&B can achieve exact solutions in polynomial time for random integer programs with good probability. Yang [60] applied the result to the 0–1 KP and derived the following theorem.
Theorem 2.
Given a set of items N where the j-th item satisfies the inequality
p j w j + r / i > p b w b
for i N , we can conclude that j N | x j y j | i 1 .
Clearly, Theorem 2 cannot apply to the UKP, and we need to make improvements to it.

2.3. Linear Diophantine Equation

Both Theorems 1 and 2 rely on the profit density of the types, and as a result, these two methods are unable to achieve exact solutions for the USSP, which is a special case of the UKP, within polynomial time complexity.
It is interesting to note that within the field of operations research, the USSP has a similar counterpart in number theory known as the linear Diophantine equation (LDE). Classic results exist concerning the integer solutions of the LDE, which can be expressed as follows.
Lemma 1
([61,62]). Given two positive integers a and b, where a < b , the greatest common divisor of a and b, denoted as gcd ( a , b ) , can be computed in time complexity O ( log a ) by the Euclidean algorithm.
Theorem 3
([51,63]). Let gcd ( W 1 ) denote the greatest common divisor of the weights associated with each type in the multisubset N 1 . If gcd ( W 1 ) | C , then the equation
j N 1 x j w j = C
has infinitely many integer solutions.
In Theorem 3, if Equation (9) has an infinite number of solutions, the existence of non-negative integer solutions becomes an important question. Frobenius was the first to bring up this problem, i.e., determining when Equation (9) must have non-negative integer solutions as C varies, and this is known as the Frobenius Problem (FP) [64]. FP has attracted significant attention from researchers [52,54,55,56], and a classic result in this field can be formulated as follows.
Theorem 4
([51,52,63,64]). If C ( min { W 1 } 1 ) ( max { W 1 } 1 ) and gcd ( W 1 ) | C , then Equation (9) must have at least one non-negative integer solution.
Additionally, Theorem 4 serves as a generalization of Exercise 19 in Section 3.7 of [51].

3. A Constant Time Complexity Algorithm for the UKPB

For the UKPB and a given constant R, the maximum number of decision variables is no more than R 2 . From the dominate rule, we can reduce the value of n , and thus obtain the following lemma.
Lemma 2.
For two types j 1 and j 2 with identical weights, i.e., w j 1 = w j 2 , if p j 1 > p j 2 , then we have y j 2 = 0 . Consequently, we have n R .
According to Lemma 2, the time and space complexity of a constant time complexity algorithm can only include constants R and the number of types n . In this paper, we propose an algorithm that can exactly solve the UKPB within a time complexity of O ( R 4 ) and a space complexity of O ( R 3 ) . The key to this algorithm lies in restricting the selection times of types under the premise of ensuring the existence of an exact solution.

3.1. An Upper Bound for the Selected Times of the Type in Set N 2

Motivated by Theorem 2, a corresponding theorem applicable to the UKP can be formulated as follows.
Theorem 5
([60]). Given a subset S i of N 2 such that for i N + , the j-th type satisfies the inequality
p j w j r / i p b w b > 0 ,
then we have j S i | y j | i 1 .
For a subset S i of N 2 that satisfies the inequality (10), each type can be selected at most i 1 times. In the case of the UKPB, if there exists an integer i with an upper bound represented by ploy ( R ) , the types in N 2 can be selected at most ploy ( R ) times. Furthermore, the time and space complexity of solving the UKPB using dynamic programming does not depend on the capacity C. We provide an upper bound for the constant i based on the definition of N 2 as follows.
Theorem 6.
For the j-th type in N 2 , if p b , w b , p j , w j R , then we have i R 2 .
Proof of Theorem 6.
By the definition of the j-th type, considering that p b , w b , p j , w j are all integers, we have the
p b w j p j w b 1 .
Bringing equality (6) and inequality (11) into inequality (10), we can conclude that
i > p b w b p b w j p j w b .
Clearly, if w b p b p b w j p j w b R 2 , then the original proposition holds. Suppose to the contrary that
p b w b p b w j p j w b > R 2 .
Bring inequality (11) into inequality (12), then we have
p b w b > R 2 ( p b w j p j w b ) R 2 .
Since p b , w b R , we can infer that
p b w b R 2 .
The inequalities expressed in inequality (13) and inequality (14) are contradictory, therefore, the original proposition holds. The proof of Theorem 6 is complete.    □
According to Theorems 5 and 6, it follows that the subsequent conclusion can be deduced.
Theorem 7.
j N 2 y j w j R 3 .
Proof of Theorem 7.
From Theorems 5 and 6, we conclude that S R 2 = N 2 . Therefore, for the optimal solution Y , the types in N 2 can be selected at most R 2 1 times, i.e., j N 2 y j R 2 1 . The maximum weight of a type in N 2 is R. Consequently, for the optimal solution Y , we can conclude that j N 2 y j w j R 3 . The proof of Theorem 7 is completed.    □
From Theorem 7 and the unbounded-DP algorithm, we can conclude as follows.
Theorem 8.
All types of set N 2 can be exactly solved in time complexity O ( R 4 ) and space complexity O ( R 3 ) .

3.2. An Algorithm for Types of Set N 1

Theorem 8 utilizes unbounded-DP to generate R 3 subproblems. Given an integer t on the interval [ 1 , R 3 ] , we need to find an optimal solution in N 1 within the polynomial time complexity, such that the weighted sum of the optimal solution does not exceed C t . At least one of the time and space complexities of directly applying the unbounded-DP to solve the subproblems exhibits a growth rate greater than C. Consequently, further processing of the subproblems is required. By employing Theorems 3 and 4, we can derive the following conclusion.
Theorem 9.
All types of set N 1 can be exactly solved in time complexity O ( R 3 ) and space complexity O ( R 2 ) .
Proof of Theorem 9.
We first divide the problem into two subcases: C t < 2 R 2 + 2 R and C t 2 R 2 + 2 R .
  • Case 1. When C t < 2 R 2 + 2 R , we can solve the problem exactly by directly applying the unbounded-DP within a time complexity of O ( R 3 ) and a space complexity of O ( R 2 ) .
  • Case 2. When C t 2 R 2 + 2 R , there exists a value of t such that gcd ( W 1 ) | t within the interval ( R 2 , R 2 + R ] . According to Theorem 4, there must be a non-negative integer solution X such that
    j N 1 x j w j = t ,
    and the solution X can be solved by unbounded-DP in the time complexity O ( R 3 ) and space complexity O ( R 2 ) . Next, we perform the modulo operation on C t . Let t be a number congruent to C t modulo t , denoted as t C t ( mod t ) , where R 2 t < t 2 t 2 R 2 + 2 R . Consequently, we have a non-negative integer solution X such that
    j N 1 x j w j = t gcd ( W 1 ) gcd ( W 1 ) .
Clearly, the solutions X and X are both solved in the same way. Additionally, for the original problem, there exists one optimal solution that satisfies the equation:
Y = X + C t t 1 X .
Since the solutions X and X are both obtained through the unbounded-DP within time and space complexities of O ( R 3 ) and O ( R 2 ) , respectively, the exact algorithm for Y will have the same time and space complexities as the exact algorithm for X .
The proof of Theorem 9 is complete.    □

3.3. Complexity Analysis

In order to calculate the overall time and space complexity of the algorithm presented in this paper, we summarize all the algorithmic operations as Algorithm 2. The pseudocode for the algorithm is provided below.
Algorithm 2 Our algorithm for UKPB
Require:  n , W , P , C
Ensure:  Y
1:
Computing the profit density of all types, and obtaining the multisubset N 1 and N 2 .
2:
Computing gcd ( W 1 ) and t .
3:
Calling Unbounded-DP to establish an iterative array DP 1 for N 2 with capacity R 3 .
4:
Calling Unbounded-DP to establish an iterative array DP 2 for N 1 with capacity 2 R 2 + 2 R .
5:
Creating a temporary array A = zeros ( 1 , R 3 )
6:
for  t = 0 : R 3  do
7:
     t C t ( mod t ) and t < t 2 t
8:
     A ( t ) = DP 2 ( t ) + C t t 1 DP 2 ( t )
9:
end for
10:
k = argmax 1 t R 3 ( DP 1 ( t ) + A ( t ) ) .
11:
Return optimal solution Y by Unbounded-DP
Algorithm 2 first computes the profit density of types in the multiset N and divides the set N into two multisubsets, N 1 and N 2 , based on the profit density. This operation is performed within time and space complexities of O ( R ) (line 1, Algorithm 2). Then, the gcd ( W 1 ) is computed by the Euclidean algorithm with a time complexity of O ( R log R ) (line 2, Algorithm 2). Next, unbounded-DP is called for multisubsets N 1 and N 2 with a capacity of R 3 and 2 R 2 + 2 R , respectively (lines 3–4, Algorithm 2). The time complexities for lines 3–4 are O ( R 4 ) and O ( R 3 ) , respectively, in Algorithm 2.
To eliminate the coefficient C from the time and space complexities, we utilize relevant conclusions from the LDE to accelerate the speed complexity and minimize the space complexity of the exact algorithm. This is demonstrated in lines 6–8, with a time complexity of O ( R 3 ) for lines 6–8. Since the lengths of DP 1 and array A are both R 3 , the time complexity of line 9 is also O ( R 3 ) . Finally, the unbounded-DP is used to return the optimal solution Y with a time complexity of O ( R 3 ) .
In summary, the time and space complexities of Algorithm 2 are O ( R 4 ) and O ( R 3 ) , respectively. For the UKPB, since the coefficients of weight and profit are both bounded by a given constant R, the UKPB can be exactly solved in constant time and space complexities.

3.4. A Small Instance

To illustrate how Algorithm 2 solves the UKPB, we introduce a small-scale example as follows.
Example 1.
Consider a small instance of the UKP with a knapsack capacity of C = 10,000 and n = 3 types. The profit and weight of each type are as follows.
j123
p j 674
w j 675
In Example 1, types are numbered in order of profit density from highest to lowest. It is evident that N 1 = { 1 , 2 } and N 2 = { 3 } . Additionally, we have R = 7 . Next, Example 1 can be solved by employing Algorithm 2. The computation process is detailed as follows.
Step 1.
The Euclidean algorithm is used to obtain gcd ( W 1 ) = 1 and t = R 2 + 1 = 50 .
Step 2.
Calling unbounded-DP to solve N 1 and N 2 , respectively, we obtain iterative arrays DP 2 and DP 1 . The capacity of DP 1 is R 3 = 343 and that of DP 2 is 2 R 2 + 2 R = 112 , respectively.
Specifically, in comparison to the method proposed in [13], due to the value of N 2 as calculated in inequality (12) as
p 1 w 1 p 1 w 3 p 3 w 1 = 36 30 24 = 6 ,
the capacity of DP 2 in Algorithm 2 only needs to be 6 × w 3 = 30 to be sufficient for Example 1, which is significantly less than R 3 = 343 .
Step 3.
The temporary array A is obtained by iterating through a loop indexed by t. For example, when t = 1 , we have t C t ( mod t ) 9999 ( mod 50 ) 49 . Consequently,
A ( 1 ) = DP 2 ( 49 ) + 9999 50 1 DP 2 ( 50 ) .
Step 4.
Finding the value of k via a search process, and subsequently utilizing unbounded-DP to determine the optimal solution Y
Since gcd ( W 1 ) = 1 | C , we can determine Y = { 1662 , 4 , 0 } .

4. The Algorithm for the AUKP

For the AUKP, as implemented in Algorithm 2, we initially employ the unbound-DP algorithm to address a subproblem with a capacity of R 3 + 2 R 2 + 2 R . For those problems with capacities exceeding R 3 + 2 R 2 + 2 R , we recursively apply the same approach to subproblems of capacity t , ensuring that R 3 + t < t R 3 + 2 t . The complexity of Algorithm 3 is O ( R 4 + C ) . The pseudocode is illustrated as follows:
Algorithm 3 Our algorithm for AUKP
Require:  n , W , P , C
Ensure:  Y
1:
Computing the profit density of all types, and obtaining the multisubset N 1 and N 2 .
2:
Computing gcd ( W 1 ) and t .
3:
Calling Unbounded-DP to establish an iterative array DP for all items with capacity R 3 + 2 R 2 + 2 R .
4:
Creating a temporary array B = zeros ( 1 , C ) and B ( 1 : R 3 + 2 R 2 + 2 R ) = DP .
5:
for  t = R 3 + 2 R 2 + 2 R : C  do
6:
     t C ( mod t ) and R 3 + t < t R 3 + 2 t
7:
     B ( t ) = DP ( t ) + C t t DP ( t ) .
8:
end for
9:
Return optimal solution Y

5. Conclusions

In this paper, we extend the theoretical results of [45,60] and propose an algorithm with pseudo-polynomial time and space complexities that do not depend on the capacity C. We specifically focus on the UKP benchmark instances where the difficulty of the problem often arises from setting the capacity coefficient C to a large value. Our algorithm is capable of achieving exact solutions within time and space complexities of O ( R 4 ) and O ( R 3 ) , respectively. Additionally, considering that the value of R is typically a given constant in the benchmark instance generation rules, for the UKP benchmark, our algorithm achieves constant time and space complexities.
In particular, the mathematical tools employed in this paper are covered in the first-year mathematics curriculum. The proof techniques are relatively straightforward and facilitate further research and potential improvements by subsequent researchers.

Funding

This research received no external funding.

Data Availability Statement

Data are contained within the article.

Conflicts of Interest

The author declare no conflicts of interest.

Abbreviations

The following abbreviations are used in this manuscript:
UKPBUnbounded Knapsack Problem with Bounded coefficients
B&BBranch and Bound
LDELinear Diophantine Equation
AUKPAll-capacities Unbounded Knapsack Problem

References

  1. Martello, S.; Toth, P. Knapsack Problems: Algorithms and Computer Implementations; John Wiley & Sons: Chichester, UK, 1990. [Google Scholar]
  2. Kellerer, H.; Pferschy, U.; Pisinger, D. Knapsack Problems; Springer: Berlin/Heidelberg, Germany, 2004. [Google Scholar]
  3. Cacchiani, V.; Iori, M.; Locatelli, A.; Martello, S. Knapsack problems—An overview of recent advances. Part I: Single knapsack problems. Comput. Oper. Res. 2022, 143, 105692. [Google Scholar] [CrossRef]
  4. Cacchiani, V.; Iori, M.; Locatelli, A.; Martello, S. Knapsack problems—An overview of recent advances. Part II: Multiple, multidimensional, and quadratic knapsack problems. Comput. Oper. Res. 2022, 143, 105693. [Google Scholar] [CrossRef]
  5. Becker, H.; Buriol, L.S. An empirical analysis of exact algorithms for the unbounded knapsack problem. Eur. J. Oper. Res. 2019, 277, 84–99. [Google Scholar] [CrossRef]
  6. Papadimitriou, C.H. On the complexity of integer programming. J. ACM 1981, 28, 765–768. [Google Scholar] [CrossRef]
  7. Sun, X.L.; Li, D. Integer Programming; Science Press: Beijing, China, 2010. (In Chinese) [Google Scholar]
  8. Wolsey, L.A. Integer Programming; John Wiley & Sons: Chichester, UK, 2020. [Google Scholar]
  9. Conforti, M.; Cornuejols, G.; Zambelli, G. Integer Programming. In Ser. Graduate Texts in Mathematics; Springer: Cham, Switzerland, 2014. [Google Scholar]
  10. Cook, S.A. The complexity of theorem-proving procedures. In Proceedings of the 3rd Annual ACM Symposium on Theory of Computing(STOC 1971), Shaker Heights, ON, USA, 3–5 May 1971; pp. 151–158. [Google Scholar]
  11. Karp, R.M. Reducibility among Combinatorial Problems. In Complexity of Computer Computations; Miller, R.E., Thatcher, J.W., Bohlinger, J.D., Eds.; Springer: Boston, MA, USA, 1972; pp. 85–103. [Google Scholar]
  12. Hannusch, C.; Major, S.R. Torch: Software Package for the Search Of Linear Binary Codes. In Proceedings of the 2nd Conference on Information Technology and Data Science (CITDS 2022), Debrecen, Hungary, 16–18 May 2022; pp. 103–106. [Google Scholar]
  13. Chan, T.M.; He, Q.Z. More on change-making and related problems. J. Comput. Syst. Sci. 2022, 124, 159–169. [Google Scholar] [CrossRef]
  14. Sapir, M.V.; Birget, J.C.; Rips, E. Isoperimetric and isodiametric functions of groups. Ann. Math. 2002, 156, 345–466. [Google Scholar] [CrossRef]
  15. Dinur, I.; Safra, S. On the hardness of approximating vertex cover. Ann. Math. 2005, 162, 439–485. [Google Scholar] [CrossRef]
  16. Garey, M.R.; Johnson, D.S. Computer and Intractablility: A Guide to the Theory of NP-Completeness; Freeman: San Francisco, CA, USA, 1979. [Google Scholar]
  17. Bellman, R. Dynamic Programming; Princeton University Press: Princeton, NJ, USA, 1957. [Google Scholar]
  18. Ailsa, H.L.; Alison, G.D. An automatic method of solving discrete programming problem. Econometrica 1960, 28, 497–520. [Google Scholar]
  19. Dantzig, G.B. Discrete-Variable Extremum Problems. Oper. Res. 1957, 5, 266–288. [Google Scholar] [CrossRef]
  20. Gomory, R.E.; Johnson, E.L. T-space and cutting planes. Math. Prog. 2003, 96, 341–375. [Google Scholar] [CrossRef]
  21. Lee, Y.T.; Sidford, A.; Wong, S.C.-W. A Faster Cutting Plane Method and its Implications for Combinatorial and Convex Optimization. In Proceedings of the 2015 IEEE 56th Annual Symposium on Foundations of Computer Science (FOCS 2015), Berkeley, CA, USA, 17–20 October 2015; pp. 1049–1065. [Google Scholar]
  22. Pisinger, D. A Minimal Algorithm for the 0–1 Knapsack Problem. Oper. Res. 1997, 46, 758–767. [Google Scholar] [CrossRef]
  23. Martello, S.; Pisinger, D.; Toth, P. Dynamic programming and strong bounds for the 0-1 knapsack problem. Manag. Sci. 1999, 45, 414–424. [Google Scholar] [CrossRef]
  24. Bianchessi, N.; Irnich, S. Branch-and-Cut for the Split Delivery Vehicle Routing Problem with Time Windows. Transport. Sci. 2019, 53, 442–462. [Google Scholar] [CrossRef]
  25. Gmys, J.; Mezmaz, M.; Melab, N.; Tuyttens, D. A computationally efficient Branch-and-Bound algorithm for the permutation flow-shop scheduling problem. Eur. J. Oper. Res. 2020, 284, 814–833. [Google Scholar] [CrossRef]
  26. Martello, S.; Toth, P. A Mixture of Dynamic Programming and Branch-andBound for the Subset-Sum Problem. Manag. Sci. 1984, 30, 765–771. [Google Scholar] [CrossRef]
  27. Bringmann, K. A Near-Linear Pseudopolynomial Time Algorithm for Subset Sum. In Proceedings of the 28th Annual ACM-SIAM Symposium on Discrete Algorithms (SODA 2017), Barcelona, Spain, 16–19 January 2017; pp. 1073–1084. [Google Scholar]
  28. Koiliaris, K.; Xu, C. Faster Pseudopolynomial Time Algorithms for Subset Sum. ACM Trans. Algorithms 2019, 15, 1–20. [Google Scholar] [CrossRef]
  29. Deng, M.Y.; Mao, X.; Zhong, Z.Q. On Problems Related to Unbounded SubsetSum: A Unified Combinatorial Approach. In Proceedings of the 34th Annual ACM Symposium on Theory of Computing (SODA 2023), Florence, Italy, 22–25 January 2023; pp. 2980–2990. [Google Scholar]
  30. Magazine, M.J.; Nemhauser, G.L.; Trotter, L.E., Jr. When the Greedy Solution Solves a Class of Knapsack Problems. Oper. Res. 1975, 23, 207–217. [Google Scholar] [CrossRef]
  31. Hu, T.C.; Lenard, M.L. Technical Note-Optimality of a Heuristic Solution for a Class of Knapsack Problems. Oper. Res. 1976, 24, 193–196. [Google Scholar] [CrossRef]
  32. Zukermana, M.; Jia, L.; Neame, T.; Woeginger, G.J. A polynomially solvable special case of the unbounded knapsack problem. Oper. Res. Lett. 2001, 29, 13–16. [Google Scholar] [CrossRef]
  33. Deineko, V.G.; Woeginger, G.J. Unbounded knapsack problems with arithmetic weight sequences. Eur. J. Oper. Res. 2011, 213, 384–387. [Google Scholar] [CrossRef]
  34. Adams, W.; Belotti, P.; Shen, R.B. Convex Hull Characterizations of Lexicographic Orderings. J. Global Optim. 2016, 66, 311–329. [Google Scholar] [CrossRef]
  35. Hirschberg, D.S.; Wong, C.K. A Polynomial-Time Algorithm for the Knapsack Problem with Two Variables. J. ACM 1976, 23, 147–154. [Google Scholar] [CrossRef]
  36. Kannan, R. A Polynomial Algorithm for the Two-Variable Integer Programming Problem. J. ACM 1980, 27, 118–122. [Google Scholar] [CrossRef]
  37. Scarf, H.E. Production Sets with Indivisibilities, Part I: Generalities. Econometrica 1981, 49, 1–32. [Google Scholar] [CrossRef]
  38. Lenstra, H.W., Jr. Integer Programming with a Fixed Number of Variables. Math. Oper. Res. 1983, 8, 533–548. [Google Scholar] [CrossRef]
  39. Chen, J.E.; Liu, Y.; Lu, S.J.; O’sullivan, B.; Razgon, I. A fixed-parameter algorithm for the directed feedback vertex set problem. J. ACM 2008, 55, 1–19. [Google Scholar]
  40. Bateni, M.; Hajiaghayi, M.; Seddighin, S.; Stein, C. Fast algorithms for knapsack via convolution and prediction. In Proceedings of the 50th Annual ACM SIGACT Symposium on Theory of Computing (STOC 2018), Los Angeles, CA, USA, 25–29 June 2018; pp. 1269–1282. [Google Scholar]
  41. Axiotis, K.; Tzamos, C. Capacitated Dynamic Programming: Faster Knapsack and Graph Algorithms. In Proceedings of the 46th International Colloquium on Automata, Languages, and Programming (ICALP 2019), Patras, Greece, 9–12 July 2019; Volume 19, pp. 1–13. [Google Scholar]
  42. Bringmann, K.; Cassis, A. Faster Knapsack Algorithms via Bounded Monotone Min-Plus-Convolution. In Proceedings of the 49th International Colloquium on Automata, Languages, and Programming (ICALP 2022), Paris, France, 4–8 July 2022; Volume 31, pp. 1–21. [Google Scholar]
  43. Chen, L.; Lian, J.Y.; Mao, Y.C.; Zhang, G.C. Faster Algorithms for Bounded Knapsack and Bounded Subset Sum Via Fine-Grained Proximity Results. In Proceedings of the 2024 Annual ACM-SIAM Symposium on Discrete Algorithms (SODA 2024), Alexandria, WV, USA, 7–10 January 2024; pp. 4828–4848. [Google Scholar]
  44. Jansen, K.; Rohwedder, L. On integer programming and convolution. Math. Oper. Res. 2023, 48, 1481–1495. [Google Scholar] [CrossRef]
  45. Dey, S.S.; Dubey, Y.; Molinaro, M. Branch-and-bound solves random binary IPs in poly(n)-time. Math. Prog. 2023, 200, 569–587. [Google Scholar] [CrossRef]
  46. Greenberg, H. An Algorithm for a Linear Diophantine Equation and a Problem of Frobenius. Numer. Math. 1980, 34, 349–352. [Google Scholar] [CrossRef]
  47. Chou, T.-W.J.; Collins, G.E. Algorithms for the Solution of Systems of Linear Diophantine Equations. SIAM J. Comput. 1982, 11, 687–708. [Google Scholar] [CrossRef]
  48. Dahmen, W.; Micchelli, C.A. The number of solutions to linear Diophantine equations and multivariate splines. Trans. Am. Math. Soc. 1988, 308, 509–532. [Google Scholar] [CrossRef]
  49. Ireland, K.; Rosen, M. A Classical Introduction to Modern Number Theory. In Ser. Graduate Texts in Mathematics; Springer: New York, NY, USA, 1990. [Google Scholar]
  50. Contejean, E.; Devie, H. An Efficient Incremental Algorithm for Solving Systems of Linear Diophantine Equations. Inform. Comput. 1994, 113, 143–172. [Google Scholar] [CrossRef]
  51. Rosen, K.H. Elementary Number Theory and Its Applications, 5th ed.; Addison-Wesley: Boston, MA, USA, 2005. [Google Scholar]
  52. Alfonsin, J.R. The Diophantine Frobenius Problem. In Ser. Oxford Lectures Series in Mathematics and Its Applications; Oxford University Press: New York, NY, USA, 2005. [Google Scholar]
  53. Evertse, J.-H.; Györy, K. Effective Results and Methods for Diophantine Equations over Finitely Generated Domains; Cambridge University Press: Cambridge, UK, 2022. [Google Scholar]
  54. Marklof, J. The asymptotic distribution of Frobenius numbers. Invent. Math. 2010, 181, 179–207. [Google Scholar] [CrossRef]
  55. Aliev, I.; Henk, M.; Hinrichs, A. Expected Frobenius numbers. J. Comb. Theory A 2011, 118, 525–531. [Google Scholar] [CrossRef]
  56. Fukshansky, L.; Schürmann, A. Bounds on generalized Frobenius numbers. Eur. J. Combin. 2011, 32, 361–368. [Google Scholar] [CrossRef]
  57. Andonov, R.; Poirriez, V.; Rajopadhye, S. Unbounded knapsack problem: Dynamic programming revisited. Eur. J. Oper. Res. 2000, 123, 394–407. [Google Scholar] [CrossRef]
  58. Pisinger, D. Dynamic programming on the word RAM. Algorithmica 2003, 35, 128–145. [Google Scholar] [CrossRef]
  59. Boyd, S.; Vandenberghe, L. Convex Optimization; Cambridge University Press: Cambridge, UK, 2004. [Google Scholar]
  60. Yang, Y. An upper bound of the mutation probability in the genetic algorithm for general 0–1 knapsack problem. arXiv 2024, arXiv:2403.11307. [Google Scholar]
  61. Shallit, J. Origins of the analysis of the Euclidean algorithm. Hist. Math. 1994, 21, 401–419. [Google Scholar] [CrossRef]
  62. Cormen, T.H.; Leiserson, C.E.; Rivest, R.L.; Stein, C. Introduction to Algorithms, 4th ed.; The MIT Press: Cambridge, UK, 2022. [Google Scholar]
  63. Everest, G.; Ward, T. An Introduction to Number Theory. In Ser. Graduate Texts in Mathematics; Springer: London, UK, 2005. [Google Scholar]
  64. Brauer, A. On a problem of partitions. Am. J. Math. 1942, 64, 299–312. [Google Scholar] [CrossRef]
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content.

Share and Cite

MDPI and ACS Style

Yang, Y. An Improved Unbounded-DP Algorithm for the Unbounded Knapsack Problem with Bounded Coefficients. Mathematics 2024, 12, 1878. https://doi.org/10.3390/math12121878

AMA Style

Yang Y. An Improved Unbounded-DP Algorithm for the Unbounded Knapsack Problem with Bounded Coefficients. Mathematics. 2024; 12(12):1878. https://doi.org/10.3390/math12121878

Chicago/Turabian Style

Yang, Yang. 2024. "An Improved Unbounded-DP Algorithm for the Unbounded Knapsack Problem with Bounded Coefficients" Mathematics 12, no. 12: 1878. https://doi.org/10.3390/math12121878

APA Style

Yang, Y. (2024). An Improved Unbounded-DP Algorithm for the Unbounded Knapsack Problem with Bounded Coefficients. Mathematics, 12(12), 1878. https://doi.org/10.3390/math12121878

Note that from the first issue of 2016, this journal uses article numbers instead of page numbers. See further details here.

Article Metrics

Back to TopTop