From 30cd4eb72e984400505a35503a267e23016a5323 Mon Sep 17 00:00:00 2001 From: Ahp06 Date: Mon, 3 Dec 2018 21:46:31 +0100 Subject: [PATCH] Added 'remove vehicles from simulation' into actions --- sumo_project/actions.py | 7 ++++--- sumo_project/config.py | 9 ++++++--- sumo_project/emissions.py | 17 ++++++++++------- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/sumo_project/actions.py b/sumo_project/actions.py index 596a788..2a9dc60 100644 --- a/sumo_project/actions.py +++ b/sumo_project/actions.py @@ -11,9 +11,10 @@ from shapely.geometry.linestring import LineString from model import Area, Vehicle from traci._trafficlight import Logic - -def remove_vehicle(veh_id): - traci.vehicle.remove(veh_id, traci.constants.REMOVE_PARKING) +def remove_vehicles(vehicles): + print(f'Removed {vehicles.size} vehicles from the simulation') + for vehicle in vehicles: + traci.vehicle.remove(vehicle.veh_id, traci.constants.REMOVE_PARKING) def compute_edge_weight(edge_id): return (traci.edge.getCOEmission(edge_id) diff --git a/sumo_project/config.py b/sumo_project/config.py index 6fcbc5d..1538099 100644 --- a/sumo_project/config.py +++ b/sumo_project/config.py @@ -22,11 +22,14 @@ weight_routing_mode = False #Limit the speed into areas when the threshold is exceeded limited_speed = 30 -limit_speed_mode = True +limit_speed_mode = False #Decrease all traffic lights duration into the area when the threshold is exceeded rf_trafficLights_duration = 0.2 -adjust_traffic_light_mode = True +adjust_traffic_light_mode = False + +#Immediately delete all vehicles in the simulation area +remove_vehicles_mode = True #Weight routing mode cannot be combinated with other actions if weight_routing_mode: @@ -39,7 +42,7 @@ sumo_cmd = [sumo_binary, "-c", _SUMOCFG] def showConfig(): return (str(f'Grid : {CELLS_NUMBER}x{CELLS_NUMBER}\n') + str(f'step number = {n_steps}\n') - + str(f'limit speed mode = {limit_speed_mode}\n') + str(f'weight routing mode= {weight_routing_mode}\n') + + str(f'limit speed mode = {limit_speed_mode}, limited speed to {limited_speed}\n') + str(f'adjust traffic light mode = {adjust_traffic_light_mode} , RF = {rf_trafficLights_duration}\n')) diff --git a/sumo_project/emissions.py b/sumo_project/emissions.py index b0753ca..127cfa6 100644 --- a/sumo_project/emissions.py +++ b/sumo_project/emissions.py @@ -59,12 +59,15 @@ def get_emissions(grid: List[Area], vehicles: List[Vehicle]): for vehicle in vehicles: if vehicle.pos in area: area.emissions += vehicle.emissions - if config.limit_speed_mode and area.emissions > config.EMISSIONS_THRESHOLD and not area.locked: - actions.limit_speed_into_area(area, vehicles, config.limited_speed) - traci.polygon.setColor(area.name, (255, 0, 0)) - traci.polygon.setFilled(area.name, True) - if config.adjust_traffic_light_mode: - actions.adjust_traffic_light_phase_duration(area, config.rf_trafficLights_duration) + if area.emissions > config.EMISSIONS_THRESHOLD and not area.locked: + if config.limit_speed_mode: + actions.limit_speed_into_area(area, vehicles, config.limited_speed) + traci.polygon.setColor(area.name, (255, 0, 0)) + traci.polygon.setFilled(area.name, True) + if config.adjust_traffic_light_mode: + actions.adjust_traffic_light_phase_duration(area, config.rf_trafficLights_duration) + '''if config.remove_vehicles_mode: + actions.remove_vehicles(vehicles)''' #Véhicules à mettre en donnée membre car variable def parsePhase(phase_repr): @@ -133,7 +136,7 @@ def main(): print(f'Total emissions = {total_emissions} mg') diff_with_lock = (total_emissions200 - total_emissions) / total_emissions200 print(f'Reduction percentage of emissions = {diff_with_lock*100} %') - print("With the configuration :\n" + str(config.showConfig())) + print("**** With the configuration : ****\n" + str(config.showConfig())) if __name__ == '__main__':