···
16
+
from statistics import stdev
17
-
def compute_area(file):
19
+
def compute_area(file):
24
-
for line in contents:
24
+
# match = re.match(r'%\sinit_area\s=\s(\d+)', line)
# match = re.match(r'%\sinit_area\s=\s(\d+)', line)
# objectives.append(int(match[1]))
···
objectives.append(int(match.group(1)))
33
-
match = re.match(r"%\stime elapsed:\s(\d\.\d+)\ss", line)
33
+
match = re.match(r"%\stime elapsed:\s(\d+\.\d+)\ss", line)
times.append(float(match.group(1)))
···
assert len(objectives) + 1 == len(times)
for i in range(len(objectives)):
46
-
area += ((times[i + 1] - times[i]) / 1000) * objectives[i]
46
+
area += (times[i + 1] - times[i]) * objectives[i]
52
-
for root, dirs, files in os.walk(folder):
54
-
if name.endswith(".sol"):
56
-
match = re.search(r"\.(\d+)\.sol", name)
58
-
seed = int(match.group(1))
59
-
with open(os.path.join(root, name)) as f:
60
-
contents = f.readlines()
62
-
area = compute_area(contents)
53
+
for config in ["original", "restart", "replay"]:
54
+
for root, dirs, files in os.walk(folder + "/" + config):
56
+
if name.endswith(".sol"):
57
+
components = name[:-(4)].split(".")
58
+
data = components[0]
61
+
if len(components) > 1:
62
+
assert len(components) == 2
63
+
seed = components[1]
65
-
for line in contents[::-1]:
67
-
match = re.match(r"objective\s=\s(\d+)", line)
69
-
objective = int(match.group(1))
65
+
if data not in statistics:
66
+
statistics[data] = dict()
67
+
if config not in statistics[data]:
68
+
statistics[data][config] = []
75
-
for line in contents:
77
-
match = re.search(r"copies:\s+(\d+)", line)
79
-
nodes = int(match.group(1))
82
-
match = re.search(r"solveTime=(\d+(.\d+)?)", line)
84
-
solvetime = float(match.group(1))
87
-
match = re.search(r"restarts=(\d+)", line)
89
-
restarts = int(match.group(1))
91
-
statistics[name[:-(4)].replace(".", ",")] = (
70
+
with open(os.path.join(root, name)) as f:
71
+
contents = f.readlines()
73
+
area = compute_area(contents)
99
-
sorted_stats = sorted(statistics.items())
100
-
a = sorted_stats[0][0][: sorted_stats[0][0].find(",")]
101
-
for key, val in sorted_stats:
102
-
if key[: key.find(",")] != a:
104
-
a = key[: key.find(",")]
105
-
print("%s,%s" % (key, ",".join([v.__str__() for v in val])))
76
+
for line in contents[::-1]:
78
+
match = re.match(r"objective\s=\s(\d+)", line)
80
+
objective = int(match.group(1))
86
+
for line in contents:
88
+
match = re.search(r"copies:\s+(\d+)", line)
90
+
nodes = int(match.group(1))
93
+
match = re.search(r"solveTime=(\d+(.\d+)?)", line)
95
+
solvetime = float(match.group(1))
98
+
match = re.search(r"restarts=(\d+)", line)
100
+
restarts = int(match.group(1))
102
+
statistics[data][config].append(
112
+
for data in instances:
113
+
for config in ["original", "restart", "replay"]:
114
+
stats = statistics[data][config]
115
+
cumulative = stats[0]
116
+
for i in range(1, len(stats)):
117
+
cumulative = tuple(map(sum, zip(cumulative, stats[i])))
118
+
avg = tuple([x / len(stats) for x in cumulative])
119
+
dev = stdev([x[1] for x in stats]) if len(stats) > 1 else 0
120
+
# (avg area, avg objective, stdev objective)
121
+
statistics[data][config] = (avg[0], avg[1], dev)
126
+
\\begin{tabular}{l|rr|rr|rr}
128
+
& \multicolumn{2}{c|}{Gecode} & \multicolumn{2}{c|}{Gecode Restart} & \multicolumn{2}{c}{Gecode Replay}\\\\
129
+
Instance & $\intobj$ & $\minobj$ & $\intobj$ & $\minobj$ & $\intobj$ & $\minobj$ \\\\
134
+
sorted_instances = sorted(instances)
135
+
for data in sorted_instances:
136
+
print(f"{data}", end="")
137
+
for config in ["original", "restart", "replay"]:
139
+
f" & {int(statistics[data][config][0] / 1000) }k & {int(statistics[data][config][1])}",
142
+
if statistics[data][config][2] != 0:
143
+
print("^{", end="")
145
+
int(statistics[data][config][2] / statistics[data][config][1] * 100),
146
+
# int(statistics[data][config][2]),
153
+
print("\n\\bottomrule\n\end{tabular}")