Execute each algorithm once

This commit is contained in:
coolneng 2021-06-22 01:47:11 +02:00
parent 1aafc9bdda
commit 03afe1a00f
Signed by: coolneng
GPG Key ID: 9893DA236405AF57
2 changed files with 14 additions and 18 deletions

0
docs/.gitkeep Normal file
View File

View File

@ -20,19 +20,18 @@ def create_dataframes():
def process_output(results): def process_output(results):
distances = [] distances = []
time = [] time = []
for element in results: for line in results:
for line in element: if line.startswith(bytes("Total distance:", encoding="utf-8")):
if line.startswith(bytes("Total distance:", encoding="utf-8")): line_elements = line.split(sep=bytes(":", encoding="utf-8"))
line_elements = line.split(sep=bytes(":", encoding="utf-8")) distances.append(float(line_elements[1]))
distances.append(float(line_elements[1])) if line.startswith(bytes("Execution time:", encoding="utf-8")):
if line.startswith(bytes("Execution time:", encoding="utf-8")): line_elements = line.split(sep=bytes(":", encoding="utf-8"))
line_elements = line.split(sep=bytes(":", encoding="utf-8")) time.append(float(line_elements[1]))
time.append(float(line_elements[1]))
return distances, time return distances, time
def populate_dataframe(df, output_list, dataset): def populate_dataframe(df, output_cmd, dataset):
distances, time = process_output(output_list) distances, time = process_output(output_cmd)
data_dict = { data_dict = {
"dataset": dataset.removeprefix("data/"), "dataset": dataset.removeprefix("data/"),
"media distancia": mean(distances), "media distancia": mean(distances),
@ -44,7 +43,7 @@ def populate_dataframe(df, output_list, dataset):
return df return df
def script_execution(filenames, df_list, iterations=2): def script_execution(filenames, df_list):
script = "src/main.py" script = "src/main.py"
parameters = [ parameters = [
["genetic", "uniform", "generational"], ["genetic", "uniform", "generational"],
@ -59,13 +58,10 @@ def script_execution(filenames, df_list, iterations=2):
print(f"Running on dataset {dataset}") print(f"Running on dataset {dataset}")
for index, params in zip(range(4), parameters): for index, params in zip(range(4), parameters):
print(f"Running {params} algorithm") print(f"Running {params} algorithm")
output_list = [] output_cmd = run(
for _ in range(iterations): [executable, script, dataset, *params], capture_output=True
output_cmd = run( ).stdout.splitlines()
[executable, script, dataset, *params], capture_output=True df_list[index] = populate_dataframe(df_list[index], output_cmd, dataset)
).stdout.splitlines()
output_list.append(output_cmd)
df_list[index] = populate_dataframe(df_list[index], output_list, dataset)
return df_list return df_list