mirror of
				https://github.com/Ahp06/SUMO_Emissions.git
				synced 2025-11-04 03:59:19 +00:00 
			
		
		
		
	Added 'remove vehicles from simulation' into actions
This commit is contained in:
		@@ -11,9 +11,10 @@ from shapely.geometry.linestring import LineString
 | 
				
			|||||||
from model import Area, Vehicle
 | 
					from model import Area, Vehicle
 | 
				
			||||||
from traci._trafficlight import Logic
 | 
					from traci._trafficlight import Logic
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def remove_vehicles(vehicles):
 | 
				
			||||||
def remove_vehicle(veh_id):
 | 
					    print(f'Removed {vehicles.size} vehicles from the simulation')
 | 
				
			||||||
    traci.vehicle.remove(veh_id, traci.constants.REMOVE_PARKING)
 | 
					    for vehicle in vehicles:
 | 
				
			||||||
 | 
					        traci.vehicle.remove(vehicle.veh_id, traci.constants.REMOVE_PARKING)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def compute_edge_weight(edge_id):
 | 
					def compute_edge_weight(edge_id):
 | 
				
			||||||
    return (traci.edge.getCOEmission(edge_id)
 | 
					    return (traci.edge.getCOEmission(edge_id)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -22,11 +22,14 @@ weight_routing_mode = False
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#Limit the speed into areas when the threshold is exceeded
 | 
					#Limit the speed into areas when the threshold is exceeded
 | 
				
			||||||
limited_speed = 30
 | 
					limited_speed = 30
 | 
				
			||||||
limit_speed_mode = True
 | 
					limit_speed_mode = False
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#Decrease all traffic lights duration into the area when the threshold is exceeded
 | 
					#Decrease all traffic lights duration into the area when the threshold is exceeded
 | 
				
			||||||
rf_trafficLights_duration = 0.2
 | 
					rf_trafficLights_duration = 0.2
 | 
				
			||||||
adjust_traffic_light_mode = True
 | 
					adjust_traffic_light_mode = False
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#Immediately delete all vehicles in the simulation area
 | 
				
			||||||
 | 
					remove_vehicles_mode = True
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#Weight routing mode cannot be combinated with other actions 
 | 
					#Weight routing mode cannot be combinated with other actions 
 | 
				
			||||||
if weight_routing_mode:
 | 
					if weight_routing_mode:
 | 
				
			||||||
@@ -39,7 +42,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'limit speed mode = {limit_speed_mode}\n')
 | 
					 | 
				
			||||||
    + str(f'weight routing mode= {weight_routing_mode}\n')
 | 
					    + str(f'weight routing mode= {weight_routing_mode}\n')
 | 
				
			||||||
 | 
					    + str(f'limit speed mode = {limit_speed_mode}, limited speed to {limited_speed}\n')
 | 
				
			||||||
    + str(f'adjust traffic light mode = {adjust_traffic_light_mode} , RF = {rf_trafficLights_duration}\n'))
 | 
					    + str(f'adjust traffic light mode = {adjust_traffic_light_mode} , RF = {rf_trafficLights_duration}\n'))
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -59,12 +59,15 @@ 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.limit_speed_mode and area.emissions > config.EMISSIONS_THRESHOLD and not area.locked:
 | 
					        if area.emissions > config.EMISSIONS_THRESHOLD and not area.locked:
 | 
				
			||||||
            actions.limit_speed_into_area(area, vehicles, config.limited_speed)
 | 
					            if config.limit_speed_mode:
 | 
				
			||||||
            traci.polygon.setColor(area.name, (255, 0, 0))
 | 
					                actions.limit_speed_into_area(area, vehicles, config.limited_speed)
 | 
				
			||||||
            traci.polygon.setFilled(area.name, True)
 | 
					                traci.polygon.setColor(area.name, (255, 0, 0))
 | 
				
			||||||
            if config.adjust_traffic_light_mode:
 | 
					                traci.polygon.setFilled(area.name, True)
 | 
				
			||||||
                actions.adjust_traffic_light_phase_duration(area, config.rf_trafficLights_duration)
 | 
					                if config.adjust_traffic_light_mode:
 | 
				
			||||||
 | 
					                    actions.adjust_traffic_light_phase_duration(area, config.rf_trafficLights_duration)
 | 
				
			||||||
 | 
					            '''if config.remove_vehicles_mode:
 | 
				
			||||||
 | 
					                actions.remove_vehicles(vehicles)''' #V<>hicules <20> mettre en donn<6E>e membre car variable 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                
 | 
					                
 | 
				
			||||||
def parsePhase(phase_repr):
 | 
					def parsePhase(phase_repr):
 | 
				
			||||||
@@ -133,7 +136,7 @@ def main():
 | 
				
			|||||||
        print(f'Total emissions = {total_emissions} mg')
 | 
					        print(f'Total emissions = {total_emissions} mg')
 | 
				
			||||||
        diff_with_lock = (total_emissions200 - total_emissions) / total_emissions200
 | 
					        diff_with_lock = (total_emissions200 - total_emissions) / total_emissions200
 | 
				
			||||||
        print(f'Reduction percentage of emissions = {diff_with_lock*100} %')
 | 
					        print(f'Reduction percentage of emissions = {diff_with_lock*100} %')
 | 
				
			||||||
        print("With the configuration :\n" + str(config.showConfig()))
 | 
					        print("**** With the configuration : ****\n" + str(config.showConfig()))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
if __name__ == '__main__':
 | 
					if __name__ == '__main__':
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user