mirror of
https://github.com/Ahp06/SUMO_Emissions.git
synced 2024-11-22 03:26:30 +00:00
Fixed some bugs
This commit is contained in:
parent
28be0142fb
commit
91eb76e7b3
@ -25,10 +25,12 @@ class Config:
|
|||||||
|
|
||||||
self._SUMOCMD = data["_SUMOCMD"]
|
self._SUMOCMD = data["_SUMOCMD"]
|
||||||
self._SUMOCFG = data["_SUMOCFG"]
|
self._SUMOCFG = data["_SUMOCFG"]
|
||||||
|
|
||||||
self.areas_number = data["areas_number"]
|
self.areas_number = data["areas_number"]
|
||||||
self.emissions_threshold = data["emissions_threshold"]
|
self.emissions_threshold = data["emissions_threshold"]
|
||||||
self.n_steps = data["n_steps"]
|
self.n_steps = data["n_steps"]
|
||||||
self.window_size = data["window_size"]
|
self.window_size = data["window_size"]
|
||||||
|
|
||||||
self.without_actions_mode = data["without_actions_mode"]
|
self.without_actions_mode = data["without_actions_mode"]
|
||||||
self.limit_speed_mode = data["limit_speed_mode"]
|
self.limit_speed_mode = data["limit_speed_mode"]
|
||||||
self.speed_rf = data["speed_rf"]
|
self.speed_rf = data["speed_rf"]
|
||||||
@ -74,7 +76,7 @@ class Config:
|
|||||||
sumo_binary = os.path.join(os.environ['SUMO_HOME'], 'bin', self._SUMOCMD)
|
sumo_binary = os.path.join(os.environ['SUMO_HOME'], 'bin', self._SUMOCMD)
|
||||||
self.sumo_cmd = [sumo_binary, "-c", self._SUMOCFG]
|
self.sumo_cmd = [sumo_binary, "-c", self._SUMOCFG]
|
||||||
|
|
||||||
def init_logger(self):
|
def init_logger(self, save_logs = True):
|
||||||
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")
|
||||||
|
|
||||||
@ -85,7 +87,10 @@ class Config:
|
|||||||
|
|
||||||
logger = logging.getLogger("sumo_logger")
|
logger = logging.getLogger("sumo_logger")
|
||||||
logger.setLevel(logging.INFO)
|
logger.setLevel(logging.INFO)
|
||||||
|
if save_logs :
|
||||||
handler = logging.FileHandler(log_filename)
|
handler = logging.FileHandler(log_filename)
|
||||||
|
else:
|
||||||
|
handler = logging.StreamHandler()
|
||||||
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
|
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
|
||||||
handler.setFormatter(formatter)
|
handler.setFormatter(formatter)
|
||||||
logger.addHandler(handler)
|
logger.addHandler(handler)
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"_SUMOCMD": "sumo",
|
"_SUMOCMD": "sumo",
|
||||||
"_SUMOCFG": "mulhouse_simulation/osm.sumocfg",
|
"_SUMOCFG": "simulations/mulhouse_simulation/osm.sumocfg",
|
||||||
|
|
||||||
"areas_number": 10,
|
"areas_number": 10,
|
||||||
"emissions_threshold": 500000,
|
"emissions_threshold": 500000,
|
||||||
|
@ -14,7 +14,7 @@ from model import Area, Vehicle, Lane , TrafficLight , Phase , Logic
|
|||||||
from traci import trafficlight
|
from traci import trafficlight
|
||||||
|
|
||||||
config = Config()
|
config = Config()
|
||||||
logger = config.init_logger()
|
logger = config.init_logger(save_logs = True)
|
||||||
|
|
||||||
def init_grid(simulation_bounds, areas_number):
|
def init_grid(simulation_bounds, areas_number):
|
||||||
grid = list()
|
grid = list()
|
||||||
@ -124,6 +124,7 @@ def main(args):
|
|||||||
grid = list()
|
grid = list()
|
||||||
try:
|
try:
|
||||||
traci.start(config.sumo_cmd)
|
traci.start(config.sumo_cmd)
|
||||||
|
logger.info(f'Loaded configuration file : {args.configfile}')
|
||||||
logger.info(f'Loaded simulation file : {config._SUMOCFG}')
|
logger.info(f'Loaded simulation file : {config._SUMOCFG}')
|
||||||
logger.info('Loading data for the simulation')
|
logger.info('Loading data for the simulation')
|
||||||
start = time.perf_counter()
|
start = time.perf_counter()
|
||||||
@ -164,8 +165,6 @@ def main(args):
|
|||||||
diff_with_actions = (ref - total_emissions)/ref
|
diff_with_actions = (ref - total_emissions)/ref
|
||||||
logger.info(f'Reduction percentage of emissions = {diff_with_actions*100} %')
|
logger.info(f'Reduction percentage of emissions = {diff_with_actions*100} %')
|
||||||
|
|
||||||
logger.info(f'With the configuration : \n{config}')
|
|
||||||
logger.info('Logs END')
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
Loading…
Reference in New Issue
Block a user