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

Add Emissions getter and simulation example

This commit is contained in:
Ahp06 2018-10-12 14:17:36 +02:00
parent c6170192d2
commit 3db7647d0b
13 changed files with 143722 additions and 7 deletions

View File

@ -8,6 +8,7 @@ import os, sys
import traci import traci
from traci import polygon from traci import polygon
'''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(tools)
@ -15,10 +16,10 @@ 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" sumoBinary = "C:\\Users\\Admin\\AppData\\Roaming\\Microsoft\\Installer\\{A63B306E-2B15-11E1-88C8-028037EC0200}\\sumogui.exe"
sumoCmd = [sumoBinary, "-c", "E:\\Cours\\3A\\Projet 3A Sources\\Mulhouse simulation\\osm.sumocfg"] sumoCmd = [sumoBinary, "-c", "mulhouse_simulation\\osm.sumocfg"]
traci.start(sumoCmd) traci.start(sumoCmd)
'''Variables and constants declaration'''
cells_step = 10 cells_step = 10
boundary = traci.simulation.getNetBoundary() boundary = traci.simulation.getNetBoundary()
areas = [[0] * cells_step for _ in range(cells_step)] areas = [[0] * cells_step for _ in range(cells_step)]
@ -28,6 +29,7 @@ height = boundary[1][1] / cells_step # height/step
CO2_threshold = 500000 CO2_threshold = 500000
'''creating multiple zones of equal sizes'''
def init_grid(): def init_grid():
default_color = (0, 255, 0) default_color = (0, 255, 0)
for i in range(cells_step): for i in range(cells_step):
@ -38,32 +40,36 @@ def init_grid():
polygon.add("area " + str(i) + "," + str(j), area, default_color, False, "rectangle") polygon.add("area " + str(i) + "," + str(j), area, default_color, False, "rectangle")
'''Emissions recovery by area'''
def getEmissionsByArea(i, j): def getEmissionsByArea(i, j):
vehicles = [] vehicles = []
'''Vehicle IDs retrieving into this area'''
for veh_id in traci.vehicle.getIDList(): for veh_id in traci.vehicle.getIDList():
pos = traci.vehicle.getPosition(veh_id) pos = traci.vehicle.getPosition(veh_id)
if((i * width < pos[0] and (i + 1) * width > pos[0]) if((i * width < pos[0] and (i + 1) * width > pos[0])
and (j * height < pos[1] and (j + 1) * height > pos[1])): and (j * height < pos[1] and (j + 1) * height > pos[1])):
vehicles.append(veh_id) vehicles.append(veh_id)
'''Sum all emissions'''
emissions = 0.0 emissions = 0.0
for veh_id in vehicles: for veh_id in vehicles:
emission = traci.vehicle.getCO2Emission(veh_id) emission = traci.vehicle.getCO2Emission(veh_id)
emissions += emission emissions += emission
'''Change area color if emisssions exceeds the threshold'''
emissionsArea[i][j] += emissions emissionsArea[i][j] += emissions
if(emissionsArea[i][j] >= CO2_threshold): if(emissionsArea[i][j] >= CO2_threshold):
red = (255, 0, 0) red = (255, 0, 0)
polygon.setColor("area " + str(i) + "," + str(j), red) polygon.setColor("area " + str(i) + "," + str(j), red)
polygon.setFilled("area " + str(i) + "," + str(j), True) polygon.setFilled("area " + str(i) + "," + str(j), True)
'''Recover emissions from all areas'''
def getAllEmissions(): def getAllEmissions():
for i in range(cells_step): for i in range(cells_step):
for j in range(cells_step): for j in range(cells_step):
getEmissionsByArea(i, j) getEmissionsByArea(i, j)
'''Display emissions information'''
def showEmissions(): def showEmissions():
for i in range(cells_step): for i in range(cells_step):
for j in range(cells_step): for j in range(cells_step):
@ -71,7 +77,7 @@ def showEmissions():
+ " = " , str(emissionsArea[i][j]) + " mg" ) + " = " , str(emissionsArea[i][j]) + " mg" )
'''Simulation launch'''
step = 0 step = 0
init_grid() init_grid()
while step < 100: # while traci.simulation.getMinExpectedNumber() > 0: while step < 100: # while traci.simulation.getMinExpectedNumber() > 0:
@ -79,6 +85,7 @@ while step < 100: # while traci.simulation.getMinExpectedNumber() > 0:
getAllEmissions() getAllEmissions()
step += 1 step += 1
'''Display emissions information and close simulation'''
showEmissions() showEmissions()
traci.close() traci.close()
sys.stdout.flush() sys.stdout.flush()

View File

@ -0,0 +1 @@
python "%SUMO_HOME%\tools\randomTrips.py" -n osm.net.xml --seed 42 --fringe-factor 5 -p 1.164091 -r osm.passenger.rou.xml -o osm.passenger.trips.xml -e 3600 --vehicle-class passenger --vclass passenger --prefix veh --min-distance 300 --trip-attributes "departLane=\"best\"" --validate

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- generated on 10/11/18 20:15:27 by Eclipse SUMO netconvert Version 1.0.1
-->
<configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/netconvertConfiguration.xsd">
<input>
<type-files value="C:\Program%20Files%20(x86)\Eclipse\Sumo\data\typemap\osmNetconvert.typ.xml"/>
<osm-files value="osm_bbox.osm.xml"/>
</input>
<output>
<output-file value="osm.net.xml"/>
<output.street-names value="true"/>
<output.original-names value="true"/>
</output>
<processing>
<geometry.remove value="true"/>
<roundabouts.guess value="true"/>
</processing>
<tls_building>
<tls.discard-simple value="true"/>
<tls.join value="true"/>
<tls.guess-signals value="true"/>
<tls.default-type value="actuated"/>
</tls_building>
<ramp_guessing>
<ramps.guess value="true"/>
</ramp_guessing>
<junctions>
<junctions.join value="true"/>
<junctions.corner-detail value="5"/>
</junctions>
<report>
<verbose value="true"/>
</report>
</configuration>

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- generated on 10/11/18 20:15:31 by Eclipse SUMO polyconvert Version 1.0.1
-->
<configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/polyconvertConfiguration.xsd">
<input>
<net-file value="osm.net.xml"/>
<osm-files value="osm_bbox.osm.xml"/>
<osm.keep-full-type value="true"/>
<type-file value="C:\Program%20Files%20(x86)\Eclipse\Sumo\data\typemap\osmPolyconvert.typ.xml"/>
</input>
<output>
<output-file value="osm.poly.xml"/>
</output>
<report>
<verbose value="true"/>
</report>
</configuration>

View File

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- generated on 10/11/18 20:15:33 by Eclipse SUMO Version 1.0.1
-->
<configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/sumoConfiguration.xsd">
<input>
<net-file value="osm.net.xml"/>
<route-files value="osm.passenger.trips.xml"/>
<additional-files value="osm.poly.xml"/>
</input>
<processing>
<ignore-route-errors value="true"/>
</processing>
<routing>
<device.rerouting.adaptation-steps value="180"/>
</routing>
<report>
<verbose value="true"/>
<duration-log.statistics value="true"/>
<no-step-log value="true"/>
</report>
<gui_only>
<gui-settings-file value="osm.view.xml"/>
</gui_only>
</configuration>

View File

@ -0,0 +1,5 @@
<viewsettings>
<scheme name="real world"/>
<delay value="20"/>
</viewsettings>

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1 @@
sumo-gui -c osm.sumocfg