-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot_SER_K.py
218 lines (175 loc) · 7.2 KB
/
plot_SER_K.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
import numpy as np
import matplotlib.pyplot as plt
from constants import *
time_epochs = 7
msg_files = 1
puser_files = 1
# arrays for broadcast
Epidemic_opt_PQ = np.zeros(shape=(time_epochs, msg_files, puser_files))
Epidemic_pes_PQ = np.zeros(shape=(time_epochs, msg_files, puser_files))
Epidemic_TV = np.zeros(shape=(time_epochs, msg_files, puser_files))
Epidemic_LTE = np.zeros(shape=(time_epochs, msg_files, puser_files))
Epidemic_CBRS = np.zeros(shape=(time_epochs, msg_files, puser_files))
Epidemic_ISM = np.zeros(shape=(time_epochs, msg_files, puser_files))
num_mules = 48
num_channels = 10
num_Pusers = 100
msgMean = 15
T = 360
startTime = 1
days = "50"
dataset = "Lexington"
buffer_type = "PQ"
protocols = ["optimistic", "pessimistic", "TV", "LTE", "CBRS", "ISM"]
# protocols = ["Epidemic_Smart_optimistic"]
# fwd_strat = ["geo_3"]
fwd_strat = [1, 2, 3, 4, 5, 6, 7]
metrics_file = "metrics.txt"
p_id = 1 # p_id = 1 for PDR, = 2 for latency, and 3 for Energy, and 4 for overhead
for i in range(msg_files):
for j in range(puser_files):
for strat in fwd_strat:
for protocol in protocols:
if strat == 1:
t = 0
elif strat == 2:
t = 1
elif strat == 3:
t = 2
elif strat == 4:
t = 3
elif strat == 5:
t = 4
elif strat == 6:
t = 5
elif strat == 7:
t = 6
elif strat == 15:
t = 7
else:
t = 8
if strat > 0:
path = "DataMules/" + dataset + "/" + days + "/3/Link_Exists/LE_" + str(startTime) + \
"_" + str(T) + "/Epidemic_Smart_" + protocol + "/" + buffer_type + "/geo_" + str(strat) + "/mules_" + \
str(num_mules) + "/channels_" + str(num_channels) + "/P_users_" + str(num_Pusers) + \
"/msgfile" + str(i) + "_" + str(msgMean) + "/puserfile" + str(j) + "/"
else:
path = "DataMules/" + dataset + "/" + days + "/3/Link_Exists/LE_" + str(startTime) + \
"_" + str(T) + "/Epidemic_Smart_" + protocol + "/" + buffer_type + "/broadcast/mules_" + \
str(num_mules) + "/channels_" + str(num_channels) + "/P_users_" + str(num_Pusers) + \
"/msgfile" + str(i) + "_" + str(msgMean) + "/puserfile" + str(j) + "/"
with open(path + metrics_file, "r") as f:
lines = f.readlines()[1:]
for line in lines:
line_arr = line.strip().split()
if int(line_arr[0]) == 360:
if "optimistic" in protocol:
Epidemic_opt_PQ[t, i, j] = float(line_arr[p_id])
elif "pessimistic" in protocol:
Epidemic_pes_PQ[t, i, j] = float(line_arr[p_id])
elif "TV" in protocol:
Epidemic_TV[t, i, j] = float(line_arr[p_id])
elif "LTE" in protocol:
Epidemic_LTE[t, i, j] = float(line_arr[p_id])
elif "CBRS" in protocol:
Epidemic_CBRS[t, i, j] = float(line_arr[p_id])
elif "ISM" in protocol:
Epidemic_ISM[t, i, j] = float(line_arr[p_id])
optB_mean = []
optB_sd = []
pesB_mean = []
pesB_sd = []
TV_mean = []
TV_sd = []
LTE_mean = []
LTE_sd = []
CBRS_mean = []
CBRS_sd = []
ISM_mean = []
ISM_sd = []
optB_temp = []
pesB_temp = []
TV_temp = []
LTE_temp = []
CBRS_temp = []
ISM_temp = []
for t in range(len(Epidemic_opt_PQ)):
t_arr_optB = []
t_arr_pesB = []
t_arr_tv = []
t_arr_lte = []
t_arr_cbrs = []
t_arr_ism = []
for i in range(len(Epidemic_opt_PQ[t])):
for j in range(len(Epidemic_opt_PQ[t][i])):
t_arr_optB.append(Epidemic_opt_PQ[t,i,j])
t_arr_pesB.append(Epidemic_pes_PQ[t,i,j])
t_arr_tv.append(Epidemic_TV[t, i, j])
t_arr_lte.append(Epidemic_LTE[t, i, j])
t_arr_cbrs.append(Epidemic_CBRS[t, i, j])
t_arr_ism.append(Epidemic_ISM[t, i, j])
optB_temp.append(t_arr_optB)
pesB_temp.append(t_arr_pesB)
TV_temp.append(t_arr_tv)
LTE_temp.append(t_arr_lte)
CBRS_temp.append(t_arr_cbrs)
ISM_temp.append(t_arr_ism)
for i in range(len(optB_temp)):
optB_mean.append(np.mean(optB_temp[i]))
pesB_mean.append(np.mean(pesB_temp[i]))
optB_sd.append(np.std(optB_temp[i]))
pesB_sd.append(np.std(pesB_temp[i]))
TV_mean.append(np.mean(TV_temp[i]))
TV_sd.append(np.std(TV_temp[i]))
LTE_mean.append(np.mean(LTE_temp[i]))
LTE_sd.append(np.std(LTE_temp[i]))
CBRS_mean.append(np.mean(CBRS_temp[i]))
CBRS_sd.append(np.std(CBRS_temp[i]))
ISM_mean.append(np.mean(ISM_temp[i]))
ISM_sd.append(np.std(ISM_temp[i]))
print(len(optB_mean))
x = [1, 2, 3, 4, 5, 6, 7]
# x.append(0)
plt.xticks(fontsize=10)
plt.yticks(fontsize=25)
plt.xticks(x)
title_str = "Channels: " + str(num_channels) + " Primary Users: " + str(num_Pusers)
# title_str = "Broadcast to everyone in range"
# plt.title(title_str)
# plt.xlim(0,12)
fig_name = "dummy.eps"
if p_id == 1:
plt.ylabel('Message delivery ratio', fontsize=25)
plt.xlabel('# mules to forward to', fontsize=25)
plt.ylim(-0.1,1)
fig_name = "Plots/pdr_K_SER.png"
if p_id == 2:
plt.ylabel('Network delay (min)', fontsize=25)
plt.xlabel('# mules to forward to', fontsize=25)
fig_name = "Plots/latency_K_SER.png"
if p_id == 3:
plt.ylabel('Energy per packet (J)', fontsize=25)
plt.xlabel('# mules to forward to', fontsize=25)
fig_name = "Plots/energy_K_SER.png"
if p_id == 4:
plt.ylabel('Message overhead', fontsize=25)
plt.xlabel('# mules to forward to', fontsize=25)
# plt.ylim(-1, 20)
fig_name = "Plots/overhead_K_SER.png"
plt.errorbar(x, optB_mean, optB_sd, marker='o', markersize=5, linestyle='-', linewidth=1, color="red")
plt.errorbar(x, pesB_mean, pesB_sd, marker='o', markersize=5, linestyle='-', linewidth=1, color="blue")
plt.errorbar(x, TV_mean, 0, marker='x', markersize=5, linestyle='--', linewidth=1, color="green")
plt.errorbar(x, LTE_mean, 0, marker='x', markersize=5, linestyle='--', linewidth=1, color="black")
plt.errorbar(x, CBRS_mean, 0, marker='x', markersize=5, linestyle='--', linewidth=1, color="brown")
plt.errorbar(x, ISM_mean, 0, marker='x', markersize=5, linestyle='--', linewidth=1, color="gray")
if p_id == 1:
plt.legend(["Optimistic", "Pessimistic", "TV", "LTE", "CBRS", "ISM"], loc="lower right", fontsize=12, ncol = 2, frameon=False)
elif p_id == 2:
plt.legend(["Optimistic", "Pessimistic", "TV", "LTE", "CBRS", "ISM"], loc="upper center", fontsize=12, ncol = 3, frameon=False)
elif p_id ==3:
plt.legend(["Optimistic", "Pessimistic", "TV", "LTE", "CBRS", "ISM"], loc="upper right", fontsize=12, ncol = 2, frameon=False)
elif p_id ==4:
plt.legend(["Optimistic", "Pessimistic", "TV", "LTE", "CBRS", "ISM"], loc="lower right", fontsize=12, ncol = 2, frameon=False)
plt.tight_layout()
plt.savefig(fig_name)
plt.show()