def get_new_runner(self, mp: 'Map', algorithm_type: Type['Algorithm'], algorithm_parameters: Tuple[List, Dict] = None, algorithm_testing: Optional[ Type['BasicTesting']] = None, with_animations: bool = False) -> 'AlgorithmRunner': if not algorithm_parameters: algorithm_parameters = [], {} from simulator.services.services import Services config = Configuration() config.simulator_initial_map = mp config.simulator_algorithm_type = algorithm_type config.simulator_testing_type = algorithm_testing config.simulator_algorithm_parameters = algorithm_parameters if with_animations and algorithm_testing: config.simulator_graphics = True config.simulator_key_frame_speed = self._services.settings.simulator_key_frame_speed config.simulator_key_frame_skip = self._services.settings.simulator_key_frame_skip s = Services(config) if with_animations and algorithm_testing: s.algorithm.__pass_root_key_frame = self.__pass_root_key_frame return s.algorithm
def augment_label_maps(self, atlases: List[str], feature_list: List[str], label_list: List[str], single_feature_list: List[str], single_label_list: List[str]) -> None: if not atlases: return self.__services.debug.write("""Starting Augmentation: [ atlases: {}, feature_list: {}, label_list: {}, single_feature_list: {}, single_label_list: {} ] """.format(atlases, feature_list, label_list, single_feature_list, single_label_list), DebugLevel.BASIC) label_atlas_name = "training_" + "_".join(atlases) self.__services.debug.write("Loading maps", DebugLevel.BASIC) maps: List[Map] = [] for name in atlases: maps = maps + self.__services.resources.maps_dir.get_atlas(name).load_all() self.__services.debug.write("Loading atlas", DebugLevel.BASIC) t: List[Dict[str, any]] = self.__services.resources.training_data_dir.load(label_atlas_name) progress_bar: Progress = self.__services.debug.progress_debug(len(t), DebugLevel.BASIC) progress_bar.start() for i in range(len(t)): config = Configuration() config.simulator_algorithm_type = AStar config.simulator_testing_type = AStarTesting config.simulator_initial_map = maps[i] services: Services = Services(config) simulator: Simulator = Simulator(services) testing: AStarTesting = simulator.start() if feature_list: seq_features = MapProcessing.get_sequential_features(testing.map, feature_list) for q in range(len(t[i]["features"])): t[i]["features"][q].update(seq_features[q]) if label_list: seq_labels = MapProcessing.get_sequential_labels(testing.map, label_list) for q in range(len(t[i]["labels"])): # print(q) t[i]["labels"][q].update(seq_labels[q]) if single_feature_list: t[i]["single_features"].update(MapProcessing.get_single_features(maps[i], single_feature_list)) if single_label_list: t[i]["single_labels"].update(MapProcessing.get_single_labels(maps[i], single_label_list)) progress_bar.step() self.__services.debug.write("Saving atlas augmentation: " + str(label_atlas_name), DebugLevel.BASIC) self.__services.resources.training_data_dir.save(label_atlas_name, t) self.__services.debug.write("Finished atlas augmentation: " + str(label_atlas_name) + "\n", DebugLevel.BASIC)
def __label_single_maps(self, atlas_name, feature_list: List[str], label_list: List[str], single_feature_list: List[str], single_label_list: List[str], overwrite: bool) -> List[ Dict[str, any]]: """ Passed atlas name, feature list, label list, and returns res object with the map features labelled for training """ if not atlas_name: return [] if not overwrite and self.__services.resources.training_data_dir.exists("training_" + atlas_name, ".pickle"): self.__services.debug.write("Found in training data. Loading from training data", DebugLevel.BASIC) return self.__services.resources.training_data_dir.load("training_" + atlas_name) self.__services.debug.write("Loading maps", DebugLevel.BASIC) maps: List[Map] = self.__services.resources.maps_dir.get_atlas(atlas_name).load_all() res: List[Dict[str, any]] = [] progress_bar: Progress = self.__services.debug.progress_debug(len(maps), DebugLevel.BASIC) progress_bar.start() # process atlas for m in maps: config = Configuration() config.simulator_algorithm_type = AStar config.simulator_testing_type = AStarTesting config.simulator_initial_map = m services: Services = Services(config) simulator: Simulator = Simulator(services) testing: AStarTesting = simulator.start() features: Dict[str, any] = {} arg: str for arg in ["map_obstacles_percentage", "goal_found", "distance_to_goal", "original_distance_to_goal", "trace", "total_steps", "total_distance", "total_time", "algorithm_type", "fringe", "search_space" ]: features[arg] = testing.get_results()[arg] features["features"] = MapProcessing.get_sequential_features(testing.map, feature_list) features["labels"] = MapProcessing.get_sequential_labels(testing.map, label_list) features["single_features"] = MapProcessing.get_single_features(m, single_feature_list) features["single_labels"] = MapProcessing.get_single_labels(m, single_label_list) res.append(features) progress_bar.step() return res
def __start_simulator_callback(gui): #Setting the configuration file. config = Configuration() mp = gui.__maps[gui.__map_choice.get()] algo = gui.__algorithms[gui.__algorithm_choice.get()] ani = gui.__animations[gui.__animations_choice.get()] debug = gui.__debug[gui.__debug_choice.get()] config.load_simulator = True config.simulator_graphics = True config.simulator_initial_map, config.simulator_grid_display = mp config.simulator_algorithm_type, config.simulator_testing_type, config.simulator_algorithm_parameters = algo config.simulator_key_frame_speed, config.simulator_key_frame_skip = ani config.simulator_write_debug_level = debug MainRunner(config).run()
def __run_simulation(self, grid: Map, algorithm_type: Type[Algorithm], testing_type: Type[BasicTesting], algo_params: Tuple[list, dict], agent_pos: Point = None) -> Dict[str, Any]: config = Configuration() config.simulator_initial_map = copy.deepcopy(grid) config.simulator_algorithm_type = algorithm_type config.simulator_testing_type = testing_type config.simulator_algorithm_parameters = algo_params if agent_pos: config.simulator_initial_map.move_agent(agent_pos, True, False) sim: Simulator = Simulator(Services(config)) return sim.start().get_results()
def main() -> bool: parser = argparse.ArgumentParser( prog="ros.py", description="PathBench 2D ROS extension runner", formatter_class=argparse.RawTextHelpFormatter) configurers: List[Callable[[Configuration, argparse.Namespace], bool]] = [] configurers.append( add_configuration_flags(parser, visualiser_flags=True, algorithms_flags=True, multiple_algorithms_specifiable=False)) parser.add_argument("-g", "--goal", nargs=2, type=int, help="goal position \"x y\"") args = parser.parse_args() print("args:{}".format(args)) config = Configuration() for c in configurers: if not c(config, args): return False if args.algorithm: config.algorithm_name = list(config.algorithms.keys())[0] config.simulator_algorithm_type, config.simulator_testing_type, config.simulator_algorithm_parameters = config.algorithms[ config.algorithm_name] goal = Point(*args.goal) if args.goal else None ros = Ros() ros.start(config, goal) return True
def main() -> bool: parser = argparse.ArgumentParser( prog="ros.py", description="ROS 2D Occupancy Grid Publish-Subscriber Demo", formatter_class=argparse.RawTextHelpFormatter) configurers: List[Callable[[Configuration, argparse.Namespace], bool]] = [] configurers.append( add_configuration_flags(parser, visualiser_flags=True, algorithms_flags=True, multiple_algorithms_specifiable=False)) parser.add_argument("-f", "--fake", action="store_true", help="fake the ROS publisher") args = parser.parse_args() print("args:{}".format(args)) config = Configuration() for c in configurers: if not c(config, args): return False if args.algorithm: config.algorithm_name = list(config.algorithms.keys())[0] config.simulator_algorithm_type, config.simulator_testing_type, config.simulator_algorithm_parameters = config.algorithms[ config.algorithm_name] ros = Ros(fake=args.fake) ros.start(config) return True
config.generator_house_expo = False analyzer_start = False config.generator_size = 64 # Change the size of the maps generated # Cache config.clear_cache = True # Generator mp = maps[chosen_map] # Chooses map for generation # Simulator config.load_simulator = sim_start config.simulator_graphics = False config.simulator_initial_map = mp config.simulator_algorithm_type, config.simulator_testing_type, config.simulator_algorithm_parameters = algo config.simulator_key_frame_speed, config.simulator_key_frame_skip = ani config.simulator_write_debug_level = debug # These are for training config.generator_labelling_features = labelling[training_algo][0] config.generator_labelling_labels = labelling[training_algo][1] config.generator_single_labelling_features = labelling[training_algo][2] config.generator_single_labelling_labels = labelling[training_algo][3] config.generator_aug_labelling_features = [] config.generator_aug_labelling_labels = [] config.generator_aug_single_labelling_features = [] config.generator_aug_single_labelling_labels = [] config.generator_modify = None config.generator_show_gen_sample = show_sample_map