From 91eb76e7b33b21ad5fa685a2a5006bd90ccbbc7f Mon Sep 17 00:00:00 2001 From: Ahp06 Date: Mon, 10 Dec 2018 14:46:43 +0100 Subject: [PATCH] Fixed some bugs --- sumo_project/config.py | 9 +++++++-- sumo_project/configs/default_config.json | 2 +- sumo_project/emissions.py | 7 +++---- .../{ => simulations}/mulhouse_simulation/build.bat | 0 .../{ => simulations}/mulhouse_simulation/osm.net.xml | 0 .../{ => simulations}/mulhouse_simulation/osm.netccfg | 0 .../mulhouse_simulation/osm.passenger.rou.alt.xml | 0 .../mulhouse_simulation/osm.passenger.rou.xml | 0 .../mulhouse_simulation/osm.passenger.trips.xml | 0 .../{ => simulations}/mulhouse_simulation/osm.poly.xml | 0 .../{ => simulations}/mulhouse_simulation/osm.polycfg | 0 .../{ => simulations}/mulhouse_simulation/osm.sumocfg | 0 .../{ => simulations}/mulhouse_simulation/osm.view.xml | 0 .../mulhouse_simulation/osm_bbox.osm.xml | 0 .../{ => simulations}/mulhouse_simulation/run.bat | 0 15 files changed, 11 insertions(+), 7 deletions(-) rename sumo_project/{ => simulations}/mulhouse_simulation/build.bat (100%) rename sumo_project/{ => simulations}/mulhouse_simulation/osm.net.xml (100%) rename sumo_project/{ => simulations}/mulhouse_simulation/osm.netccfg (100%) rename sumo_project/{ => simulations}/mulhouse_simulation/osm.passenger.rou.alt.xml (100%) rename sumo_project/{ => simulations}/mulhouse_simulation/osm.passenger.rou.xml (100%) rename sumo_project/{ => simulations}/mulhouse_simulation/osm.passenger.trips.xml (100%) rename sumo_project/{ => simulations}/mulhouse_simulation/osm.poly.xml (100%) rename sumo_project/{ => simulations}/mulhouse_simulation/osm.polycfg (100%) rename sumo_project/{ => simulations}/mulhouse_simulation/osm.sumocfg (100%) rename sumo_project/{ => simulations}/mulhouse_simulation/osm.view.xml (100%) rename sumo_project/{ => simulations}/mulhouse_simulation/osm_bbox.osm.xml (100%) rename sumo_project/{ => simulations}/mulhouse_simulation/run.bat (100%) diff --git a/sumo_project/config.py b/sumo_project/config.py index 6703b69..0558ab1 100644 --- a/sumo_project/config.py +++ b/sumo_project/config.py @@ -25,10 +25,12 @@ class Config: 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.window_size = data["window_size"] + self.without_actions_mode = data["without_actions_mode"] self.limit_speed_mode = data["limit_speed_mode"] self.speed_rf = data["speed_rf"] @@ -74,7 +76,7 @@ class Config: sumo_binary = os.path.join(os.environ['SUMO_HOME'], 'bin', self._SUMOCMD) self.sumo_cmd = [sumo_binary, "-c", self._SUMOCFG] - def init_logger(self): + def init_logger(self, save_logs = True): now = datetime.datetime.now() current_date = now.strftime("%Y_%m_%d_%H_%M_%S") @@ -85,7 +87,10 @@ class Config: logger = logging.getLogger("sumo_logger") logger.setLevel(logging.INFO) - handler = logging.FileHandler(log_filename) + if save_logs : + handler = logging.FileHandler(log_filename) + else: + handler = logging.StreamHandler() formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s") handler.setFormatter(formatter) logger.addHandler(handler) diff --git a/sumo_project/configs/default_config.json b/sumo_project/configs/default_config.json index 1608a2a..4bf6bf2 100644 --- a/sumo_project/configs/default_config.json +++ b/sumo_project/configs/default_config.json @@ -1,6 +1,6 @@ { "_SUMOCMD": "sumo", - "_SUMOCFG": "mulhouse_simulation/osm.sumocfg", + "_SUMOCFG": "simulations/mulhouse_simulation/osm.sumocfg", "areas_number": 10, "emissions_threshold": 500000, diff --git a/sumo_project/emissions.py b/sumo_project/emissions.py index 8a49cbc..91f2316 100644 --- a/sumo_project/emissions.py +++ b/sumo_project/emissions.py @@ -14,7 +14,7 @@ from model import Area, Vehicle, Lane , TrafficLight , Phase , Logic from traci import trafficlight config = Config() -logger = config.init_logger() +logger = config.init_logger(save_logs = True) def init_grid(simulation_bounds, areas_number): grid = list() @@ -124,6 +124,7 @@ def main(args): grid = list() try: traci.start(config.sumo_cmd) + logger.info(f'Loaded configuration file : {args.configfile}') logger.info(f'Loaded simulation file : {config._SUMOCFG}') logger.info('Loading data for the simulation') start = time.perf_counter() @@ -163,9 +164,7 @@ def main(args): if not (ref is None): diff_with_actions = (ref - total_emissions)/ref 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__': diff --git a/sumo_project/mulhouse_simulation/build.bat b/sumo_project/simulations/mulhouse_simulation/build.bat similarity index 100% rename from sumo_project/mulhouse_simulation/build.bat rename to sumo_project/simulations/mulhouse_simulation/build.bat diff --git a/sumo_project/mulhouse_simulation/osm.net.xml b/sumo_project/simulations/mulhouse_simulation/osm.net.xml similarity index 100% rename from sumo_project/mulhouse_simulation/osm.net.xml rename to sumo_project/simulations/mulhouse_simulation/osm.net.xml diff --git a/sumo_project/mulhouse_simulation/osm.netccfg b/sumo_project/simulations/mulhouse_simulation/osm.netccfg similarity index 100% rename from sumo_project/mulhouse_simulation/osm.netccfg rename to sumo_project/simulations/mulhouse_simulation/osm.netccfg diff --git a/sumo_project/mulhouse_simulation/osm.passenger.rou.alt.xml b/sumo_project/simulations/mulhouse_simulation/osm.passenger.rou.alt.xml similarity index 100% rename from sumo_project/mulhouse_simulation/osm.passenger.rou.alt.xml rename to sumo_project/simulations/mulhouse_simulation/osm.passenger.rou.alt.xml diff --git a/sumo_project/mulhouse_simulation/osm.passenger.rou.xml b/sumo_project/simulations/mulhouse_simulation/osm.passenger.rou.xml similarity index 100% rename from sumo_project/mulhouse_simulation/osm.passenger.rou.xml rename to sumo_project/simulations/mulhouse_simulation/osm.passenger.rou.xml diff --git a/sumo_project/mulhouse_simulation/osm.passenger.trips.xml b/sumo_project/simulations/mulhouse_simulation/osm.passenger.trips.xml similarity index 100% rename from sumo_project/mulhouse_simulation/osm.passenger.trips.xml rename to sumo_project/simulations/mulhouse_simulation/osm.passenger.trips.xml diff --git a/sumo_project/mulhouse_simulation/osm.poly.xml b/sumo_project/simulations/mulhouse_simulation/osm.poly.xml similarity index 100% rename from sumo_project/mulhouse_simulation/osm.poly.xml rename to sumo_project/simulations/mulhouse_simulation/osm.poly.xml diff --git a/sumo_project/mulhouse_simulation/osm.polycfg b/sumo_project/simulations/mulhouse_simulation/osm.polycfg similarity index 100% rename from sumo_project/mulhouse_simulation/osm.polycfg rename to sumo_project/simulations/mulhouse_simulation/osm.polycfg diff --git a/sumo_project/mulhouse_simulation/osm.sumocfg b/sumo_project/simulations/mulhouse_simulation/osm.sumocfg similarity index 100% rename from sumo_project/mulhouse_simulation/osm.sumocfg rename to sumo_project/simulations/mulhouse_simulation/osm.sumocfg diff --git a/sumo_project/mulhouse_simulation/osm.view.xml b/sumo_project/simulations/mulhouse_simulation/osm.view.xml similarity index 100% rename from sumo_project/mulhouse_simulation/osm.view.xml rename to sumo_project/simulations/mulhouse_simulation/osm.view.xml diff --git a/sumo_project/mulhouse_simulation/osm_bbox.osm.xml b/sumo_project/simulations/mulhouse_simulation/osm_bbox.osm.xml similarity index 100% rename from sumo_project/mulhouse_simulation/osm_bbox.osm.xml rename to sumo_project/simulations/mulhouse_simulation/osm_bbox.osm.xml diff --git a/sumo_project/mulhouse_simulation/run.bat b/sumo_project/simulations/mulhouse_simulation/run.bat similarity index 100% rename from sumo_project/mulhouse_simulation/run.bat rename to sumo_project/simulations/mulhouse_simulation/run.bat