本文整理汇总了Python中solver.Solver.search方法的典型用法代码示例。如果您正苦于以下问题:Python Solver.search方法的具体用法?Python Solver.search怎么用?Python Solver.search使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类solver.Solver
的用法示例。
在下文中一共展示了Solver.search方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: solve_blocksword_puzzle
# 需要导入模块: from solver import Solver [as 别名]
# 或者: from solver.Solver import search [as 别名]
def solve_blocksword_puzzle():
solver = Solver()
algorithms = [
('bfs', 'BFS'),
# ('dfs', 'DFS'),
('id_dfs', 'Iterative Deepening DFS'),
('a_star', 'A* (Heuristic: Sum of Manhattan distances)'),
]
total_results = {
'bfs': {
'times': [],
'iterations': [],
'moves': [],
'queue_size': []
},
'dfs': {
'times': [],
'iterations': [],
'moves': [],
'queue_size': []
},
'id_dfs': {
'times': [],
'iterations': [],
'moves': [],
'queue_size': []
},
'a_star': {
'times': [],
'iterations': [],
'moves': [],
'queue_size': []
}
}
for i in range(10):
print("")
print(i)
for algorithm, output_text in algorithms:
stdout.write(output_text)
result = solver.search(algorithm)
total_seconds = get_seconds(result.total_time)
total_results[algorithm]['times'].append(total_seconds)
total_results[algorithm]['iterations'].append(result.total_iters)
total_results[algorithm]['moves'].append(result.moves_count)
total_results[algorithm]['queue_size'].append(result.queue_size)
print_search_result(result)
plot_times({
'bfs': total_results['bfs']['times'],
'id_dfs': total_results['id_dfs']['times'],
'a_star': total_results['a_star']['times']
}, 85, 'Search Algorithms Execution Times')
plot_iterations({
'bfs': total_results['bfs']['iterations'],
'id_dfs': total_results['id_dfs']['iterations'],
'a_star': total_results['a_star']['iterations']
}, 1600000, title='Search Algorithms Total Iterations')
plot_queue_sizes({
'bfs': total_results['bfs']['queue_size'],
'id_dfs': total_results['id_dfs']['queue_size'],
'a_star': total_results['a_star']['queue_size']
}, 100000, title='Search Algorithms Queue Size at execution end')
plot_moves({
'bfs': total_results['bfs']['moves'],
'id_dfs': total_results['id_dfs']['moves'],
'a_star': total_results['a_star']['moves']
}, title='Search Algorithms Total Moves')