From 421eeee0d6bf1f6993c8e642cff3ffaec9839648 Mon Sep 17 00:00:00 2001 From: Edouard Leurent Date: Sat, 27 Apr 2024 13:24:30 +0100 Subject: [PATCH] Set one goal per controlled vehicle in ParkingEnv Fix https://github.com/Farama-Foundation/HighwayEnv/issues/593 --- highway_env/envs/common/observation.py | 2 +- highway_env/envs/parking_env.py | 15 ++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/highway_env/envs/common/observation.py b/highway_env/envs/common/observation.py index 4c79f8d3e..09cd3198e 100644 --- a/highway_env/envs/common/observation.py +++ b/highway_env/envs/common/observation.py @@ -545,7 +545,7 @@ def observe(self) -> Dict[str, np.ndarray]: pd.DataFrame.from_records([self.observer_vehicle.to_dict()])[self.features] ) goal = np.ravel( - pd.DataFrame.from_records([self.env.goal.to_dict()])[self.features] + pd.DataFrame.from_records([self.observer_vehicle.goal.to_dict()])[self.features] ) obs = OrderedDict( [ diff --git a/highway_env/envs/parking_env.py b/highway_env/envs/parking_env.py index 505ddf458..68a02eb3b 100644 --- a/highway_env/envs/parking_env.py +++ b/highway_env/envs/parking_env.py @@ -189,13 +189,14 @@ def _create_vehicles(self) -> None: empty_spots.remove(vehicle.lane_index) # Goal - lane_index = empty_spots[self.np_random.choice(np.arange(len(empty_spots)))] - lane = self.road.network.get_lane(lane_index) - self.goal = Landmark( - self.road, lane.position(lane.length / 2, 0), heading=lane.heading - ) - self.road.objects.append(self.goal) - empty_spots.remove(lane_index) + for vehicle in self.controlled_vehicles: + lane_index = empty_spots[self.np_random.choice(np.arange(len(empty_spots)))] + lane = self.road.network.get_lane(lane_index) + vehicle.goal = Landmark( + self.road, lane.position(lane.length / 2, 0), heading=lane.heading + ) + self.road.objects.append(vehicle.goal) + empty_spots.remove(lane_index) # Other vehicles for i in range(self.config["vehicles_count"]):