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
1
.gitignore
vendored
|
|
@ -1,2 +1 @@
|
|||
/target
|
||||
/landmarks
|
||||
|
|
|
|||
|
|
@ -2,11 +2,12 @@
|
|||
|
||||
from sys import argv, exit
|
||||
import os
|
||||
from csv import writer
|
||||
from typing import Tuple, List
|
||||
import re
|
||||
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
from pprint import pprint
|
||||
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
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 files if re.match(r"greedy_64_.+", f) is not None ]
|
||||
|
||||
|
||||
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
|
||||
|
||||
results = dict()
|
||||
|
||||
frames = list()
|
||||
with open("times.csv", "w+") as times_file:
|
||||
times = writer(times_file)
|
||||
|
||||
for i, file in enumerate(files):
|
||||
time, pops = parse_file(f"{ path }/{ file }")
|
||||
with open("pops.csv", "w+") as pops_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 = {
|
||||
"name": parts[0],
|
||||
"time": time,
|
||||
"pops": int(sum(pops)),
|
||||
}
|
||||
total_pops = sum(pop)/len(pop)
|
||||
|
||||
if len(parts) > 1:
|
||||
data["num_landmarks"] = int(parts[1])
|
||||
if len(parts) > 2:
|
||||
data["best_size"] = int(parts[2])
|
||||
results[name] = (total_pops, time)
|
||||
|
||||
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")
|
||||
# | (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()
|
||||
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)
|
||||
|
||||
|
||||
# comparison greedy vs. random, best_size = 4
|
||||
|
||||
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
|
||||
x = np.arange(len(labels)) # the label locations
|
||||
width = 0.35 # the width of the bars
|
||||
|
||||
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.bar_label(greedy_bars)
|
||||
# ax.bar_label(random_bars)
|
||||
|
||||
fig.save("random_greedy_comp.svg")
|
||||
ax.set_xticks(x, labels)
|
||||
|
||||
plt.show()
|
||||
|
||||
|
||||
# comparison greedy best_size
|
||||
# comparison random best_size
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue