-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvisualize.py
101 lines (74 loc) · 2.17 KB
/
visualize.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import numpy as np
import matplotlib.pyplot as plt
from collections import defaultdict
import json
class MapInfo:
def __init__(self):
self.nodes = 0
self.edges = 0
data = defaultdict(dict)
maps = {}
map_infos = {}
# RESULTS_FILE = 'results-rust.txt'
# palette = ['b', 'b', 'b', 'skyblue', 'skyblue', 'skyblue']
RESULTS_FILE = 'results.txt'
palette = ['b', 'g', 'r', 'c', 'm', 'y', 'k', 'skyblue', 'burlywood']
f = open(RESULTS_FILE, 'r')
total = 0
for line in f.xreadlines():
j = json.loads(line)
# skip tiny maps
if j["edges"] < 100:
continue
# skip duplicate
if j["map"] == "vancouver.txt":
continue
total += 1
data[j["name"]][j["map"]] = float(j["time"])
maps[j["map"]] = j["edges"]
map_info = MapInfo()
map_info.nodes = j["nodes"]
map_info.edges = j["edges"]
map_infos[j["map"]] = map_info
maps_list = sorted(maps.keys(), key=lambda x: maps[x])
# print (maps_list)
def get_values_list(values, maps_list, baseline):
result = []
for m in maps_list:
result.append(values[m] / baseline[m])
return result
def print_maps():
counter = 0
# header = ", ".join(sorted(data.keys()))
# print (header)
for m in maps_list:
print("{}: {} v={} e={}".format(
counter, m, map_infos[m].nodes, map_infos[m].edges))
counter += 1
print_maps()
def print_csv():
tags = sorted(data.keys())
print ("")
print ("map, vertices, edges, {}".format(", ".join(tags)))
for m in maps_list:
baseline = data["cpp"][m]
values = [data[tag][m] for tag in tags]
values_print = ", ".join(map(lambda x : ("%.2f" % x), values))
print("{}, {}, {}, {}".format(
m, map_infos[m].nodes, map_infos[m].edges, values_print))
print_csv()
x = range(len(maps_list))
fig, ax = plt.subplots()
num = 0
for tag in sorted(data.keys()):
y = get_values_list(data[tag], maps_list, data["cpp"])
c = palette[num]
LOG_SCALE = False
if LOG_SCALE:
ax.semilogy(x, y, marker='o', color=c, label=tag)
else:
plt.plot(x, y, marker='o', color=c, label=tag)
num += 1
ax.grid()
plt.legend(loc=1, ncol=2)
plt.show()