From 03afe1a00f1209ba8b1c8a24fd9f02ba36013522 Mon Sep 17 00:00:00 2001 From: coolneng Date: Tue, 22 Jun 2021 01:47:11 +0200 Subject: [PATCH] Execute each algorithm once --- docs/.gitkeep | 0 src/execution.py | 32 ++++++++++++++------------------ 2 files changed, 14 insertions(+), 18 deletions(-) create mode 100644 docs/.gitkeep diff --git a/docs/.gitkeep b/docs/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/src/execution.py b/src/execution.py index 57927c4..d8de670 100644 --- a/src/execution.py +++ b/src/execution.py @@ -20,19 +20,18 @@ def create_dataframes(): def process_output(results): distances = [] time = [] - for element in results: - for line in element: - if line.startswith(bytes("Total distance:", encoding="utf-8")): - line_elements = line.split(sep=bytes(":", encoding="utf-8")) - distances.append(float(line_elements[1])) - if line.startswith(bytes("Execution time:", encoding="utf-8")): - line_elements = line.split(sep=bytes(":", encoding="utf-8")) - time.append(float(line_elements[1])) + for line in results: + if line.startswith(bytes("Total distance:", encoding="utf-8")): + line_elements = line.split(sep=bytes(":", encoding="utf-8")) + distances.append(float(line_elements[1])) + if line.startswith(bytes("Execution time:", encoding="utf-8")): + line_elements = line.split(sep=bytes(":", encoding="utf-8")) + time.append(float(line_elements[1])) return distances, time -def populate_dataframe(df, output_list, dataset): - distances, time = process_output(output_list) +def populate_dataframe(df, output_cmd, dataset): + distances, time = process_output(output_cmd) data_dict = { "dataset": dataset.removeprefix("data/"), "media distancia": mean(distances), @@ -44,7 +43,7 @@ def populate_dataframe(df, output_list, dataset): return df -def script_execution(filenames, df_list, iterations=2): +def script_execution(filenames, df_list): script = "src/main.py" parameters = [ ["genetic", "uniform", "generational"], @@ -59,13 +58,10 @@ def script_execution(filenames, df_list, iterations=2): print(f"Running on dataset {dataset}") for index, params in zip(range(4), 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) - df_list[index] = populate_dataframe(df_list[index], output_list, dataset) + output_cmd = run( + [executable, script, dataset, *params], capture_output=True + ).stdout.splitlines() + df_list[index] = populate_dataframe(df_list[index], output_cmd, dataset) return df_list