diff --git a/sumo_project/config.py b/sumo_project/config.py new file mode 100644 index 0000000..4b04b14 --- /dev/null +++ b/sumo_project/config.py @@ -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] + + diff --git a/sumo_project/emissions.py b/sumo_project/emissions.py index e76ac22..7766ade 100644 --- a/sumo_project/emissions.py +++ b/sumo_project/emissions.py @@ -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())