1 / 35

Optimal Knapsack Subset Problem

Given a number B and a collection of items A, each with a value and size, find a subset A' maximizing value within size limit B. Example provided.

Download Presentation

Optimal Knapsack Subset Problem

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Knapsack: Given a number B and a collection of n items A = {x[0], x[1], x[2],..., x[n]}, each with some positive integer value v(x[i]) and some positive integer size s(x[i]), find a subset A' of A such that the sum of the values of items in A' is greatest over all subsets of A whose sum of sizes is no greater than B. Example: B=27 A = { x[0]...x[4] } v(x[0]) = 23, s(x[0]) = 11 v(x[1]) = 17, s(x[1]) = 7 v(x[2]) = 21, s(x[2]) = 16 v(x[3]) = 26, s(x[3]) = 10 v(x[4]) = 19, s(x[4]) = 9 Solution: { x[1], x[3], x[4] }

  2. 0 : <23,11>, <17,7>, <21,16>, <26,10>, <19,9> : 27

  3. 0 : <23,11>, <17,7>, <21,16>, <26,10>, <19,9> : 27 Assume x[0] is in the knapsack 23 : <17,7>, <21,6>, <26,10>, <19,9> : 16

  4. 0 : <23,11>, <17,7>, <21,16>, <26,10>, <19,9> : 27 Assume x[0] is in the knapsack 23 : <17,7>, <21,6>, <26,10>, <19,9> : 16 . x[1] is in the knapsack 40 : <21,6>, <26,10>, <19,9> : 9

  5. 0 : <23,11>, <17,7>, <21,16>, <26,10>, <19,9> : 27 Assume x[0] is in the knapsack 23 : <17,7>, <21,6>, <26,10>, <19,9> : 16 . x[1] is in the knapsack 40 : <21,6>, <26,10>, <19,9> : 9 . x[2] is in the knapsack 61 : <26,10>, <19,9> : 3

  6. 0 : <23,11>, <17,7>, <21,16>, <26,10>, <19,9> : 27 Assume x[0] is in the knapsack 23 : <17,7>, <21,6>, <26,10>, <19,9> : 16 . x[1] is in the knapsack 40 : <21,6>, <26,10>, <19,9> : 9 . x[2] 61 : <26,10>, <19,9> : 3 Best value so far: 61

  7. 0 : <23,11>, <17,7>, <21,16>, <26,10>, <19,9> : 27 Assume x[0] is in the knapsack 23 : <17,7>, <21,6>, <26,10>, <19,9> : 16 . x[1] is in the knapsack 40 : <21,6>, <26,10>, <19,9> : 9 . x[2] not in the knapsack . x[2] 61 : <26,10>, <19,9> : 3 40 : <26,10>, <19,9> : 9 Best value so far: 61

  8. 0 : <23,11>, <17,7>, <21,16>, <26,10>, <19,9> : 27 Assume x[0] is in the knapsack 23 : <17,7>, <21,6>, <26,10>, <19,9> : 16 . x[1] is in the knapsack 40 : <21,6>, <26,10>, <19,9> : 9 . x[2] not in the knapsack . x[2] 61 : <26,10>, <19,9> : 3 40 : <26,10>, <19,9> : 9 Best value so far: 61 . x[3] not in the knapsack 40 : <19,9> : 9

  9. 0 : <23,11>, <17,7>, <21,16>, <26,10>, <19,9> : 27 Assume x[0] is in the knapsack 23 : <17,7>, <21,6>, <26,10>, <19,9> : 16 . x[1] is in the knapsack 40 : <21,6>, <26,10>, <19,9> : 9 . x[2] not in the knapsack . x[2] 61 : <26,10>, <19,9> : 3 40 : <26,10>, <19,9> : 9 Best value so far: 61 . x[3] not in the knapsack 40 : <19,9> : 9 . x[4] in the knapsack 59 : : 0

  10. 0 : <23,11>, <17,7>, <21,16>, <26,10>, <19,9> : 27 Assume x[0] is in the knapsack 23 : <17,7>, <21,6>, <26,10>, <19,9> : 16 . x[1] 40 : <21,6>, <26,10>, <19,9> : 9 . x[2] 61 : <26,10>, <19,9> : 3 Best value so far: 61

  11. 0 : <23,11>, <17,7>, <21,16>, <26,10>, <19,9> : 27 Assume x[0] is in the knapsack 23 : <17,7>, <21,6>, <26,10>, <19,9> : 16 . x[1] not in the knapsack . x[1] 40 : <21,6>, <26,10>, <19,9> : 9 23 : <21,6>, <26,10>, <19,9> : 16 . x[2] 61 : <26,10>, <19,9> : 3 Best value so far: 61

  12. 0 : <23,11>, <17,7>, <21,16>, <26,10>, <19,9> : 27 Assume x[0] is in the knapsack 23 : <17,7>, <21,6>, <26,10>, <19,9> : 16 . x[1] not in the knapsack . x[1] 40 : <21,6>, <26,10>, <19,9> : 9 23 : <21,6>, <26,10>, <19,9> : 16 . x[2] . x[2] in the knapsack 61 : <26,10>, <19,9> : 3 44 : <26,10>, <19,9> : 10 Best value so far: 61

  13. 0 : <23,11>, <17,7>, <21,16>, <26,10>, <19,9> : 27 Assume x[0] is in the knapsack 23 : <17,7>, <21,6>, <26,10>, <19,9> : 16 . x[1] not in the knapsack . x[1] 40 : <21,6>, <26,10>, <19,9> : 9 23 : <21,6>, <26,10>, <19,9> : 16 . x[2] . x[2] in the knapsack 61 : <26,10>, <19,9> : 3 44 : <26,10>, <19,9> : 10 Best value so far: 61 . x[3] in the knapsack 70 : <19,9> : 0

  14. 0 : <23,11>, <17,7>, <21,16>, <26,10>, <19,9> : 27 Assume x[0] is in the knapsack 23 : <17,7>, <21,6>, <26,10>, <19,9> : 16 . x[1] not in the knapsack . x[1] 40 : <21,6>, <26,10>, <19,9> : 9 23 : <21,6>, <26,10>, <19,9> : 16 . x[2] . x[2] in the knapsack 61 : <26,10>, <19,9> : 3 44 : <26,10>, <19,9> : 10 . x[3] in the knapsack 70 : <19,9> : 0 Best value so far: 70

  15. 0 : <23,11>, <17,7>, <21,16>, <26,10>, <19,9> : 27 Assume x[0] is in the knapsack 23 : <17,7>, <21,6>, <26,10>, <19,9> : 16 . x[1] not in the knapsack 23 : <21,6>, <26,10>, <19,9> : 16 . x[2] in the knapsack 44 : <26,10>, <19,9> : 10 . x[3] in the knapsack 70 : <19,9> : 0 Best value so far: 70

  16. 0 : <23,11>, <17,7>, <21,16>, <26,10>, <19,9> : 27 Assume x[0] is in the knapsack 23 : <17,7>, <21,6>, <26,10>, <19,9> : 16 . x[1] not in the knapsack 23 : <21,6>, <26,10>, <19,9> : 16 . x[2] in the knapsack 44 : <26,10>, <19,9> : 10 . x[3] in the knapsack 70 : <19,9> : 0 Best value so far: 70

  17. 0 : <23,11>, <17,7>, <21,16>, <26,10>, <19,9> : 27 Assume x[0] is in the knapsack 23 : <17,7>, <21,6>, <26,10>, <19,9> : 16 . x[1] not in the knapsack 23 : <21,6>, <26,10>, <19,9> : 16 . x[2] in the knapsack 44 : <26,10>, <19,9> : 10 . x[3] not in the knapsack . x[3] in the knapsack 70 : <19,9> : 0 44 : <19,9> : 10 Best value so far: 70

  18. 0 : <23,11>, <17,7>, <21,16>, <26,10>, <19,9> : 27 Assume x[0] is in the knapsack 23 : <17,7>, <21,6>, <26,10>, <19,9> : 16 . x[1] not in the knapsack 23 : <21,6>, <26,10>, <19,9> : 16 . x[2] in the knapsack 44 : <26,10>, <19,9> : 10 . x[3] not in the knapsack . x[3] in the knapsack 70 : <19,9> : 0 44 : <19,9> : 10 Cannot beat 70 Best value so far: 70

  19. 0 : <23,11>, <17,7>, <21,16>, <26,10>, <19,9> : 27 Assume x[0] is in the knapsack 23 : <17,7>, <21,6>, <26,10>, <19,9> : 16 . x[1] not in the knapsack 23 : <21,6>, <26,10>, <19,9> : 16 . x[2] in the knapsack 44 : <26,10>, <19,9> : 10 . x[3] in the knapsack 70 : <19,9> : 0 Best value so far: 70

  20. 0 : <23,11>, <17,7>, <21,16>, <26,10>, <19,9> : 27 Assume x[0] is in the knapsack 23 : <17,7>, <21,6>, <26,10>, <19,9> : 16 . x[1] not in the knapsack 23 : <21,6>, <26,10>, <19,9> : 16 . x[2] is not in the knapsack . x[2] in the knapsack 44 : <26,10>, <19,9> : 10 23 : <26,10>, <19,9> : 16 . x[3] in the knapsack 70 : <19,9> : 0 Best value so far: 70

  21. 0 : <23,11>, <17,7>, <21,16>, <26,10>, <19,9> : 27 Assume x[0] is in the knapsack 23 : <17,7>, <21,6>, <26,10>, <19,9> : 16 . x[1] not in the knapsack 23 : <21,6>, <26,10>, <19,9> : 16 . x[2] is not in the knapsack . x[2] in the knapsack 44 : <26,10>, <19,9> : 10 23 : <26,10>, <19,9> : 16 . x[3] in the knapsack Cannot beat 70 70 : <19,9> : 0 Best value so far: 70

  22. 0 : <23,11>, <17,7>, <21,16>, <26,10>, <19,9> : 27 Assume x[0] is in the knapsack 23 : <17,7>, <21,6>, <26,10>, <19,9> : 16 . x[1] not in the knapsack 23 : <21,6>, <26,10>, <19,9> : 16 . x[2] in the knapsack 44 : <26,10>, <19,9> : 10 . x[3] in the knapsack 70 : <19,9> : 0 Best value so far: 70

  23. 0 : <23,11>, <17,7>, <21,16>, <26,10>, <19,9> : 27 Assume x[0] is in the knapsack . x[0] not in knapsack 23 : <17,7>, <21,6>, <26,10>, <19,9> : 16 0 : <17,7>, ..., <19,9> : 16 . x[1] not in the knapsack 23 : <21,6>, <26,10>, <19,9> : 16 . x[2] in the knapsack 44 : <26,10>, <19,9> : 10 . x[3] in the knapsack 70 : <19,9> : 0 Best value so far: 70

  24. 0 : <23,11>, <17,7>, <21,16>, <26,10>, <19,9> : 27 Assume x[0] is in the knapsack . x[0] not in knapsack 23 : <17,7>, <21,6>, <26,10>, <19,9> : 16 0 : <17,7>, ..., <19,9> : 27 . x[1] in knapsack . x[1] not in the knapsack 23 : <21,6>, <26,10>, <19,9> : 16 17 : <21,6>, <26,10>, <19,9> : 20 . x[2] in the knapsack 44 : <26,10>, <19,9> : 10 . x[3] in the knapsack 70 : <19,9> : 0 Best value so far: 70

  25. 0 : <23,11>, <17,7>, <21,16>, <26,10>, <19,9> : 27 Assume x[0] is in the knapsack . x[0] not in knapsack 23 : <17,7>, <21,6>, <26,10>, <19,9> : 16 0 : <17,7>, ..., <19,9> : 27 . x[1] in knapsack . x[1] not in the knapsack 23 : <21,6>, <26,10>, <19,9> : 16 17 : <21,6>, <26,10>, <19,9> : 20 . x[2] in the knapsack . x[2] in the knapsack 44 : <26,10>, <19,9> : 10 38 : <26,10>, <19,9> : 14 . x[3] in the knapsack 70 : <19,9> : 0 Best value so far: 70

  26. 0 : <23,11>, <17,7>, <21,16>, <26,10>, <19,9> : 27 Assume x[0] is in the knapsack . x[0] not in knapsack 23 : <17,7>, <21,6>, <26,10>, <19,9> : 16 0 : <17,7>, ..., <19,9> : 27 . x[1] in knapsack . x[1] not in the knapsack 23 : <21,6>, <26,10>, <19,9> : 16 17 : <21,6>, <26,10>, <19,9> : 20 . x[2] in the knapsack . x[2] in the knapsack 44 : <26,10>, <19,9> : 10 38 : <26,10>, <19,9> : 14 . x[3] in the knapsack . x[3] in the knapsack 70 : <19,9> : 0 64 : <19,9> : 4 Best value so far: 70 Cannot beat 70

  27. 0 : <23,11>, <17,7>, <21,16>, <26,10>, <19,9> : 27 Assume x[0] is in the knapsack . x[0] not in knapsack 23 : <17,7>, <21,6>, <26,10>, <19,9> : 16 0 : <17,7>, ..., <19,9> : 27 . x[1] in knapsack . x[1] not in the knapsack 23 : <21,6>, <26,10>, <19,9> : 16 17 : <21,6>, <26,10>, <19,9> : 20 . x[2] in the knapsack . x[2] in the knapsack 44 : <26,10>, <19,9> : 10 38 : <26,10>, <19,9> : 14 . x[3] in the knapsack 70 : <19,9> : 0 Best value so far: 70

  28. 0 : <23,11>, <17,7>, <21,16>, <26,10>, <19,9> : 27 Assume x[0] is in the knapsack . x[0] not in knapsack 23 : <17,7>, <21,6>, <26,10>, <19,9> : 16 0 : <17,7>, ..., <19,9> : 27 . x[1] in knapsack . x[1] not in the knapsack 23 : <21,6>, <26,10>, <19,9> : 16 17 : <21,6>, <26,10>, <19,9> : 20 . x[2] in the knapsack . x[2] in the knapsack 44 : <26,10>, <19,9> : 10 38 : <26,10>, <19,9> : 14 . x[3] in the knapsack . x[3] not in the knapsack 70 : <19,9> : 0 38 : <19,9> : 14 Best value so far: 70 Cannot beat 70

  29. 0 : <23,11>, <17,7>, <21,16>, <26,10>, <19,9> : 27 Assume x[0] is in the knapsack . x[0] not in knapsack 23 : <17,7>, <21,6>, <26,10>, <19,9> : 16 0 : <17,7>, ..., <19,9> : 27 . x[1] in knapsack . x[1] not in the knapsack 23 : <21,6>, <26,10>, <19,9> : 16 17 : <21,6>, <26,10>, <19,9> : 20 . x[2] in the knapsack 44 : <26,10>, <19,9> : 10 . x[3] in the knapsack 70 : <19,9> : 0 Best value so far: 70

  30. 0 : <23,11>, <17,7>, <21,16>, <26,10>, <19,9> : 27 Assume x[0] is in the knapsack . x[0] not in knapsack 23 : <17,7>, <21,6>, <26,10>, <19,9> : 16 0 : <17,7>, ..., <19,9> : 27 . x[1] in knapsack . x[1] not in the knapsack 23 : <21,6>, <26,10>, <19,9> : 16 17 : <21,6>, <26,10>, <19,9> : 20 . x[2] in the knapsack . x[2] not in the knapsack 44 : <26,10>, <19,9> : 10 17 : <26,10>, <19,9> : 20 . x[3] in the knapsack 70 : <19,9> : 0 Best value so far: 70

  31. 0 : <23,11>, <17,7>, <21,16>, <26,10>, <19,9> : 27 Assume x[0] is in the knapsack . x[0] not in knapsack 23 : <17,7>, <21,6>, <26,10>, <19,9> : 16 0 : <17,7>, ..., <19,9> : 27 . x[1] in knapsack . x[1] not in the knapsack 23 : <21,6>, <26,10>, <19,9> : 16 17 : <21,6>, <26,10>, <19,9> : 20 . x[2] in the knapsack . x[2] not in the knapsack 44 : <26,10>, <19,9> : 10 17 : <26,10>, <19,9> : 20 . x[3] in the knapsack Cannot beat 70 70 : <19,9> : 0 Best value so far: 70

  32. 0 : <23,11>, <17,7>, <21,16>, <26,10>, <19,9> : 27 Assume x[0] is in the knapsack . x[0] not in knapsack 23 : <17,7>, <21,6>, <26,10>, <19,9> : 16 0 : <17,7>, ..., <19,9> : 27 . x[1] not in the knapsack 23 : <21,6>, <26,10>, <19,9> : 16 . x[2] in the knapsack 44 : <26,10>, <19,9> : 10 . x[3] in the knapsack 70 : <19,9> : 0 Best value so far: 70

  33. 0 : <23,11>, <17,7>, <21,16>, <26,10>, <19,9> : 27 Assume x[0] is in the knapsack . x[0] not in knapsack 23 : <17,7>, <21,6>, <26,10>, <19,9> : 16 0 : <17,7>, ..., <19,9> : 27 . x[1] not in the knapsack . x[1] not in knapsack 23 : <21,6>, <26,10>, <19,9> : 16 0 : <21,6>, <26,10>, <19,9> : 27 . x[2] in the knapsack 44 : <26,10>, <19,9> : 10 . x[3] in the knapsack 70 : <19,9> : 0 Best value so far: 70

  34. 0 : <23,11>, <17,7>, <21,16>, <26,10>, <19,9> : 27 Assume x[0] is in the knapsack . x[0] not in knapsack 23 : <17,7>, <21,6>, <26,10>, <19,9> : 16 0 : <17,7>, ..., <19,9> : 27 . x[1] not in the knapsack . x[1] not in knapsack 23 : <21,6>, <26,10>, <19,9> : 16 0 : <21,6>, <26,10>, <19,9> : 27 Cannot beat 70 . x[2] in the knapsack 44 : <26,10>, <19,9> : 10 . x[3] in the knapsack 70 : <19,9> : 0 Best value so far: 70

  35. 0 : <23,11>, <17,7>, <21,16>, <26,10>, <19,9> : 27 Assume x[0] is in the knapsack . x[0] not in knapsack 23 : <17,7>, <21,6>, <26,10>, <19,9> : 16 0 : <17,7>, ..., <19,9> : 27 . x[1] not in the knapsack . x[1] not in knapsack 23 : <21,6>, <26,10>, <19,9> : 16 0 : <21,6>, <26,10>, <19,9> : 27 . x[2] in the knapsack 44 : <26,10>, <19,9> : 10 . x[3] in the knapsack 70 : <19,9> : 0 Solution: 70

More Related