m.successors) if solution_dfs == None: print("No solution using dfs") else: path_dfs: List[MazeLocation] = node_to_path(solution_dfs) m.mark(path_dfs) print(m) m.clear(path_dfs) #Testing breadth first search solution_bfs: Optional[Node[MazeLocation]] = bfs(m.start, m.goal_test, m.successors) if solution_bfs == None: print("No solution using bfs") else: path_bfs: List[MazeLocation] = node_to_path(solution_bfs) m.mark(path_bfs) print(m) m.clear(path_bfs) #Testing A* distance: Callable[[MazeLocation], float] = euclidean_distance(m.goal) solution_astar_euclidean: Optional[Node[MazeLocation]] = astar( m.start, m.goal_test, m.successors, distance) if solution_astar_euclidean is None: print("No solution found using A*") else: path_astar_euclidean: List[MazeLocation] = node_to_path( solution_astar_euclidean) m.mark(path_astar_euclidean) print(m)
= dfs(m.start, m.goal_test, m.successors) if solution1 is None: print("No solution found using depth-first search!") else: path1: List[MazeLocation] = node_to_path(solution1) m.mark(path1) print(m) m.clear(path1) # Test BFS solution2: Optional[Node[MazeLocation]] \ = bfs(m.start, m.goal_test, m.successors) if solution2 is None: print("No solution found using breadth-first search!") else: path2: List[MazeLocation] = node_to_path(solution2) m.mark(path2) print(m) m.clear(path2) # Test A* distance: Callable[[MazeLocation], float] = manhattan_distance(m.goal) solution3: Optional[Node[MazeLocation]] \ = astar(m.start, m.goal_test, m.successors, distance) if solution3 is None: print("No solution found using A*!") else: path3: List[MazeLocation] = node_to_path(solution3) m.mark(path3) print(m)
print(m) m.clear(path1) # Test BFS solution2: Optional[Node[MazeLocation]] = bfs(m.start, m.goal_test, m.successors) if solution2 is None: print("No solution found using breadth-first search!") else: path2: List[MazeLocation] = node_to_path(solution2) m.mark(path2) print(m) m.clear(path2) # Test A* manhattan distance: Callable[[MazeLocation], float] = manhattan_distance(m.goal) solution3: Optional[Node[MazeLocation]] = astar(m.start, m.goal_test, m.successors, distance) if solution3 is None: print("No solution found using A* [manhattan]!") else: path3: List[MazeLocation] = node_to_path(solution3) m.mark(path3) print(m) m.clear(path3) # Test A* euclidean distance = euclidean_distance(m.goal) solution4: Optional[Node[MazeLocation]] = astar(m.start, m.goal_test, m.successors, distance) if solution4 is None: print("No solution found using A* [euclidean]!") else:
print(maze) maze.clear(path1) print('\n\n') solution2: typing.Optional[Node[MazeLocation]] = bfs( maze.start, maze.goal_test, maze.successors) if solution2 is None: print("No solution found") else: path2: typing.List[MazeLocation] = node_to_path(solution2) maze.mark(path2) print(maze) maze.clear(path2) print('\n\n') solution3: typing.Optional[Node[MazeLocation]] = astar( maze.start, maze.goal_test, maze.successors, euclidian_distance(maze.goal)) if solution3 is None: print("No solution found") else: path3: typing.List[MazeLocation] = node_to_path(solution3) maze.mark(path3) print(maze) maze.clear(path3) print('\n\n') solution4: typing.Optional[Node[MazeLocation]] = astar( maze.start, maze.goal_test, maze.successors, manhattan_distance(maze.goal)) if solution4 is None: print("No solution found") else: path4: typing.List[MazeLocation] = node_to_path(solution4)
start = time.time() node = bfs(initial=m.start, goal_test=m.is_goal, successors=m.successors) end = time.time() path = node_to_path(node) print(f"Path length: {len(path)}, Time: {end - start}") if path: m.mark(path) print(m) else: print(m) print("Unsolvable") m.clear() print("A* search solution") start = time.time() node = astar( initial=m.start, goal_test=m.is_goal, successors=m.successors, heuristic=manhattan_distance(m.goal), ) end = time.time() path = node_to_path(node) print(f"Path length: {len(path)}, Time: {end - start}") if path: m.mark(path) print(m) else: print(m) print("Unsolvable")
solution2: Optional[Node[MazeLocation]] = bfs(maze.start, maze.goal_test, maze.sucessors) if solution2 is None: print("Bread-first search não achou uma solução") else: print("Bread-first") path2: List[MazeLocation] = node_to_path(solution2) maze.mark(path2) print(maze) maze.clear(path2) distance: Callable[[MazeLocation], float] = manhattan_distance(maze.goal) solution3: Optional[Node[MazeLocation]] = astar(maze.start, maze.goal_test, maze.sucessors, distance) if solution3 is None: print("A star não achou uma solução") else: print("A star") path3: List[MazeLocation] = node_to_path(solution3) maze.mark(path3) print(maze) maze.clear(path3)