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:
parent
af05ad08d0
commit
c1a66c45de
@ -23,7 +23,7 @@ def adjust_edges_weights():
|
||||
for edge_id in traci.edge.getIDList():
|
||||
weight = compute_edge_weight(edge_id) # by default edges weight = length/mean speed
|
||||
traci.edge.setEffort(edge_id, weight)
|
||||
|
||||
|
||||
for veh_id in traci.vehicle.getIDList():
|
||||
traci.vehicle.rerouteEffort(veh_id)
|
||||
|
||||
@ -59,19 +59,20 @@ def lock_area(area):
|
||||
|
||||
def reverse_actions(area):
|
||||
#Reset max speed to original
|
||||
if not area.limited_speed:
|
||||
if area.limited_speed:
|
||||
area.limited_speed = False
|
||||
for lane in area.lanes:
|
||||
traci.lane.setMaxSpeed(lane.lane_id, lane.initial_max_speed / 3.6)
|
||||
for lane in area._lanes:
|
||||
traci.lane.setMaxSpeed(lane.lane_id, lane.initial_max_speed)
|
||||
|
||||
#Reset traffic lights initial duration
|
||||
if not area.tls_adjusted:
|
||||
if area.tls_adjusted:
|
||||
area.tls_adjusted = False
|
||||
for initial_logic in tl._logics:
|
||||
traci.trafficlights.setCompleteRedYellowGreenDefinition(tl.tl_id, initial_logic)
|
||||
for tl in area._tls:
|
||||
for initial_logic in tl._logics:
|
||||
traci.trafficlights.setCompleteRedYellowGreenDefinition(tl.tl_id, initial_logic._logic)
|
||||
|
||||
#Unlock the area
|
||||
if not area.locked:
|
||||
if area.locked:
|
||||
area.locked = False
|
||||
for lane in area._lanes:
|
||||
traci.lane.setAllowed(lane.lane_id, '') #empty means all classes are allowed
|
||||
|
@ -76,6 +76,7 @@ lock_area_mode = False
|
||||
if weight_routing_mode:
|
||||
limit_speed_mode = False
|
||||
adjust_traffic_light_mode = False
|
||||
lock_area_mode = False
|
||||
|
||||
#If without_actions_mode is choosen
|
||||
if without_actions_mode:
|
||||
|
@ -108,6 +108,9 @@ def get_emissions(grid: List[Area], vehicles: List[Vehicle], current_step):
|
||||
if actions.count_vehicles_in_area(area):
|
||||
logger.info(f'Action - {area.name} blocked')
|
||||
actions.lock_area(area)
|
||||
|
||||
else:
|
||||
actions.reverse_actions(area)
|
||||
|
||||
|
||||
def main():
|
||||
@ -133,7 +136,6 @@ def main():
|
||||
get_emissions(grid, vehicles,step)
|
||||
|
||||
if config.weight_routing_mode:
|
||||
logger.info('Action - Lane weights adjusted')
|
||||
actions.adjust_edges_weights()
|
||||
|
||||
step += 1
|
||||
|
Loading…
Reference in New Issue
Block a user