def test_best_first_search_finds_best_solution(self): possible_shortest_paths = { ((1, 0), (1, 1), (2, 2), (2, 3), (3, 4), (4, 5), (5, 5)), ((1, 0), (1, 1), (2, 2), (2, 3), (3, 4), (4, 4), (5, 5)) } found_path = Bfs.a_star(self.board_spec[1], self.board_spec[2], self.board.get_successors, Board.distance_between, Board.distance_between)['solution'] self.assertIn(found_path, possible_shortest_paths)
'Open', 'Passed', 'Assumptions for solution', 'Time (secs)'])) if __name__ == '__main__': f = open(sys.argv[1]) spec = f.readlines() for i in range(len(spec)): row_as_strings = spec[i].strip().split() for j in range(len(row_as_strings)): row_as_strings[j] = int(row_as_strings[j]) spec[i] = row_as_strings a = time() ngp = NGP(spec) for i in range(2, len(sys.argv)): ngp.create_constraint_from_text(sys.argv[i]) ngp.initialize_queue_and_filter() gfx = Gfx(ngp, 1, (500, 500)) result = BFS.a_star(ngp, NGP.all_domains_have_size_one, lambda x, y: 0, NGP.domain_sizes_minus_one, gui_function=gfx.draw) b = time() result['current'].print_final_solution() print_statistics_to_console(result, a, b) sleep(5)
passed_nodes, len(results['solution'])-1, round(end_time-start_time, 2)]) print(tabulate(table_data, headers=['Total', 'Closed', 'Open', 'Passed', 'Assumptions for solution', 'Time (secs)'])) if __name__ == '__main__': f = open(sys.argv[1]) k = int(sys.argv[2]) spec = f.readlines() for i in range(len(spec)): spec[i] = spec[i].strip().split() vcp = VCP(spec, k) for i in range(3, len(sys.argv)): vcp.create_constraint_from_text(sys.argv[i]) vcp.initialize_queue_and_filter() gfx = Gfx(vcp, 100, (800, 800)) a = time() result = BFS.a_star(vcp, VCP.all_domains_have_size_one, lambda x, y: 0, VCP.domain_sizes_minus_one, mode='best_first', gui_function=gfx.draw) b = time() print_statistics_to_console(result, a, b) sleep(5)