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 os, sys
 | 
				
			||||||
import traci
 | 
					 | 
				
			||||||
from traci import polygon
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
'''Launch traci'''
 | 
					'''Launch traci'''
 | 
				
			||||||
if 'SUMO_HOME' in os.environ:
 | 
					if 'SUMO_HOME' in os.environ:
 | 
				
			||||||
    tools = os.path.join(os.environ['SUMO_HOME'], 'tools')
 | 
					    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:
 | 
					else:
 | 
				
			||||||
    sys.exit("please declare environment variable 'SUMO_HOME'")
 | 
					    sys.exit("please declare environment variable 'SUMO_HOME'")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
sumoBinary = "C:\\Users\\Admin\\AppData\\Roaming\\Microsoft\\Installer\\{A63B306E-2B15-11E1-88C8-028037EC0200}\\sumogui.exe"
 | 
					import traci
 | 
				
			||||||
sumoCmd = [sumoBinary, "-c", "mulhouse_simulation\\osm.sumocfg"]
 | 
					from traci import polygon
 | 
				
			||||||
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
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
'''creating multiple zones of equal sizes'''
 | 
					'''creating multiple zones of equal sizes'''
 | 
				
			||||||
@@ -77,16 +67,28 @@ def showEmissions():
 | 
				
			|||||||
                  + " = " , str(emissionsArea[i][j]) + " mg" )
 | 
					                  + " = " , str(emissionsArea[i][j]) + " mg" )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
'''Simulation launch'''
 | 
					if __name__ == "__main__":
 | 
				
			||||||
step = 0
 | 
					    '''Simulation launch'''
 | 
				
			||||||
init_grid()      
 | 
					    traci.start(sumoCmd)
 | 
				
			||||||
while step < 100:  # while traci.simulation.getMinExpectedNumber() > 0: 
 | 
					 | 
				
			||||||
    traci.simulationStep()
 | 
					 | 
				
			||||||
    getAllEmissions()
 | 
					 | 
				
			||||||
    step += 1
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
'''Display emissions information and close simulation'''
 | 
					    '''Variables and constants declaration'''
 | 
				
			||||||
showEmissions()
 | 
					    cells_step = 10
 | 
				
			||||||
traci.close()
 | 
					    boundary = traci.simulation.getNetBoundary()
 | 
				
			||||||
sys.stdout.flush()
 | 
					    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()
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user