You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
def save_csv(self, out_csv_name, episode):
"""Save metrics of the simulation to a .csv file.
Args:
out_csv_name (str): Path to the output .csv file. E.g.: "results/my_results
episode (int): Episode number to be appended to the output file name.
"""
if out_csv_name is not None:
df = pd.DataFrame(self.metrics)
Path(Path(out_csv_name).parent).mkdir(parents=True, exist_ok=True)
df.to_csv(out_csv_name + f"_conn{self.label}_ep{episode}" + ".csv", index=False)
def _compute_info(self):
info = {"step": self.sim_step}
if self.add_system_info:
info.update(self._get_system_info())
if self.add_per_agent_info:
info.update(self._get_per_agent_info())
self.metrics.append(info.copy())
return info
def _get_system_info(self):
vehicles = self.sumo.vehicle.getIDList()
speeds = [self.sumo.vehicle.getSpeed(vehicle) for vehicle in vehicles]
waiting_times = [self.sumo.vehicle.getWaitingTime(vehicle) for vehicle in vehicles]
num_backlogged_vehicles = len(self.sumo.simulation.getPendingVehicles())
return {
"system_total_running": len(vehicles),
"system_total_backlogged": num_backlogged_vehicles,
"system_total_stopped": sum(
int(speed < 0.1) for speed in speeds
), # In SUMO, a vehicle is considered halting if its speed is below 0.1 m/s
"system_total_arrived": self.num_arrived_vehicles,
"system_total_departed": self.num_departed_vehicles,
"system_total_teleported": self.num_teleported_vehicles,
"system_total_waiting_time": sum(waiting_times),
"system_mean_waiting_time": 0.0 if len(vehicles) == 0 else np.mean(waiting_times),
"system_median_waiting_time": 0.0 if len(waiting_times) == 0 else np.median(waiting_times), #------traget data
"system_mean_speed": 0.0 if len(vehicles) == 0 else np.mean(speeds),
}
the above code means if I want to get new index in csv,I need to update info,but when i try to add it into _get_system_info,There hasn't been any change in output csv.otherwise,the output csv only has partial information of _get_system_info.
The text was updated successfully, but these errors were encountered:
def save_csv(self, out_csv_name, episode):
"""Save metrics of the simulation to a .csv file.
def _compute_info(self):
info = {"step": self.sim_step}
if self.add_system_info:
info.update(self._get_system_info())
if self.add_per_agent_info:
info.update(self._get_per_agent_info())
self.metrics.append(info.copy())
return info
def _get_system_info(self):
vehicles = self.sumo.vehicle.getIDList()
speeds = [self.sumo.vehicle.getSpeed(vehicle) for vehicle in vehicles]
waiting_times = [self.sumo.vehicle.getWaitingTime(vehicle) for vehicle in vehicles]
num_backlogged_vehicles = len(self.sumo.simulation.getPendingVehicles())
return {
"system_total_running": len(vehicles),
"system_total_backlogged": num_backlogged_vehicles,
"system_total_stopped": sum(
int(speed < 0.1) for speed in speeds
), # In SUMO, a vehicle is considered halting if its speed is below 0.1 m/s
"system_total_arrived": self.num_arrived_vehicles,
"system_total_departed": self.num_departed_vehicles,
"system_total_teleported": self.num_teleported_vehicles,
"system_total_waiting_time": sum(waiting_times),
"system_mean_waiting_time": 0.0 if len(vehicles) == 0 else np.mean(waiting_times),
"system_median_waiting_time": 0.0 if len(waiting_times) == 0 else np.median(waiting_times), #------traget data
"system_mean_speed": 0.0 if len(vehicles) == 0 else np.mean(speeds),
}
the above code means if I want to get new index in csv,I need to update info,but when i try to add it into _get_system_info,There hasn't been any change in output csv.otherwise,the output csv only has partial information of _get_system_info.
The text was updated successfully, but these errors were encountered: