mirror of
https://github.com/Ahp06/SUMO_Emissions.git
synced 2024-11-25 04:56:30 +00:00
Externalize configuration in config.py
This commit is contained in:
parent
6c36eafe09
commit
7cbc1d85a0
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 traci
|
||||||
import sys
|
import config
|
||||||
|
|
||||||
from SUMOFactory import SUMOFactory
|
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
|
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):
|
def init_grid(simulation_bounds, cells_number):
|
||||||
width = simulation_bounds[1][0] / cells_number
|
width = simulation_bounds[1][0] / cells_number
|
||||||
@ -46,7 +33,7 @@ def emission_for_area(area):
|
|||||||
def get_emissions(areas, factory):
|
def get_emissions(areas, factory):
|
||||||
for area in areas:
|
for area in areas:
|
||||||
emission_for_area(area)
|
emission_for_area(area)
|
||||||
if area.emissions > CO2_THRESHOLD:
|
if area.emissions > config.CO2_THRESHOLD:
|
||||||
# print(f'Threshold exceeded in {area.name} : {area.emissions}')
|
# print(f'Threshold exceeded in {area.name} : {area.emissions}')
|
||||||
factory.lock_area(area)
|
factory.lock_area(area)
|
||||||
traci.polygon.setColor(area.name, (255, 0, 0))
|
traci.polygon.setColor(area.name, (255, 0, 0))
|
||||||
@ -55,8 +42,8 @@ def get_emissions(areas, factory):
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
try:
|
try:
|
||||||
traci.start(sumoCmd)
|
traci.start(config.sumo_cmd)
|
||||||
grid = init_grid(traci.simulation.getNetBoundary(), CELLS_NUMBER)
|
grid = init_grid(traci.simulation.getNetBoundary(), config.CELLS_NUMBER)
|
||||||
while traci.simulation.getMinExpectedNumber() > 0:
|
while traci.simulation.getMinExpectedNumber() > 0:
|
||||||
traci.simulationStep()
|
traci.simulationStep()
|
||||||
get_emissions(grid, SUMOFactory())
|
get_emissions(grid, SUMOFactory())
|
||||||
|
Loading…
Reference in New Issue
Block a user