M2-T1-dynamic Programming Fiba Rod Cutting
M2-T1-dynamic Programming Fiba Rod Cutting
Origin of Name
• Coined by Richard Bellman in the 1950s
bottom-up fashion.
• Expected Output
• Maximum revenue rn obtainable by cutting up the rod and selling
the pieces
• r5 = 13 from solution 5 = 2 + 3
• r6 = 17 from solution 6 = 6 (no cuts)
• r7 = 18 from solution 7 = 1 + 6
• r8 = 22 from solution 8 = 2 + 6
• r9 = 25 from solution 9 = 3 + 6
• r10 = 30 from solution 10 = 10 (no cuts)
Rod cutting
• More generally, we can frame the values rn for n ≥ 1 in terms of
optimal revenues from shorter rods:
• rn = max (pn, r1 + rn-1,r2 + rn-2, ... , rn-1 + r1)
• First argument, p n , corresponds to making no cuts at all and
selling the rod of length n as it is
• other n-1 arguments to max correspond to the maximum revenue
obtained by making an initial cut of the rod into two pieces of
size i and n - i for each i = 1, 2, ..., n - 1
Rod cutting
• and then optimally cutting up those pieces further, obtaining
revenues ri and rn-i from those two pieces
• Since we don’t know ahead of time which value of i optimizes
revenue, we have to consider all possible values for i and pick
the one that maximizes revenue
• We also have the option of picking no 'i' at all if we can obtain
more revenue by selling the rod uncut
Rod cutting
• to solve the original problem of size n, we solve smaller problems
of same type, but of smaller sizes
• Once we make the first cut, we may consider the two pieces as
independent instances of the rod-cutting problem.
• Overall optimal solution incorporates optimal solutions to the two
related subproblems, maximizing revenue from each of those two
pieces
Rod cutting
• We say that the rod-cutting problem exhibits optimal
substructure: optimal solutions to a problem incorporate
• Optimal solutions to related subproblems, which we may solve
independently
• Slightly simpler, view a decomposition as consisting of a first
piece of length i
• Cut off the left-hand end, and then a right-hand remainder of
length n-i
Rod cutting
• Only remainder, and not the first piece, may be further divided
• For n = 40, you would find that your program takes at least
several minutes, and most likely more than an hour
• Thus, T(0) = 1
Analysis of Running Time of Rod-Cut
• The initial 1 is for the call at the root, and the term T(j) counts
the number of calls (including recursive calls) due to the call
CUT-ROD(p, n-i), where j = n - i
• T(n) = 2n