mirror of
https://github.com/Ahp06/SUMO_Emissions.git
synced 2024-11-21 19:16:30 +00:00
Merge branch 'global-configuration' into dev
This commit is contained in:
commit
429ab253f0
22
sumo_project/config.py
Normal file
22
sumo_project/config.py
Normal file
@ -0,0 +1,22 @@
|
||||
"""
|
||||
Global configuration for the simulation
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
if 'SUMO_HOME' in os.environ:
|
||||
tools = os.path.join(os.environ['SUMO_HOME'], 'tools')
|
||||
sys.path.append(tools)
|
||||
else:
|
||||
sys.exit("please declare environment variable 'SUMO_HOME'")
|
||||
|
||||
_SUMOCMD = 'sumo-gui'
|
||||
_SUMOCFG = "mulhouse_simulation/map.sumocfg"
|
||||
CELLS_NUMBER = 10
|
||||
CO2_THRESHOLD = 500000
|
||||
|
||||
sumo_binary = os.path.join(os.environ['SUMO_HOME'], 'bin', _SUMOCMD)
|
||||
sumo_cmd = [sumo_binary, "-c", _SUMOCFG]
|
||||
|
||||
|
@ -1,22 +1,9 @@
|
||||
import os
|
||||
import sys
|
||||
import traci
|
||||
import config
|
||||
|
||||
from SUMOFactory import SUMOFactory
|
||||
|
||||
if 'SUMO_HOME' in os.environ:
|
||||
tools = os.path.join(os.environ['SUMO_HOME'], 'tools')
|
||||
sys.path.append(tools)
|
||||
else:
|
||||
sys.exit("please declare environment variable 'SUMO_HOME'")
|
||||
|
||||
import traci
|
||||
from area import Area
|
||||
|
||||
sumoBinary = os.path.join(os.environ['SUMO_HOME'], 'bin', 'sumo-gui')
|
||||
sumoCmd = [sumoBinary, "-c", "mulhouse_simulation/map.sumocfg"]
|
||||
CELLS_NUMBER = 10
|
||||
CO2_THRESHOLD = 500000
|
||||
|
||||
|
||||
def init_grid(simulation_bounds, cells_number):
|
||||
width = simulation_bounds[1][0] / cells_number
|
||||
@ -46,7 +33,7 @@ def emission_for_area(area):
|
||||
def get_emissions(areas, factory):
|
||||
for area in areas:
|
||||
emission_for_area(area)
|
||||
if area.emissions > CO2_THRESHOLD:
|
||||
if area.emissions > config.CO2_THRESHOLD:
|
||||
# print(f'Threshold exceeded in {area.name} : {area.emissions}')
|
||||
factory.lock_area(area)
|
||||
traci.polygon.setColor(area.name, (255, 0, 0))
|
||||
@ -55,8 +42,8 @@ def get_emissions(areas, factory):
|
||||
|
||||
def main():
|
||||
try:
|
||||
traci.start(sumoCmd)
|
||||
grid = init_grid(traci.simulation.getNetBoundary(), CELLS_NUMBER)
|
||||
traci.start(config.sumo_cmd)
|
||||
grid = init_grid(traci.simulation.getNetBoundary(), config.CELLS_NUMBER)
|
||||
while traci.simulation.getMinExpectedNumber() > 0:
|
||||
traci.simulationStep()
|
||||
get_emissions(grid, SUMOFactory())
|
||||
|
Loading…
Reference in New Issue
Block a user