IE172 – Algorithms in Systems EngineeringLecture 32Pietro BelottiDepartment of Industrial & Systems EngineeringLehigh UniversityApril 6, 2009Next time: matrix operations. Read Chapter 28, Section 28.1Back to ca p ital budgetingAll calculations are done recursively:◮Stage 2 calculations are based on stage 1◮Stage 3 only on stage 2.◮At a given state, all future decisions are made independentof how you got to the state⇒the principle of optimality, and DP rests on this assumption.◮r(kj), c(kj): Revenue and cost for proposal kjat stage j◮so k1∈ {1, 2, 3}, k2∈ {1, 2, 3, 4}, and k3∈ {1, 2}◮fj(xj) : max. revenue with budget xjin stage jf1(x1) = max{k1| c(k1)≤x1}{r(k1)}f2(x2) = max{k2| c(k2)≤x2}{r(k2) + f1(x2− c(k2))}f3(x3) = max{k3| c(k3)≤x3}{r(k3) + f2(x3− c(k3))}From one plant to the nextRepresentative 1 gives the table for plant 1 (f1) to Rep. 2:Capital x10 1 2 3 4 5Plant 1Best Proposal 1 2 3 3 3 3Revenue f (x1) 0 5 6 6 6 6Rep. 2 looks at f1and cost/revs. for plant 2 to get table 2, i.e., f2:Capital x20 1 2 3 4 5Plant 2Best Proposal 1 1 2 2 2/3 4Revenue f (x2) 0 5 8 13 14 17. . . and gives it to Re p. 3, whose x3= 5Another Way◮y1: amount allocated to stages 1, 2, and 3,◮y2: amount allocated to stages 2 and 3,◮y3: amount allocated to stage 3f3(y3) = max{k3| c(k3)≤y3}{r(k3)}f2(y2) = max{k2| c(k2)≤y2}{f3(y2− c(k2))}f1(y1) = max{k1| c(k1)≤y1}{f2(y1− c(k1))}◮Sometimes backwards recursion is faster◮Sometimes forward recursion is faster◮Sometimes it doesn’t matte rDP for as sembly line schedulingProblem: optimize the scheduling of a car factory.◮There are two assembly lines. Each has n different stations:S11, S12. . . , S1nandS21, S22. . . , S2n.◮Stations S1jand S2jperform the same function, put take adifferent amount of time: a1jand a2jOnce a car is processed at station Sij, it can either◮Stay o n the same line (i) with no time pen alty◮Transfer to the other line, but is then de layed by tijProblem:What stations should be chosen from each line in order tominimize the time that a car is in the factory?We can’t check all possibilities: there are2nA better way◮A better way to find an optimal solution is to think aboutwhat properties an optimal solution must have.What is the fastest way to get through station S1j?◮If j = 1 : a11◮If j ≥ 2, two choices for how to get through S1j:◮Through S1,j−1then to S1j◮Through S2,j−1then to S1jKey observation◮Suppose faste st way through S1jis through S1,j−1◮We must have taken a fastest way to get through S1,j−1inthis faste st solution through S1j.◮If there was a faster way through S1,j−1, we could haveused it instead to ge t through S1jfaster.◮Likewise, suppose the fastest way through S1jis fromS2,j−1. We must have used a fastest way through S2,j−1Optimal SubstructureAn optimal solution to the problem (The fastest way throughS1j) contains within it an optimal solution to subproblems: ei-ther the fastest way through S1,j−1or S2,j−1Optimal substructure◮Fastest way through S1jis either (fastest of)◮fastest way through S1,j−1then directly S1j◮fastest way through S2,j−1, transfer lines (t2,j−1), then S1j◮Fastest way through S2jis either (fastest of)◮fastest way through S2,j−1then directly S2j◮fastest way through S1,j−1, transfer lines (t1,j−1), then S2jtj−1,1tj−1,2f1(j − 1)f2(j − 1)A recursive soluti onSuppose that we have entry times eiand exit times xi.Letf1(j), f2(j): fastest time to get t h rough S1j, S2j∀j = 1, 2 . . . n⇒ A DP for the Optimal Solution Value:f1(1) = e1+ a11f2(1) = e2+ a21f1(j) = min(f1(j − 1) + a1j, f2(j − 1) + t2,j−1+ a1j)f2(j) = min(f2(j − 1) + a2j, f1(j − 1) + t1,j−1+ a2j)f∗= min(f1(n) + x1, f2(n) + x2)Looks like a shortest path.Analyze the recursionDefine ri(j) as the # of times do we reference/compute fi(j)◮r1(n) = r2(n) = 1◮r1(j) = r2(j) = r1(j − 1) + r2(j − 1) for j = 1 . . . n − 1Actually ri(j) is independent of i, and it’s a well-knownrecurrence: r1(j) = r2(j) =2n−j!◮This is because we compute f∗in a top down fashion◮fi(j) only depend s on f1(j − 1) and f2(j − 1)⇒ Compute fi(j) in increasing order of j⇒ “Build a table” of the fi(j)’s for each i = 1, 2, j = 1, 2 . . . n◮To build an optimal solution, “keep track” as you go.◮ℓi(j): Line nu mber whose j − 1 station was used to find thefastest way through i◮This “keep track” technique is called memoization.Memoization, or “keeping track”We applied it with the Fibonacci numbers: in principle,F(n) =1 if n ≤ 1F(n − 1) + F(n − 2) if n > 1⇒ we have to call a function anexponential number of times:F(20) = F(19) + F(18) = (2 terms)= (F(18) + F(17)) + (F(17) + F(16)) = (4 terms)= ((F(17) + F(16)) + (F(16) + F(15)))++((F(16) + F(15)) + (F(15) + F(14))) . . . (8 terms)But what we actually do is O(n):FIBONACCI(n)1 a = 0; b = 12 for i ← 2 to n3 do c ← a + b4 a ← b5 b ← c6 return cCommon C haracteristicsThere are a number of characteristics that are common to the setwo problems and to all dynamic programming problems.1. The problem can be d ivided into stage s with a decisionrequired at each stage.... Capital budgeting (CB): the stages are the allocations to asingle plant, and the decision is how much to spe n d... Shortest path (SP): they are defin ed by the structure of thegraph. The d ecision is were to go next.2. Each stage has a number of states associated with it.CB: states correspond to the amount spent at that point in time.SP: state is the node reached.Common C haracteristics3. The decision at one stage transforms one state into a st atein t h e next stage.CB: Decision of how much to spen d gives a total amount spentfor the n ext stage.SP: Where to go next defines where you arrive in next stage.4. At the current state, the optimal decision for the remainingstatesdoes not depend on the previous states/decisionsCB: not necessary to know how the mone y was spent inprevious stages, only how much was spent.SP: not necessary to know how you got to a node, only thatyou did.Common C haracteristics◮There is a recursive relationship that identifies the optimaldecision for stage j + 1, given that stage j is already solved.◮The final stage mus t be solvable by itself.The last two properties are tied up in the recursiverelationships given above.◮The big skill in dynamic programming is to d eterminestages and states so that all of the above hold.◮The recursive relationship
View Full Document