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

Added initial max speed information into Lane class

This commit is contained in:
Ahp06 2018-11-23 19:40:14 +01:00
parent 0df0897c72
commit 9a964c97e9
4 changed files with 17 additions and 16 deletions

View File

@ -22,7 +22,6 @@ def compute_edge_weight(edge_id):
+ traci.edge.getPMxEmission(edge_id)
+ traci.edge.getCO2Emission(edge_id))
def adjust_edges_weights():
for edge_id in traci.edge.getIDList():
weight = compute_edge_weight(edge_id) # by default edges weight = length/mean speed

View File

@ -17,8 +17,9 @@ CELLS_NUMBER = 10
EMISSIONS_THRESHOLD = 500000
n_steps = 200
lock_mode = True
routing_mode = False
limit_speed_mode = True
weight_routing_mode = False
adjust_traffic_light_mode = True
sumo_binary = os.path.join(os.environ['SUMO_HOME'], 'bin', _SUMOCMD)
sumo_cmd = [sumo_binary, "-c", _SUMOCFG]
@ -26,6 +27,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'lock mode = {lock_mode}\n')
+ str(f'routing mode = {routing_mode}\n'))
+ str(f'limit speed mode = {limit_speed_mode}\n')
+ str(f'weight routing mode= {weight_routing_mode}\n')
+ str(f'adjust traffic light mode = {adjust_traffic_light_mode}\n'))

View File

@ -48,7 +48,8 @@ def get_all_lanes() -> List[Lane]:
lanes = []
for lane_id in traci.lane.getIDList():
polygon_lane = LineString(traci.lane.getShape(lane_id))
lanes.append(Lane(lane_id, polygon_lane))
initial_max_speed = traci.lane.getMaxSpeed(lane_id)
lanes.append(Lane(lane_id, polygon_lane,initial_max_speed))
return lanes
@ -57,22 +58,21 @@ def get_emissions(grid: List[Area], vehicles: List[Vehicle]):
for vehicle in vehicles:
if vehicle.pos in area:
area.emissions += vehicle.emissions
if config.lock_mode and area.emissions > config.EMISSIONS_THRESHOLD and not area.locked:
if config.limit_speed_mode and area.emissions > config.EMISSIONS_THRESHOLD and not area.locked:
actions.limit_speed_into_area(area, vehicles,30)
actions.adjust_traffic_light_phase_duration(area, 0.5)
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, 0.75)
def add_data_to_areas(areas: List[Area]):
lanes = get_all_lanes()
for area in areas:
for lane in lanes:
for lane in lanes: #add lanes
if area.rectangle.intersects(lane.polygon):
area.add_lane(lane)
for tl_id in traci.trafficlight.getIDList():
for tl_id in traci.trafficlight.getIDList(): #add traffic lights
if lane.lane_id in traci.trafficlight.getControlledLanes(tl_id):
area.add_tl(TrafficLight(tl_id))
@ -92,9 +92,8 @@ def main():
vehicles = get_all_vehicles()
get_emissions(grid, vehicles)
if config.routing_mode:
if config.weight_routing_mode:
actions.adjust_edges_weights()
# actions.rerouteAllVehicles()
step += 1
progress = round(step/config.n_steps*100,2)

View File

@ -7,9 +7,10 @@ from shapely.geometry.base import BaseGeometry
class Lane:
def __init__(self, lane_id: str, polygon: LineString):
def __init__(self, lane_id: str, polygon: LineString, initial_max_speed: float):
self.polygon = polygon
self.lane_id = lane_id
self.initial_max_speed = initial_max_speed
def __hash__(self):
"""Overrides the default implementation"""