-
Notifications
You must be signed in to change notification settings - Fork 2
/
04__prepare.py
92 lines (63 loc) · 2.69 KB
/
04__prepare.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# %%
import os
import pandas as pd
from aemeasure import read_as_pd
# %%
from pcpptc import PolygonInstance, Solution
tables = []
for f in os.listdir("./solutions2"):
if not f.endswith(".results.json"):
continue
f = os.path.join("./solutions2", f)
tables.append(read_as_pd(f))
data = pd.concat(tables, ignore_index=True)
data.groupby(["solver"])["instance"].nunique()
# %%
print(data[data.isna().any(axis=1)])
# %%
data.dropna(inplace=True)
data = data[data["solver"] != "MeshAlgorithm(0.95)"]
data.groupby(["solver"])["instance"].nunique()
# %%
def rename(s):
names = {
"RotatingHexagonalAlgorithm(RotatingRegularHexagonal(full_coverage=False, point_based=False, with_boundary=False))": "Regular (Partial)",
"RotatingHexagonalAlgorithm(RotatingRegularHexagonal(full_coverage=True, point_based=False, with_boundary=False))": "Regular (Full)",
"RotatingHexagonalAlgorithm(RotatingRegularHexagonal(full_coverage=True, point_based=True, with_boundary=False))": "Regular (Full, PB)",
"MeshAlgorithm(0.95, full_coverage=False)": "Mesh (Partial)",
"MeshAlgorithm(0.95, full_coverage=True)": "Mesh (Full)",
}
return names.get(s, s)
data["solver"] = data["solver"].apply(rename)
data = data[data["solver"] != "Regular (Full, PB)"]
# %%
data["type"] = data["solver"].apply(lambda s: "hex" if "Hex" in s else "square")
data["point_based"] = data["solver"].apply(lambda s: "pb=True" in s)
# %%
# %%
instance_paths = list(data["instance_path"].unique())
instances = {f: PolygonInstance.from_json(file_path=f) for f in instance_paths}
instance_areas = pd.DataFrame(
data={"area": [i.original_area.area for i in instances.values()]},
index=instance_paths,
)
data = data.merge(instance_areas, left_on="instance_path", right_index=True)
def compute_objective(row):
instance = instances[row["instance_path"]]
solution = Solution.from_json(data=row["solution"])
instance: PolygonInstance
return instance.compute_touring_cost(
solution.waypoints
) + instance.compute_missed_covering_value(solution.waypoints)
data["Obj"] = data.apply(compute_objective, axis=1)
# %%
t_ = data.groupby("instance")[["touring_cost"]].min()
data = data.merge(t_, left_on="instance", right_index=True, suffixes=("", "_min"))
data["relative_cost"] = 100 * ((data["touring_cost"] / data["touring_cost_min"]) - 1)
data["relative_coverage"] = 100 * data["coverage"] / data["area"]
data["type"] = data["solver"].apply(lambda s: s[0])
# %%
t_ = data.groupby("instance")[["Obj"]].min()
data = data.merge(t_, left_on="instance", right_index=True, suffixes=("", "_min"))
data["relative_obj"] = 100 * ((data["Obj"] / data["Obj_min"]) - 1)
data.to_json("04_data.json")