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

Added JSON config file reader

This commit is contained in:
Ahp06 2018-12-09 19:49:37 +01:00
parent 289c09b253
commit 27d48f24d6
2 changed files with 99 additions and 77 deletions

View File

@ -6,11 +6,32 @@ import datetime
import logging
import os
import sys
import json
class config:
def __init__(self, config_file = None):
if not (config_file is None):
with open(config_file) as f:
data = json.load(f)
self._SUMOCMD = data["_SUMOCMD"]
self._SUMOCFG = data["_SUMOCFG"]
self.areas_number = data["areas_number"]
self.emissions_threshold = data["emissions_threshold"]
self.n_steps = data["n_steps"]
self.without_actions_mode = data["without_actions_mode"]
self.limit_speed_mode = data["limit_speed_mode"]
self.speed_rf = data["speed_rf"]
self.adjust_traffic_light_mode = data["adjust_traffic_light_mode"]
self.trafficLights_duration_rf = data["trafficLights_duration_rf"]
self.weight_routing_mode = data["weight_routing_mode"]
self.lock_area_mode = data["lock_area_mode"]
###############################################################################
############################# SIMULATION FILE #################################
###############################################################################
if 'SUMO_HOME' in os.environ:
tools = os.path.join(os.environ['SUMO_HOME'], 'tools')
sys.path.append(tools)
@ -49,7 +70,7 @@ logger.addHandler(handler)
areas_number = 10 # Simulation boundary will be divided into areas_number x areas_number areas
emissions_threshold = 500000
n_steps = 200
window_size = 100
window_size = 200
###############################################################################
########################## ACTIONS CONFIGURATION ##############################
@ -99,20 +120,20 @@ total_emissions300 = 87382632.0821697
########################## CONFIGURATION METHODS ##############################
###############################################################################
def get_basics_emissions():
if n_steps == 100:
return total_emissions100
if n_steps == 200:
return total_emissions200
if n_steps == 300:
return total_emissions300
def get_basics_emissions(self):
if self.n_steps == 100:
return self.total_emissions100
if self.n_steps == 200:
return self.total_emissions200
if self.n_steps == 300:
return self.total_emissions300
def show_config():
return (str(f'Grid : {areas_number}x{areas_number}\n')
+ str(f'step number = {n_steps}\n')
+ str(f'window size = {window_size}\n')
+ str(f'weight routing mode = {weight_routing_mode}\n')
+ str(f'lock area mode = {lock_area_mode}\n')
+ str(f'limit speed mode = {limit_speed_mode}, RF = {speed_rf*100}%\n')
+ str(f'adjust traffic light mode = {adjust_traffic_light_mode} , RF = {trafficLights_duration_rf*100}%\n'))
def show_config(self):
return (str(f'Grid : {self.areas_number}x{self.areas_number}\n')
+ str(f'step number = {self.n_steps}\n')
+ str(f'window size = {self.window_size}\n')
+ str(f'weight routing mode = {self.weight_routing_mode}\n')
+ str(f'lock area mode = {self.lock_area_mode}\n')
+ str(f'limit speed mode = {self.limit_speed_mode}, RF = {self.speed_rf*100}%\n')
+ str(f'adjust traffic light mode = {self.adjust_traffic_light_mode} , RF = {self.trafficLights_duration_rf*100}%\n'))

View File

@ -7,11 +7,12 @@ from shapely.geometry import LineString
from parse import search
import actions
import config
from config import config
import sys
from model import Area, Vehicle, Lane , TrafficLight , Phase , Logic
from traci import trafficlight
config = config('C:\\Users\\Admin\\Desktop\\config.json')
logger = config.logger
def init_grid(simulation_bounds, areas_number):