mirror of
https://github.com/Ahp06/SUMO_Emissions.git
synced 2024-11-25 04:56:30 +00:00
Added initial max speed information into Lane class
This commit is contained in:
parent
0df0897c72
commit
9a964c97e9
@ -22,7 +22,6 @@ def compute_edge_weight(edge_id):
|
|||||||
+ traci.edge.getPMxEmission(edge_id)
|
+ traci.edge.getPMxEmission(edge_id)
|
||||||
+ traci.edge.getCO2Emission(edge_id))
|
+ traci.edge.getCO2Emission(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
|
||||||
|
@ -17,8 +17,9 @@ CELLS_NUMBER = 10
|
|||||||
EMISSIONS_THRESHOLD = 500000
|
EMISSIONS_THRESHOLD = 500000
|
||||||
n_steps = 200
|
n_steps = 200
|
||||||
|
|
||||||
lock_mode = True
|
limit_speed_mode = True
|
||||||
routing_mode = False
|
weight_routing_mode = False
|
||||||
|
adjust_traffic_light_mode = True
|
||||||
|
|
||||||
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]
|
||||||
@ -26,6 +27,7 @@ sumo_cmd = [sumo_binary, "-c", _SUMOCFG]
|
|||||||
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')
|
||||||
+ str(f'lock mode = {lock_mode}\n')
|
+ str(f'limit speed mode = {limit_speed_mode}\n')
|
||||||
+ str(f'routing mode = {routing_mode}\n'))
|
+ str(f'weight routing mode= {weight_routing_mode}\n')
|
||||||
|
+ str(f'adjust traffic light mode = {adjust_traffic_light_mode}\n'))
|
||||||
|
|
||||||
|
@ -48,7 +48,8 @@ def get_all_lanes() -> List[Lane]:
|
|||||||
lanes = []
|
lanes = []
|
||||||
for lane_id in traci.lane.getIDList():
|
for lane_id in traci.lane.getIDList():
|
||||||
polygon_lane = LineString(traci.lane.getShape(lane_id))
|
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
|
return lanes
|
||||||
|
|
||||||
|
|
||||||
@ -57,22 +58,21 @@ 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 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.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.setColor(area.name, (255, 0, 0))
|
||||||
traci.polygon.setFilled(area.name, True)
|
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]):
|
def add_data_to_areas(areas: List[Area]):
|
||||||
lanes = get_all_lanes()
|
lanes = get_all_lanes()
|
||||||
for area in areas:
|
for area in areas:
|
||||||
for lane in lanes:
|
for lane in lanes: #add lanes
|
||||||
if area.rectangle.intersects(lane.polygon):
|
if area.rectangle.intersects(lane.polygon):
|
||||||
area.add_lane(lane)
|
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):
|
if lane.lane_id in traci.trafficlight.getControlledLanes(tl_id):
|
||||||
area.add_tl(TrafficLight(tl_id))
|
area.add_tl(TrafficLight(tl_id))
|
||||||
|
|
||||||
@ -92,9 +92,8 @@ def main():
|
|||||||
vehicles = get_all_vehicles()
|
vehicles = get_all_vehicles()
|
||||||
get_emissions(grid, vehicles)
|
get_emissions(grid, vehicles)
|
||||||
|
|
||||||
if config.routing_mode:
|
if config.weight_routing_mode:
|
||||||
actions.adjust_edges_weights()
|
actions.adjust_edges_weights()
|
||||||
# actions.rerouteAllVehicles()
|
|
||||||
|
|
||||||
step += 1
|
step += 1
|
||||||
progress = round(step/config.n_steps*100,2)
|
progress = round(step/config.n_steps*100,2)
|
||||||
|
@ -7,9 +7,10 @@ from shapely.geometry.base import BaseGeometry
|
|||||||
|
|
||||||
class Lane:
|
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.polygon = polygon
|
||||||
self.lane_id = lane_id
|
self.lane_id = lane_id
|
||||||
|
self.initial_max_speed = initial_max_speed
|
||||||
|
|
||||||
def __hash__(self):
|
def __hash__(self):
|
||||||
"""Overrides the default implementation"""
|
"""Overrides the default implementation"""
|
||||||
|
Loading…
Reference in New Issue
Block a user