cs209 lab10


http://www.maths.nuigalway.ie/~gettrick/teach/cs209/l10.html




In this weeks lab, you should write a program in PYTHON to "solve" the 0/1 knapsack problem using the greedy strategy.

(Please see lab6 for a description/definition of the original 0/1 Knapsack problem.)
In the 0/1 Knapsack problem, we have a bag of (weight) capacity K kilograms. We have n items of weight w(1), w(2), w(3), ... , w(n) (in Kg) and of respective values v(1), v(2), v(3), ... , v(n) (in euro). We have to decide which items to fit in to our bag to obtain maximum value. There is only one of each item, and you can also assume w(1)+w(2)+w(3)+...+w(n) > K (i.e. all the items won't fit in our bag). In the one PYTHON program, you should solve this problem using greed based on

  1. maximizing the value
  2. minimizing the weight
  3. maximizing the ratio of value/weight

Note: Run your program on the data:
  1. WEIGHTS: 21,40,30,3,17,19,26,23,31,7,16,18
  2. VALUES: 40,70,41,6,33,39,48,34,50,15,29,37
and bag capacities 50kg, 80kg and 110kg. Submit all 9 answers (the 3 different greedy approaches used for each of the 3 different bag capacities) with your report.

© NUI, Galway