
Taking object 1.2 and object 1.3 with profit 25 and weight 15, but this items are supposed to be exclusive (if you take 2 items of element 1 you can't take 3 also). Python code below uses data from wiki page and shows both table and linear array implementations. If the capacity of the knapsack here is 15 the 0-1 knapsack algorithm will give you an invalid optimal answer. Moreover, we can use approach with one-dimensional array, applying a trick - to avoid reusing item, we can perform traversal in backward direction.


2) Solve MCKP by using Branch and Bound method and Greedy algorithm.
BOUNDED KNAPSACK PROBLEM UPDATE
So at every step of outer loop we update previous best results using current item.īut we use only the last row of table (look at indices i and i-1), so we can diminish table size to 2 x Capacity using only current and last rows. 1) Discuss the steps to solve MCKP by combining the constraints into a 0-1 knapsack problem. Note that for 0-1 Knapsack Problem we must exclude possibility to reuse item twice. Table approach is simpler to explain and debug, that is why algorithm decriptions usually show such way.
