1 11:56 practical example practical example some of us face it almost every weekend.... namely,...

31
09:04 Practical Practical Example Example Some of us face it almost every Some of us face it almost every weekend .... namely, the famous weekend .... namely, the famous Knapsack Problem Knapsack Problem

Upload: ernest-dwight-dawson

Post on 20-Jan-2018

215 views

Category:

Documents


0 download

DESCRIPTION

3 11:56 Ware-HouseWare-House

TRANSCRIPT

Page 1: 1 11:56 Practical Example Practical Example Some of us face it almost every weekend.... namely, the…

1

04:37

Practical Example Practical Example

Some of us face it almost every weekend .... Some of us face it almost every weekend .... namely, the famousnamely, the famous

Knapsack ProblemKnapsack Problem

Page 2: 1 11:56 Practical Example Practical Example Some of us face it almost every weekend.... namely, the…

2

04:37

My Yachty

Page 3: 1 11:56 Practical Example Practical Example Some of us face it almost every weekend.... namely, the…

3

04:37

Ware-HouseWare-House

Page 4: 1 11:56 Practical Example Practical Example Some of us face it almost every weekend.... namely, the…

4

04:37FormalismFormalism(0-1) Version(0-1) Version

We have n items: i=1,2,3,...,n Each item is characterised by two properties:

– Value : v(1),...,v(n)– Volume: c(1),...,c(n)

We have a container of capacity C.

Page 5: 1 11:56 Practical Example Practical Example Some of us face it almost every weekend.... namely, the…

5

04:37

Question:

What items should be selected so as to maximize the total value of the collection, subject to the capacity constraint ?

Page 6: 1 11:56 Practical Example Practical Example Some of us face it almost every weekend.... namely, the…

6

04:37

Math CornerMath Corner

z* :=maxx

vjj=1

n

∑ xj

s.t.

cjj=1

n

∑ xj ≤C

xj ∈{0,1}, j=1, 2,...,n

Page 7: 1 11:56 Practical Example Practical Example Some of us face it almost every weekend.... namely, the…

7

04:37

Conceptual ModelConceptual Model

Item 1 Item 2 Item 3 Item 4 Item 5

Yes orNo??

Page 8: 1 11:56 Practical Example Practical Example Some of us face it almost every weekend.... namely, the…

8

04:37

Item 1 Item 2 Item 3 Item 4 Item 5

Yes orNo??

Page 9: 1 11:56 Practical Example Practical Example Some of us face it almost every weekend.... namely, the…

9

04:37

Item 1 Item 2 Item 3 Item 4 Item 5

Yes orNo??

Page 10: 1 11:56 Practical Example Practical Example Some of us face it almost every weekend.... namely, the…

10

04:37

Item 1 Item 2 Item 3 Item 4 Item 5

Yes orNo??

Page 11: 1 11:56 Practical Example Practical Example Some of us face it almost every weekend.... namely, the…

11

04:37

Item 1 Item 2 Item 3 Item 4 Item 5

Yes orNo??

Page 12: 1 11:56 Practical Example Practical Example Some of us face it almost every weekend.... namely, the…

12

04:37

Item 1 Item 2 Item 3 Item 4 Item 5

Page 13: 1 11:56 Practical Example Practical Example Some of us face it almost every weekend.... namely, the…

13

04:37

Item 1 Item 2 Item 3 Item 4 Item 5

I hope itwill be better this week!

Page 14: 1 11:56 Practical Example Practical Example Some of us face it almost every weekend.... namely, the…

14

04:37

Modified Problems Modified Problems

Let f(i,s) := maximum value of remaining items if I

am about to decide on item i and still have s units of volume available.

Observations: Original problem requires f(1,C). f(n,s)=0, s<c(n); f(n,s)=v(n), s >= c(n).

Page 15: 1 11:56 Practical Example Practical Example Some of us face it almost every weekend.... namely, the…

15

04:37

Conceptual ModelConceptual Model

f(i,s) = the best I can do with the remaining decisions given where I am (i) and how much capacity (s) is left.

Item i-1 Item i Item i+1

Yes or No ??

Page 16: 1 11:56 Practical Example Practical Example Some of us face it almost every weekend.... namely, the…

16

04:37

Conceptual ModelConceptual Model

Item i-1 Item i Item i+1

Yes or No ??

Jack!You can’t takethis item. You do not have enought space

Page 17: 1 11:56 Practical Example Practical Example Some of us face it almost every weekend.... namely, the…

17

04:37Conditional Conditional AnalysisAnalysis

Let f(i,s,Yes) := Best I can do in the remaining stages if given

(i,s) I select item i. f(i,s,No) := Best I can do in the remaining stages if given (i,s)

I do not select item i.Then clearly,f(i,s) = f(i,s,No) , if s < c(i) and f(i,s) = max { f(i,s,Yes) , f(i,s,No)} , s>=c(i)

Page 18: 1 11:56 Practical Example Practical Example Some of us face it almost every weekend.... namely, the…

18

04:37 Principle of Optimality Principle of Optimality f(i,s,No) = f(i+1,s) f(i,s,Yes) = v(i) + f(i+1,s-c(i))Hence:f(i,s)=f(i+1,s) , s<c(i)f(i,s) = max {f(i+1,s) , v(i) + f(i+1,s-c(i)}, s >= c(i)

Page 19: 1 11:56 Practical Example Practical Example Some of us face it almost every weekend.... namely, the…

19

04:37 Principle of Optimality Principle of Optimality f(i,s,No) = f(i+1,s) f(i,s,Yes) = v(i) + f(i+1,s-c(i))Hence:f(i,s)=f(i+1,s) , s<c(i)f(i,s) = max {f(i+1,s) , v(i) + f(i+1,s-c(i))} s>=c(i) s

sis-c(i)

i+1

No

Yes

Page 20: 1 11:56 Practical Example Practical Example Some of us face it almost every weekend.... namely, the…

20

04:37 Principle of Optimality Principle of Optimality f(i,s,No) = f(i+1,s) f(i,s,Yes) = v(i) + f(i+1,s-c(i))Hence:

f(i,s)=f(i+1,s) , s<c(i)f(i,s) = max {f(i+1,s) , v(i) + f(i+1,s-c(i)}, i<n

ssi

s-c(i)i+1

No

Yes

f(i+1,s)

v(i) + f(i+1,s-c(i))

Page 21: 1 11:56 Practical Example Practical Example Some of us face it almost every weekend.... namely, the…

21

04:37

The Master’s Voice The Master’s Voice

“ ... This observation, simple as it is, is the key to all our subsequent mathematical analysis. It is worthwhile for the reader to pause here a moment and make sure that he really agrees with this observation which has the deceptive simplicity of a half- truth ...”

Bellman, 1957 [page 8].

Page 22: 1 11:56 Practical Example Practical Example Some of us face it almost every weekend.... namely, the…

22

04:37

ExampleExample

c = (1,2,3,4)c = (1,2,3,4)v = (3,7,8,11)v = (3,7,8,11)C = 27C = 27

f(i,s) = max {f(i+1,s) , v(i) + f(i+1,s-c(i)}, i<n

f(n,s) = 0, s < c(n)f(n,s) = v(n), s >= c(n)

Page 23: 1 11:56 Practical Example Practical Example Some of us face it almost every weekend.... namely, the…

23

04:37ExampleExample

c = (1,2,3,4) ; v = (3,7,8,11) ; C = 27c = (1,2,3,4) ; v = (3,7,8,11) ; C = 27i=nf(n,s) = 0, s < c(n) ; f(n,s) = v(n), s >= c(n)i<n:f(i,s) =f(i+1,s) , s < c(i) f(i,s) = max {f(i+1,s) , v(i) + f(i+1,s-c(i)}, s>=c(i)

Page 24: 1 11:56 Practical Example Practical Example Some of us face it almost every weekend.... namely, the…

24

04:37

Initialization i=n=4Initialization i=n=4

f(n,s) = 0, s < c(n) ; f(n,s) = v(n), s >= c(n)

f(4,s) = 0 , s < 4 = 11 , s >= 4

Page 25: 1 11:56 Practical Example Practical Example Some of us face it almost every weekend.... namely, the…

25

04:37Iteration i=3 Iteration i=3

i<n:f(i,s) =f(i+1,s) , s < c(i) f(i,s) = max {f(i+1,s) , v(i) + f(i+1,s-c(i)}, s>=c(i)i=3:i=3:f(3,s) = f(4,s) , s < 3f(3,s) = f(4,s) , s < 3 = 0= 0f(3,s) = max {f(4,s) , v(3) + f(4,s-c(3)}, s >=3f(3,s) = max {f(4,s) , v(3) + f(4,s-c(3)}, s >=3 = max {f(4,s) , 8 +f(4,s-3)}= max {f(4,s) , 8 +f(4,s-3)}

Page 26: 1 11:56 Practical Example Practical Example Some of us face it almost every weekend.... namely, the…

26

04:37Iteration i= 3Iteration i= 3i<n:f(i,s) =f(i+1,s) , s < c(i) f(i,s) = max {f(i+1,s) , v(i) + f(i+1,s-c(i)}, s>=c(i)s=3:s=3:f(3,3) =f(3,3) = max {f(4,3) , 8 +f(4,3-3)}max {f(4,3) , 8 +f(4,3-3)} = max {f(4,3) , 8+f(4,0)}= max {f(4,3) , 8+f(4,0)} = max {0,8+0}= max {0,8+0} = 8= 8

Page 27: 1 11:56 Practical Example Practical Example Some of us face it almost every weekend.... namely, the…

27

04:37Iteration i= 3Iteration i= 3i<n:f(i,s) =f(i+1,s) , s < c(i) f(i,s) = max {f(i+1,s) , v(i) + f(i+1,s-c(i)}, s>=c(i)s=4:s=4:f(3,4) =f(3,4) = max {f(4,4) , 8 +f(4,4-3)}max {f(4,4) , 8 +f(4,4-3)} = max {f(4,4) , 8+f(4,1)}= max {f(4,4) , 8+f(4,1)} = max {11,8+0}= max {11,8+0} = 11= 11

Page 28: 1 11:56 Practical Example Practical Example Some of us face it almost every weekend.... namely, the…

28

04:37Iteration i= 3Iteration i= 3

c = (1,2,3,4) ; v = (3,7,8,11) ;c = (1,2,3,4) ; v = (3,7,8,11) ;By By inspectioninspection: : f(3,s) =f(3,s) = 11 for 4 <= s <= 6 = 19 for s >= 7 = 19 for s >= 7

Page 29: 1 11:56 Practical Example Practical Example Some of us face it almost every weekend.... namely, the…

29

04:37Iteration i=2Iteration i=2i<n:f(i,s) =f(i+1,s) , s < c(i) f(i,s) = max {f(i+1,s) , v(i) + f(i+1,s-c(i)}, s>=c(i)i=3:i=3:f(2,s) = f(3,s) , s < 2f(2,s) = f(3,s) , s < 2 = 0= 0f(2,s) = max {f(3,s) , v(2) + f(3,s-c(2)}, s >=2f(2,s) = max {f(3,s) , v(2) + f(3,s-c(2)}, s >=2 = max {f(3,s) , 7 +f(3,s-2)}= max {f(3,s) , 7 +f(3,s-2)}

Page 30: 1 11:56 Practical Example Practical Example Some of us face it almost every weekend.... namely, the…

30

04:37Iteration i=2Iteration i=2

c = (1,2,3,4) ; v = (3,7,8,11) c = (1,2,3,4) ; v = (3,7,8,11) f(2,s) = max {f(3,s) , 7 +f(3,s-2)} , s >=2f(2,s) = max {f(3,s) , 7 +f(3,s-2)} , s >=2By By inspectioninspection::f(2,2) = 7 ; f(2,3) = 8f(2,2) = 7 ; f(2,3) = 8f(2,4) = 11 ; f(2,5) = 15f(2,4) = 11 ; f(2,5) = 15f(2,6) = 18 ; f(2,7) = 19f(2,6) = 18 ; f(2,7) = 19f(2,8) = 19 ; f(2,s) = 126 , s >= 9f(2,8) = 19 ; f(2,s) = 126 , s >= 9

Page 31: 1 11:56 Practical Example Practical Example Some of us face it almost every weekend.... namely, the…

31

04:37

Iteration i=1Iteration i=1 Complete on your ownComplete on your own Check your solution via complete enumeration.Check your solution via complete enumeration.