From 085f8c82b4d48424cf8ab61f52f824d185b63f0e Mon Sep 17 00:00:00 2001 From: Edouard Leurent Date: Sat, 14 Oct 2023 12:35:25 +0100 Subject: [PATCH] Use speed instead of speed_index in merge env Fix https://github.com/Farama-Foundation/HighwayEnv/issues/519 --- highway_env/envs/merge_env.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/highway_env/envs/merge_env.py b/highway_env/envs/merge_env.py index b305bb84d..32faed792 100644 --- a/highway_env/envs/merge_env.py +++ b/highway_env/envs/merge_env.py @@ -27,6 +27,7 @@ def default_config(cls) -> dict: "collision_reward": -1, "right_lane_reward": 0.1, "high_speed_reward": 0.2, + "reward_speed_range": [20, 30], "merging_speed_reward": -0.5, "lane_change_reward": -0.05, }) @@ -48,10 +49,11 @@ def _reward(self, action: int) -> float: [0, 1]) def _rewards(self, action: int) -> Dict[Text, float]: + scaled_speed = utils.lmap(self.vehicle.speed, self.config["reward_speed_range"], [0, 1]) return { "collision_reward": self.vehicle.crashed, "right_lane_reward": self.vehicle.lane_index[2] / 1, - "high_speed_reward": self.vehicle.speed_index / (self.vehicle.target_speeds.size - 1), + "high_speed_reward": scaled_speed, "lane_change_reward": action in [0, 2], "merging_speed_reward": sum( # Altruistic penalty (vehicle.target_speed - vehicle.speed) / vehicle.target_speed