forked from zcaicaros/L2D
-
Notifications
You must be signed in to change notification settings - Fork 2
/
boxplot_results.py
137 lines (114 loc) · 5.06 KB
/
boxplot_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
import matplotlib.pyplot as plt
import numpy as np
import pickle
import seaborn as sns
def boxplot_makespan(results_rules, results_agent, rule_set, test, j, m):
# loading dataset
data = []
for rule in rule_set:
data.append(np.array(results_rules[(rule, 'c_max')]))
data.append(np.array(results_agent['c_max']))
fig = plt.figure(figsize=(10, 7))
ax = fig.add_subplot(111)
ax.boxplot(data, notch=True, vert=False)
labels = rule_set + ['agent']
ax.set_yticklabels(labels)
plt.xlabel("Makespan")
if test:
plt.title(f"Box plot of makespan on 1000 instances of size {j}x{m}")
else:
plt.title(f"Box plot of makespan on instances of size {j}x{m}")
if save:
plt.savefig(
'./experiment_plots/boxplot_makespan_{}_{}_{}_{}.png'.format(str(n_m), str(n_j), str(low), str(high)))
if show:
plt.show()
def boxplot_diff_to_opt(results_rules, results_agent, opt_results, rule_set, test, j, m):
data = []
for rule in rule_set:
diff = np.array(results_rules[(rule, 'c_max')]) - opt_results
data.append(diff)
diff = np.array(results_agent['c_max']) - opt_results
data.append(diff)
fig = plt.figure(figsize=(10, 7))
ax = fig.add_subplot(111)
ax.boxplot(data, notch=True, vert=False)
labels = rule_set + ['agent']
ax.set_yticklabels(labels)
plt.xlabel("Absolute difference with optimal makespan")
if test:
plt.title(f"Box plot of difference with optimal makespan on 1000 instances of size {j}x{m}")
else:
plt.title(f"Box plot of difference with optimal makespan on instances of size {j}x{m}")
if save:
plt.savefig('./experiment_plots/boxplot_diff_to_opt_{}_{}_{}_{}.png'.format(str(n_m), str(n_j), str(low), str(high)))
if show:
plt.show()
def boxplot_gap_to_opt(results_rules, results_agent, opt_results, rule_set, test, j, m):
data = []
for rule in rule_set:
gap = (np.array(results_rules[(rule, 'c_max')]) - opt_results) / opt_results
data.append(gap)
gap = (np.array(results_agent['c_max']) - opt_results) / opt_results
data.append(gap)
fig = plt.figure(figsize=(10, 7))
ax = fig.add_subplot(111)
ax.boxplot(data, notch=True, vert=False)
labels = rule_set + ['agent']
ax.set_yticklabels(labels)
plt.xlabel("Gap to optimal makespan")
if test:
plt.title(f"Box plot of gap to optimal makespan on 1000 instances of size {j}x{m}")
else:
plt.title(f"Box plot of gap to optimal makespan on instances of size {j}x{m}")
if save:
plt.savefig('./experiment_plots/boxplot_gap_to_opt_{}_{}_{}_{}.png'.format(str(n_m), str(n_j), str(low), str(high)))
if show:
plt.show()
if __name__ == '__main__':
show = False
save = True
n_j = 10
n_m = 10
low = 1
high = 99
run_type = 'L2D'
np_seed_val = 200
np_seed_test = 100
test_set = False
rules = ['mor', 'mwr', 'edd', 'rand']
sns.set_style("darkgrid", {'axes.grid': True,
'axes.edgecolor': 'black',
'grid.color': '.6',
'grid.linestyle': ':'
})
if test_set:
with open('./dispatching_rule_results/test_set_' + str(run_type) + '_' + str(n_j) + '_' + str(n_m) + '_Seed' +
str(np_seed_test) + '.pkl', 'rb') as f:
loaded_dict_rules = pickle.load(f)
# print(loaded_dict_rules)
with open('./agent_results/test_set_' + str(run_type) + '_' + str(n_j) + '_' + str(n_m) + '_Seed' +
str(np_seed_test) + '.pkl', 'rb') as f:
loaded_dict_agent = pickle.load(f)
# print(loaded_dict_agent)
with open(f'./optimal_results/test_set_{run_type}_optimal_{n_j}_{n_m}_{low}_{high}.txt') as f:
lines = f.readline()
loaded_results = lines.strip('][').split(', ')
opt_results = np.array([float(res) for res in loaded_results])
print(np.sum(opt_results) / opt_results.shape[0])
else:
with open('./dispatching_rule_results/' + str(run_type) + '_' + str(n_j) + '_' + str(n_m) + '_Seed' +
str(np_seed_val) + '.pkl', 'rb') as f:
loaded_dict_rules = pickle.load(f)
# print(loaded_dict_rules)
with open('./agent_results/' + str(run_type) + '_' + str(n_j) + '_' + str(n_m) + '_Seed' +
str(np_seed_val) + '.pkl', 'rb') as f:
loaded_dict_agent = pickle.load(f)
# print(loaded_dict_agent)
with open(f'./optimal_results/{run_type}_optimal_{n_j}_{n_m}_{low}_{high}.txt') as f:
lines = f.readline()
loaded_results = lines.strip('][').split(', ')
opt_results = np.array([float(res) for res in loaded_results])
boxplot_makespan(loaded_dict_rules, loaded_dict_agent, rules, test_set, n_j, n_m)
boxplot_diff_to_opt(loaded_dict_rules, loaded_dict_agent, opt_results, rules, test_set, n_j, n_m)
boxplot_gap_to_opt(loaded_dict_rules, loaded_dict_agent, opt_results, rules, test_set, n_j, n_m)