Skip to content

Commit

Permalink
Add average speed reward function
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasAlegre committed Mar 17, 2022
1 parent b13bdc5 commit 495cf9a
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion sumo_rl/environment/traffic_signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,14 @@ def compute_observation(self):
return observation

def compute_reward(self):
self.last_reward = self._waiting_time_reward()
self.last_reward = self._waiting_time_reward() # self._average_speed_reward()
return self.last_reward

def _pressure_reward(self):
return -self.get_pressure()

def _average_speed_reward(self):
return self.get_average_speed()

def _queue_average_reward(self):
new_average = np.mean(self.get_stopped_vehicles_num())
Expand Down Expand Up @@ -180,6 +183,13 @@ def get_waiting_time_per_lane(self):
wait_time_per_lane.append(wait_time)
return wait_time_per_lane

def get_average_speed(self):
avg_speed = 0.0
vehs = self._get_veh_list()
for v in vehs:
avg_speed += self.sumo.vehicle.getSpeed(v) / self.sumo.vehicle.getAllowedSpeed(v)
return avg_speed / len(vehs)

def get_pressure(self):
return abs(sum(self.sumo.lane.getLastStepVehicleNumber(lane) for lane in self.lanes) - sum(self.sumo.lane.getLastStepVehicleNumber(lane) for lane in self.out_lanes))

Expand Down

0 comments on commit 495cf9a

Please sign in to comment.