1 11:56 practical example practical example some of us face it almost every weekend.... namely,...
DESCRIPTION
3 11:56 Ware-HouseWare-HouseTRANSCRIPT
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
2
04:37
My Yachty
3
04:37
Ware-HouseWare-House
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.
5
04:37
Question:
What items should be selected so as to maximize the total value of the collection, subject to the capacity constraint ?
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
7
04:37
Conceptual ModelConceptual Model
Item 1 Item 2 Item 3 Item 4 Item 5
Yes orNo??
8
04:37
Item 1 Item 2 Item 3 Item 4 Item 5
Yes orNo??
9
04:37
Item 1 Item 2 Item 3 Item 4 Item 5
Yes orNo??
10
04:37
Item 1 Item 2 Item 3 Item 4 Item 5
Yes orNo??
11
04:37
Item 1 Item 2 Item 3 Item 4 Item 5
Yes orNo??
12
04:37
Item 1 Item 2 Item 3 Item 4 Item 5
13
04:37
Item 1 Item 2 Item 3 Item 4 Item 5
I hope itwill be better this week!
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).
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 ??
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
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)
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)
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
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))
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].
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)
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)
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
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)}
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
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
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
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)}
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
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.