def main(): args = parser.parse_args() bounds, ghosts, pacman, goal = mapPositions(args.layout) print('Barreiras:', bounds) print('Fantasmas:', ghosts) print('Pacman:', pacman) print('Gol:', goal) print() #Problema e algoritmos problem = PacmanProblem(obstacles=bounds | ghosts, initial=pacman, goal=goal) gfsProblem = greedy_best_first_search(problem) astarProblem = astar_search(problem) bfsProblem = breadth_first_graph_search(problem) dfsProblem = depth_first_graph_search(problem) print('Greedy Best First Search:') print('Caminho:', gfsProblem.path()) print('Gol:', gfsProblem) print('A* Search:') print('Caminho:', astarProblem.path()) print('Gol:', astarProblem) print('Breadth-First Search:') print('Caminho:', bfsProblem.path()) print('Gol:', dfsProblem) print('Depth-First Search:') print('Caminho:', dfsProblem.path()) print('Gol:', dfsProblem) print() print('Gerando saídas...') generateOutput(gfsProblem.path(), args.layout, 'gfs') generateOutput(astarProblem.path(), args.layout, 'astar') generateOutput(dfsProblem.path(), args.layout, 'bfs') generateOutput(dfsProblem.path(), args.layout, 'dfs') print() print('Desempenho:') report([ greedy_best_first_search, astar_search, breadth_first_graph_search, depth_first_graph_search ], [problem])
print("Running UNIFORM-COST-TREE-SEARCH") print('-' * 50) ucts = uniform_cost_search(ep, search_type=best_first_tree_search) print("Solution", ucts.solution()) print() print('-' * 50) print( "Running GREEDY-BEST-FIRST-TREE-SEARCH USING # MISPLACED TILES HEURISTIC" ) print('-' * 50) gbfts = greedy_best_first_search(ep, misplaced_tiles_heuristic, search_type=best_first_tree_search) print("Solution", gbfts.solution()) print() print('-' * 50) print("Running A*-TREE-SEARCH USING # MISPLACED TILES HEURISTIC") print('-' * 50) asts = astar_search(ep, misplaced_tiles_heuristic, search_type=best_first_tree_search) print("Solution", asts.solution())
import search from graph import Graph if __name__ == "__main__": # Setting graph we initiated to search class... graph = Graph() search.graph = graph search.depth_first_search() search.breath_first_search() search.iterative_deepening_search() search.uniform_cost_search() search.greedy_best_first_search() search.a_star_search()
print() print('-' * 50) print("Q3: UNIFORM-COST-GRAPH-SEARCH") print('-' * 50) ucs = uniform_cost_search(travel_problem, search_type=best_first_graph_search) print("Solution", ucs.solution()) print() print('-' * 50) print("Q4: GREEDY-BEST-FIRST-TREE-SEARCH") print('-' * 50) gbfs = greedy_best_first_search(travel_problem, city_h, search_type=best_first_tree_search) print("Solution", gbfs.solution()) print() print('-' * 50) print("Q5: A*-TREE-SEARCH") print('-' * 50) asts = astar_search(travel_problem, city_h, search_type=best_first_tree_search) print("Solution", asts.solution())
def main(): args = parser.parse_args() bounds, ghosts, pacman, goal = mapPositions(args.layout) print('Barreiras:', bounds) print('Fantasmas:', ghosts) print('Pacman:', pacman) print('Gol:', goal) print() #Problema e algoritmos problem = PacmanProblem(obstacles=bounds | ghosts, initial=pacman, goal=goal) gfsProblem = greedy_best_first_search(problem) astarProblem = astar_search(problem) bfsProblem = breadth_first_graph_search(problem) dfsProblem = depth_first_graph_search(problem) hcProblem = hill_climbing(problem) print('Greedy Best First Search:') print('Caminho:', gfsProblem.path()) print('Gol:', gfsProblem) print('A* Search:') print('Caminho:', astarProblem.path()) print('Solução:', astarProblem.solution()) print('Estados:', path_states(astarProblem)) print('Gol:', astarProblem) print('Breadth-First Search:') print('Caminho:', bfsProblem.path()) print('Solução:', bfsProblem.solution()) print('Estados:', path_states(bfsProblem)) print('Gol:', dfsProblem) print('Depth-First Search:') print('Caminho:', dfsProblem.path()) print('Solução:', dfsProblem.solution()) print('Estados:', path_states(dfsProblem)) print('Gol:', dfsProblem) print('Hill Climbing:') print('Caminho:', hcProblem.path()) print('Solução:', hcProblem.solution()) print('Estados:', path_states(hcProblem)) print('Gol:', dfsProblem) print() print('Gerando saídas...') generateOutput( set(gfsProblem.solution()) - {pacman, goal}, gfsProblem.explored - {pacman, goal}, args.layout, 'gfs') generateOutput( set(astarProblem.solution()) - {pacman, goal}, astarProblem.explored - {pacman, goal}, args.layout, 'astar') generateOutput( set(bfsProblem.solution()) - {pacman, goal}, bfsProblem.explored - {pacman, goal}, args.layout, 'bfs') generateOutput( set(dfsProblem.solution()) - {pacman, goal}, dfsProblem.explored - {pacman, goal}, args.layout, 'dfs') generateOutput( set(hcProblem.solution()) - {pacman, goal}, hcProblem.explored - {pacman, goal}, args.layout, 'hc') print() print('Desempenho:') report([ greedy_best_first_search, astar_search, breadth_first_graph_search, depth_first_graph_search, hill_climbing ], [problem])
print print '-' * 50 print "Running UNIFORM-COST-TREE-SEARCH" print '-' * 50 ucts = uniform_cost_search(ep, search_type=best_first_tree_search) print "Solution", ucts.solution() print print '-' * 50 print "Running GREEDY-BEST-FIRST-TREE-SEARCH USING # MISPLACED TILES HEURISTIC" print '-' * 50 gbfts = greedy_best_first_search(ep, misplaced_tiles_heuristic, search_type=best_first_tree_search) print "Solution", gbfts.solution() print print '-' * 50 print "Running A*-TREE-SEARCH USING # MISPLACED TILES HEURISTIC" print '-' * 50 asts = astar_search(ep, misplaced_tiles_heuristic, search_type=best_first_tree_search) print "Solution", asts.solution() print print '=' * 50 print '=' * 50
print print '-' * 50 print "Running UNIFORM-COST-GRAPH-SEARCH" print '-' * 50 ucs = uniform_cost_search(travel_problem, search_type=best_first_graph_search) print "Solution", ucs.solution() print print '-' * 50 print "Running GREEDY-BEST-FIRST-TREE-SEARCH" print '-' * 50 gbfs = greedy_best_first_search(travel_problem, city_h, search_type=best_first_tree_search) print "Solution", gbfs.solution() print print '-' * 50 print "Running A*-TREE-SEARCH" print '-' * 50 asts = astar_search(travel_problem, city_h, search_type=best_first_tree_search) print "Solution", asts.solution() print print '=' * 50