Пример #1
0
 def decode(self, ciphertext):
     "Search for a decoding of the ciphertext."
     self.ciphertext = ciphertext
     problem = PermutationDecoderProblem(decoder=self)
     return search.best_first_tree_search(problem, self.score)
Пример #2
0
    def h2(node):
        #count = 0
        for (i, j) in node.state.iter_empty_cell():
            if len(list(node.state.possible_values(i, j))) == 0:
                return None
        if node.action:
            (i, j, val) = node.action
            possibilities = list(node.state.possible_values(i, j))
            return len(possibilities) - 1
        return 0

    choices = {
        'depth_first': depth_first_tree_search,
        # 'best_first_uniform': uniform_cost_tree_search,
        'best_first_h1': lambda x: best_first_tree_search(x, h1),
        'best_first_h2': lambda x: best_first_tree_search(x, h2),
        'best_first_greedy_h1': lambda x: best_first_greedy_tree_search(x, h1),
        'best_first_greedy_h2': lambda x: best_first_greedy_tree_search(x, h2),
        'best_first_h3': lambda x: best_first_tree_search(x, h3),
        'best_first_greedy_h3': lambda x: best_first_greedy_tree_search(x, h3),
        'best_first_graph_h1': lambda x: best_first_graph_search(x, h1),
        'best_first_graph_h2': lambda x: best_first_graph_search(x, h2),
        'hill_climbing': lambda x: hill_climbing(x),
        'annealing': lambda x: simulated_annealing(x, schedule=sim)
    }

    #    print(sys.argv)
    searchers = sys.argv[1:]
    lewisProblems = map(LewisSudokuProblem, sudokus)
    naiveProblems = map(SudokuProblem, sudokus)
Пример #3
0
 def decode(self, ciphertext):
     "Search for a decoding of the ciphertext."
     self.ciphertext = ciphertext
     problem = PermutationDecoderProblem(decoder=self)
     return search.best_first_tree_search(problem, self.score)
Пример #4
0
 def decode(self, ciphertext):
     """Search for a decoding of the ciphertext."""
     self.ciphertext = ciphertext
     problem = PermutationDecoderProblem(decoder=self)
     return search.best_first_tree_search(
         problem, lambda node: self.score(node.state))