636 Y.-C. He et al. / Information Sciences 369 (2016) 634–647
maximum of total value when the sum of weight coefficients is less than the knapsack capacity j :
G
[
i, j
]
=
⎧
⎪
⎪
⎪
⎪
⎪
⎨
⎪
⎪
⎪
⎪
⎪
⎩
G
[
i − 1 , j
]
, if 0 ≤ j < w
3 i
max
[
G
[
i − 1 , j
]
, G
[
i − 1 , j − w
3 i
]
+ p
3 i
]
, if w
3 i
≤ j < w
3 i +1
max
G
[
i − 1 , j
]
, G
[
i − 1 , j − w
3 i
]
+ p
3 i
,
G
[
i − 1 , j − w
3 i +1
]
+ p
3 i +1
, if w
3 i +1
≤ j < w
3 i +2
max
G
[
i − 1 , j
]
, G
[
i − 1 , j − w
3 i
]
+ p
3 i
,
G
[
i − 1 , j − w
3 i +1
]
+ p
3 i +1
, G
[
i − 1 , j − w
3 i +2
]
+ p
3 i +2
, if w
3 i +2
≤ j ≤ C
. (5)
The initial G [0, j ] is defined as
G
[
0 , j
]
=
⎧
⎪
⎨
⎪
⎩
0 , if 0 ≤ j < w
0
p
0
, if w
0
≤ j < w
1
p
1
, if w
1
≤ j < w
2
p
2
, if w
2
≤ j ≤ C
. (6)
Let Opt
1
denote the optimal value of OE-DKP. According to Eqs. (5) and (6) , we can get Opt
1
= G
[
n − 1 , C
]
. OE-DKP is an
exact algorithm with pseudo polynomial time and its computational complexity of OE-DKP is O ( nC ).
3.
NE-DKP: the new exact algorithm for D{0-1}KP
The recursion formula Eq. (5) of OE-DKP is designed based on “maximizing the total value with the given sum of weight
coefficients”. This section presents a new exact algorithm for D{0-1}KP based on dynamic programming by deriving the
recursion formula with principle of “minimizing the total weight with the given sum of value coefficients”. The new exact
algorithm is abbreviated as NE-DKP.
The weight minimization principle is to minimize the sum of weight coefficients corresponding to items satisfying the
constraint conditions (2) and (3) when the total value is given. Let E [ i , j ] be the minimum of total weight when the sum
of value coefficients is j , where i = 1 , 2 , ··· , n − 1 , j = 0 , 1 , ··· , S, S =
n −1
i =0
p
3 i +2
. When there is no the subset of items of
which the sum of value coefficients is j , E
[
i, j
]
= + ∞ . In addition, E [0, j ] satisfies E
[
0 , 0
]
= 0 , E
[
0 , p
0
]
= w
0
, E
[
0 , p
1
]
= w
1
,
E
[
0 , p
2
]
= w
2
, and E
0 , j
= + ∞ ( j
∈ {0, 1, , S } and j
= 0, p
0
, p
1
, p
2
). Assume E
[
i − 1 , j
]
is known and p
3 i
≤ p
3 i +1
, E [ i , j ]
can be calculated as following procedures.
1. When 0 ≤ j < p
3 i
, because p
3 i
≤ p
3 i +1
< p
3 i +2
, the value coefficients of items 3 i , 3 i + 1 , and 3 i + 2 are all larger than
j . It indicates that these three items can not be put into knapsack, then we get E
[
i, j
]
= E
[
i − 1 , j
]
.
2. When p
3 i
≤ j < p
3 i +1
, there is only one item 3 i whose value coefficient is less than j . The item 3 i can be considered
to put into knapsack, then we can get E [ i , j ] = min
[
E
[
i − 1 , j
]
, E
[
i − 1 , j − p
3 i
]
+ w
3 i
]
.
3. When p
3 i +1
≤ j < p
3 i +2
, the value coefficients of items 3 i and 3 i + 1 are all less than j . They can all be put into
knapsack, then we can get E [ i , j ] = min
[
E
[
i − 1 , j
]
, E
[
i − 1 , j − p
3 i
]
+ w
3 i
, E
[
i − 1 , j − p
3 i +1
]
+ w
3 i +1
]
.
4. When p
3 i +2
≤ j ≤ S, the value coefficients of three items in item group i are all less than j . All items can
be put into knapsack, then we can get E [ i , j ] = min
[
E
[
i − 1 , j
]
, E
[
i − 1 , j − p
3 i
]
+ w
3 i
, E
[
i − 1 , j − p
3 i +1
]
+ w
3 i +1
,
E
[
i − 1 , j − p
3 i +2
]
+ w
3 i +2
]
.
Based on the above-mentioned analysis, the recursion formula of NE-DKP is derived as
E
[
i, j
]
=
⎧
⎪
⎪
⎪
⎪
⎪
⎨
⎪
⎪
⎪
⎪
⎪
⎩
E
[
i − 1 , j
]
, if 0 ≤ j < p
3 i
min
[
E
[
i − 1 , j
]
, E
[
i − 1 , j − p
3 i
]
+ w
3 i
]
, if p
3 i
≤ j < p
3 i +1
min
E
[
i − 1 , j
]
, E
[
i − 1 , j − p
3 i
]
+ w
3 i
,
E
[
i − 1 , j − p
3 i +1
]
+ w
3 i +1
, if p
3 i +1
≤ j < p
3 i +2
min
E
[
i − 1 , j
]
, E
[
i − 1 , j − p
3 i
]
+ w
3 i
,
E
[
i − 1 , j − p
3 i +1
]
+ w
3 i +1
, E
[
i − 1 , j − p
3 i +2
]
+ w
3 i +2
, if p
3 i +2
≤ j ≤ S
. (7)
The initial E [0, j ] is defined as
E
[
0 , j
]
=
⎧
⎪
⎪
⎨
⎪
⎪
⎩
0 , if j = 0
w
0
, if j = p
0
w
1
, if j = p
1
w
2
, if j = p
2
+ ∞ , ot herwise
. (8)
The optimal value of NE-DKP is Op t
2
= max
j=1 , 2 , ··· ,S
[
j
|
E
[
n − 1 , j
]
≤ C
]
which represents the total value of items in knapsack
is j and the sum of weight coefficients is less than C .
Now, we discuss how to get the optimal solution X =
(
x
0
, x
1
, ··· , x
3 n −1
)
∈
{
0 , 1
}
3 n
corresponding to Opt
2
by using Eqs.
(7) and (8) . Without loss of generality, we assume we have selected the items form item groups n − 1 , n − 2 , ··· , i + 1 .
According to Eq. (7) and the value of E [ i , j ], we discuss whether there is an item which should be selected from item
group i .