From 2f20a9c2b5457e4e1d9a064f43e1d3b5d324b7d8 Mon Sep 17 00:00:00 2001 From: Ahp06 Date: Sun, 20 Jan 2019 15:56:05 +0100 Subject: [PATCH] Separated data loading and simulation run --- sumo_project/config.py | 9 +- sumo_project/data.py | 19 +-- .../files/configs/default_config.json | 2 - sumo_project/files/imgs/runner_example.PNG | Bin 3619 -> 0 bytes sumo_project/files/imgs/runner_help.PNG | Bin 20732 -> 0 bytes sumo_project/model.py | 7 +- sumo_project/runner.py | 138 +++++++++--------- 7 files changed, 87 insertions(+), 88 deletions(-) delete mode 100644 sumo_project/files/imgs/runner_example.PNG delete mode 100644 sumo_project/files/imgs/runner_help.PNG diff --git a/sumo_project/config.py b/sumo_project/config.py index 21ba604..4c17a9c 100644 --- a/sumo_project/config.py +++ b/sumo_project/config.py @@ -31,7 +31,7 @@ class Config: """ Default constructor """ - + def import_config_file(self, config_file): """ Import your configuration file in JSON format @@ -78,8 +78,8 @@ class Config: f'adjust traffic light mode = {self.adjust_traffic_light_mode},' f'RF = {self.trafficLights_duration_rf * 100}%\n' ) - - def init_traci(self): + + def init_traci(self, simulation_dir): """ Init the Traci API :return: @@ -89,7 +89,8 @@ class Config: sys.path.append(tools) else: sys.exit("please declare environment variable 'SUMO_HOME'") - + + self._SUMOCFG = f'files/simulations/{simulation_dir}/osm.sumocfg' sumo_binary = os.path.join(os.environ['SUMO_HOME'], 'bin', self._SUMOCMD) self.sumo_cmd = [sumo_binary, "-c", self._SUMOCFG] diff --git a/sumo_project/data.py b/sumo_project/data.py index 039d4f7..eda25c0 100644 --- a/sumo_project/data.py +++ b/sumo_project/data.py @@ -25,30 +25,25 @@ from parse import search from shapely.geometry import LineString import actions -from config import Config from model import Area, Vehicle, Lane, TrafficLight, Phase, Logic, Emission class Data: - def __init__(self, map_bounds, config : Config): + def __init__(self, map_bounds, areas_number,simulation_dir): """ Data constructor """ self.map_bounds = map_bounds - self.config = config - + self.areas_number = areas_number + self.dir = simulation_dir + def init_grid(self): """ - Initialize the grid of the loaded map from the configuration - :param self.map_bounds: The map bounds - :param areas_number: The number of areas - :param window_size: The size of the acquisition window - :return: A list of areas + Initialize the grid of the loaded map from the cfg file with areas_number x areas_number areas """ self.grid = list() - areas_number = self.config.areas_number - window_size = self.config.window_size + areas_number = self.areas_number width = self.map_bounds[1][0] / areas_number height = self.map_bounds[1][1] / areas_number @@ -58,7 +53,7 @@ class Data: ar_bounds = ((i * width, j * height), (i * width, (j + 1) * height), ((i + 1) * width, (j + 1) * height), ((i + 1) * width, j * height)) name = 'Area ({},{})'.format(i, j) - area = Area(ar_bounds, name, window_size) + area = Area(ar_bounds, name) self.grid.append(area) return self.grid diff --git a/sumo_project/files/configs/default_config.json b/sumo_project/files/configs/default_config.json index ddb2037..ded4d80 100644 --- a/sumo_project/files/configs/default_config.json +++ b/sumo_project/files/configs/default_config.json @@ -1,8 +1,6 @@ { "_SUMOCMD": "sumo", - "_SUMOCFG": "files/simulations/mulhouse_simulation/osm.sumocfg", - "areas_number": 10, "emissions_threshold": 500000, "n_steps": 200, "window_size":100, diff --git a/sumo_project/files/imgs/runner_example.PNG b/sumo_project/files/imgs/runner_example.PNG deleted file mode 100644 index 639ce844a3c0072c39b1b5de7f7e23f1ebc7f677..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3619 zcmc(iTU6579>;AOGfy*F)@0>vnlkg4nVNUhF)MYPq_j*4A>|~QqA8gmh&fZ4c_GKV zBTS9=3&bcY3fd_zSqi68N%4|5{wab2Au1q8&&zo^59i^mbsqNq?BC0Gt^HlU-(LHh ze!<`S+rJ$AiQ_8@d#7QhEj{~8P7`?m}o2`LD)jQJ2_`wU-snGZ>QgT zyS#m9U8HySZgkhsPEFfTqW@{%BikQ0l8O?00|7tdX2XX-)YxV9EKt-h^7I{fjp9XCL`S&B;C1GAfmVp z18wo@UgjS#o~PB)*RyHO6e5kE`bDjl%OpdipO@BU7Df?ms&EHriiU+|A#DVghxK9r zzYhoCzje5ecM2UeEKn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C&(?y#qEc?R(b$4E6N2U;YU<6J(+Q diff --git a/sumo_project/files/imgs/runner_help.PNG b/sumo_project/files/imgs/runner_help.PNG deleted file mode 100644 index 3eeee9d77ea097ca66605e1c92998fe48d87b2e0..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 20732 zcmdRWcT|&Iwp$bAk z=^zOmsiBvIme3}=-`qPhYu2o}-~2aOi*5eQeQJ$~3J~8y5 zqPpRE_H%B^8t6+!^*sLRW5t)gX6xzUUaPVUkMfZ?b@ivW?%swS^*)^CcRTm=dA8MP zokwpv@&|KxH1Ewr!&BpveHzMiR8&IQ*Up;1g&&p9+PC>PY0sVgk`W zLCyT72Rowki>9Rg{o_OO*d-UugBF3ryNKlJ=FOmAk1m-9LAt6S=7SD&O@eHwpyM@@ z&3m%mD#i36<*$2fgWAw(S3^6%wX-hgN9=wZ7ODlKo81}RF?pT zHGDx$(dn`QF`!QIT2EN}yV0SJrVJ7mA`@VW6s1h8Yt@?kYVd?%!#o zwl{0ke;p?P>RemrR1UrxwoTJlEO({EdOw=eDk%mF7RNYg^qAIs29ov3W*)C4cirgi zhfoMEamWMGN#g;WyQUM~+&lr4*3&a|h;3ez;K~jgoeS{gZai+nKAWkkd1Q{CVL2n4 zSyS!tsW47;pda)g-0|rKOIAx~$2@0CgEQyp`bMUr83du`XiaYKCu2^tuAinw31N*c z`_sUFvJ)%z4YPH@YC2SsrpgUiQi9v^$jhdgjj`lnoafF{Pr**u!Zm6h4>_)Us>8mzL4ym{>KspP0ETh8|Ii7G7 zZ(oXQv&?d;r_K#}uaz!~9m@Be%nVm)FRc`D3{Ww#QQ6CCK$1_~+%1sUl^+^wfYz}| z-@An8Nu0lr#C9ydb(cx{MB*0lr9o7WshPxYBStR{u2M^>O8>QY813P70z_-=A$;kx z{30ThQi}SWew=(WO)ilhnO<)&m#I|^A0}VX|#gou-f6{5tR5Kp`Ca!9k9AN&@t9nx_a0B z6{4dn!GW!@xuUAljed`%&i?4u{Lp*b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A;W4MXKBO%vWL9;f$JW&&2&5w-Z2KtO<}Of3rbZt59EJdaN086_f8F>AoZbNQ$Yy z{F}-9^#W6ZMJzRnUw#N}gupABN&_7&86Dq0I4u~OaT)9t9F6_^?QvNVv zi&$N`J=m5x!UF&VhpSvi1acya_aTgcXkm<0KIMt)zn~f#bhwPBtFCna(Ffh^tG$@^y6)JD}jc zNF{>guL<_Vlb>hSfZ>haj6F?XN@goEr4Dwr55lTVa~{%$BnG!-3t|gtl{N@-UWBjD zo5J@D(`=!U3xewu1-wZpOXeyy{ zA|&02Gdh@#M<4RjCnVrg{-ydUK(FzAcQ1R1v0cDfd2@-9#S2)YIFEtmMn@Vv4H`$2h1%hYlU z5TogcW_ZYA)fxp|{wN&Ks!(0fOTDu-cWm%;CA8@S@xzDb(wb7wYUJ3+E-UVoEl<`X zJpim`h0|Kg%HP0C%?L${KaeaLN;A@xE$bg`pic!#S=Y=AX9lVz3HKcwry7q9QkY;< z@Lu%0-k-R-vfaonmn!@*4)4t&fjNSCwY%6ss)8(h#Xs@688qjU8f%@%82t|S_Jn+! zb-czU(7EmD9jG@{-6!skhnd+Gl@#eK-MXXtM}mOzazKtxt_ICC6)L4;Pm;a#vpy$N zP!7x!Z;kW)`)xTkqV42v88ICA7!m>adr#15FF2l5YbUp(hWe6#jY!!T4SS+9K)SBY zRr{^ht|zQYV=h)UWmJaYRmR9Bx@GCjloj1Nbm$jASA0Ku_$*YY)kv(D+&h|oUWkM7 zk6v7HwYZO>E4*p8u_`kaR{X1v_B>m^5_=K~(d~iW(?3&fPsF%D!%`RCQQ+~Z2@-KCh Bt8oAT diff --git a/sumo_project/model.py b/sumo_project/model.py index 25cea9c..2d1593f 100644 --- a/sumo_project/model.py +++ b/sumo_project/model.py @@ -153,13 +153,12 @@ class Area: The Area class defines a grid area of the simulation map """ - def __init__(self, coords, name, window_size): + def __init__(self, coords, name): """ Area constructor :param coords: The coordinates of the zone, defined by the bounds coordinates of this area : (xmin, ymin, xmax, ymax) :param name: The Area name - :param window_size: The size of the acquisition window """ self.limited_speed = False self.locked = False @@ -168,10 +167,12 @@ class Area: self.rectangle = Polygon(coords) self.name = name self.emissions_by_step = [] - self.window = collections.deque(maxlen=window_size) self._lanes: Set[Lane] = set() self._tls: Set[TrafficLight] = set() + def set_window_size(self, window_size): + self.window = collections.deque(maxlen=window_size) + def __eq__(self, other): """ Overrides the equal definition diff --git a/sumo_project/runner.py b/sumo_project/runner.py index 9c1cf7f..e732027 100644 --- a/sumo_project/runner.py +++ b/sumo_project/runner.py @@ -1,7 +1,7 @@ ''' Created on 19 janv. 2019 -@author: Admin +@author: Axel Huynh-Phuc ''' import argparse @@ -17,50 +17,58 @@ from data import Data import emissions from model import Emission +""" +Init the Traci API +""" +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'") + def add_options(parser): """ Add command line options :param parser: The command line parser :return: """ - parser.add_argument("-new_dump", "--new_dump", metavar=('config_file', 'dump_name'), nargs=2, type=str, + + # TODO: Faire que -areas & -simulation_dir soit requis si -new_dump + # Faire que -c soit requis si -run + + parser.add_argument("-new_dump", "--new_dump", type=str, required=False, help='Load and create a new data dump with the configuration file chosen') - parser.add_argument("-run", "--run", type=str, required=False, + parser.add_argument("-areas", "--areas", type=int, required=False, + help='Will create a grid with "areas x areas" areas') + parser.add_argument("-simulation_dir", "--simulation_dir", type=str, required=False, + help='Choose the simulation directory') + + parser.add_argument("-run", "--run", type=str, help='Run a simulation with the dump chosen') - + parser.add_argument("-c", "--c", type=str, + help='Choose your configuration file from your working directory') parser.add_argument("-save", "--save", action="store_true", help='Save the logs into the logs folder') parser.add_argument("-csv", "--csv", action="store_true", help="Export all data emissions into a CSV file") + - parser.add_argument("-steps", "--steps", type=int, default=200, required=False, - help='Choose the simulated time (in seconds)') - parser.add_argument("-ref", "--ref", action="store_true", - help='Launch a reference simulation (without acting on areas)') - parser.add_argument("-gui", "--gui", action="store_true", - help="Set GUI mode") - - -def create_dump(config_file, dump_name): +def create_dump(dump_name, simulation_dir, areas_number): """ Create a new dump with config file and dump_name chosen - :param config_file: The configuration file - :param dump_name: The dump name + :param cfg_file: The simulation file + :param areas_number: The number of areas in grid :return: """ - config = Config() - config.import_config_file(config_file) - config.check_config() - config.init_traci() sumo_binary = os.path.join(os.environ['SUMO_HOME'], 'bin', 'sumo') - sumo_cmd = [sumo_binary, "-c", config._SUMOCFG] + sumo_cmd = [sumo_binary, "-c", f'files/simulations/{simulation_dir}/osm.sumocfg'] traci.start(sumo_cmd) if not os.path.isfile(f'files/dump/{dump_name}.json'): start = time.perf_counter() - data = Data(traci.simulation.getNetBoundary(), config) + data = Data(traci.simulation.getNetBoundary(), areas_number, simulation_dir) data.init_grid() data.add_data_to_areas() data.save(dump_name) @@ -74,32 +82,33 @@ def create_dump(config_file, dump_name): traci.close(False) -def run(data : Data, logger): +def run(data : Data, config : Config, logger): """ Run a data set :param data: The data instance :param logger: The logger instance """ try: - traci.start(data.config.sumo_cmd) + traci.start(config.sumo_cmd) - for area in data.grid: + for area in data.grid: # Set acquisition window size + area.set_window_size(config.window_size) traci.polygon.add(area.name, area.rectangle.exterior.coords, (255, 0, 0)) # Add polygon for UI - logger.info(f'Loaded simulation file : {data.config._SUMOCFG}') + logger.info(f'Loaded simulation file : {config._SUMOCFG}') logger.info('Loading data for the simulation') start = time.perf_counter() logger.info('Simulation started...') step = 0 - while step < data.config.n_steps: + while step < config.n_steps: traci.simulationStep() vehicles = emissions.get_all_vehicles() - emissions.get_emissions(data.grid, vehicles, step, data.config, logger) + emissions.get_emissions(data.grid, vehicles, step, config, logger) step += 1 - print(f'step = {step}/{data.config.n_steps}', end='\r') + print(f'step = {step}/{config.n_steps}', end='\r') finally: traci.close(False) @@ -116,59 +125,54 @@ def main(args): args = parser.parse_args(args) if args.new_dump is not None: - create_dump(args.new_dump[0], args.new_dump[1]) # (config_file, dump_name) + if (args.simulation_dir is not None) and (args.areas is not None): + create_dump(args.new_dump, args.simulation_dir, args.areas) if args.run is not None: dump_path = f'files/dump/{args.run}.json' if os.path.isfile(dump_path): with open(dump_path, 'r') as f: data = jsonpickle.decode(f.read()) - - data.config.init_traci() - logger = data.config.init_logger(dump_name=args.run, save_logs=args.save) - - if args.gui: - data.config._SUMOCMD = "sumo-gui" - - if args.ref: - data.config.without_actions_mode = True - logger.info(f'Reference simulation') - - if args.steps: - data.config.n_steps = args.steps - data.config.check_config() + config = Config() + if args.c is not None: + config.import_config_file(args.c) + config.init_traci(data.dir) + logger = config.init_logger(dump_name=args.run, save_logs=args.save) + config.check_config() logger.info(f'Running simulation dump {args.run}...') start = time.perf_counter() - run(data, logger) + + run(data, config, logger) + simulation_time = round(time.perf_counter() - start, 2) logger.info(f'End of the simulation ({simulation_time}s)') - if args.csv: - emissions.export_data_to_csv(data.config, data.grid, dump_name=args.run) - logger.info(f'Exported data into the csv folder') + if args.csv: + emissions.export_data_to_csv(config, data.grid, dump_name=args.run) + logger.info(f'Exported data into the csv folder') - # 1 step is equal to one second simulated - logger.info(f'Real-time factor : {data.config.n_steps / simulation_time}') - - total_emissions = Emission() - for area in data.grid: - total_emissions += area.sum_all_emissions() - - logger.info(f'Total emissions = {total_emissions.value()} mg') - - if not data.config.without_actions_mode: # If it's not a simulation without actions - ref = data.config.get_ref_emissions() - if not (ref is None): # If a reference value exist (add yours into config.py) - global_diff = (ref.value() - total_emissions.value()) / ref.value() - - logger.info(f'Global reduction percentage of emissions = {global_diff * 100} %') - logger.info(f'-> CO2 emissions = {emissions.get_reduction_percentage(ref.co2, total_emissions.co2)} %') - logger.info(f'-> CO emissions = {emissions.get_reduction_percentage(ref.co, total_emissions.co)} %') - logger.info(f'-> Nox emissions = {emissions.get_reduction_percentage(ref.nox, total_emissions.nox)} %') - logger.info(f'-> HC emissions = {emissions.get_reduction_percentage(ref.hc, total_emissions.hc)} %') - logger.info(f'-> PMx emissions = {emissions.get_reduction_percentage(ref.pmx, total_emissions.pmx)} %') + # 1 step is equal to one second simulated + logger.info(f'Real-time factor : {config.n_steps / simulation_time}') + + total_emissions = Emission() + for area in data.grid: + total_emissions += area.sum_all_emissions() + + logger.info(f'Total emissions = {total_emissions.value()} mg') + + if not config.without_actions_mode: # If it's not a simulation without actions + ref = config.get_ref_emissions() + if not (ref is None): # If a reference value exist (add yours into config.py) + global_diff = (ref.value() - total_emissions.value()) / ref.value() + + logger.info(f'Global reduction percentage of emissions = {global_diff * 100} %') + logger.info(f'-> CO2 emissions = {emissions.get_reduction_percentage(ref.co2, total_emissions.co2)} %') + logger.info(f'-> CO emissions = {emissions.get_reduction_percentage(ref.co, total_emissions.co)} %') + logger.info(f'-> Nox emissions = {emissions.get_reduction_percentage(ref.nox, total_emissions.nox)} %') + logger.info(f'-> HC emissions = {emissions.get_reduction_percentage(ref.hc, total_emissions.hc)} %') + logger.info(f'-> PMx emissions = {emissions.get_reduction_percentage(ref.pmx, total_emissions.pmx)} %') if __name__ == '__main__':