mirror of
				https://github.com/Ahp06/SUMO_Emissions.git
				synced 2025-11-04 03:59:19 +00:00 
			
		
		
		
	Change absolute to relative path using SUMO_HOME
This commit is contained in:
		@@ -5,28 +5,18 @@ Created on 11 oct. 2018
 | 
			
		||||
'''
 | 
			
		||||
 | 
			
		||||
import os, sys
 | 
			
		||||
import traci
 | 
			
		||||
from traci import polygon
 | 
			
		||||
 | 
			
		||||
'''Launch traci'''
 | 
			
		||||
if 'SUMO_HOME' in os.environ:
 | 
			
		||||
    tools = os.path.join(os.environ['SUMO_HOME'], 'tools')
 | 
			
		||||
    sys.path.append(tools)
 | 
			
		||||
    sys.path.append(os.path.join(os.environ['SUMO_HOME'], tools))
 | 
			
		||||
    sumoBinary = os.path.join(os.environ['SUMO_HOME'], 'bin', 'sumo-gui')
 | 
			
		||||
    sumoCmd = [sumoBinary, "-c", "mulhouse_simulation/osm.sumocfg"]
 | 
			
		||||
else:
 | 
			
		||||
    sys.exit("please declare environment variable 'SUMO_HOME'")
 | 
			
		||||
 | 
			
		||||
sumoBinary = "C:\\Users\\Admin\\AppData\\Roaming\\Microsoft\\Installer\\{A63B306E-2B15-11E1-88C8-028037EC0200}\\sumogui.exe"
 | 
			
		||||
sumoCmd = [sumoBinary, "-c", "mulhouse_simulation\\osm.sumocfg"]
 | 
			
		||||
traci.start(sumoCmd) 
 | 
			
		||||
 | 
			
		||||
'''Variables and constants declaration'''
 | 
			
		||||
cells_step = 10
 | 
			
		||||
boundary = traci.simulation.getNetBoundary()
 | 
			
		||||
areas = [[0] * cells_step for _ in range(cells_step)]
 | 
			
		||||
emissionsArea = [[0] * cells_step for _ in range(cells_step)]
 | 
			
		||||
width = boundary[1][0] / cells_step  # width/step
 | 
			
		||||
height = boundary[1][1] / cells_step  # height/step 
 | 
			
		||||
CO2_threshold = 500000
 | 
			
		||||
import traci
 | 
			
		||||
from traci import polygon
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
'''creating multiple zones of equal sizes'''
 | 
			
		||||
@@ -77,16 +67,28 @@ def showEmissions():
 | 
			
		||||
                  + " = " , str(emissionsArea[i][j]) + " mg" )
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
'''Simulation launch'''
 | 
			
		||||
step = 0
 | 
			
		||||
init_grid()      
 | 
			
		||||
while step < 100:  # while traci.simulation.getMinExpectedNumber() > 0: 
 | 
			
		||||
if __name__ == "__main__":
 | 
			
		||||
    '''Simulation launch'''
 | 
			
		||||
    traci.start(sumoCmd)
 | 
			
		||||
 | 
			
		||||
    '''Variables and constants declaration'''
 | 
			
		||||
    cells_step = 10
 | 
			
		||||
    boundary = traci.simulation.getNetBoundary()
 | 
			
		||||
    areas = [[0] * cells_step for _ in range(cells_step)]
 | 
			
		||||
    emissionsArea = [[0] * cells_step for _ in range(cells_step)]
 | 
			
		||||
    width = boundary[1][0] / cells_step  # width/step
 | 
			
		||||
    height = boundary[1][1] / cells_step  # height/step 
 | 
			
		||||
    CO2_threshold = 500000
 | 
			
		||||
 | 
			
		||||
    step = 0
 | 
			
		||||
    init_grid()
 | 
			
		||||
    while traci.simulation.getMinExpectedNumber() > 0:
 | 
			
		||||
        print("Vehicle count :", traci.vehicle.getIDCount())
 | 
			
		||||
        traci.simulationStep()
 | 
			
		||||
        getAllEmissions()
 | 
			
		||||
        step += 1
 | 
			
		||||
 | 
			
		||||
'''Display emissions information and close simulation'''
 | 
			
		||||
showEmissions()
 | 
			
		||||
traci.close()
 | 
			
		||||
sys.stdout.flush()
 | 
			
		||||
 | 
			
		||||
    '''Display emissions information and close simulation'''
 | 
			
		||||
    showEmissions()
 | 
			
		||||
    traci.close()
 | 
			
		||||
    sys.stdout.flush()
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user