20121127 Chapter 15 P 2 151 Assemblyline scheduling An automobile chassis enters each assembly line has parts added to it at a number of stations and a finished auto exits at the end of the line ID: 569440
Download Presentation The PPT/PDF document "1 Dynamic Programming (II)" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.
Slide1
1
Dynamic Programming (II)
2012/11/27Slide2
Chapter 15
P.
2
15.1 Assembly-line scheduling
An automobile chassis enters each assembly line, has parts added to it at a number of stations, and a finished auto exits at the end of the line.
Each assembly line has n stations, numbered j = 1, 2,...,n. We denote the
j
th
station on line
i
( where
i
is 1 or 2) by
S
i,j
. The
j
th
station on line 1 (S
1,j
) performs the same function as the
j
th
station on line 2 (S
2,j
). Slide3
Chapter 15
P.
3
The stations were built at different times and with different technologies, however, so that the time required at each station varies, even between stations at the same position on the two different lines. We denote the assembly time required at station S
i,j
by a
i,j
.
As the coming figure shows, a chassis enters station 1 of one of the assembly lines, and it progresses from each station to the next. There is also an entry time e
i
for the chassis to enter assembly line i and an exit time x
i
for the completed auto to exit assembly line i.Slide4
Chapter 15
P.
4
a manufacturing problem
to find the fast way through a factorySlide5
Chapter 15
P.
5
Normally, once a chassis enters an assembly line, it passes through that line only. The time to go from one station to the next within the same assembly line is negligible.
Occasionally a special rush order comes in, and the customer wants the automobile to be manufactured as quickly as possible.
For the rush orders, the chassis still passes through the n stations in order, but the factory manager may switch the partially-completed auto from one assembly line to the other after any station.Slide6
Chapter 15
P.
6
The time to transfer a chassis away from assembly line i after having gone through station S
ij
is t
i,j
, where i = 1, 2 and j = 1, 2, ..., n-1 (since after the n
th
station, assembly is complete). The problem is to determine which stations to choose from line 1 and which to choose from line 2 in order to minimize the total time through the factory for one auto.Slide7
Chapter 15
P.
7
An instance of the assembly-line
problem with costsSlide8
Chapter 15
P.
8
Step1 The structure of the fastest way through the factory
the fast way through station S
1,j
is either
the fastest way through Station S
1,j-1
and then directly through station S
1,j
, or
the fastest way through station S
2,j-1
, a transfer from line 2 to line 1, and then through station S
1,j
.
Using symmetric reasoning, the fastest way through station S
2,j
is either
the fastest way through station S
2,j-1
and then directly through Station S
2,j
, or
the fastest way through station S
1,j-1
, a transfer from line 1 to line 2, and then through Station S
2,j
.Slide9
Chapter 15
P.
9
Step 2: A recursive solution Slide10
Chapter 15
P.
10
step 3: computing the fastest times
Let
r
i
(
j
)be the number of references made to
f
i
[
j
] in a recursive algorithm.
r
1
(
n
)=
r
2
(
n
)=1
r
1
(
j
) =
r
2
(
j
)=
r
1
(
j
+1)+
r
2
(
j
+1)
The total number of references to all
f
i
[
j
] values is
(2
n
).
We can do much better if we compute the
f
i
[
j
] values in different order from the recursive way. Observe that for
j
2, each value of
f
i
[
j
] depends only on the values of
f
1
[
j
-1] and
f
2
[
j
-1].Slide11
Chapter 15
P.
11
F
ASTEST
-W
AY
procedure
F
ASTEST
-W
AY
(
a
,
t
,
e
,
x
,
n
)
1
f
1
[1]
e
1
+
a
1,1
2
f
2
[1]
e
2
+
a
2,1
3
for
j
2 to
n
4
do if
f
1
[
j
-1] +
a
1,
j
f
2
[
j
-1] +
t
2,
j
-1
+
a
1,
j
5
then
f
1
[
j
]
f
1
[
j
-1] +
a
1,
j
6
l
1
[
j
]
1
7
else
f
1
[
j
]
f
2
[
j
-1] +
t
2,
j
-1
+a
1,
j
8
l
1
[
j
]
2
9
if
f
2
[
j
-1] +
a
2,
j
f
1
[
j
-1] + t
1,
j
-1
+a
2,
jSlide12
Chapter 15
P.
12
10
then
f
2
[
j
]
f
2
[
j
– 1] + a
2,
j
11
l
2[
j
]
2
12
else
f
2
[
j
]
f
1
[j – 1] +
t
1,
j
-1
+
a
2
,
j
13
l
2
[
j
]
1
14
if
f
1
[
n
] +
x
1
f
2
[
n
] +
x
2
15
then
f
*
=
f
1
[
n
] +
x
1
16
l
*
= 1
17
else
f
*
=
f
2
[
n
] +
x
2
18
l
*
= 2Slide13
Chapter 15
P.
13
step 4: constructing the fastest way through the factory
P
RINT
-S
TATIONS
(
l
,
n
)
1 i
l*
2 print “line” i “,station” n
3 for
j
n downto 2
4 do i
l
i
[
j
]
5 print “line” i “,station” j – 1
output
line 1, station 6
line 2, station 5
line 2, station 4
line 1, station 3
line 2, station 2
line 1, station 1Slide14
P.14
Optimal Binary search trees
cost:2.80
cost:2.75
optimal!!Slide15
P.15
expected cost
the expected cost of a search in T isSlide16
P.16
For a given set of probabilities, our goal is to construct a binary search tree whose expected search is smallest. We call such a tree an
optimal binary search tree
.Slide17
P.17
Step 1: The structure of an optimal binary search tree
Consider any subtree of a binary search tree. It must contain keys in a contiguous range
k
i
, ...,
k
j
,
for some
1
i
j
n
. In addition, a subtree that contains keys
k
i
, ...,
k
j
must also have as its leaves the dummy keys
d
i
-1
, ...,
d
j
.
If an optimal binary search tree T has a subtree
T'
containing keys
k
i
, ...,
k
j
, then this subtree
T'
must be optimal as well for the subproblem with keys
k
i
, ...,
k
j
and dummy keys
d
i
-1
, ...,
d
j
.Slide18
P.18
Step 2: A recursive solution
î
í
ì
£
+
+
+
-
=
=
å
+
å
=
£
£
-
-
=
=
.
if
)}
,
(
]
,
1
[
]
1
,
[
{
min
1,
-
i
j
if
]
,
[
)
,
(
1
1
j
i
j
i
w
j
r
e
r
i
e
q
j
i
e
q
p
j
i
w
j
r
i
i
j
i
l
l
j
i
l
l
If the optimal tree containing
k
i
,…,
k
j
is rooted at
k
r
, then
e
[
i
,
j
]=
p
r
+(
e
[
i
,
r
-1]+
w
(
i
,
r
-1))+(
e
[
r
+1,
j
]+
w
(
r
+1,
j
))
w
[
i
,
j
] =
w
[
i
,
j
– 1] +
p
j
+
q
j
Slide19
P.19
Step 3:computing the expected search cost of an optimal binary search tree
O
PTIMAL
-BST(
p,q,n
)
1
for
i
1 to
n
+ 1
2
e
[
i
,
i
– 1]
q
i
-1
3
w
[
i
,
i
– 1]
q
i
-1
4
for
l
1
to
n
5
for
i
1
to
n
–
l
+ 1
6
j
i
+
l
– 1
7
e
[
i
,
j
]
8
w
[
i
,
j
]
w
[
i
,
j
– 1] +
p
j
+
q
jSlide20
P.20
9
for
r
i
to
j
10
t
e
[
i
,
r
–1]+e[
r
+1,
j
]+
w
[
i
,
j
]
11
if
t
<
e
[
i
,
j
]
12
then
e
[
i
,
j
]
t
13
root
[
i
,
j
]
r
14 return
e
and
root
the O
PTIMAL
-BST procedure takes
(
n
3
)Slide21
P.21
The table e[i,j], w[i,j], and root[i,j] computed by O
PTIMAL
-BST on the key distribution.Slide22
22
0/1 knapsack problem
n items, with weights w
1
, w
2
,
,
w
n
values (profits) v
1
, v
2
,
,
v
n
the capacity W
to maximize
subject to
W
x
i
= 0 or 1, 1
i
n
(We let T={
i
| x
i
=1}
S={1,…,n})Slide23
23
Brute force solution
The 0/1 knapsack problem is an optimization problem.
We may try all 2
n
possible subsets of S to solve it.
Question: Any solution better than the brute-force
?
Answer:
Yes, the
dynamic
programming (DP
)
!
We
trade space for time
.Slide24
24
Table (Array)
We construct an
array V[0..n, 0..M]
.
The entry V[
i
,
w
], 1
in, and 0
wW,
will store the
maximum (combined
) value of
any subset of
items
1,2,…,
i
of the (combined
)
weight
at most w
.
If
we can compute all the entries of this array,
then the
array
entry V[
n
,
W
] will
contain the
maximum value of any subset of items
1,2,…,n
that
can fit into
the knapsack of capacity
W
.Slide25
25
Recursive relation
Initial settings:
V[0, w]=0 for 0
wW
V[
i
, w]=max(V[i-1, w],
v
i
+V
[i-1, w-
w
i
])
for
0
in and
0
w
W if
w
i
w
.
Otherwise,
V[
i
, w
]=V[i-1
, w
]. Slide26
26Slide27
27Slide28
28Slide29
29Slide30
30Slide31
31Slide32
32
0/1 knapsack problem in multistage representation
n objects , weight W
1
, W
2
,
,W
n
profit P
1
, P
2
,
,P
n
capacity M
maximize
subject to
M
x
i
= 0 or 1, 1
i
n
E.g. Slide33
33
0/1 knapsack problem in multistage representation
Multi-stage graph: Slide34
34
The resource allocation problem
Given m resources, n projects with
profit p(
i
, j) :
i
resources are allocated to project j.
The goal is to maximize the total profit.
E.g.
i: # of resources
Project j
1
2
3
1
2
8
9
2
5
6
7
3
4
4
4
4
2
4
5
Slide35
35
Multistage graph
(
i, j) : the state where
i
resources are allocated to
projects 1, 2,
…
, j
E.g. node
H=(3, 2)
:
3
resources are been allocated to
projects 1, 2
.
The Resource Allocation Problem Described as a Multi-Stage Graph. Slide36
36
Multistage graph
Find the longest path from S to T :
S C H L T , 8+5=13
2 resources allocated to project 1
1 resource allocated to project 2
0 resource allocated to projects 3, 4Slide37
Comment
If a problem can be described by a multistage graph then it can be solved by dynamic programming.
37Slide38
Q&A
38