Compare commits
2 commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8052f4a4d7 | |||
| d4d621eea7 |
2 changed files with 72 additions and 40 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -1 +1,2 @@
|
||||||
/target
|
/target
|
||||||
|
/landmarks
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,11 @@
|
||||||
|
|
||||||
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
|
|
||||||
from pprint import pprint
|
|
||||||
|
|
||||||
|
import numpy as np
|
||||||
|
import pandas as pd
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
|
|
||||||
if len(argv) != 2:
|
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 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]]:
|
||||||
|
|
||||||
|
|
@ -41,57 +38,91 @@ def parse_file(file: str) -> Tuple[float, List[int]]:
|
||||||
|
|
||||||
return time, pops
|
return time, pops
|
||||||
|
|
||||||
results = dict()
|
|
||||||
|
|
||||||
with open("times.csv", "w+") as times_file:
|
frames = list()
|
||||||
times = writer(times_file)
|
|
||||||
|
|
||||||
with open("pops.csv", "w+") as pops_file:
|
for i, file in enumerate(files):
|
||||||
pops = writer(pops_file)
|
time, pops = parse_file(f"{ path }/{ file }")
|
||||||
|
|
||||||
for file in files:
|
parts = file.split(".")[0].split("_")
|
||||||
name = file.split(".")[0]
|
|
||||||
full_path = f"{ path }/{ file }"
|
|
||||||
time, pop = parse_file(full_path)
|
|
||||||
|
|
||||||
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])
|
results = pd.concat(frames)
|
||||||
rel_pops = list()
|
|
||||||
abs_pops = list()
|
|
||||||
rel_time = list()
|
|
||||||
abs_time = list()
|
|
||||||
labels = list()
|
|
||||||
|
|
||||||
|
|
||||||
|
# dijkstra vs A* vs greedy and random ALT
|
||||||
|
|
||||||
pprint(results)
|
#condition = ((results["name"] == "astar")
|
||||||
baseline = "dijkstra"
|
# | (results["name"] == "dijkstra")
|
||||||
base_pops = results[baseline][0]
|
# | ((results["num_landmarks"] == 32) & (results["best_size"] == 4)))
|
||||||
base_time = results[baseline][1]
|
#
|
||||||
|
# basic = results[condition].sort_values(by=["time"], ascending=False)
|
||||||
for name, values in results.items():
|
# names = basic["name"].to_list()
|
||||||
pops, time = values
|
# for i in range(len(names)):
|
||||||
labels.append(name)
|
# if names[i] == "greedy":
|
||||||
rel_pops.append(pops/base_pops)
|
# names[i] = "ALT 32 greedy"
|
||||||
rel_time.append(time/base_time)
|
# if names[i] == "random":
|
||||||
abs_pops.append(pops)
|
# names[i] = "ALT 32 random"
|
||||||
abs_time.append(time)
|
# 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
|
condition = (((results["name"] == "greedy") | (results["name"] == "random")) & (results["best_size"] == 4))
|
||||||
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')
|
|
||||||
|
|
||||||
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.set_xticks(x, labels)
|
||||||
|
ax.legend()
|
||||||
|
# ax.bar_label(greedy_bars)
|
||||||
|
# ax.bar_label(random_bars)
|
||||||
|
|
||||||
|
fig.save("random_greedy_comp.svg")
|
||||||
|
|
||||||
plt.show()
|
plt.show()
|
||||||
|
|
||||||
|
|
||||||
|
# comparison greedy best_size
|
||||||
|
# comparison random best_size
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue