def _reward_per_navigation(self, vehicle, navi, goal_name):
        """Compute the reward for the given goal. goal_name='default' means we use the vehicle's own navigation."""
        reward = 0.0

        # Get goal-dependent information
        if navi.current_lane in navi.current_ref_lanes:
            current_lane = navi.current_lane
            positive_road = 1
        else:
            current_lane = navi.current_ref_lanes[0]
            current_road = navi.current_road
            positive_road = 1 if not current_road.is_negative_road() else -1
        long_last, _ = current_lane.local_coordinates(vehicle.last_position)
        long_now, lateral_now = current_lane.local_coordinates(vehicle.position)

        # Reward for moving forward in current lane
        reward += self.config["driving_reward"] * (long_now - long_last) * positive_road

        left, right = vehicle._dist_to_route_left_right(navigation=navi)
        out_of_route = (right < 0) or (left < 0)

        # Reward for speed, sign determined by whether in the correct lanes (instead of driving in the wrong
        # direction).
        reward += self.config["speed_reward"] * (vehicle.speed_km_h / vehicle.max_speed_km_h) * positive_road
        if self._is_arrive_destination(vehicle):
            if self._is_arrive_destination(vehicle, goal_name):
                reward += self.config["success_reward"]
            else:
                # if goal_name == "default":
                #     print("WRONG WAY")
                reward = -self.config["wrong_way_penalty"]
        else:
            if self._is_out_of_road(vehicle):
                reward = -self.config["out_of_road_penalty"]
            elif vehicle.crash_vehicle:
                reward = -self.config["crash_vehicle_penalty"]
            elif vehicle.crash_object:
                reward = -self.config["crash_object_penalty"]
            elif vehicle.crash_sidewalk:
                reward = -self.config["crash_sidewalk_penalty"]
            elif out_of_route:
                # if goal_name == "default":
                #     print("OUT OF ROUTE")
                reward = -self.config["out_of_route_penalty"]

        return reward, navi.route_completion
Compute the reward for the given goal. goal_name='default' means we use the vehicle's own navigation.
metadrive/envs/multigoal_intersection.py