mirror of
https://github.com/Ahp06/SUMO_Emissions.git
synced 2024-11-22 03:26:30 +00:00
Added 'remove vehicles from simulation' into actions
This commit is contained in:
parent
e249fbe30c
commit
30cd4eb72e
@ -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)
|
||||
|
@ -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'))
|
||||
|
||||
|
@ -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:
|
||||
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__':
|
||||
|
Loading…
Reference in New Issue
Block a user