print(" ".join(line)) def testLocalSearch(self, problem, local_search): # times = 10 # cnt = 0 # start = time() # for i in range(times): result = local_search(problem) build = test.make_board(size, result) test.printBoard(build) from hill_climbing import hill_climbing from GA import GA from simulated_annealing import simulated_annealing from NQueens import NQueensSearch if __name__ == "__main__": test = TestLocalSearch() print("Running local search for N Queens Problem") size = eval(input(" - Please input the size of the board: ")) print() problem = NQueensSearch(size) algorithms = [hill_climbing, simulated_annealing, GA] names = ["hill_climbing", "simulated_annealing", "GA"] problems = [problem, problem, problem] for i in range(len(algorithms)): print(names[i]) board = test.testLocalSearch(problems[i], algorithms[i])
from hill_climbing import hill_climbing from hill_climbing import random_restart from simulated_annealing import simulated_annealing from NQueens import NQueensSearch if __name__ == "__main__": # Parametros str = "N-queens problem solver by using local search algorithms.\n\t Author: Vitor Veras.\t Default arguments: -n=8 ; -i=10 ; --all=0" parser = argparse.ArgumentParser(description=str) parser.add_argument("-n", type=int, default=8, help="Size of the board") parser.add_argument("-i", type=int, default=10, help="Number of iterations") parser.add_argument("--all", type=int, dest='all', action='store', choices=range(0, 2), default=0, help="0 = show one solution | 1 = show all solutions") args = parser.parse_args() # Inicia a busca test = localSearch() # Inicia o problema passando o tamanho do tabuleiro problem = NQueensSearch(args.n) algorithms = [hill_climbing, random_restart] names = ["hill_climbing", "hc_random_restart"] problems = [problem, problem, problem] for i in range(len(algorithms)): print(names[i]) result_board = test.localSearch(problems[i], algorithms[i], args.i) # Imprime um tabuleiro com base no argumento --all passado printBoard(result_board, args.all)