1
0
mirror of https://github.com/Ahp06/SUMO_Emissions.git synced 2024-11-24 12:36:30 +00:00

Added reverse actions method

This commit is contained in:
Ahp06 2018-12-09 15:05:33 +01:00
parent af05ad08d0
commit c1a66c45de
3 changed files with 13 additions and 9 deletions

View File

@ -23,7 +23,7 @@ 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.setEffort(edge_id, weight) traci.edge.setEffort(edge_id, weight)
for veh_id in traci.vehicle.getIDList(): for veh_id in traci.vehicle.getIDList():
traci.vehicle.rerouteEffort(veh_id) traci.vehicle.rerouteEffort(veh_id)
@ -59,19 +59,20 @@ def lock_area(area):
def reverse_actions(area): def reverse_actions(area):
#Reset max speed to original #Reset max speed to original
if not area.limited_speed: if area.limited_speed:
area.limited_speed = False area.limited_speed = False
for lane in area.lanes: for lane in area._lanes:
traci.lane.setMaxSpeed(lane.lane_id, lane.initial_max_speed / 3.6) traci.lane.setMaxSpeed(lane.lane_id, lane.initial_max_speed)
#Reset traffic lights initial duration #Reset traffic lights initial duration
if not area.tls_adjusted: if area.tls_adjusted:
area.tls_adjusted = False area.tls_adjusted = False
for initial_logic in tl._logics: for tl in area._tls:
traci.trafficlights.setCompleteRedYellowGreenDefinition(tl.tl_id, initial_logic) for initial_logic in tl._logics:
traci.trafficlights.setCompleteRedYellowGreenDefinition(tl.tl_id, initial_logic._logic)
#Unlock the area #Unlock the area
if not area.locked: if area.locked:
area.locked = False area.locked = False
for lane in area._lanes: for lane in area._lanes:
traci.lane.setAllowed(lane.lane_id, '') #empty means all classes are allowed traci.lane.setAllowed(lane.lane_id, '') #empty means all classes are allowed

View File

@ -76,6 +76,7 @@ lock_area_mode = False
if weight_routing_mode: if weight_routing_mode:
limit_speed_mode = False limit_speed_mode = False
adjust_traffic_light_mode = False adjust_traffic_light_mode = False
lock_area_mode = False
#If without_actions_mode is choosen #If without_actions_mode is choosen
if without_actions_mode: if without_actions_mode:

View File

@ -108,6 +108,9 @@ def get_emissions(grid: List[Area], vehicles: List[Vehicle], current_step):
if actions.count_vehicles_in_area(area): if actions.count_vehicles_in_area(area):
logger.info(f'Action - {area.name} blocked') logger.info(f'Action - {area.name} blocked')
actions.lock_area(area) actions.lock_area(area)
else:
actions.reverse_actions(area)
def main(): def main():
@ -133,7 +136,6 @@ def main():
get_emissions(grid, vehicles,step) get_emissions(grid, vehicles,step)
if config.weight_routing_mode: if config.weight_routing_mode:
logger.info('Action - Lane weights adjusted')
actions.adjust_edges_weights() actions.adjust_edges_weights()
step += 1 step += 1