From b560df36ea62a765e977618f9883a73c5127a83d Mon Sep 17 00:00:00 2001 From: wvul Date: Wed, 7 Aug 2024 11:56:17 -0700 Subject: [PATCH] Fix np.int and incorrect bounds for additional parking cost in car_rental_synchronous.py np.int has been deprecated. I've replaced it with np.int32. Also, the problem statement says that the additional parking cost is incurred if (strictly) more than 10 cars are parked at either location; I've fixed the code so that cost isn't paid if exactly 10 cars are parked at either location. --- chapter04/car_rental_synchronous.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/chapter04/car_rental_synchronous.py b/chapter04/car_rental_synchronous.py index 812406a2..4893822c 100644 --- a/chapter04/car_rental_synchronous.py +++ b/chapter04/car_rental_synchronous.py @@ -55,7 +55,7 @@ def __init__(self, truncate, parallel_processes, delta=1e-2, gamma=0.9, solve_4_ self.actions = np.arange(-MAX_MOVE, MAX_MOVE + 1) self.inverse_actions = {el: ind[0] for ind, el in np.ndenumerate(self.actions)} self.values = np.zeros((MAX_CARS + 1, MAX_CARS + 1)) - self.policy = np.zeros(self.values.shape, dtype=np.int) + self.policy = np.zeros(self.values.shape, dtype=np.int32) self.delta = delta self.gamma = gamma self.solve_extension = solve_4_5 @@ -151,9 +151,9 @@ def bellman(self, values, action, state): reward = (real_rental_first_loc + real_rental_second_loc) * RENT_REWARD if self.solve_extension: - if num_of_cars_first_loc >= 10: + if num_of_cars_first_loc > 10: reward += ADDITIONAL_PARK_COST - if num_of_cars_second_loc >= 10: + if num_of_cars_second_loc > 10: reward += ADDITIONAL_PARK_COST num_of_cars_first_loc -= real_rental_first_loc