def compute_reward(self, rl_actions, **kwargs):
    'See class definition.'
    reward = 0
    rl_velocity = np.array(self.k.vehicle.get_speed(self.rl_veh))
    target_vel = self.env_params.additional_params['target_velocity']
    max_cost = np.array(([target_vel] * self.num_rl))
    max_cost = np.linalg.norm(max_cost)
    cost = (rl_velocity - target_vel)
    cost = np.linalg.norm(cost)
    eps = np.finfo(np.float32).eps
    reward += (max((max_cost - cost), 0) / (max_cost + eps))
    gain = 0.5
    thresh = 0.3
    penalize = len(rl_velocity[(rl_velocity < thresh)])
    reward -= (gain * penalize)
    for veh_id in self.rl_veh:
        if (self.k.vehicle.get_last_lc(veh_id) == self.time_counter):
            reward -= 10
    if self.stuck:
        reward -= 100
    return reward
See class definition.
def compute_reward(self, rl_actions, **kwargs):
    
    reward = 0
    rl_velocity = np.array(self.k.vehicle.get_speed(self.rl_veh))
    target_vel = self.env_params.additional_params['target_velocity']
    max_cost = np.array(([target_vel] * self.num_rl))
    max_cost = np.linalg.norm(max_cost)
    cost = (rl_velocity - target_vel)
    cost = np.linalg.norm(cost)
    eps = np.finfo(np.float32).eps
    reward += (max((max_cost - cost), 0) / (max_cost + eps))
    gain = 0.5
    thresh = 0.3
    penalize = len(rl_velocity[(rl_velocity < thresh)])
    reward -= (gain * penalize)
    for veh_id in self.rl_veh:
        if (self.k.vehicle.get_last_lc(veh_id) == self.time_counter):
            reward -= 10
    if self.stuck:
        reward -= 100
    return reward