-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimulator_data_summary.py
118 lines (96 loc) · 5.08 KB
/
simulator_data_summary.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
import pandas as pd
from typing import Literal
from scipy.stats import wilcoxon
from simulator import ITERATIONS
def __get_time_type(df_n_stars_iteration: pd.DataFrame, df_binpacking_iteration: pd.DataFrame,
df_smart_iteration: pd.DataFrame, df_result: dict, data_type: Literal['execution', 'idle']):
# Filters by the column 'type' == 'execution' and retrieves the mean and std
df_n_stars_iteration_execution = df_n_stars_iteration[df_n_stars_iteration['type'] == data_type]
df_binpacking_iteration_execution = df_binpacking_iteration[df_binpacking_iteration['type'] == data_type]
df_smart_iteration_execution = df_smart_iteration[df_smart_iteration['type'] == data_type]
# Retrieves the mean and std
mean_n_stars = round(df_n_stars_iteration_execution['time'].mean(), 3)
std_n_stars = round(df_n_stars_iteration_execution['time'].std(), 3)
mean_binpacking = round(df_binpacking_iteration_execution['time'].mean(), 3)
std_binpacking = round(df_binpacking_iteration_execution['time'].std(), 3)
mean_smart = round(df_smart_iteration_execution['time'].mean(), 3)
std_smart = round(df_smart_iteration_execution['time'].std(), 3)
# Retrieves the strategy with the minimum mean
if mean_smart < mean_binpacking and mean_smart < mean_n_stars:
strategy_min = 'smart'
elif mean_binpacking < mean_smart and mean_binpacking < mean_n_stars:
strategy_min = 'binpacking'
else:
strategy_min = 'n_stars'
# Computes Wilcoxon test between the smart strategy and the closest strategy
if abs(mean_binpacking - mean_smart) < abs(mean_n_stars - mean_smart):
closest_data = df_binpacking_iteration_execution['time'].values
else:
closest_data = df_n_stars_iteration_execution['time'].values
_, p_value = wilcoxon(df_smart_iteration_execution['time'].values, closest_data)
# Generates a symbol '=' if the p-value is greater than 0.05, otherwise generates a symbol '+'/'-' depending on
# the strategy with the minimum mean
if p_value > 0.05:
symbol = '='
else:
if strategy_min == 'smart':
symbol = '+'
else:
symbol = '-'
# Appends the data to the result dataframe
df_result[f'mean_n_stars_{data_type}'].append(mean_n_stars)
df_result[f'std_n_stars_{data_type}'].append(std_n_stars)
df_result[f'mean_binpacking_{data_type}'].append(mean_binpacking)
df_result[f'std_binpacking_{data_type}'].append(std_binpacking)
df_result[f'mean_smart_{data_type}'].append(f'{mean_smart} ({symbol})')
df_result[f'std_smart_{data_type}'].append(std_smart)
df_result[f'strategy_min_{data_type}'].append(strategy_min)
def __get_dtype(key: str) -> type:
if key == 'iteration':
return int
if key in ['mean_smart_execution', 'mean_smart_idle', 'strategy_min_execution', 'strategy_min_idle']:
return str
return float
def main(random_seed: int):
df_n_stars = pd.read_csv(f'Simulator_results/data_n_stars_random_{random_seed}.csv')
df_binpacking = pd.read_csv(f'Simulator_results/data_binpacking_random_{random_seed}.csv')
df_smart = pd.read_csv(f'Simulator_results/data_smart_random_{random_seed}.csv')
df_result = {
'iteration': [],
'mean_n_stars_execution': [],
'mean_binpacking_execution': [],
'mean_smart_execution': [],
'std_n_stars_execution': [],
'std_binpacking_execution': [],
'std_smart_execution': [],
'strategy_min_execution': [],
'mean_n_stars_idle': [],
'mean_binpacking_idle': [],
'mean_smart_idle': [],
'std_n_stars_idle': [],
'std_binpacking_idle': [],
'std_smart_idle': [],
'strategy_min_idle': [],
}
# Iterates over the number of iterations and retrieves all the data from the dataframes
for iteration in range(ITERATIONS):
df_n_stars_iteration = df_n_stars[df_n_stars['iteration'] == iteration]
df_binpacking_iteration = df_binpacking[df_binpacking['iteration'] == iteration]
df_smart_iteration = df_smart[df_smart['iteration'] == iteration]
# Adds iteration
df_result['iteration'].append(iteration + 1) # Starts at 1 like the bar plots
# Retrieves the mean and std for the execution and idle time for each strategy
__get_time_type(df_n_stars_iteration, df_binpacking_iteration, df_smart_iteration, df_result, 'execution')
__get_time_type(df_n_stars_iteration, df_binpacking_iteration, df_smart_iteration, df_result, 'idle')
# Creates the dataframe with the results
df_result = {k: pd.Series(v, dtype=__get_dtype(k)) for k, v in df_result.items()}
df_result = pd.DataFrame(df_result)
print(df_result)
# Saves the dataframe to a csv file
df_result.to_csv(f'Simulator_results/comparison_result_random_{random_seed}.csv', index=False)
if __name__ == '__main__':
for random_seed_to_test in range(100, 1000, 100):
print(f'Random seed: {random_seed_to_test}')
print('====================================')
main(random_seed=random_seed_to_test)
break # To just test one random seed