diff --git a/solutions/ex02/deterministic_inventory_TODO_1.py b/solutions/ex02/deterministic_inventory_TODO_1.py new file mode 100644 index 0000000000000000000000000000000000000000..7e93e6c74bc98dc123e7f2b78b7db98ab4ece65d --- /dev/null +++ b/solutions/ex02/deterministic_inventory_TODO_1.py @@ -0,0 +1 @@ + return {k + 1: 1} \ No newline at end of file diff --git a/solutions/ex02/dp_TODO_1.py b/solutions/ex02/dp_TODO_1.py new file mode 100644 index 0000000000000000000000000000000000000000..a266a96faac19f97576e30e2ab483c3518f64eb4 --- /dev/null +++ b/solutions/ex02/dp_TODO_1.py @@ -0,0 +1,4 @@ + Qu = {u: sum(pw * (model.g(x, u, w, k) + J[k + 1][model.f(x, u, w, k)]) for w, pw in model.Pw(x, u, k).items()) for u in model.A(x, k)} + umin = min(Qu, key=Qu.get) + J[k][x] = Qu[umin] # Compute the expected cost function + pi[k][x] = umin # Compute the optimal policy \ No newline at end of file diff --git a/solutions/ex02/dp_agent_TODO_1.py b/solutions/ex02/dp_agent_TODO_1.py new file mode 100644 index 0000000000000000000000000000000000000000..18f9f782a449efa896b4e9516a633aff48d78a37 --- /dev/null +++ b/solutions/ex02/dp_agent_TODO_1.py @@ -0,0 +1 @@ + action = self.pi_[k][s] \ No newline at end of file diff --git a/solutions/ex02/flower_store_TODO_1.py b/solutions/ex02/flower_store_TODO_1.py new file mode 100644 index 0000000000000000000000000000000000000000..4fec1d31c73c6e3a40dd0f340ef1e3c40f4a950f --- /dev/null +++ b/solutions/ex02/flower_store_TODO_1.py @@ -0,0 +1,23 @@ +class FlowerStoreModel(InventoryDPModel): + def __init__(self, N=3, c=0., prob_empty=False): + self.c = c + self.prob_empty = prob_empty + super().__init__(N=N) + + def g(self, x, u, w, k): # Cost function g_k(x,u,w) + if self.prob_empty: + return 0 + return u * self.c + np.abs(x + u - w) + + def f(self, x, u, w, k): # Dynamics f_k(x,u,w) + return max(0, min(max(self.S(k)), x + u - w)) + + def Pw(self, x, u, k): # Distribution over random disturbances + pw = {0: .1, 1: .3, 2: .6} + return pw + + def gN(self, x): + if self.prob_empty: + return -1 if x == 1 else 0 + else: + return 0 \ No newline at end of file diff --git a/solutions/ex02/flower_store_TODO_2.py b/solutions/ex02/flower_store_TODO_2.py new file mode 100644 index 0000000000000000000000000000000000000000..29eed8491b7026d6ca202083467679520c7cdb23 --- /dev/null +++ b/solutions/ex02/flower_store_TODO_2.py @@ -0,0 +1,3 @@ + model = FlowerStoreModel(N=N, c=c, prob_empty=False) + J, pi = DP_stochastic(model) + u = pi[0][x0] \ No newline at end of file diff --git a/solutions/ex02/flower_store_TODO_3.py b/solutions/ex02/flower_store_TODO_3.py new file mode 100644 index 0000000000000000000000000000000000000000..62bdb1dc5fd12c76ae2092df7cc21e98b72d55cc --- /dev/null +++ b/solutions/ex02/flower_store_TODO_3.py @@ -0,0 +1,3 @@ + model = FlowerStoreModel(N=N, prob_empty=True) + J, pi = DP_stochastic(model) + pr_empty = -J[0][x0] \ No newline at end of file diff --git a/solutions/ex02/inventory_TODO_1.py b/solutions/ex02/inventory_TODO_1.py new file mode 100644 index 0000000000000000000000000000000000000000..38ded4d6bdfbf7113936292bd1bb4857da6c48ac --- /dev/null +++ b/solutions/ex02/inventory_TODO_1.py @@ -0,0 +1 @@ + return {0:.1, 1:.7, 2:0.2} \ No newline at end of file