-
Notifications
You must be signed in to change notification settings - Fork 2
/
eval_results.py
144 lines (123 loc) · 5.05 KB
/
eval_results.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import io
import json
import statistics
from collections import defaultdict
from os import listdir, path
def read_references():
out = {}
for t in ['lots', 'machines']:
out[t] = {}
for ds in ['HVLM', 'LVHM']:
out[t][ds] = defaultdict(lambda: 0)
file_name = f'datasets/{t}_SMT2020_{ds}.txt'
with io.open(file_name, 'r') as f:
lines = f.read().split('\n')
headers = lines[0].split(' ')
rows = [a.split(' ') for a in lines[1:]]
for row in rows:
for h, c in zip(headers[1:], row[1:]):
out[t][ds][(h, row[0])] = c
return out
def handle_obj(datas):
o = {}
for k, v in datas[0].items():
its = [d[k] for d in datas]
if type(v) is dict:
o[k] = handle_obj(its)
elif type(v) in [int, float]:
o[k] = (statistics.mean(its), statistics.stdev(its))
else:
assert False
return o
def loadfile(f):
with io.open(f, 'r') as q:
return q.read()
def main():
dirs = ['greedy']
results = {}
names = set()
runs = 10
lots = defaultdict(lambda: defaultdict(lambda: defaultdict(int)))
machines = defaultdict(lambda: defaultdict(lambda: defaultdict(int)))
for d in dirs:
subs = listdir(d)
for s in subs:
if path.isfile(d + '/' + s) and 'seed0' in s and s.endswith('.json'):
file_locs = [d + '/' + s.replace('seed0_', f'seed{r}_') for r in range(runs)]
name = f'{len(file_locs)}x {s.replace("seed0_", "")}'
results[name] = {'files': file_locs}
elif path.isdir(d + '/' + s) and s.startswith('0_'):
s = s[2:]
ds = 'HVLM' if 'HVLM' in s else 'LVHM'
dispatcher = 'fifo' if 'fifo' in s else 'cr'
y2n = f'rl2y_730days_{ds}_{dispatcher}.json'
d180n = f'rl180_180days_{ds}_{dispatcher}.json'
file_locs_2y = [path.join(d, str(r) + '_' + s, y2n) for r in range(runs)]
file_locs_180d = [path.join(d, str(r) + '_' + s, d180n) for r in range(runs)]
name180 = f'{len(file_locs_2y)}x {d}_180days_{s}'
name730 = f'{len(file_locs_2y)}x {d}_730days_{s}'
results[name180] = {'files': file_locs_180d}
results[name730] = {'files': file_locs_2y}
for name in results.keys():
names.add(name)
d = results[name]
files = d['files']
datas = [json.loads(loadfile(f)) for f in files]
r = d['avgs'] = handle_obj(datas)
for k, v in sorted(r['lots'].items(), key=lambda k: k[0]):
lots[k][name] = dict(
act=round(v["ACT"][0], 2),
th=round(v["throughput"][0], 2),
on_time=round(v["on_time"][0] / v["throughput"][0] * 100),
tardiness=round(v["tardiness"][0] / v["throughput"][0] / 24),
)
for k, v in sorted(r['machines'].items(), key=lambda k: k[0]):
machines[k][name] = dict(
avail=round(v["avail"][0] * 100, 2),
util=round(v["util"][0] * 100, 2),
pm=round(v["pm"][0] * 100, 2),
br=round(v["br"][0] * 100, 2),
setup=round(v["setup"][0] * 100, 2),
waiting_time=round(v["waiting_time"][0], 2),
)
print('\t', end='')
names = sorted(list(names))
for name in names:
print(name.replace(':', '').replace('\t', ''), '\t\t', end='')
print()
print('', end='\t')
for name in names:
print('act\tth\ton_time\ttardiness', end='\t')
print()
ref = read_references()
for lot in sorted(lots.keys()):
t = lots[lot]
print(lot, end='\t')
for name in names:
i = ref['lots']['HVLM' if 'HVLM' in name else 'LVHM']
for x in ['act', 'th', 'on_time']:
i[(x, lot)] = float(i[(x, lot)])
print(f"{i[(x, lot)]}->{t[name][x]} ({round(t[name][x] - i[(x, lot)], 2)})", end='\t')
print(t[name]['tardiness'], end='\t')
print()
print('', end='\t')
for name in names:
print('avail\t\t\tutil\t\t\tpm\t\t\tbr\t\t\tsetup\t\t\twaiting_time_before', end='\t')
print()
print('', end='\t')
for name in names:
print('old\tnew\tdelta\told\tnew\tdelta\told\tnew\tdelta\told\tnew\tdelta\told\tnew\tdelta\tnew', end='\t')
print()
for machine in sorted(machines.keys()):
t = machines[machine]
print(machine, end='\t')
for name in names:
i = ref['machines']['HVLM' if 'HVLM' in name else 'LVHM']
for x in ['avail', 'util', 'pm', 'br', 'setup']:
i[(x, machine)] = float(i[(x, machine)])
print(f"{i[(x, machine)]}\t{t[name][x]}\t{round(t[name][x] - i[(x, machine)], 2)}", end='\t')
# print(f"{round(t[name][x] - i[(x, machine)], 2)}", end='\t')
print(t[name]['waiting_time'], end='\t')
print()
if __name__ == '__main__':
main()