def cpp_test(G, v_I, v_W, v_F, min_cost): res = Mstar(G, v_I, v_W, v_F, False).solve() if res[1] < min_cost: print(res[1]) assert res[1] < min_cost or math.isclose(res[1], min_cost) paths = res[0] for i in range(len(v_I)): assert v_I[i] == list(paths[i][0]) for i in range(len(v_W)): if len(v_W[i]) > 0: for waypoint in v_W[i]: if waypoint != [-1, -1]: assert tuple(waypoint) in paths[i] for i in range(len(v_F)): assert v_F[i] == list(paths[i][-1]) @pytest.mark.parametrize( "test_id", get_all_benchmarks(without=[10, 19, 21, 23, 24, 54, 58, 59, 61])) def test_cpp_benchmark(test_id): benchmarker = MapfwBenchmarker("42cf6ce8D2A5B954", test_id, "M*", "Test", True) for problem in benchmarker: cpp_waypoints = problem.waypoints for i in range(len(cpp_waypoints)): if len(cpp_waypoints[i]) == 0: cpp_waypoints[i] = [[-1, -1]] cpp_test(problem.grid, problem.starts, cpp_waypoints, problem.goals, min_cost[test_id])
neighbours = [] if i != 0 and problem.grid[i - 1][j] == 0: neighbours.append((j, i - 1)) if j != 0 and problem.grid[i][j - 1] == 0: neighbours.append((j - 1, i)) if i != problem.height - 1 and problem.grid[i + 1][j] == 0: neighbours.append((j, i + 1)) if j != problem.width - 1 and problem.grid[i][j + 1] == 0: neighbours.append((j + 1, i)) grap_new[current] = neighbours # Create V_I and v_F v_I = tuple(tuple(start) for start in problem.starts) v_W = [] for agent_waypoints in problem.waypoints: if len(agent_waypoints) > 0: v_W_i = [] for waypoint in agent_waypoints: v_W_i.append(tuple(tuple(waypoint))) v_W.append(v_W_i) else: v_W.append(()) v_W = tuple(v_W) v_F = tuple(tuple(target) for target in problem.goals) return grap_new, v_I, v_W, v_F @pytest.mark.parametrize("test_id", get_all_benchmarks(without=[10, 19, 21, 23, 24, 54, 58, 59, 61])) def test_python_benchmark(test_id): benchmarker = MapfwBenchmarker("42cf6ce8D2A5B954", test_id, "M*", "Test", True) for problem in benchmarker: graph, v_I, v_W, v_F = setup_benchmark(problem) python_test(graph, v_I, v_W, v_F, min_cost[test_id])
77, 54, 112000, 18, np.nan, 210, 7030, 88, 857, np.nan, 4280, 92, 11990, 13760, 516, np.nan, 1980, np.nan, 7, 6660, 154 ] MLA_times = [ 1, 1, 6, np.nan, 53, 1, 35, 134, 228, 385, 7, 12, 2, 1, 13, 17, 8, 3, 861, np.nan, 20, 23, 45, 244, 14, 9, 27, np.nan, np.nan, 104, np.nan, 246, np.nan, 6, np.nan ] BCP_times = [ 11, 172, 13, 45, 341, 28, np.nan, np.nan, np.nan, 30940, 17, 49, 30, np.nan, 30, 27, 385, 24, np.nan, 15, 38, 9, 922, 1460, 494, 14, 2320, 8710, 67, 2549000, 247, 653000, 12, 599, 6930 ] y_axis = ["WM*", "inflated WM*", "CBS", "MLA*", "A*+OD+ID", "BCP"] x_axis = sorted(get_all_benchmarks(without=[54, 58, 77, 78])) zipper = zip(Mstar_times, Mstar_inflated_times, CBS_times, MLA_times, Astar_times, BCP_times) data = [] remove = [] for i in range(len(y_axis)): data.append([]) for i, benchmark in enumerate(zipper): optimal = np.nanmin(benchmark) if all(val == optimal or np.isnan(val) for val in benchmark): remove.append(i) else: for i in range(len(benchmark)): if (benchmark[i] - optimal) == 0: data[i].append(1)