def generate_data(self, num_iterations, remaining, num_alternatives, plot_maps=False, plot_limit=10): maps = [] goals = [] plot_count = 0 # Generate the cost_map cost_map = CostMap(self.width, self.height) cost_map.create_random_map(self.obstacle_width, self.obstacle_height, self.num_obstacles) # Generate the possible goals (alternatives) self.generate_goals(cost_map, num_alternatives) for i in range(num_iterations): if i != 0: if not self.one_map: # Update cost_map and possible goals (alternatives) cost_map = CostMap(self.width, self.height) cost_map.create_random_map(self.obstacle_width, self.obstacle_height, self.num_obstacles) self.generate_goals(cost_map, num_alternatives) elif not self.static_alternatives: # Update just the possible goals (alternatives) self.generate_goals(cost_map, num_alternatives) paths = self.generate_paths(cost_map) for path in paths: planner_map, planner_goal = self.write_alternatives_on_map(path[-1], cost_map, num_alternatives) planner_partial_path = self.cut_path(path, remaining) planner_map = self.write_path_on_map(planner_partial_path, planner_map) if plot_maps and plot_count < plot_limit: self.plot_map(planner_map, planner_goal) plot_count += 1 goals.append(planner_goal) maps.append(planner_map) maps, goals = shuffle(maps, goals, random_state=0) return maps, goals
if save_fig: plt.savefig('%s.%s' % (filename, fig_format), format=fig_format) if show_fig: plt.show() # Environment's parameters WIDTH = 160 HEIGHT = 120 OBSTACLE_WIDTH = 20 OBSTACLE_HEIGHT = 15 NUM_OBSTACLES = 20 cost_map = CostMap(WIDTH, HEIGHT) # Initializing the random seed so we have reproducible results # Please, do not change the seed random.seed(15) # Create a random map cost_map.create_random_map(OBSTACLE_WIDTH, OBSTACLE_HEIGHT, NUM_OBSTACLES) # Create the path planner using the cost map path_planner = PathPlanner(cost_map) # These vectors will hold the computation time and path cost for each iteration, # so we may compute mean and standard deviation statistics in the Monte Carlo analysis. times = np.zeros((num_iterations, 1)) costs = np.zeros((num_iterations, 1)) for i in range(num_iterations): problem_valid = False while not problem_valid: # Trying to generate a new problem