mirror of
https://github.com/Ahp06/SUMO_Emissions.git
synced 2024-11-22 03:26:30 +00:00
Changed config class
This commit is contained in:
parent
cf163fb567
commit
28be0142fb
@ -8,7 +8,7 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
import json
|
import json
|
||||||
|
|
||||||
class config:
|
class Config:
|
||||||
|
|
||||||
# Total of emissions of all pollutants in mg for n steps of simulation without locking areas
|
# Total of emissions of all pollutants in mg for n steps of simulation without locking areas
|
||||||
# These constants are simulation dependant, you must change them according to your simulation
|
# These constants are simulation dependant, you must change them according to your simulation
|
||||||
@ -16,9 +16,11 @@ class config:
|
|||||||
total_emissions200 = 43970763.15084738
|
total_emissions200 = 43970763.15084738
|
||||||
total_emissions300 = 87382632.0821697
|
total_emissions300 = 87382632.0821697
|
||||||
|
|
||||||
def __init__(self, config_file = None):
|
def __init__(self):
|
||||||
if not (config_file is None):
|
'''Default constructor'''
|
||||||
with open(config_file) as f:
|
|
||||||
|
def import_config_file(self,config_file):
|
||||||
|
with open(config_file,'r') as f:
|
||||||
data = json.load(f)
|
data = json.load(f)
|
||||||
|
|
||||||
self._SUMOCMD = data["_SUMOCMD"]
|
self._SUMOCMD = data["_SUMOCMD"]
|
||||||
@ -53,7 +55,7 @@ class config:
|
|||||||
|
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
return (str(f'Grid : {self.areas_number}x{self.areas_number}\n')
|
return (str(f'grid : {self.areas_number}x{self.areas_number}\n')
|
||||||
+ str(f'step number = {self.n_steps}\n')
|
+ str(f'step number = {self.n_steps}\n')
|
||||||
+ str(f'window size = {self.window_size}\n')
|
+ str(f'window size = {self.window_size}\n')
|
||||||
+ str(f'weight routing mode = {self.weight_routing_mode}\n')
|
+ str(f'weight routing mode = {self.weight_routing_mode}\n')
|
||||||
@ -75,6 +77,10 @@ class config:
|
|||||||
def init_logger(self):
|
def init_logger(self):
|
||||||
now = datetime.datetime.now()
|
now = datetime.datetime.now()
|
||||||
current_date = now.strftime("%Y_%m_%d_%H_%M_%S")
|
current_date = now.strftime("%Y_%m_%d_%H_%M_%S")
|
||||||
|
|
||||||
|
if not os.path.exists('logs'):
|
||||||
|
os.makedirs('logs')
|
||||||
|
|
||||||
log_filename = f'logs/sumo_logs_{current_date}.log'
|
log_filename = f'logs/sumo_logs_{current_date}.log'
|
||||||
|
|
||||||
logger = logging.getLogger("sumo_logger")
|
logger = logging.getLogger("sumo_logger")
|
||||||
|
@ -7,12 +7,12 @@
|
|||||||
"n_steps": 200,
|
"n_steps": 200,
|
||||||
"window_size":100,
|
"window_size":100,
|
||||||
|
|
||||||
"without_actions_mode": false,
|
"without_actions_mode": true,
|
||||||
|
|
||||||
"limit_speed_mode": true,
|
"limit_speed_mode": false,
|
||||||
"speed_rf": 0.1,
|
"speed_rf": 0.1,
|
||||||
|
|
||||||
"adjust_traffic_light_mode": true,
|
"adjust_traffic_light_mode": false,
|
||||||
"trafficLights_duration_rf": 0.2,
|
"trafficLights_duration_rf": 0.2,
|
||||||
|
|
||||||
"weight_routing_mode": false,
|
"weight_routing_mode": false,
|
@ -2,18 +2,18 @@ from typing import List
|
|||||||
|
|
||||||
import traci
|
import traci
|
||||||
import time
|
import time
|
||||||
|
import argparse
|
||||||
|
|
||||||
from shapely.geometry import LineString
|
from shapely.geometry import LineString
|
||||||
from parse import search
|
from parse import search
|
||||||
|
|
||||||
import actions
|
import actions
|
||||||
from config import config
|
from config import Config
|
||||||
import sys
|
import sys
|
||||||
from model import Area, Vehicle, Lane , TrafficLight , Phase , Logic
|
from model import Area, Vehicle, Lane , TrafficLight , Phase , Logic
|
||||||
from traci import trafficlight
|
from traci import trafficlight
|
||||||
|
|
||||||
config = config('config.json')
|
config = Config()
|
||||||
config.init_traci()
|
|
||||||
logger = config.init_logger()
|
logger = config.init_logger()
|
||||||
|
|
||||||
def init_grid(simulation_bounds, areas_number):
|
def init_grid(simulation_bounds, areas_number):
|
||||||
@ -112,7 +112,15 @@ def get_emissions(grid: List[Area], vehicles: List[Vehicle], current_step):
|
|||||||
actions.reverse_actions(area)
|
actions.reverse_actions(area)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main(args):
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser(description="")
|
||||||
|
parser.add_argument("-f", "--configfile", type=str, default= 'configs/default_config.json', required=False)
|
||||||
|
args = parser.parse_args(args)
|
||||||
|
|
||||||
|
config.import_config_file(args.configfile)
|
||||||
|
config.init_traci()
|
||||||
|
|
||||||
grid = list()
|
grid = list()
|
||||||
try:
|
try:
|
||||||
traci.start(config.sumo_cmd)
|
traci.start(config.sumo_cmd)
|
||||||
@ -161,4 +169,4 @@ def main():
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main(sys.argv[1:])
|
||||||
|
Loading…
Reference in New Issue
Block a user