1
0
mirror of https://github.com/Ahp06/SUMO_Emissions.git synced 2024-11-22 03:26:30 +00:00

Merge pull request #1 from Ahp06/dev

Change absolute to relative path using SUMO_HOME
This commit is contained in:
Thibaud Gasser 2018-10-19 08:43:08 +02:00 committed by GitHub
commit d8982b8c3b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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,10 +67,23 @@ def showEmissions():
+ " = " , str(emissionsArea[i][j]) + " mg" ) + " = " , str(emissionsArea[i][j]) + " mg" )
if __name__ == "__main__":
'''Simulation launch''' '''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 step = 0
init_grid() init_grid()
while step < 100: # while traci.simulation.getMinExpectedNumber() > 0: while traci.simulation.getMinExpectedNumber() > 0:
print("Vehicle count :", traci.vehicle.getIDCount())
traci.simulationStep() traci.simulationStep()
getAllEmissions() getAllEmissions()
step += 1 step += 1
@ -89,4 +92,3 @@ while step < 100: # while traci.simulation.getMinExpectedNumber() > 0:
showEmissions() showEmissions()
traci.close() traci.close()
sys.stdout.flush() sys.stdout.flush()