diff --git a/sumo_project/actions.py b/sumo_project/actions.py index 527a5c6..484d7f5 100644 --- a/sumo_project/actions.py +++ b/sumo_project/actions.py @@ -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 diff --git a/sumo_project/config.py b/sumo_project/config.py index c92c7ec..f1a8888 100644 --- a/sumo_project/config.py +++ b/sumo_project/config.py @@ -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: diff --git a/sumo_project/emissions.py b/sumo_project/emissions.py index 4fe9194..3fbaf09 100644 --- a/sumo_project/emissions.py +++ b/sumo_project/emissions.py @@ -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