-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathplots.py
92 lines (77 loc) · 3.85 KB
/
plots.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
import time
import datetime
import logging
import numpy as np
# mpl.use('agg') #TODO: for use in the command-line-only (no GUI) server
from matplotlib import rcParams
# rcParams['font.family'] = 'sans-serif'
# rcParams['font.sans-serif'] = ['Times New Roman', 'Times']
# rcParams['font.size'] = 24
import matplotlib.pyplot as plt
logging.getLogger('matplotlib').setLevel(logging.WARNING)
def plot_simulation_progress(env):
"""
Plots results for a particular configuration.
"""
plt.figure(figsize=(10, 4))
plt.subplot(1, 2, 1)
if any(i > 0 for i in env.tracked_results['request_blocking_ratio']):
plt.semilogy([x * env.track_stats_every for x in range(1, len(env.tracked_results['request_blocking_ratio'])+1)],
env.tracked_results['request_blocking_ratio'])
plt.xlabel('Arrival')
plt.ylabel('Req. blocking ratio')
plt.subplot(1, 2, 2)
plt.plot([x * env.track_stats_every for x in range(1, len(env.tracked_results['average_link_usage'])+1)],
env.tracked_results['average_link_usage'])
plt.xlabel('Arrival')
plt.ylabel('Avg. link usage')
plt.tight_layout()
# plt.show()
for format in env.plot_formats:
plt.savefig('./results/{}/progress_{}_{}_{}.{}'.format(env.output_folder,
env.policy.name, env.load, env.id_simulation, format))
plt.close()
def plot_final_results(env, results, start_time, savefile=True, show=False, timedelta=None):
"""
Consolidates the statistics and plots it periodically and at the end of all simulations.
"""
markers = ['', 'x']
plt.figure(figsize=(10, 4))
plt.subplot(1, 2, 1)
for idp, policy in enumerate(results):
if any(results[policy][load][x]['request_blocking_ratio'] > 0 for load in results[policy] for x in range(len(results[policy][load]))):
plt.semilogy([load for load in results[policy]],
[np.mean([results[policy][load][x]['request_blocking_ratio'] for x in range(len(results[policy][load]))])
for load in results[policy]], label=policy, marker=markers[idp])
plt.xlabel('Load [Erlang]')
plt.ylabel('Req. blocking ratio')
plt.subplot(1, 2, 2)
has_data = False
for idp, policy in enumerate(results):
if any(results[policy][load][x]['average_link_usage'] > 0 for load in results[policy] for x in range(len(results[policy][load]))):
has_data = True
plt.plot([load for load in results[policy]],
[np.mean([results[policy][load][x]['average_link_usage'] for x in range(len(results[policy][load]))]) for
load in results[policy]], label=policy, marker=markers[idp])
plt.xlabel('Load [Erlang]')
plt.ylabel('Avg. link usage')
if has_data:
plt.legend(loc=2)
total_simulations = np.sum([1 for p in results for l in results[p]]) * env.num_seeds
performed_simulations = np.sum([len(results[p][l]) for p in results for l in results[p]])
percentage_completed = float(performed_simulations) / float(total_simulations) * 100.
plt.tight_layout()
if timedelta is None:
timedelta = datetime.timedelta(seconds=(time.time() - start_time))
plt.text(0.01, 0.02, 'Progress: {} out of {} ({:.3f} %) / {}'.format(performed_simulations,
total_simulations,
percentage_completed,
timedelta),
transform=plt.gcf().transFigure,
fontsize=rcParams['font.size'] - 4.)
if savefile:
for format in env.plot_formats:
plt.savefig('./results/{}/final_results.{}'.format(env.output_folder, format))
if show:
plt.show()
plt.close()