Add execution script
This commit is contained in:
parent
ed76d07345
commit
9ab8ec3d8a
|
@ -0,0 +1,52 @@
|
||||||
|
from glob import glob
|
||||||
|
from subprocess import run
|
||||||
|
from sys import executable
|
||||||
|
from numpy import mean, std
|
||||||
|
from pandas import DataFrame
|
||||||
|
|
||||||
|
|
||||||
|
def file_list(path):
|
||||||
|
file_list = []
|
||||||
|
for fname in glob(path):
|
||||||
|
file_list.append(fname)
|
||||||
|
return file_list
|
||||||
|
|
||||||
|
|
||||||
|
def create_dataframes(datasets):
|
||||||
|
greedy = DataFrame(columns=["dataset", "distancia"])
|
||||||
|
local = DataFrame(columns=["dataset", "distancia"])
|
||||||
|
greedy["dataset"] = datasets
|
||||||
|
local["dataset"] = datasets
|
||||||
|
return greedy, local
|
||||||
|
|
||||||
|
|
||||||
|
def process_output(results):
|
||||||
|
for line in results:
|
||||||
|
if line.startswith(bytes("Total distance:", encoding="utf-8")):
|
||||||
|
line_elements = line.split(sep=bytes(":", encoding="utf-8"))
|
||||||
|
distance = float(line_elements[1])
|
||||||
|
return distance
|
||||||
|
|
||||||
|
|
||||||
|
def script_execution(filenames, greedy, local, iterations=3):
|
||||||
|
script = "src/main.py"
|
||||||
|
for dataset in filenames:
|
||||||
|
greedy_list = []
|
||||||
|
local_list = []
|
||||||
|
for _ in range(iterations):
|
||||||
|
greedy_cmd = run(
|
||||||
|
[executable, script, dataset, "greedy"], capture_output=True
|
||||||
|
).stdout.splitlines()
|
||||||
|
greedy_list.append(greedy_cmd)
|
||||||
|
local_cmd = run(
|
||||||
|
[executable, script, dataset, "local"], capture_output=True
|
||||||
|
).stdout.splitlines()
|
||||||
|
local_list.append(local_cmd)
|
||||||
|
greedy.loc[greedy["dataset"] == dataset, ["distancia"]] = mean(greedy_list)
|
||||||
|
local.loc[local["dataset"] == dataset, ["distancia"]] = mean(local_list)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
datasets = file_list(path="data/*.txt")
|
||||||
|
greedy, local = create_dataframes(datasets)
|
||||||
|
script_execution(filenames=datasets, greedy=greedy, local=local)
|
Loading…
Reference in New Issue