···
16
+
from statistics import stdev
def compute_area(file, time):
···
objectives.append(int(match.group(1)))
33
-
match = re.match(r"%\stime elapsed:\s(\d+)\sms", line)
35
+
match = re.match(r"%\stime elapsed:\s(\d+\.\d+)\ss", line)
35
-
times.append(int(match.group(1)))
37
+
times.append(float(match.group(1)))
39
+
# Not proven optimal
40
+
if len(times) == len(objectives):
assert len(objectives) > 0
assert len(objectives) + 1 == len(times)
for i in range(len(objectives)):
43
-
area += ((times[i + 1] - times[i]) / 1000) * objectives[i]
47
+
area += (times[i + 1] - times[i]) * objectives[i]
49
-
for root, dirs, files in os.walk(folder):
51
-
if name.endswith(".sol"):
53
-
match = re.search(r"\.(\d+)\.sol", name)
55
-
seed = int(match.group(1))
56
-
with open(os.path.join(root, name)) as f:
57
-
contents = f.readlines()
54
+
for config in ["original", "restart"]:
55
+
for root, dirs, files in os.walk(folder + "/" + config):
57
+
if name.endswith(".sol"):
58
+
components = name[:-(4)].split(".")
59
+
data = components[0]
62
+
if len(components) > 1:
63
+
assert len(components) == 2
64
+
seed = components[1]
61
-
for line in contents:
63
-
match = re.search(r"nodes=(\d+)", line)
65
-
statistics["nodes"] = int(match.group(1))
68
-
match = re.search(r"solveTime=(\d+\.\d+)", line)
70
-
statistics["search_time"] = int(float(match.group(1)) * 1000)
73
-
match = re.search(r"restart count:\s+(\d+)", line)
75
-
statistics["restarts"] = int(match.group(1))
66
+
if data not in statistics:
67
+
statistics[data] = dict()
68
+
if config not in statistics[data]:
69
+
statistics[data][config] = []
78
-
for line in contents[::-1]:
80
-
match = re.match(r"objective\s=\s(\d+)", line)
82
-
statistics["objective"] = int(match.group(1))
85
-
area = compute_area(contents, statistics["search_time"])
71
+
with open(os.path.join(root, name)) as f:
72
+
contents = f.readlines()
87
-
stats[name[:-(4)].replace(".", ",")] = (
89
-
statistics["objective"],
90
-
statistics["search_time"],
91
-
statistics["restarts"],
92
-
statistics["nodes"],
78
+
for line in contents:
80
+
match = re.search(r"%%%mzn-stat: nodes=(\d+)", line)
82
+
nodes = int(match.group(1))
85
+
match = re.search(r"%%%mzn-stat: solveTime=(\d+\.\d+)", line)
87
+
solvetime = float(match.group(1))
90
+
match = re.search(r"%%%mzn-stat: restarts=(\d+)", line)
92
+
restarts = int(match.group(1))
95
-
sorted_stats = sorted(stats.items())
96
-
a = sorted_stats[0][0][: sorted_stats[0][0].find(",")]
97
-
for key, val in sorted_stats:
98
-
if key[: key.find(",")] != a:
100
-
a = key[: key.find(",")]
101
-
print("%s,%s" % (key, ",".join([v.__str__() for v in val])))
95
+
for line in contents[::-1]:
97
+
match = re.match(r"%%%mzn-stat: objective=(-?\d+)", line)
99
+
objective = int(match.group(1))
102
+
area = compute_area(contents, solvetime)
104
+
statistics[data][config].append(
114
+
for data in instances:
115
+
for config in ["original", "restart"]:
116
+
stats = statistics[data][config]
117
+
cumulative = stats[0]
118
+
for i in range(1, len(stats)):
119
+
cumulative = tuple(map(sum, zip(cumulative, stats[i])))
120
+
avg = tuple([x / len(stats) for x in cumulative])
121
+
dev = stdev([x[1] for x in stats]) if len(stats) > 1 else 0
122
+
# (avg area, avg objective, stdev objective)
123
+
statistics[data][config] = (avg[0], avg[1], dev)
128
+
\\begin{tabular}{l|rr|rr|rr}
130
+
& \multicolumn{2}{c|}{Chuffed} & \multicolumn{2}{c|}{Chuffed Restart} \\\\
131
+
Instance & $\intobj$ & $\minobj$ & $\intobj$ & $\minobj$ \\\\
136
+
sorted_instances = sorted(instances)
137
+
for data in sorted_instances:
138
+
print(f"{data}", end="")
139
+
for config in ["original", "restart"]:
141
+
f" & {int(statistics[data][config][0] / 1000) }k & {int(statistics[data][config][1])}",
144
+
if statistics[data][config][2] != 0:
145
+
print("^{", end="")
147
+
int(statistics[data][config][2] / statistics[data][config][1] * 100),
148
+
# int(statistics[data][config][2]),
155
+
print("\n\\bottomrule\n\end{tabular}")