def main(): n = 5 main_grid = generate_grid(n, 100) val, path = find_path_recursive(main_grid, 0, 0, "", main_grid[0][0]) print_grid(main_grid) print("--------") print(val) print_path(path)
def main(): n = 3 grid = generate_grid(n, 100) val, path = find_path_bidirectional(grid, False) print_map(grid) print("-----") print(val) print_path(path)
def run_time_analysis(function, n): times = list() for x in range(2, n + 1): t0 = time.time() main_grid = generate_grid(n) function(main_grid) t1 = time.time() total = t1 - t0 times.append((x, total)) return times
def accuracy_analysis(num_trials, n, max_range): avg_error = list() for x in range(0, num_trials): main_grid = generate_grid(n, max_range) val, path = find_path_recursive(main_grid, 0, 0, "", main_grid[0][0]) val1, path1 = find_path_a_star(main_grid) res = (val - val1) / val avg_error.append(res) return sum(avg_error) / len(avg_error)
sum_res += grid[x][y] return sum_res, path def sum_row(grid, x, y, n, sum_type): sum_res = 0 num_cells = (n - y) if sum_type == "right" else (n - x) n += 1 if sum_type == "right": y += 1 for z in range(y, n): sum_res += grid[x][z] elif sum_type == "down": x += 1 for x in range(x, n): sum_res += grid[x][y] return float(sum_res) / (num_cells) if __name__ == '__main__': n = 20 grid = generate_grid(n, 50) val, path = find_path_heuristic(grid) print_map(grid) print("----------") print(val) print_path(path)
if curr_val > best_val: best_val, best_path = curr_val, curr_path curr_val -= grid[popped_cell.x][popped_cell.y] curr_path = curr_path[:len(my_stack) - 1] continue if cell.x < n and not cell.down_expanded: cell.down_expanded = True curr_val += grid[cell.x + 1][cell.y] curr_path.append("D") my_stack.append(GridCell(cell.x + 1, cell.y, n)) elif cell.y < n and not cell.right_expanded: cell.right_expanded = True curr_val += grid[cell.x][cell.y + 1] curr_path.append("R") my_stack.append(GridCell(cell.x, cell.y + 1, n)) return best_val, best_path if __name__ == '__main__': n = 2 grid = generate_grid(n, 100) val, path = find_path_dfs(grid) print_map(grid) print("-----") print(val) print_path(path)