Refactor execution script
This commit is contained in:
parent
4e640ffc2d
commit
20aa6b2d1e
|
@ -14,9 +14,7 @@ def file_list(path):
|
|||
|
||||
|
||||
def create_dataframes():
|
||||
greedy = DataFrame()
|
||||
local = DataFrame()
|
||||
return greedy, local
|
||||
return [DataFrame() for _ in range(7)]
|
||||
|
||||
|
||||
def process_output(results):
|
||||
|
@ -33,51 +31,55 @@ def process_output(results):
|
|||
return distances, time
|
||||
|
||||
|
||||
def populate_dataframes(greedy, local, greedy_list, local_list, dataset):
|
||||
greedy_distances, greedy_time = process_output(greedy_list)
|
||||
local_distances, local_time = process_output(local_list)
|
||||
greedy_dict = {
|
||||
def populate_dataframes(df, output_list, dataset):
|
||||
df_distances, df_time = process_output(output_list)
|
||||
df_dict = {
|
||||
"dataset": dataset.removeprefix("data/"),
|
||||
"media distancia": mean(greedy_distances),
|
||||
"desviacion distancia": std(greedy_distances),
|
||||
"media tiempo": mean(greedy_time),
|
||||
"desviacion tiempo": std(greedy_time),
|
||||
"media distancia": mean(df_distances),
|
||||
"desviacion distancia": std(df_distances),
|
||||
"media tiempo": mean(df_time),
|
||||
"desviacion tiempo": std(df_time),
|
||||
}
|
||||
local_dict = {
|
||||
"dataset": dataset.removeprefix("data/"),
|
||||
"media distancia": mean(local_distances),
|
||||
"desviacion distancia": std(local_distances),
|
||||
"media tiempo": mean(local_time),
|
||||
"desviacion tiempo": std(local_time),
|
||||
}
|
||||
greedy = greedy.append(greedy_dict, ignore_index=True)
|
||||
local = local.append(local_dict, ignore_index=True)
|
||||
return greedy, local
|
||||
df = df.append(df_dict, ignore_index=True)
|
||||
return df
|
||||
|
||||
|
||||
def script_execution(filenames, greedy, local, iterations=3):
|
||||
def script_execution(filenames, df_list, iterations=2):
|
||||
script = "src/main.py"
|
||||
parameters = [
|
||||
["genetic", "uniform", "generational"],
|
||||
["genetic", "position", "generational"],
|
||||
["geneti,c" "uniform", "stationary"],
|
||||
["genetic," "position", "stationary"],
|
||||
["memetic", "all"],
|
||||
["memetic", "random"],
|
||||
["memetic", "best"],
|
||||
]
|
||||
populated_list = []
|
||||
for dataset in filenames:
|
||||
print(f"Running on dataset {dataset}")
|
||||
greedy_list = []
|
||||
local_list = []
|
||||
for _ in range(iterations):
|
||||
greedy_cmd = run(
|
||||
[executable, script, dataset, "greedy"], capture_output=True
|
||||
).stdout.splitlines()
|
||||
local_cmd = run(
|
||||
[executable, script, dataset, "local"], capture_output=True
|
||||
).stdout.splitlines()
|
||||
greedy_list.append(greedy_cmd)
|
||||
local_list.append(local_cmd)
|
||||
greedy, local = populate_dataframes(
|
||||
greedy, local, greedy_list, local_list, dataset
|
||||
)
|
||||
return greedy, local
|
||||
for df, params in zip(df_list, parameters):
|
||||
print(f"Running {params} algorithm")
|
||||
output_list = []
|
||||
for _ in range(iterations):
|
||||
output_cmd = run(
|
||||
[executable, script, dataset, *params], capture_output=True
|
||||
).stdout.splitlines()
|
||||
output_list.append(output_cmd)
|
||||
populated_list.append(populate_dataframes(df, output_list, dataset))
|
||||
return populated_list
|
||||
|
||||
|
||||
def export_results(greedy, local):
|
||||
dataframes = {"Greedy": greedy, "Local search": local}
|
||||
def export_results(df_list):
|
||||
dataframes = {
|
||||
"Generational uniform genetic": df_list[0],
|
||||
"Generational position genetic": df_list[1],
|
||||
"Stationary uniform genetic": df_list[2],
|
||||
"Stationary position genetic": df_list[3],
|
||||
"All genes memetic": df_list[4],
|
||||
"Random genes memetic": df_list[5],
|
||||
"Best genes memetic": df_list[6],
|
||||
}
|
||||
writer = ExcelWriter(path="docs/algorithm-results.xlsx", engine="xlsxwriter")
|
||||
for name, df in dataframes.items():
|
||||
df.to_excel(writer, sheet_name=name, index=False)
|
||||
|
@ -91,9 +93,9 @@ def export_results(greedy, local):
|
|||
|
||||
def main():
|
||||
datasets = file_list(path="data/*.txt")
|
||||
greedy, local = create_dataframes()
|
||||
populated_greedy, populated_local = script_execution(datasets, greedy, local)
|
||||
export_results(populated_greedy, populated_local)
|
||||
df_list = create_dataframes()
|
||||
populated_df_list = script_execution(datasets, df_list)
|
||||
export_results(populated_df_list)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
Loading…
Reference in New Issue