1
0
mirror of https://github.com/Ahp06/SUMO_Emissions.git synced 2024-11-22 03:26:30 +00:00

Changed config and added lock area mode

This commit is contained in:
Ahp06 2018-12-06 21:49:01 +01:00
parent 30cd4eb72e
commit 70b29c47b2
4 changed files with 53 additions and 23 deletions

View File

@ -21,16 +21,19 @@ def compute_edge_weight(edge_id):
+ traci.edge.getNOxEmission(edge_id) + traci.edge.getNOxEmission(edge_id)
+ traci.edge.getHCEmission(edge_id) + traci.edge.getHCEmission(edge_id)
+ traci.edge.getPMxEmission(edge_id) + traci.edge.getPMxEmission(edge_id)
+ traci.edge.getCO2Emission(edge_id)) + traci.edge.getCO2Emission(edge_id))/(traci.edge.getLaneNumber(edge_id))
def adjust_edges_weights(): def adjust_edges_weights():
for edge_id in traci.edge.getIDList(): for edge_id in traci.edge.getIDList():
weight = compute_edge_weight(edge_id) # by default edges weight = length/mean speed weight = compute_edge_weight(edge_id) # by default edges weight = length/mean speed
traci.edge.adaptTraveltime(edge_id, weight) traci.edge.setEffort(edge_id, weight)
for veh_id in traci.vehicle.getIDList():
traci.vehicle.rerouteEffort(veh_id)
def limit_speed_into_area(area: Area, vehicles: Iterable[Vehicle], max_speed): def limit_speed_into_area(area: Area, vehicles: Iterable[Vehicle], max_speed):
print(f'Setting max speed into {area.name} to {max_speed} km/h') print(f'Setting max speed into {area.name} to {max_speed} km/h')
area.locked = True area.limited_speed = True
for lane in area._lanes: for lane in area._lanes:
traci.lane.setMaxSpeed(lane.lane_id, max_speed/3.6) traci.lane.setMaxSpeed(lane.lane_id, max_speed/3.6)
@ -48,5 +51,15 @@ def adjust_traffic_light_phase_duration(area, reduction_factor):
for logic in tl._logics: for logic in tl._logics:
traci.trafficlights.setCompleteRedYellowGreenDefinition(tl.tl_id, modifyLogic(logic,reduction_factor)) traci.trafficlights.setCompleteRedYellowGreenDefinition(tl.tl_id, modifyLogic(logic,reduction_factor))
#phaseDuration = traci.trafficlight.getPhaseDuration(tl.tl_id) def lock_area(area):
#traci.trafficlight.setPhaseDuration(tl.tl_id, phaseDuration*reduction_factor) #Trying to lock area
vehicles_in_area = 0
for lane in area._lanes:
vehicles_in_area += traci.lane.getLastStepVehicleNumber(lane.lane_id)
#Waiting for the area to be empty before blocking it
if vehicles_in_area == 0:
area.locked = True
print(f'Area locked : {area.name}')
for lane in area._lanes:
traci.lane.setDisallowed(lane.lane_id, 'passenger')

View File

@ -17,19 +17,22 @@ CELLS_NUMBER = 10
EMISSIONS_THRESHOLD = 500000 EMISSIONS_THRESHOLD = 500000
n_steps = 200 n_steps = 200
#Vehicles are routed according to the less polluted route
weight_routing_mode = False
#Limit the speed into areas when the threshold is exceeded #Limit the speed into areas when the threshold is exceeded
limited_speed = 30 limited_speed = 30
limit_speed_mode = False limit_speed_mode = False
#Decrease all traffic lights duration into the area when the threshold is exceeded #Decrease all traffic lights duration into the area when the threshold is exceeded
rf_trafficLights_duration = 0.2 rf_trafficLights_duration = 1.4
adjust_traffic_light_mode = False adjust_traffic_light_mode = False
#Immediately delete all vehicles in the simulation area #Immediately delete all vehicles in the simulation area
remove_vehicles_mode = True remove_vehicles_mode = False
#Vehicles are routed according to the less polluted route (HEAVY)
weight_routing_mode = True
#Lock the area when the threshold is exceeded (NOT FIXED)
lock_area_mode = False
#Weight routing mode cannot be combinated with other actions #Weight routing mode cannot be combinated with other actions
if weight_routing_mode: if weight_routing_mode:
@ -39,6 +42,16 @@ if weight_routing_mode:
sumo_binary = os.path.join(os.environ['SUMO_HOME'], 'bin', _SUMOCMD) sumo_binary = os.path.join(os.environ['SUMO_HOME'], 'bin', _SUMOCMD)
sumo_cmd = [sumo_binary, "-c", _SUMOCFG] sumo_cmd = [sumo_binary, "-c", _SUMOCFG]
# Total of emissions of all pollutants in mg for n steps of simulation without locking areas
total_emissions200 = 43970763.15084749
total_emissions300 = 87382632.08217141
def get_basics_emissions():
if n_steps == 200:
return total_emissions200
if n_steps == 300:
return total_emissions300
def showConfig(): def showConfig():
return (str(f'Grid : {CELLS_NUMBER}x{CELLS_NUMBER}\n') return (str(f'Grid : {CELLS_NUMBER}x{CELLS_NUMBER}\n')
+ str(f'step number = {n_steps}\n') + str(f'step number = {n_steps}\n')

View File

@ -1,3 +1,5 @@
# -*- coding: latin-1 -*-
from typing import List from typing import List
import traci import traci
@ -59,15 +61,17 @@ def get_emissions(grid: List[Area], vehicles: List[Vehicle]):
for vehicle in vehicles: for vehicle in vehicles:
if vehicle.pos in area: if vehicle.pos in area:
area.emissions += vehicle.emissions area.emissions += vehicle.emissions
if area.emissions > config.EMISSIONS_THRESHOLD and not area.locked: if area.emissions > config.EMISSIONS_THRESHOLD:
if config.limit_speed_mode:
if config.limit_speed_mode and not area.limited_speed:
actions.limit_speed_into_area(area, vehicles, config.limited_speed) actions.limit_speed_into_area(area, vehicles, config.limited_speed)
traci.polygon.setColor(area.name, (255, 0, 0)) traci.polygon.setColor(area.name, (255, 0, 0))
traci.polygon.setFilled(area.name, True) traci.polygon.setFilled(area.name, True)
if config.adjust_traffic_light_mode: if config.adjust_traffic_light_mode:
actions.adjust_traffic_light_phase_duration(area, config.rf_trafficLights_duration) 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 if config.lock_area_mode and not area.locked:
actions.lock_area(area)
def parsePhase(phase_repr): def parsePhase(phase_repr):
@ -127,15 +131,14 @@ def main():
total_emissions = 0 total_emissions = 0
for area in grid: for area in grid:
total_emissions += area.emissions total_emissions += area.emissions
# Total of emissions of all pollutants in mg for n steps of simulation without locking areas
total_emissions200 = 43970763.15084749
total_emissions300 = 87382632.08217141
print("\n**** RESULTS ****") print("\n**** RESULTS ****")
print(f'Total emissions = {total_emissions} mg') 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} %') ref = config.get_basics_emissions()
diff_with_actions = (ref - total_emissions)/ref
print(f'Reduction percentage of emissions = {diff_with_actions*100} %')
print("**** With the configuration : ****\n" + str(config.showConfig())) print("**** With the configuration : ****\n" + str(config.showConfig()))

View File

@ -46,6 +46,7 @@ class TrafficLight:
class Area: class Area:
def __init__(self, coords, name=''): def __init__(self, coords, name=''):
self.limited_speed = False
self.locked = False self.locked = False
self.rectangle = Polygon(coords) self.rectangle = Polygon(coords)
self.name = name self.name = name