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 _setup_sim(self, config: Optional[Configuration] = None, goal: Optional[Point] = None) -> Simulator: """ Sets up the simulator (e.g. algorithm and map configuration). """ while self.grid is None or self.agent is None: rospy.loginfo("Waiting for grid and agent to initialise...") rospy.sleep(0.5) if config is None: config = Configuration() # general config.simulator_graphics = True config.simulator_key_frame_speed = 0.16 config.simulator_key_frame_skip = 20 config.get_agent_position = lambda: self._world_to_grid( Point(self.agent.pose.position.x, self.agent.pose.position.y)) config.visualiser_simulator_config = False # hide the simulator config window # algorithm if config.algorithm_name is None: config.algorithm_name = "WPN-view" config.simulator_algorithm_type, config.simulator_testing_type, config.simulator_algorithm_parameters = config.algorithms[ config.algorithm_name] # map goal = Goal(Point(0, 0) if goal is None else goal) agent = Agent(self._world_to_grid( Point(self.agent.pose.position.x, self.agent.pose.position.y)), radius=self.INFLATE) mp = RosMap(agent, goal, lambda: self.grid, traversable_threshold=self.TRAVERSABLE_THRESHOLD, unmapped_value=-1, wp_publish=self._send_way_point, update_requested=self._map_update_requested, name="ROS Map") config.maps = {mp.name: mp} config.simulator_initial_map = list(config.maps.values())[0] config.map_name = list(config.maps.keys())[0] # create the simulator s = Services(config) s.algorithm.map.request_update() sim = Simulator(s) return sim
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 _setup_sim(self, config: Optional[Configuration] = None) -> Simulator: """ Sets up the simulator (e.g. algorithm and map configuration). """ while self.grid is None: rospy.loginfo("Waiting for grid to initialise...") rospy.sleep(0.5) if config is None: config = Configuration() # general config.simulator_graphics = True config.simulator_key_frame_speed = 0.16 config.simulator_key_frame_skip = 20 config.visualiser_simulator_config = False # hide the simulator config window # algorithm if config.algorithm_name is None: config.algorithm_name = "A*" config.simulator_algorithm_type, config.simulator_testing_type, config.simulator_algorithm_parameters = config.algorithms[ config.algorithm_name] # map mp = RosMap(Agent(Point(40, 40)), Goal(Point(30, 20)), lambda: self.grid, traversable_threshold=0.4, name="ROS Map") config.maps = {mp.name: mp} config.simulator_initial_map = list(config.maps.values())[0] config.map_name = list(config.maps.keys())[0] # create the simulator s = Services(config) s.algorithm.map.request_update() sim = Simulator(s) return sim
def __init__(self, configuration: Configuration): self.main_services: Services = Services(configuration) self.run = self.main_services.debug.debug_func(DebugLevel.BASIC)( self.run)