Polynomial Time Instances for the IKHO Problem

,


Introduction
Interactive Knapsacks Heuristic Optimization problem (IKHO) is a particular knapsacks model in which, given an array of knapsacks, an insertion in a knapsack influences the nearest knapsacks, in terms both of weight and of profit. It was introduced by Aho in [1], for solving the load clipping problem arising in electricity management application. It belongs to the general framework of the Interactive Knapsacks problems (IK) (also defined in [1]) which has several other applications, for example, in electricity management, single and multiprocessor scheduling, and packing of ndimensional items to different knapsacks. Since IKHO is NPcomplete [1] and APX-hard [2], the research of polynomial time instances is very important. In [3], Aho introduces a few classes of such instances restricting the values of certain parameters of the problem: c and u, which determine the dimension of the influence on other knapsacks caused by an insertion, and K, that limits the number of insertions. We keep on this line of investigation by adding a wide and significant class of polynomial time instances for the IKHO problem in the case when (c + 2u)/c is bounded.
Intuitively, in IKHO, when we insert an item in a knapsack, this item is replicated (cloned) to the c next knapsacks (hence forming a cloning block over c + 1 consecutive knapsacks), and it causes an arbitrary but predetermined modification (radiation) of the weight and profit of the knapsacks at distance at most u from the cloning block (on both sides of the cloning block). After a knapsack is involved in a cloning operation, we are not allowed to insert any other item in that knapsack. Therefore, the cloning blocks are disjoint. In this paper, we are mainly interested in the case where the ratio between the whole width c + 2u of the influenced zone (cloning plus radiation zones) and the width c of the cloning part is bounded by a constant r. We propose a dynamic programming algorithm based on a matrix of size O(c r × K), and having time complexity of O(c r × m × K), where m is the number of knapsacks and K represents the maximum number of cloning block that we can insert in the knapsacks array.
In Section 2, we give the original formulation of the problem from [1] and we then simplify it to ease our exposition in later sections. In Section 3, we give the algorithm. In Section 4, we sharpen the complexity result.

ISRN Electronics
Finally, in Section 5, we design a memory saving version of that algorithm.
We conclude this section by defining some useful notation. Henceforth, we write 0 m to denote a zero constant vector of length m, that is, 0 m i = 0 for i = 1, . . . , m. Moreover, if x, y ∈ {0, 1} m , we write x · y to indicate the concatenation of the two binary strings. Furthermore, [a, b] always denotes a range of integers and, if a > b, we assume that [a, b] is empty. In the same way, if a > b, the notation for i = a, . . . , b means for no i.

Formulation of the IKHO Problem
We are given an array of m knapsacks, each one of capacity b , for = 1, . . . , m. There is a single item that we are asked to insert at most K times in the knapsacks array, where K is a natural given as part of the input. The profit and weight of an insertion depend on the knapsack in which we insert for i = 1, . . . , m the naturals w i and p i represent the weight and the profit of an insertion in the knapsack i. The main feature of IK problems is that every insertion has also an influence on the weight and profit of the nearby knapsacks. In this way, the weight charged on and the profit relative to a knapsack are established by the insertions in all the knapsacks. To describe this mechanism, Aho introduces a function (called interactive function) I i for each knapsack i = 1, . . . , m, that determines the interaction from a knapsack i to every other knapsack. In particular, given naturals c and u, for each knapsack i, we know that   (2) with the profits p . Furthermore, Constraint (4) specifies the maximum number of cloning blocks to be put into the knapsacks array, while Constraint (5) tells that the cloning blocks must be disjoint. The IKHO model is more widely explained and motivated in [1,4].

Simplifying the Formulation.
Our first step here is to simplify the formulation of the problem by making the notion of weight independent from the interaction functions, and the profit dependent only on the knapsack where we insert. This is accomplished by exploiting the transformation proposed by Aho in [2], in order to reduce IKHO to MDKP, an IPL formulation surveyed in [5]. We define so that p i represents the total profit of an insertion in the knapsack i, and w i is the weight that an insertion in the knapsack i charges over the knapsack . From the features of I i ( ) exposed in (1), it follows that w i and p i are both rational numbers. Thus, notice that they can be also negative. Now, we can reformulate the problem as follows: and (5).
Henceforth we refer always to the latter formulation of the problem, since it simplifies the description of the algorithm. Let us restate the behavior of parameter w as inherited by functions I i . For i = 1, . . . , m, we have that 2.2. Polynomial Time Instances. The classes of instances isolated by Aho are the following: (a) the instances with c = u = 0; ISRN Electronics 3 (c) those with u = 0; (d) those with c + 2u + 1 = O(log(m α )), for a constant α.
The restriction of IKHO obtained by considering only the instances in (a) corresponds to the situation in which there are no interactions, whence the decision on whether to insert an item can be taken independently on each knapsack. As for (b), notice that any instance of IKHO admits at most m K feasible solutions, which is only a polynomial number of possibilities whenever K = O (1). We refer to [3] for details on Aho's algorithm for instances of type (c) and (d).
In Section 3, we describe an algorithm for IKHO that has time complexity of O(m × K × c (c+2u)/c ). When (c + 2u)/c is bounded by a constant, it clearly becomes a polynomial time algorithm. Indeed, note that the term c (c+2u)/c is polynomial also when c + 2u = O(ln(m α )), for a constant α. In fact, c (c+2u)/c = (c 1/c ) c+2u , and c 1/c is a decreasing function on c.
Therefore, our results imply those reported in (a), (c), and (d).

The Algorithm
In the following, A = (m, b, c, u, w , p , K) always denotes the input IKHO instance.  [1, h], that is, when x starts with the signature s in the knapsacks [h + 1, h + L], whence having the form x = 0 · · · 0 h sx .
3.1. The Subproblems of Our DP Approach. Given a natural k ≤ K, a natural h ≤ m − L, and a signature s, we consider a modified problem Sub[k, h, s], whose solutions are those |x| ≤ k, and (5).
The objective function is the same as in the IKHO formulation. The differences between the IKHO problem and the above-defined subproblems are in the additional parameters s, h, k and their use in the constraints.

The Dynamic Programming Algorithm.
Our dynamic programming approach is based on Lemmas 1 and 2, whose proofs are given later in this subsection. In particular, Lemma 1 shows how to read out an optimal solution to the IKHO instance, from the optimal solutions to the subproblems.
Lemma 2 explains how to recursively solve the subproblems. We need some additional notation. Given x ∈ {0, 1} m , b ∈ {0, 1}, for i = 1, . . . , m, we write x + (b, i) to denote the binary string obtained from x by setting its i-th element to b.
obeys the capacity constraint for the knapsack h + c + u + 1 and if s := (s 2 , s 3 , . . . , s L , b) ∈ S. Indeed, The base for the recursion, that is, the cases where h = m − L and k = 0, is handled in Section 3.3.
In order to prove Lemmas 1 and 2, let us begin by pointing out some basic facts that directly derive from the IKHO formulation. Observations 1 and 2 play an important 4 ISRN Electronics Observation 2 covers the left/right-reverse situation.
. . , m. Then, for each ≥ a + c + u, x satisfies the capacity constraint if and only if y satisfies it. Indeed, for each ≥ a + c + u, w(x, ) = w(y, ).
Now, we are ready to prove Lemmas 1 and 2.
Proof of Lemma 1. First, let us show that every feasible solution to IKHO is a feasible solution to one of the subproblems Sub[K, 0, s] for an s ∈ S 0 . Clearly, for each x ∈ X[A], taking s := (x 1 , x 2 , . . . , x L ), we get that x ∈ X[K, 0, s]. By exploiting Observation 1 with a = L, we get that y := s · 0 m−L obeys the capacity constraint on knapsacks [1, c + u], and then  Clearly, x must satisfy the capacity constraint on the knapsacks [h + c + u + 1, m]. Moreover, notice that the radiation from the bit s 1 does not reach the knapsacks after h + c + u + 1, and then, for those knapsacks, x satisfies the capacity constraint only if y does. Therefore, we need to check the capacity constraint only for the knapsack h + c + u + 1. Furthermore, the bits after b are not involved when we check the capacity constraint on that knapsack. Thus, in order to check the capacity constraint on the knapsack h + c + u + 1, it is enough to know the bits of the string s · b. Notice that, for a signature s, L is the smallest width that holds the properties we showed above. s ∈ S 0 . To prove the opposite inclusion, take s ∈ S 0 and x ∈ X[K, 0, s]. We show that x ∈ X[A]. Constraint (4), Constraint (5), and the capacity constraint on knapsacks [c + u + 1, m] are clearly satisfied. Since s ∈ S 0 , Observation 1 let us verify the capacity constraint on knapsacks [1, c + u].
Lemma 2 directly follows from the two opposite inclusions, that we show separately. While reading these proofs, Figure 3 can be useful to visualize the structure of the vectors x, y involved in the proofs.
Proof of Lemma 2. First, we show that The inclusion follows by two facts:  (10) and (12) of Sub[k, h, s] easily follow from subproblems definition. Moreover, since y satisfies Constraint (5) and s ∈ S, then x satisfies Constraint (5). It remains to verify Constraint (11). Since s is (h, b)-good, then z := 0 h · s · b · 0 m−h−L−1 obeys the capacity constraint on the knapsack h+c+u+1. By applying Observation 1 with a = h+L+1, we derive that also x obeys the capacity constraint on that knapsack. Moreover, since y ∈ X[k − s 1 , h + 1, s ], then y obeys the capacity constraint on the knapsacks [h + c + u + 2, m]. Since y i = x i for i = (h+2, . . . , m), by Observation 2, x obeys the capacity constraint also for the knapsacks [h + c + u + 2, m].

The Base of the Recursion.
We have two base cases. Observation 3 handles the case when h = m − L, while Observation 4 treats the case when k = 0.
Proof. Clearly, since h + L = m and by Constraint (10)

Complexity
In this section, we prove Lemma 3.     Proof. Clearly, |S| ≤ 2 L , because the number of binary strings s ∈ {0, 1} L is 2 L . Moreover, when c = 0, we supposed L constant. When c > 0, since L/c ≤ r, we get that L ≤ rc, with constant r and c.
For nonconstant values of c, let us find a general form for |S|. Let S c (n) denote the number of binary strings s ∈ {0, 1} n such that s obeys Constraint (5). Note that Constraint (5) contains the parameter c. When n ∈ [0, c], we have n places where to insert, and at most one insertion is possible by Constraint (5). Moreover, we have to count the string with no insertions. Thus, we get that S c (n) = n + 1 for all n ∈ [0, c]. For greater values of n, we refer to the recursion shown in Figure 4. If the first bit of s is 0, the choice of the following bits is not influenced. Therefore, it is enough to find the number of strings s ∈ {0, 1} n−1 such that s obeys Constraint (5), that is exactly S c (n − 1). If the first bit is 1, by Constraint (5), the following c bits are necessarily 0's. In this case, we continue to choose after the c + 1-th bit. Thus, we have S c (n − c − 1) ways to choose the remaining bits. Therefore, we can express S c (n) by the recurrence equation: Lemma 4 gives a general estimate of the recurrence S c (n), in order to bound |S| for nonconstant values of c.
Since L = c + 2u ≥ c, we can apply Lemma 4 to deduce that |S| = S c (L) = O(c L/c ), as (c + 1)/c ≤ 2 for c > 0. Therefore, when L/c is bounded by a constant r, we get |S| = O(c r ).

Ranking the Set S.
We use Recurrence (20) to define a function pos : S → [0, |S| − 1], which provides a unique index for each signature, and hence, it gives a ranking for the set S.
Note that S c (L − i) is the number of signatures having length L − i, and it is equivalent to the number of signatures of length L − i + 1 that start with a 0. Hence, as illustrated in Figure 5 Evidently, in order to efficiently perform such ordering on the set S, we need to compute and store the recurrence S c (n), for n = 1, . . . , L − 1, at the beginning of the algorithm.

This takes O(L) time and space, whereas the ranking and unranking operations take O(L) time.
Indeed, we can avoid to encode and decode the signatures for the computation of each subproblem. This can be done by initializing a table at the beginning of the algorithm, that stores, for each position pos(s ) relative to a signature s , a list of the bits that are changed from the previous signature s, that is, the signature having pos(s) = pos(s ) − 1. It is easy to verify the following procedure finds the next signature from the previous one (it works similarly to the function that increments a binary counter, but considering Constraint (5)).
(i) Scan the previous string s starting from the least significant bit (right most) and find the first range of c + 1 consecutive 0's, or a range of consecutive 0's that includes the most significant bit (left most).
(ii) If such a range exists, the next string is obtained by setting to 1 the right most bit of the range, and by setting to 0 all the bits at the right of the range.
(iii) If such a range does not exist, s is the last signature.
Above all, observe that, by Constraint (5), there are at most L/(c + 1) insertions in a signature s ∈ |S|, and we know that L/(c + 1) ≤ L/c ≤ r. Therefore, for every kind of ranking for the set S, the number of the bits changing between two adjacent signatures is O(r). Thus, if we know the changing bits from a signature s to the next s , we can use an incremental approach for computing the value w(s , ), from w(s, ), in constant time. This allows us to check in constant time the capacity constraints of the (h, b)-goodness (14), those regarding the definition of the set S 0 (13), and when computing the base case (Observation 3). Note that also Constraint (5) of the (h, b)-goodness can be computed in O(r) with the same technique.
Moreover, note that when computing the matrix opt, if we place the cycle on the variable s, externally to the cycle on the variable k, we can clearly find the next signature and check the capacity constraints only once every K subproblems. In this way, the cost of finding the next signature is made inessential.
Thus, we can conclude that our algorithm has time and space complexity of O(c r × m × K).

Memory Saving Version
Consider (14). Given an h ∈ [1, m − L − 1], in order to compute opt[k, h, s] for each s ∈ S and k ≤ K, we need only the elements having h = h + 1 of the matrix opt. Moreover, by (13), only the elements with h = 0 are required for computing opt [A]. Thus, in order to work out the profit of a best solution, we only need O(|S| × K) space. Unfortunately, this simplification does not apply to the matrix used to compute the best solution.
In [6], Hirschberg showed an elegant and practical space reduction method for the longest common subsequence problem, which works for many dynamic programming algorithms (well exposed also in [7]). In general, this method allows to compute an optimal solution, taking as much space and time as if we had only to compute the optimal solution value. This is accomplished by exploiting the equation which handles the recursion in the original algorithm (in our case (14)). Its space policy exploits the space improvement mentioned at the beginning of this section.
Conceptually, the basic idea of the method is to halve a dimension of the dynamic programming matrix and find how the best solution is divided in the other dimensions. This permits the two halves obtained to be solved separately and recursively in the same way. In order to apply this method to our algorithm, we follow the next steps.
(i) We halve the knapsack array.
(ii) We find how many insertions of the best solution are placed in each half of the knapsack array.
(iii) We locate a number of insertions placed around the middle of the knapsack array. This allows us to break up the IKHO problem in two independent subproblems, which are then solved recursively.
Notice that, in the last sentence, the word subproblems does not refer to the subproblems Sub[k, h, s] defined in Section 3. In Section 5.1, we implement this idea. In Section 5.2, we show that the new defined algorithm decreases the space complexity to O(|S| × K), without increasing the time complexity. Given a natural k ≤ K, a natural h ∈ [L + 1, m + 1], and a signature s, we consider a modified problem Sub R [k, h, s] whose solutions are those x ∈ {0, 1} m which obey In the following, let |s| to be the number of insertions in a signature s.
This new operator defines a new space of solutions given by the concatenation of the feasible solutions of two symmetrical subproblems. Notice that the signature s represents the joining point when concatenating the two strings. This situation is represented in Figure 6, which is also useful to visualize the proof of Lemma 6, which represents the main innovation on our algorithm.
Let s opt and k opt be the values of s and k that maximize (24). Moreover, let x opt ∈ {0, 1} m be a best solution for an IKHO instance A. Clearly, the signature s opt represents a piece of x opt , that is, s opt = x opt (h + 1, h − 1). In addition, note that k opt determines a distribution of the best solution insertions, that is, |x opt (h+1, m)| ≤ k opt and |x opt (1, h −1)| ≤ K − k opt + |s opt |. If we do not consider the insertions given by the signature s opt , we obtain |x opt (h , m)| ≤ k opt − |s opt | and |x opt (1, h)| ≤ K − k opt , as described in Figure 7.
Having fixed the L middle elements of x opt has an important consequence. The radiations of weight starting from the insertions at the left of s opt cannot interfere with the radiations coming from the insertions placed at the right of s opt , as shown in Figure 8. In particular, by (9), the right Therefore, in order to compute the entire part of x opt which stands at the right of s opt , it is enough to know s opt , because the checks on the capacity constraints are independent from the insertions at the left of s opt . The same clearly holds also for finding the left piece of x opt . Thus, we subdivided the main problem in two independent subproblems, as follows: (ii) to find the best solution in the knapsacks [1, h], obeying the capacity constraints over the knapsacks [1, h + c + u], having at most K − k opt insertions and knowing that x opt (h + 1, h − 1) = s opt .
The above-obtained subproblems are solvable as an IKHO instance, by recursively applying (24) with some adjustments. The only significant difference between the main call and the recursive calls is that, in the second ones, when checking the capacity constraints, we have to consider the insertions given by the previously fixed s opt . Indeed, we can simplify this task by progressively updating the vector of capacities b, by subtracting w(s opt , ) for each ∈ [1, m]. For each step of recursion, the new vector b will be passed to the input of the lower level subproblems. The solution of each subproblem fixes over x opt a signature s opt , so as to recursively cover x opt with substrings of length L. This is visualized in Figure 9. Finally, note that the base cases for this recursion are the subproblems which involve a number of knapsacks lower than L. In order to compute the best solution for them, we simply list all the feasible solutions and compare the profits.

Complexity.
As mentioned at the beginning of this section, in the first call (root node of the recursion tree), the computing of (24) takes O(|S| × K) space. The recursive calls occupy geometrically less memory than the first call, as they deal with an halvened number of knapsacks (and with a lower value of K), whence the total memory consumption is of the same order as the memory consumption for the sole first call. Note that, for each step of recursion, once we found k opt and s opt , we can deallocate the matrices opt and opt R . Besides these matrices, we need O(m) space for dynamically compose the best solution x opt . Therefore, the new algorithm takes only O(m + [|S| × K]) space.
Let us now analyze its time complexity. In the first call, for the computation of (24), the algorithm spends O(m × |S| × K) time to compute the matrices opt and opt R , and O(|S| × K) time to pick out the values s opt and k opt . It also spends O(L 2 ) time in order to update the vector b by subtracting the radiations of weight given by s opt . In fact, a signature has width L, and the range of influence of an insertion is c + 2u + 1 = L + 1. To give an estimate for the subproblems computation, we need to study how the two terms found, O(L 2 ) and O(m × |S| × K), propagate on the next levels of calls. Moreover, let us write them as α · L 2 and β · (m × |S| × K), for some constants α, β.
First, note that the recursive calling scheme for (24) can be approximated with a binary tree of height log 2 (m) . Indeed, since the calls on an input of L knapsacks are treated as leaf cases, the height of the binary tree corresponds to the first integer n such that L · 2 n ≥ m, that is, log 2 (m/L) . Moreover, it is simple to find that such a binary tree has O(m/L) nodes. In fact, since for each level i, we have at most 2 i nodes, the total number of nodes is Therefore, considering all the calls of (24), for the first term, we obtain αL 2 · γ(m/L) = O(m × L).
Note that, when we call the two children of a node, both the knapsack array dimension and the K dimension are subdivided. In particular, we call the children resolution on two half of the knapsacks array (m/2 and m/2), and taking parameters K and K such that K + K ≤ K. Thus, for each level i, and each node j, the second term of complexity is β × (m/2 i ) × K j × |S|, such that j K j ≤ K. Therefore, for the second term, the complexity for each entire level i, is clearly β × (m/2 i ) × K × |S|. Moreover, by adding up each level, we get that the total complexity for the second term is Since |S| = S c (L) ≥ L, the second term O(m×|S|×K) always bounds the first O(m × L). Therefore, the complexity of the nodes computation is O(m × |S| × K).
Regarding the computation of the leaf cases, note that we have to find the best feasible piece of solution, for an input of at most L knapsacks. Since these pieces have length lower than L, and they must obey Constraint (5), they are at most |S|. Moreover, we have to consider the cost of checking the capacity constraints on O(L) knapsacks. Thus, a leaf case can be solved in O(|S| × L) time. Since we have O(m/L) leaf cases, the total cost of the leaf cases is O(m × |S|), that is not higher than the complexity needed for computing the nodes. Therefore, the memory-saving version of the algorithm has time complexity of O(m × |S| × K), which is the same as for the base version.

Conclusions
In [3], Aho exhibited a few classes of polynomial instances for the IKHO problem, motivated by the fact that IKHO is NP-complete [1] and APX-hard [2]. The most important class of instances identified by Aho is represented by the instances where c + 2u + 1 = O(log(m α )), for a constant α. Throughout Sections 3 and 4, we identified a new and wide class of instances allowing for a polynomial time algorithm. We achieved this by showing how to build a dynamic programming algorithm which executes in time of O(c r × m × K) and takes space of O(c r × m × K) for the instances where (c + 2u)/c is bounded by a constant r. These results represent a significant improvement to the understanding of the IKHO problem and more in general for the Interactive Knapsacks problems to which IKHO belongs and that are extensively presented by Aho in [4]. Note that our results imply Aho's results for IKHO, as shown in Section 2.2. In Section 5, we also exploited Hirschberg's approach in order to create a memory saving version of our algorithm which decreases the space complexity to O(c r × K + m) without increasing the time complexity.
Extensive experimental evaluations have been performed on the c++ implementations of both algorithms, confirming the complexity estimates given in Sections 4 and 5. In addition, these experiments pointed out that, despite the heavy constants introduced in the time complexity bound of the memory saving version, the last version of the algorithm is often faster than the base version in the practice. This is mainly due to the fact that the higher memory usage of the base version brings the operative system to allocate data in the slowest memory devices like the RAM and the hard disk, instead of using the CPU cache.

Proving the Base of Lemma 4
In this appendix, we prove the base of the induction of Lemma 4. We have to show that, assuming c ≥ e, S c (n) ≤ ((c + 1)/c)c n/c for n ∈ [c, 2c].
In the following, let First, notice that F c (i) = S c (c + i) for i ∈ [0, c]. Indeed, for i ∈ [0, c], we can compute S c (c + i) by simply counting the number of signatures of length c + i, and then verify that this number is exactly F c (i). By Constraint (5), in a signature of length 2c, or smaller than 2c, there can be at most two insertions. Thus, since c + i ≤ 2c, we can count the signatures of length c + i, by grouping them according to the number of insertions (no one, one, or two). Obviously, only the signature 0 c+i has no insertions. Moreover, there are exactly c + i ways to place one insertion. For the case where we have two insertions, note that the first one can be only in the first i − 1 positions, because if we place it on the i-th position, by Constraint (5), there cannot be later insertions in a signature of length i + c. Moreover, notice that if we fix the first insertion in position j, then we have i − j possible places where to put the second one, again by Constraint (5). Therefore, the number of signatures with two insertions is clearly So F c (i) = S c (c+i) for i ∈ [0, c], as anticipated. Therefore, in order to prove the base of the induction of Lemma 4, it is enough to show that F c (i) ≤ f c (i), with f c (i) = ((c + 1)/c) c (c+i)/c = ((c + 1)/c)c 1+i/c = (c + 1)c i/c .
Clearly, for i = 0, we get F c (0) = c + 1 ≤ (c + 1) c 0/c = f c (0). Our plan is then to observe that ∂F c (i)/∂i ≤ ∂ f c (i)/∂i holds for every i ≥ 0, when c ≥ e. Indeed, ∂F c (i)/∂i = i + 1/2, whereas ∂ f c (i)/∂i = (c + 1) c i/c (ln(c)/c). When i = 0, we get That is, F c (0) ≤ f c (0). Moreover, it is simple to see that F c (i) is linear, whereas f c (i) is an exponential on the variable i, and, therefore, f c (i) ≥ F c (i) for every i ≥ 0, as anticipated.