diff --git a/utils/plot_results.py b/utils/plot_results.py index 12828fa..9e99208 100755 --- a/utils/plot_results.py +++ b/utils/plot_results.py @@ -2,12 +2,11 @@ from sys import argv, exit import os -from csv import writer from typing import Tuple, List import re -import numpy as np -from pprint import pprint +import numpy as np +import pandas as pd import matplotlib.pyplot as plt if len(argv) != 2: @@ -18,8 +17,6 @@ path = argv[1] files = [f for f in os.listdir(path) if os.path.isfile(f"{ path }/{f}")] -# files = [f for f in files if re.match(r"greedy_64_.+", f) is not None ] - def parse_file(file: str) -> Tuple[float, List[int]]: @@ -41,57 +38,91 @@ def parse_file(file: str) -> Tuple[float, List[int]]: return time, pops -results = dict() -with open("times.csv", "w+") as times_file: - times = writer(times_file) +frames = list() - with open("pops.csv", "w+") as pops_file: - pops = writer(pops_file) +for i, file in enumerate(files): + time, pops = parse_file(f"{ path }/{ file }") - for file in files: - name = file.split(".")[0] - full_path = f"{ path }/{ file }" - time, pop = parse_file(full_path) + parts = file.split(".")[0].split("_") - total_pops = sum(pop)/len(pop) + data = { + "name": parts[0], + "time": time, + "pops": int(sum(pops)), + } - results[name] = (total_pops, time) + if len(parts) > 1: + data["num_landmarks"] = int(parts[1]) + if len(parts) > 2: + data["best_size"] = int(parts[2]) - times.writerow([name, time]) + frames.append(pd.DataFrame(data, index=[i])) - pops.writerow([name, *pop]) -rel_pops = list() -abs_pops = list() -rel_time = list() -abs_time = list() -labels = list() +results = pd.concat(frames) +# dijkstra vs A* vs greedy and random ALT -pprint(results) -baseline = "dijkstra" -base_pops = results[baseline][0] -base_time = results[baseline][1] - -for name, values in results.items(): - pops, time = values - labels.append(name) - rel_pops.append(pops/base_pops) - rel_time.append(time/base_time) - abs_pops.append(pops) - abs_time.append(time) +#condition = ((results["name"] == "astar") +# | (results["name"] == "dijkstra") +# | ((results["num_landmarks"] == 32) & (results["best_size"] == 4))) +# +# basic = results[condition].sort_values(by=["time"], ascending=False) +# names = basic["name"].to_list() +# for i in range(len(names)): +# if names[i] == "greedy": +# names[i] = "ALT 32 greedy" +# if names[i] == "random": +# names[i] = "ALT 32 random" +# times = basic["time"] * 1000 +# +# fig, ax = plt.subplots() +# +# bar = ax.bar(names, times) +# ax.set_title("Average query time by algorithm") +# ax.set_ylabel("time in ms") +# ax.bar_label(bar) +# fig.savefig("basic.svg") +# plt.show() +# comparison greedy vs. random, best_size = 4 -x = np.arange(len(labels)) # the label locations -width = 0.35 # the width of the bars +condition = (((results["name"] == "greedy") | (results["name"] == "random")) & (results["best_size"] == 4)) + +data = results[condition] +greedy = data[data["name"] == "greedy"] +random = data[data["name"] == "random"] + +print(greedy) +print(random) + +labels = greedy["num_landmarks"].to_list() +labels = [int(label) for label in labels] +greedy_times = greedy["time"].to_list() +random_times = random["time"].to_list() + +width = 0.35 fig, ax = plt.subplots() -rects1 = ax.bar(x - width/2, abs_time , width, label='time') -# rects2 = ax.bar(x + width/2, abs_pops, width, label='pops') -ax.legend() +x = np.arange(len(labels)) + +greedy_bars = ax.bar(x - width/2, greedy_times, width, label="Greedy") +random_bars = ax.bar(x + width/2, random_times, width, label="Random") +ax.set_title("Comparison of ALT with random and greedy landmark selection") +ax.set_ylabel("time in ms") +ax.set_xlabel("number of landmarks") ax.set_xticks(x, labels) +ax.legend() +# ax.bar_label(greedy_bars) +# ax.bar_label(random_bars) + +fig.save("random_greedy_comp.svg") plt.show() + + +# comparison greedy best_size +# comparison random best_size