-
Notifications
You must be signed in to change notification settings - Fork 0
/
visualise_runs.py
executable file
·102 lines (73 loc) · 3.38 KB
/
visualise_runs.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
#!/bin/python3
"""
FOMO simulator, visualises results from a cluster run
"""
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
###############################################################################
def lostTripsPlot(cities, policies, starv, starv_stdev, cong, cong_stdev):
fig, subPlots = plt.subplots(nrows=1, ncols=len(cities), sharey=True)
fig.suptitle("FOMO simulator - lost trips results", fontsize=15)
if len(cities) == 1:
subPlots = [ subPlots ]
w = 0.3
pos = []
for city in range(len(cities)):
pos.append([])
for i in range(len(cong[city])):
pos[city].append(starv[city][i] + cong[city][i])
subPlots[city].bar(policies, starv[city], w, label='Starvation')
subPlots[city].errorbar(policies, starv[city], yerr = starv_stdev[city], fmt='none', ecolor='red')
subPlots[city].bar(policies, cong[city], w, bottom=starv[city], label='Congestion')
# skew the upper error-bar with delta to avoid that they can overwrite each other
delta = 0.05
policiesPlussDelta = []
for i in range(len(policies)):
policiesPlussDelta.append(i + delta)
subPlots[city].errorbar(policiesPlussDelta, pos[city], yerr= cong_stdev[city], fmt='none', ecolor='black')
subPlots[city].set_xlabel(cities[city])
if city == 0:
subPlots[city].set_ylabel("Violations (% of total number of trips)")
subPlots[city].legend()
###############################################################################
if __name__ == "__main__":
with open("output.csv", "r") as infile:
lines = infile.readlines()
run = {}
for line in lines:
words = line.split(';')
n = int(words[0])
instance_name = words[1]
analysis_name = words[2]
trips = float(words[3])
starvations = float(words[4])
congestions = float(words[5])
starvations_stdev = float(words[6])
congestions_stdev = float(words[7])
if instance_name not in run:
run[instance_name] = {}
run[instance_name][analysis_name] = (trips, starvations, congestions, starvations_stdev, congestions_stdev)
instance_names = []
starvations = []
congestions = []
starvations_stdev = []
congestions_stdev = []
for instance_name in run.keys():
instance_names.append(instance_name)
starvations.append([])
congestions.append([])
starvations_stdev.append([])
congestions_stdev.append([])
analysis_names = []
for analysis_name in run[instance_name].keys():
analysis_names.append(analysis_name)
scale = 100 / run[instance_name][analysis_name][0]
starvations[-1].append(scale * run[instance_name][analysis_name][1])
congestions[-1].append(scale * run[instance_name][analysis_name][2])
starvations_stdev[-1].append(scale * run[instance_name][analysis_name][3])
congestions_stdev[-1].append(scale * run[instance_name][analysis_name][4])
print(starvations)
print(congestions)
lostTripsPlot(instance_names, analysis_names, starvations, starvations_stdev, congestions, congestions_stdev)
plt.show()