1 / 20

Dr. O.Bushehrian

Algorithm design Knapsack Problem. Dr. O.Bushehrian. signs telling us that a node is nonpromising 1) Weight > W 2) Bound < MaxProfit Bound = ( Profit + ∑ J=i+1 to J=k P J ) + ( W – Weight – Total ) * p k+1 / W k+1. Suppose that n = 4, W = 16, and we have the following:.

nyla
Télécharger la présentation

Dr. O.Bushehrian

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. Algorithm designKnapsack Problem Dr. O.Bushehrian

  2. signs telling us that a node is nonpromising 1) Weight > W 2) Bound < MaxProfit Bound = ( Profit + ∑J=i+1 toJ=k PJ ) + ( W – Weight – Total ) * pk+1 / Wk+1

  3. Suppose that n = 4, W = 16, and we have the following:

  4. Profit=0 Weight=0 Bound=$115 Item1 $40 2

  5. Profit=0 Weight=0 Bound=$115 Item1 $40 2 Profit=40 Weight=2 Bound=$115

  6. Profit=0 Weight=0 Bound=$115 Item1 $40 2 Profit=40 Weight=2 Bound=$115 Item2 $30 5 Profit=70 Weight=7 Bound=$115

  7. Profit=0 Weight=0 Bound=$115 Item1 $40 2 Profit=40 Weight=2 Bound=$115 Item2 $30 5 Profit=70 Weight=7 Bound=$115 Item3 $50 10 Profit=120 Weight=17

  8. Profit=0 Weight=0 Bound=$115 Item1 $40 2 Profit=40 Weight=2 Bound=$115 Item2 $30 5 Profit=70 Weight=7 Bound=$115 Item3 $50 10 Profit=120 Weight=17

  9. Profit=0 Weight=0 Bound=$115 Item1 $40 2 Profit=40 Weight=2 Bound=$115 Item2 $30 5 Profit=70 Weight=7 Bound=$115 Item3 $50 10 Profit=120 Weight=17 Profit=70 Weight=7 Bound=$80

  10. Profit=0 Weight=0 Bound=$115 Item1 $40 2 Profit=40 Weight=2 Bound=$115 Item2 $30 5 Profit=70 Weight=7 Bound=$115 Item3 $50 10 Profit=120 Weight=17 Profit=70 Weight=7 Bound=$80 Profit=80 Weight=12 Bound=$80 Item4 $10 5

  11. Profit=0 Weight=0 Bound=$115 Item1 $40 2 Profit=40 Weight=2 Bound=$115 Item2 $30 5 Profit=70 Weight=7 Bound=$115 Item3 $50 10 Profit=120 Weight=17 Profit=70 Weight=7 Bound=$80 Profit=80 Weight=12 Bound=$80 Profit=70 Weight=7 Bound=$70 Item4 $10 5

  12. Profit=0 Weight=0 Bound=$115 Item1 $40 2 Profit=40 Weight=2 Bound=$115 Item2 $30 5 Profit=70 Weight=7 Bound=$115 Profit=40 Weight=2 Bound=$98 Item3 $50 10 Profit=120 Weight=17 Profit=70 Weight=7 Bound=$80 Profit=80 Weight=12 Bound=$80 Profit=70 Weight=7 Bound=$7 Item4 $10 5

  13. Profit=0 Weight=0 Bound=$115 Item1 $40 2 Profit=40 Weight=2 Bound=$115 Item2 $30 5 Profit=70 Weight=7 Bound=$115 Profit=40 Weight=2 Bound=$98 Item3 $50 10 Profit=120 Weight=17 Profit=70 Weight=7 Bound=$80 Profit=90 Weight=12 Bound=$98 Profit=80 Weight=12 Bound=$80 Profit=70 Weight=7 Bound=$7 Item4 $10 5

  14. Profit=0 Weight=0 Bound=$115 Item1 $40 2 Profit=40 Weight=2 Bound=$115 Item2 $30 5 Profit=70 Weight=7 Bound=$115 Profit=40 Weight=2 Bound=$98 Item3 $50 10 Profit=120 Weight=17 Profit=70 Weight=7 Bound=$80 Profit=90 Weight=12 Bound=$98 Profit=80 Weight=12 Bound=$80 Profit=70 Weight=7 Bound=$7 Item4 $10 5

  15. Profit=0 Weight=0 Bound=$115 Item1 $40 2 Profit=40 Weight=2 Bound=$115 Item2 $30 5 Profit=70 Weight=7 Bound=$115 Profit=40 Weight=2 Bound=$98 Item3 $50 10 Profit=40 Weight=2 Bound=$50 Profit=120 Weight=17 Profit=70 Weight=7 Bound=$80 Profit=90 Weight=12 Bound=$98 Profit=80 Weight=12 Bound=$80 Profit=70 Weight=7 Bound=$7 Item4 $10 5

  16. Profit=0 Weight=0 Bound=$115 Item1 $40 2 Profit=40 Weight=2 Bound=$115 Item2 $30 5 Profit=70 Weight=7 Bound=$115 Profit=40 Weight=2 Bound=$98 Item3 $50 10 Profit=40 Weight=2 Bound=$50 Profit=120 Weight=17 Profit=70 Weight=7 Bound=$80 Profit=90 Weight=12 Bound=$98 Profit=80 Weight=12 Bound=$80 Profit=70 Weight=7 Bound=$7 Item4 $10 5

  17. Profit=0 Weight=0 Bound=$115 Item1 $40 2 Profit=40 Weight=2 Bound=$115 Item2 $30 5 Profit=70 Weight=7 Bound=$115 Profit=40 Weight=2 Bound=$98 Item3 $50 10 Profit=40 Weight=2 Bound=$50 Profit=120 Weight=17 Profit=70 Weight=7 Bound=$80 Profit=90 Weight=12 Bound=$98 Profit=80 Weight=12 Bound=$80 Profit=70 Weight=7 Bound=$7 Item4 $10 5

  18. Profit=0 Weight=0 Bound=$115 Item1 $40 2 Profit=40 Weight=2 Bound=$115 Profit=0 Weight=0 Bound=$82 Item2 $30 5 Profit=70 Weight=7 Bound=$115 Profit=40 Weight=2 Bound=$98 Item3 $50 10 Profit=40 Weight=2 Bound=$50 Profit=120 Weight=17 Profit=70 Weight=7 Bound=$80 Profit=90 Weight=12 Bound=$98 Profit=80 Weight=12 Bound=$80 Profit=70 Weight=7 Bound=$7 Item4 $10 5

  19. Backtracking Algorithm for the 0–1 Knapsack Problem void knapsack (index i, intprofit, int weight) { if (weight <= W&& profit > maxprofit){ maxprofit = profit; numbest = i; bestset = include; } if (promising(i)){ include [i + 1] = 1; knapsack(i + 1, profit + p[i + 1], weight + w[i + 1]); include [i + 1] = 0; knapsack (i + 1, profit, weight); } }

  20. booleanpromising (index i) { index j, k; inttotweight; float bound; if (weight >= W) return false; else { j = i + 1; bound = profit; totweight = weight; while (j <= n && totweight + w[j] < = W){ totweight = totweight + w[j]; bound = bound + p[j]; j++; } k = j; if (k <=n) bound = bound + (W - totweight) * p[k]/w[k]; return bound > maxprofit; } }

More Related