COMP 6651 Fall 2013 B Jaumard 24 Dynamic Prog Assembly Line Scheduling Knapsack

Comp 6651 fall 2013 b jaumard 24 dynamic prog

This preview shows page 35 - 43 out of 90 pages.

COMP 6651 / Fall 2013 - B. Jaumard 24
Image of page 35
. . . . . . . . . . Dynamic Prog. . . . . . . . . . . . . . . . . Assembly-Line Scheduling . . . . . . . . . . . . . . Knapsack Pb . . . . . . . . . Shortest Path . . . . . . . . . . . . . . . . . . Longest Common Subseq. . . . Conclusions The 0/1 Knapsack Problem (2/2) Given : A set S of n items, with each item i having w i a positive weight b i a positive benefit Goal : Choose items with maximum total benefit but with weight at most W . Well known problem, usually expressed as a mathematical program Objective : maximize i T b i Constraint : i T w i W where T : index set of the selected items If we are not allowed to take fractional amounts, then this is the 0/1 knapsack problem . COMP 6651 / Fall 2013 - B. Jaumard 25
Image of page 36
. . . . . . . . . . Dynamic Prog. . . . . . . . . . . . . . . . . Assembly-Line Scheduling . . . . . . . . . . . . . . Knapsack Pb . . . . . . . . . Shortest Path . . . . . . . . . . . . . . . . . . Longest Common Subseq. . . . Conclusions Solving the 0/1 Knapsack Problem: First Attempt S k : Set of items numbered 1 to k . Define B [ k ] = best selection from S k . Difficulty: does not have subproblem optimality: Consider set S = { ( 3 , 2 ) , ( 5 , 4 ) , ( 8 , 5 ) , ( 4 , 3 ) , ( 10 , 9 ) } of (benefit, weight) pairs and total weight W = 20 COMP 6651 / Fall 2013 - B. Jaumard 26
Image of page 37
. . . . . . . . . . Dynamic Prog. . . . . . . . . . . . . . . . . Assembly-Line Scheduling . . . . . . . . . . . . . . Knapsack Pb . . . . . . . . . Shortest Path . . . . . . . . . . . . . . . . . . Longest Common Subseq. . . . Conclusions Solving the 0/1 Knapsack Problem: Second Attempt S k : Set of items numbered 1 to k . Define B [ k , w ] to be the value of the best selection from S k with weight at most w Good news : B [ k , w ] has the subproblem optimality. B [ k , w ] = { B [ k - 1 , w ] if w k > w max { B [ k - 1 , w ] , B [ k - 1 , w - w k ] + b k } otherwise. i.e., the best subset of S k with weight at most w is either the best subset of S k - 1 with weight at most w or the best subset of S k - 1 with weight at most w - w k plus item k COMP 6651 / Fall 2013 - B. Jaumard 27
Image of page 38
. . . . . . . . . . Dynamic Prog. . . . . . . . . . . . . . . . . Assembly-Line Scheduling . . . . . . . . . . . . . . Knapsack Pb . . . . . . . . . Shortest Path . . . . . . . . . . . . . . . . . . Longest Common Subseq. . . . Conclusions Solving the 0/1 Knapsack Problem using Dynamic Programming (1/2) B [ k , w ] = { B [ k - 1 , w ] if w k > w max { B [ k - 1 , w ] , B [ k - 1 , w - w k ] + b k } otherwise. Running time: O ( nW ) . Not a polynomial-time algorithm since W may be large This is a pseudo-polynomial (running time is polynomial in the numerical value of the input, but exponential in the length of the input) time algorithm: COMP 6651 / Fall 2013 - B. Jaumard 28
Image of page 39
. . . . Dynamic Prog. . . . . . . . . . . . . . . . . Assembly-Line Scheduling . . . . . . . . . . . . . . Knapsack Pb . . . . . . . . . Shortest Path . . . . . . . . . . . . . . . . . . Longest Common Subseq. . . . Conclusions Solving the 0/1 Knapsack Problem using Dynamic Programming (2/2) B [ k , w ] = { B [ k - 1 , w ] if w k > w max { B [ k - 1 , w ] , B [ k - 1 , w - w k ] + b k } otherwise. B [ k , w ] is defined in terms of B [ k - 1 , * ] , use of two one-dimensional arrays of length W + 1. For each k value, A stores the B [ k - 1 , * ] values and A + the B [ k , * ] ones. Input: Set S of n items with benefit b i and weight w i ; maximum weight W Output: Benefit of best subset of S with weight at most W . Knapsack Problem . . . . . for w 0 to W do A + [ w ] 0 · · · for k 0 to n do copy array A + into array A for w w k to W do if A [ w - w k ] + b k > A [ w ] then A + [ w ] A [ w - w k ] + b k return A + [ w ] COMP 6651 / Fall 2013 - B. Jaumard 29
Image of page 40
. . . . . . . . . . Dynamic Prog. . . . . . . . . . . . . . . . . Assembly-Line Scheduling . . . . . . . . . . . . . . Knapsack Pb . . . . . . . . . Shortest Path . . . . . . . . . . . . . . . . . . Longest Common Subseq. . . . Conclusions 0-1 Knapsack: An Example (1/7) 4 items Benefit values b [ 1 ] = 3 ; b [ 2 ] = 4 ; b [ 3 ] = 5 ; b [ 4 ] = 6 Weight values w [ 1 ] = 5 ; w [ 2 ] = 4 ; w [ 3 ] = 3 ; w [ 4 ] = 2 Objective: maximize the benefit while not exceeding the knapsack capacity ( W = 5) COMP 6651 / Fall 2013 - B. Jaumard 30
Image of page 41
. . . . . .
Image of page 42
Image of page 43

You've reached the end of your free preview.

Want to read all 90 pages?

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes