MS-E2148 Dynamic optimization Exercise 1 (fri 4.11.2016) Exercise 1.1 (demo) Let A, B, C, D be matrices with dimensions 5 × 4, 4 × 6, 6 × 2 and 2 × 5, respectively. Using dynamic programming, determine the multiplication sequence that minimizes the number of scalar multiplications in computing ABCD. Exercise 1.2 The graph of Figure 1 depicts a exible production line. The initial product A has to go through three phases to become the nal product J. The cost from each node to another is given next to the corresponding arc. Figure 1: Graph of Exercise 1.2 Calculate the optimal cost-to-go function for each node and determine the steps that have to be taken to minimize the cost. Exercise 1.3 You want to plant tomatoes, potatoes and peas on a 180 cm wide allotment. A row of tomatoes or potatoes takes up 40 cm of space, and a row of peas 20 cm. The utility is 10 for a row of tomatoes, 7 for a row of potatoes and 3 for a row of peas. Additionally, according to an EU-directive the maximum number of allowed rows of tomatoes is two. Give a dynamic programming algorithm that could be used to solve this problem. Exercise 1.4 A certain string-processing language oers a primitive operation which splits a string into two pieces. Since this operation involves copying the original string, it takes n units of time for a string of length n, regardless of the location of the cut. Suppose, now, that you want to break a string into many pieces. The order in which the breaks are made can aect the total running time. For example, if you want to cut a 20-character string at positions 3 and 10, then making the rst cut at position 3 incurs a total cost of 20 + 17 = 37, while doing position 10 rst has a better cost of 20 + 10 = 30. Give a dynamic programming algorithm that, given the locations of m cuts in a string of length n, nds the minimum cost of breaking the string into m + 1 pieces. Exercise 1.5 (solution given) Initially there is A amount of a resource, and it has to be used until√the end of N periods. The amount u(k) of the resource used on period k produces the utility u(k). a) Formulate the problem, i.e., dene the state equation, utility function, control constraints, and boundary conditions for the state variable. Notice that the state and control are continuous! b) Show that Jk (xk ) = √ (N − k)xk is the optimal cost-to-go function. Solution a) State variable: xk (remaining resource in the end of period k ). State equation: xk+1 = xk − uk . Utility function: g(xk , uk ) = Control constraint: Boundary conditions: Objective function: √ uk . 0 ≤ uk ≤ xk , ∀ k. x0 = A, xN = 0 . J= ∑N −1 k=0 g(xk , uk ) ,→ max!. b) The cost-to-go function of dynamic programming: JN∗ (xN ) := 0 √ JN∗ −1 (xN −1 ) := xN −1 [ ] ∗ Jk∗ (xk ) := max gk (xk , uk ) + Jk+1 (xk+1 ) uk ∈Uk [√ ] ∗ = max uk + Jk+1 (xk − uk ) , 0≤uk ≤xk Claim: Jk∗ (xk ) = √ k = 0, . . . , N − 2. (N − k)xk . Lets prove it by induction. Initial step: OK, when k = N . Lets assume the claim holds for the ∗ cost-to-go function Jk+1 (xk+1 ): Jk∗ (xk ) [√ ] ∗ = max uk + Jk+1 (xk − uk ) 0≤uk ≤xk ] [√ √ uk + (N − k − 1)xk+1 = max 0≤uk ≤xk [√ ] √ = max uk + (N − k − 1)[xk − uk ] . 0≤uk ≤xk Derivate with regard to uk and set the derivative to equal zero: √ 1 N −k−1 √ ∗− √ =0 2 uk 2 xk − u∗k ⇓ N −k−1 1 = ∗ uk xk − u∗k ⇕ u∗k = 1 xk N −k This is a feasible control for all xk ≥ 0. Insert the optimal control into the cost-to-go function: √ xk (N − k − 1)2 xk + N −k N −k √ √ xk xk + (N − k − 1) N −k N −k √ xk (N − k) N −k √ (N − k)xk √ Jk∗ (xk ) = = = = and the claim has been proved. The initial condition x0 = A gives the control u∗0 = A/N . Then x1 = A(N − 1)/N , and the corresponding control is u∗1 = A/N . Notice, that as a matter of fact, the optimal control u∗ is constant on each period. Exercise 1.6 (home assignment) You are the chief of a production line in a marble factory. The factory buys large blocks of marble and cuts them into smaller pieces, and sells them further to customers. The factory produces marble pieces in three dierent sizes (from smallest to largest): y1 × x1 , y2 × x2 and y3 × x3 . A piece i is smaller than j if yi · xi < yj · xj . There is a utility assigned to the dierent pieces: 2, 10, 11 (here also from smallest to largest). The utility reects that some of the pieces are more protable than others. The marble is quite fragile, so there is a certain way to cut it. Let say you have bought a block of marble of size m × n. Now, if you want to cut a y1 × x1 piece out of a m × n block, you either rst have to cut a m × x1 piece and then further cut the y1 × x1 piece out of the m × x1 block. Alternatively, you can start by cutting a y1 × n block and then further cut the y1 × x1 piece out of the y1 × n block. The allowed ways to cut are depicted in the gure below. For simplicity, you do not have to consider the possibility to rotate the blocks. Figure 2: Permitted ways to cut out the piece. All cuts have to be straight lines through the whole (sub)block being cut. Given any m × n block of marble, and any three dierent sized pieces i = 1, 2, 3, your task is to cut the initial block of marble, so that the sum of the utility of the blocks being sold is maximized. Use dynamic programming to solve the problem. In your answer, return a MATLAB code that takes as an input the size of the block, and the dimensions of the pieces you want to cut out of it, and returns the optimal utility. The MATLAB code used to test your function will be the following: 1 2 3 % Clear persistent variables. You should store the cost-to-gos for the % subproblems using a persistent variable (matrix) inside the function. clear functions 4 5 6 7 % Dimensions of the initial marble block. These will be altered by us. sy = 100; sx = 100; 8 9 10 11 12 % % m n Dimensions of the block being cut. In the first cut these will be same as sy and sx. = sy; = sx; 13 14 15 16 % Dimensions of the pieces. The code will be tested with varying inputs. y = [1,3,4]; x = [2,3,2]; 17 18 19 20 % Calling your DP-algorithm to solve the problem of cutting the % m x n block into smaller pieces. opt_util = student_dp(m,n,y,x,sy,sx)
© Copyright 2026 Paperzz