-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetrics.py
77 lines (64 loc) · 2.65 KB
/
metrics.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
import matplotlib.pyplot as plt
def check_if_congested(traffic_map, intersections):
congested_intersections = 0
for intersection in intersections:
if traffic_map[intersection.position_x, intersection.position_y] == 1:
congested_intersections += 1
return congested_intersections
def plot_congested(congested_dir, timesteps):
time = []
for t in range(timesteps):
time.append(t)
for key, value in congested_dir.items():
plt.plot(time, value, linewidth=1)
plt.xlabel('Time (s)')
plt.ylabel('Congested Intersections')
plt.legend(["Cycle duration: 5 seconds", "Cycle duration: 10 seconds", "Cycle duration: 15 seconds", "Cycle duration: 20 seconds"], loc="lower right", fontsize=8)
plt.savefig("congestion.png")
avg = []
for cycle, value in congested_dir.items():
summary = 0
for val in value:
summary += val
avg.append(summary)
plt.figure()
for val in avg:
congestion_timestep = []
val = val/timesteps
for t in range(timesteps):
congestion_timestep.append(val)
plt.plot(time, congestion_timestep, linewidth=1)
plt.xlabel('Time (s)')
plt.ylabel('Average Congested Intersections')
plt.legend(["Cycle duration: 5 seconds", "Cycle duration: 10 seconds", "Cycle duration: 15 seconds", "Cycle duration: 20 seconds"], loc="lower right", fontsize=8)
plt.savefig("average_congestion.png")
def plot_flow(flow_dict, timesteps):
time = []
plt.figure()
for t in range(timesteps):
time.append(t)
for key, value in flow_dict.items():
for val in range(len(value)):
value[val] = value[val]*3600
plt.plot(time, value, linewidth=1)
plt.xlabel('Time (sec)')
plt.ylabel(f'Flow Rate (vehicles/hour)')
plt.legend(["Cycle duration: 5 seconds", "Cycle duration: 10 seconds", "Cycle duration: 15 seconds", "Cycle duration: 20 seconds"], loc="lower right", fontsize=8)
plt.savefig("Flow_rate.png")
avg = []
for cycle, value in flow_dict.items():
summary = 0
for val in value:
summary += val
avg.append(summary)
plt.figure()
for val in avg:
congestion_timestep = []
val = val/timesteps
for t in range(timesteps):
congestion_timestep.append(val)
plt.plot(time, congestion_timestep, linewidth=1)
plt.xlabel('Time (s)')
plt.ylabel('Average Congested Intersections')
plt.legend(["Cycle duration: 5 seconds", "Cycle duration: 10 seconds", "Cycle duration: 15 seconds", "Cycle duration: 20 seconds"], loc="lower right", fontsize=8)
plt.savefig("average_flow.png")