コード例 #1
0
    def HillClimbing(self, n):
        p = Problem(n)
        queue = p.getMatrix()
        listOfPermutations = p.getListOfPermutations()
        print("I am going to print the best solution found: ")

        possible_solution = []
        row = 1
        while queue:
            row_state = queue.pop()

            next_state, listOfPermutations = p.expand(row_state,
                                                      listOfPermutations, row)
            possible_solution.append(next_state)

            print(possible_solution)
            time.sleep(0.5)

            row += 1

        fitnessOptim = p.fitness(possible_solution, n)
        p = PrettyTable()
        for row in possible_solution:
            p.add_row(row)
        pretty = p.get_string(header=False, border=False)

        return pretty, fitnessOptim