CE 191 — CEE Systems Analysis Professor Scott Moura — University of California, Berkeley
=
1
4
c
k
p(x
k
+ u
k
) u
k
, k = 0, · · · , N − 1 (22)
Since we require the dishwasher to complete all cycles by 24:00, we define the following terminal
cost:
g
N
(x
N
) =
(
0 : x
N
= 5
∞ : otherwise
(23)
Let V
k
(x
k
) represent the minimum cost-to-go from time step k to final time period N, given the last
completed dishwasher cycle is x
k
. Then the principle of optimality equations are:
V
k
(x
k
) = min
u
k
∈{0,1}
1
4
c
k
p(x
k
+ u
k
)u
k
+ V
k+1
(x
k+1
)
= min
u
k
∈{0,1}
1
4
c
k
p(x
k
+ u
k
)u
k
+ V
k+1
(x
k
+ u
k
)
= min
V
k+1
(x
k
),
1
4
c
k
p(x
k
+ 1) + V
k+1
(x
k
+ 1)
(24)
with the boundary condition
V
N
(5) = 0, V
N
(i) = ∞ for i 6= 5 (25)
We can also write the optimal control action as:
u
∗
(x
k
) = arg min
u
k
∈{0,1}
1
4
c
k
p(x
k
+ u
k
)u
k
+ V
k+1
(x
k
+ u
k
)
Equation (24) is solved recursively, using the boundary condition (25) as the first step. Next, we
show how to solve this algorithmically in Matlab.
3.3 Matlab Implementation
The code below provides an implementation of the dynamic programming equations.
1 %% Problem Data
2 % Cycle power
3 p = [0; 1.5; 2.0; 0.5; 0.5; 1.0];
4
5 % Electricity Price Data
6 c = [12,12,12,10,9,8,8,8,7,7,6,5,5,5,5,5,5,5,6,7,7,8,9,9,10,11,11,...
7 12,12,14,15,15,16,17,19,19,20,21,21,22,22,22,20,20,19,17,15,15,16,...
8 17,17,18,18,16,16,17,17,18,20,20,21,21,21,20,20,19,19,18,17,17,...
9 16,19,21,22,23,24,26,26,27,28,28,30,30,30,29,28,28,26,23,21,20,18,18,17,17,16,16];
10
Revised December 10, 2014 | NOT FOR DISTRIBUTION Page 10