MIT1_204S10_lec15

MIT1_204S10_lec15 - 1.204 Lecture 15 Dynamic programming...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
1.204 Lecture 15 Dynamic programming: Knapsack When multistage graphs don’t work If the resource has many levels: Large range of ints Floating point number Then the multistage graph can’t be constructed And label correction is not a sufficient implementation for pruning We need a set representation instead Different than our Set data structure, alas We keep all the elements in the solution at any stage in a set W d i t d l We purge dominated elements In a knapsack problem, for example, we purge any element whose weight is same or higher and its profit is same or lower than another element This is how we implement pruning We still need to structure the problem so that feasibility constraints keep the size of the sets low 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Knapsack problem Problem is modeled as a series of decisions on whether to include item 1, item 2, item 3, … Each item has a profit (benefit) and a weight (cost) The knapsack has a maximum weight (cost) Each project is either in or out of the knapsack No fractional values allowed, as were in the greedy version Algorithm Forward pass: builds sets instead of graph Sets contain cumulative (profit, weight) pairs Backward pass: traces sets back from sink to source to recover solution Algorithm can produce solution for all weights less than or equal to maximum weight in a single run First example Item Profit Weight Maximum weight= 9 000 112 223 354 Item 0 is a sentinel with 0 weight, 0 profit always
Background image of page 2
Forward pass: build sets S(0)= (0,0) S holds cumulative profit, weight (1,2) S’ is set of items to merge S’= (1,2) S is set of items to merge S(1)= (0,0) (1,2) S(n) is merged S(n-1) and S’ S’= (2,3) (3,5) S(2)= (0,0) (1,2) (2,3) (3,5) S’= (5,4) (6,6) (7,7) (8,9) S(3)= (0,0) (1,2) (2,3) (5,4) (6,6) (7,7) (8,9) Note that (3,5) is purged when S(3) is constructed It is dominated by (5,4): higher profit, lower weight If maximum weight were 7, (8,9) pair would not be built Infeasibility Backward pass: get solution S(0)= (0,0) Item S(1)= (0,0) (1,2) (1,2) S(2)= (0,0) (1,2) (2,3) (3,5) (2,3) S(3)= (0,0) (1,2) (2,3) (5,4) (6,6) (7,7) (8,9) (5,4) M a x im umw e i g h t : 4 56789 6 7 8 9 Maximum weight: 4 Last pair is optimal (profit, weight) for entire problem If pair exists in previous set, item not in solution If pair not in previous set, item is in solution Subtract item profit, weight and find that pair in previous set Continue to trace back to source node 3
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 Second example Item Profit Weight 00 0 11 1 1 22 1 1 1 33 1 2 1 43 3 2 3 54 3 3 3 65 3 4 3 Maximum weight 110 Item 0 is sentinel 75 5 4 5 86 5 5 5 Forward pass: build sets Traceback uses same logic as before
Background image of page 4
Algorithm implementation Follows examples, but there are complications: We must keep each set S(i) to trace back the answer In example 1, if we kept only the final set S(3), the pair (3,5) would have been purged and we would not be able to trace back the solution Pairs dominated by pairs considered later can still be part of an optimal subsequence in the optimal solution Storage requirements for all the sets are significant
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/04/2011 for the course ESD 1.204 taught by Professor Georgekocur during the Spring '10 term at MIT.

Page1 / 14

MIT1_204S10_lec15 - 1.204 Lecture 15 Dynamic programming...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online