def test_population(new_maze_population): print "--------------------" print "Population Solvability Check" for curr_maze_count in range(new_maze_population.qsize()): curr_maze = new_maze_population.queue[curr_maze_count] curr_maze_result_dict = dfs_traversal(copy.deepcopy(curr_maze[1]), dim) if not curr_maze_result_dict["is_solvable"]: print "ERROR!!!" maze_runner.visualize_maze(copy.deepcopy(curr_maze[1])) print curr_maze_result_dict["max_fringe_length"] print "--------------------"
def test_a_star(dim, p): test_maze = maze_runner.get_maze(dim, p) # a-star with manhattan heuristic maze = copy.deepcopy(test_maze) manhattan_result_dict = a_star_traversal(maze, "manhattan") if manhattan_result_dict["is_solvable"]: path = maze_runner.get_path(dim - 1, dim - 1, maze) print "Path", path print "Length of path: ", len(path) maze_runner.trace_path(maze, path) else: maze_runner.visualize_maze(maze) # a-star with euclidian heuristic maze = copy.deepcopy(test_maze) euclidian_result_dict = a_star_traversal(maze, "euclidian") if euclidian_result_dict["is_solvable"]: path = maze_runner.get_path(dim - 1, dim - 1, maze) print "Path", path print "Length of path: ", len(path) maze_runner.trace_path(maze, path) else: maze_runner.visualize_maze(maze)
maze_runner.visualize_maze(maze) # a-star with euclidian heuristic maze = copy.deepcopy(test_maze) euclidian_result_dict = a_star_traversal(maze, "euclidian") if euclidian_result_dict["is_solvable"]: path = maze_runner.get_path(dim - 1, dim - 1, maze) print "Path", path print "Length of path: ", len(path) maze_runner.trace_path(maze, path) else: maze_runner.visualize_maze(maze) #Fire code ''' dim = 50 p = 0.306 q = 0.1 maze = maze_runner.get_maze(dim, p) maze_runner.visualize_maze(maze) manhattan_result, manhattan_steps, manhattan_max_fringe_length, manhattan_avg_fringe_length, manhattan_closed_set, x_cord, y_cord = a_star_traversal_with_fire(maze, "manhattan", q) maze_runner.visualize_maze(maze) if manhattan_result == 1: print "Solution found" path = maze_runner.get_path(dim-1, dim-1, maze) maze_runner.trace_path(maze, path) elif manhattan_result == 0: print "Solution not found" maze_runner.visualize_maze(maze) else:
columns=column_list, index=[generation_count]) generation_stats_df = generation_stats_df.append(df_entry) print "fitness of the fittest maze: ", fitness_fittest print "average fitness of the new population: ", fitness_average """ Approach1: We take the weakest 10% of the popluation to the new population # print "fitness of fittest: ", fitness_fittest # print "average fitness of fittest population: ", fitness_average # while maze_population.qsize()>worst_mazes_count: # maze_population.get() # for count in range(worst_mazes_count): # (fitness, maze) = maze_population.get() # if count == worst_mazes_count-1 # fitness_worst = fitness # new_maze_population.put((fitness, copy.deepcopy(maze))) """ maze_population = new_maze_population print generation_stats_df generation_stats_df.to_csv("generation_tmp.csv") hardest_maze = maze_population.get() print "fitness of the hardest maze: ", hardest_maze[0] maze_runner.visualize_maze(hardest_maze[1]) hardest_maze_result_dict = a_star_traversal(copy.deepcopy(hardest_maze[1]), "manhattan") maze_runner.visualize_explored_cells(hardest_maze[1], hardest_maze_result_dict["closed_set"]) pdb.set_trace()
if fringe_len>max_fringe_length: max_fringe_length = fringe_len avg_fringe_length = avg_fringe_length + (fringe_len - avg_fringe_length)/exploration_steps closed_set.add((x,y)) # Spreads fire to the neighboring cell as mentioned in the question. Since we might have # more cells on fire, the boundary_cells also get updated maze, boundary_cells = spread_fire(maze, dim, q, boundary_cells) fringe = update_fringe_using_boundary_cells(fringe, maze, boundary_cells) # No Solution return 0, exploration_steps, max_fringe_length, avg_fringe_length, closed_set, -1, -1 # Main code dim = 30 p = 0.22 q = 0.2 maze = mr.get_maze(dim, p) mr.visualize_maze(maze) manhattan_result, manhattan_steps, manhattan_max_fringe_length, manhattan_avg_fringe_length, manhattan_closed_set, x_cord, y_cord = fire_traversal(maze, q) mr.visualize_maze(maze) if manhattan_result == 1: print "Solution found" path = mr.get_path(dim-1, dim-1, maze) mr.trace_path(maze, path) elif manhattan_result == 0: print "Solution not found" mr.visualize_maze(maze) else: print "Burnt at " + str(x_cord) + ", " + str(y_cord) maze[x_cord][y_cord].value = 1.5 path = mr.get_path(x_cord, y_cord, maze) mr.trace_path(maze, path)