def runtime_of_dirts_test(): width = 20 height = 20 robots_num = 3 log_name = create_new_file_name('.'.join( ['runtime_of_dirts', str(date.today()), 'data'])) log = open(log_name, 'w') problem = generate_hard_board(width, height, robots_num) problem.dirt_locations = frozenset() prevent_list = list(problem.obstacle_locations) + list(problem.robots) msg(str(problem), log) print 'GOING TO TEST HEURISTICS WITH A-STAR-ALGORITHM AND ALGORITHMS WITH IGNORE-OBSTACLES-HEURISTIC' d = { OneDirtPerRobotHeuristic.__name__: [], DirtsDivisionHeuristic.__name__: [], BeamSearch.__name__: [], AStar.__name__: [] } for dirt_num in range(3, 100): problem.dirt_locations = frozenset( generate_elms(width, height, prevent_list, dirt_num)) for h in [OneDirtPerRobotHeuristic, DirtsDivisionHeuristic]: start = time.clock() AStar(max_depth=infinity).find(problem, h()) runtime = time.clock() - start d[h.__name__].append((dirt_num, runtime / dirt_num)) if h.__name__ == OneDirtPerRobotHeuristic.__name__: d[AStar.__name__].append((dirt_num, runtime / dirt_num)) start = time.clock() BeamSearch(max_depth=infinity, beam_width=15).find(problem, OneDirtPerRobotHeuristic()) runtime = time.clock() - start d[BeamSearch.__name__].append((dirt_num, runtime / dirt_num)) msg('runtime_of_dirts_dict = ' + str(d), log) print 'runtime_of_dirts_test done! see results in log'