Compare commits

..

No commits in common. "master" and "Abgabe" have entirely different histories.

2 changed files with 40 additions and 72 deletions

1
.gitignore vendored
View file

@ -1,2 +1 @@
/target /target
/landmarks

View file

@ -2,11 +2,12 @@
from sys import argv, exit from sys import argv, exit
import os import os
from csv import writer
from typing import Tuple, List from typing import Tuple, List
import re import re
import numpy as np import numpy as np
import pandas as pd from pprint import pprint
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
if len(argv) != 2: if len(argv) != 2:
@ -17,6 +18,8 @@ path = argv[1]
files = [f for f in os.listdir(path) if os.path.isfile(f"{ path }/{f}")] 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]]: def parse_file(file: str) -> Tuple[float, List[int]]:
@ -38,91 +41,57 @@ def parse_file(file: str) -> Tuple[float, List[int]]:
return time, pops return time, pops
results = dict()
frames = list() with open("times.csv", "w+") as times_file:
times = writer(times_file)
for i, file in enumerate(files): with open("pops.csv", "w+") as pops_file:
time, pops = parse_file(f"{ path }/{ file }") pops = writer(pops_file)
parts = file.split(".")[0].split("_") for file in files:
name = file.split(".")[0]
full_path = f"{ path }/{ file }"
time, pop = parse_file(full_path)
data = { total_pops = sum(pop)/len(pop)
"name": parts[0],
"time": time,
"pops": int(sum(pops)),
}
if len(parts) > 1: results[name] = (total_pops, time)
data["num_landmarks"] = int(parts[1])
if len(parts) > 2:
data["best_size"] = int(parts[2])
frames.append(pd.DataFrame(data, index=[i])) times.writerow([name, time])
results = pd.concat(frames) pops.writerow([name, *pop])
rel_pops = list()
abs_pops = list()
rel_time = list()
abs_time = list()
labels = list()
# dijkstra vs A* vs greedy and random ALT
#condition = ((results["name"] == "astar") pprint(results)
# | (results["name"] == "dijkstra") baseline = "dijkstra"
# | ((results["num_landmarks"] == 32) & (results["best_size"] == 4))) base_pops = results[baseline][0]
# base_time = results[baseline][1]
# basic = results[condition].sort_values(by=["time"], ascending=False)
# names = basic["name"].to_list() for name, values in results.items():
# for i in range(len(names)): pops, time = values
# if names[i] == "greedy": labels.append(name)
# names[i] = "ALT 32 greedy" rel_pops.append(pops/base_pops)
# if names[i] == "random": rel_time.append(time/base_time)
# names[i] = "ALT 32 random" abs_pops.append(pops)
# times = basic["time"] * 1000 abs_time.append(time)
#
# 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
condition = (((results["name"] == "greedy") | (results["name"] == "random")) & (results["best_size"] == 4)) x = np.arange(len(labels)) # the label locations
width = 0.35 # the width of the bars
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() 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')
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.legend()
# ax.bar_label(greedy_bars) ax.set_xticks(x, labels)
# ax.bar_label(random_bars)
fig.save("random_greedy_comp.svg")
plt.show() plt.show()
# comparison greedy best_size
# comparison random best_size