-
Notifications
You must be signed in to change notification settings - Fork 2
/
plot_linha.py
288 lines (211 loc) · 7.46 KB
/
plot_linha.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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
# -*- coding: UTF-8 -*-
# File name: plot_linha.py
# Author: Joahannes Costa
# Data create: 14/12/2017
# Data last modified: 14/12/2017
# Python version: 2.7
# Description: plota graficos de linha para algoritmos de disseminacao
from __future__ import division
import math
import matplotlib.pyplot as plt
import numpy as np
# summary_file:
# 0 REPLICATION
# 1 HOST
# 2 LOSS
# 3 DELAY
# 4 RECEIVED
# 5 TRANSMITTED
# 6 DUPLICATES
# 7 COLLISIONS
ALGORITHMS = ("DDRX", "CARRO", "UV-CAST", "CC-DEGREE", "Flooding") #
TRAFFICS = (100,200,300,400,500,600,700) #
COLORS = {"DDRX" : "k", "CARRO" : "r", "UV-CAST" : "b", "CC-DEGREE" : "magenta", "Flooding" : "g"}
MARKS = {"DDRX" : "H", "CARRO" : "^", "UV-CAST" : "d", "CC-DEGREE" : "*", "Flooding" : "s"}
LINES = {"DDRX" : "-", "CARRO" : "--", "UV-CAST" : "-.", "CC-DEGREE" : "-", "Flooding" : ":"}
#VARIABLES PLOT
X_LEGEND = u'Densidade (veículos/km$^2$)'
x_lim = 750
x_fig = 6.8 #6.8
y_fig = 5.5 #5.5
formato = '.eps'
legenda_size = 16
#bbox_inches = 'tight', pad_inches = 0.05 -> remove borda desnecessaria da imagem
#CONFIDENCE INTERVAL - BAR ERROR
def confidence_interval(values):
N = len(values)
Z = 1.96
std_dev = np.std(values)
std_error = std_dev / math.sqrt(N)
return Z * std_error
#COVERAGE
def plot_coverage():
for algorithm in ALGORITHMS:
coverage_values = []
confidence_intervals = []
coverage = float(0)
for traffic in TRAFFICS:
values = []
file_input_name = algorithm + "/summary-" + str(traffic) + ".txt"
replication = 0
coverage = 0.0
for line in open(file_input_name):
if replication == int(line.split()[0]):
if line.split()[4] != "0":
coverage += int(line.split()[4])
else:
# CHANGED
if not coverage == 0:
values.append(coverage)
coverage = 0
while replication != int(line.split()[0]):
replication += 1
values = np.divide(values, traffic)
values = np.multiply(values, 100)
coverage_values.append(np.mean(values))
confidence_intervals.append(confidence_interval(values))
plt.errorbar(TRAFFICS, coverage_values, yerr=confidence_intervals, label=algorithm, color=COLORS[algorithm], marker=MARKS[algorithm], linestyle=LINES[algorithm], markersize = 8, linewidth = 2, zorder=3)
yticks = np.arange(90, 102, 2)
plt.xlabel(X_LEGEND, fontsize=legenda_size)
plt.ylabel('Cobertura (%)', fontsize=legenda_size)
plt.xlim(50, x_lim)
plt.xticks(TRAFFICS, fontsize=legenda_size)
plt.yticks(yticks, fontsize=legenda_size)
#plt.yscale("log")
plt.grid()
plt.legend(numpoints=1, loc=4, fancybox=True)
fig = plt.gcf()
fig.set_size_inches(x_fig, y_fig)
fig.savefig('cobertura' + formato, dpi=200, bbox_inches = 'tight', pad_inches = 0.05)
plt.show()
#DELAY
def plot_delay():
for algorithm in ALGORITHMS:
delay_values = []
confidence_intervals = []
delay = float(0)
for traffic in TRAFFICS:
values = []
file_input_name = algorithm + "/summary-" + str(traffic) + ".txt"
replication = 0
delay = 0.0
for line in open(file_input_name):
if replication == int(line.split()[0]):
if line.split()[3] != "NA":
delay += float(line.split()[3])
else:
# CHANGED
if not delay == 0.0:
values.append(delay)
delay = 0.0
while replication != int(line.split()[0]):
replication += 1
#values = np.divide(values,traffic)
#values = np.multiply(values,60)
delay_values.append(np.mean(values))
confidence_intervals.append(confidence_interval(values))
#print (algorithm, delay_values)
plt.errorbar(TRAFFICS, delay_values, yerr=confidence_intervals, label=algorithm, color=COLORS[algorithm], marker=MARKS[algorithm], linestyle=LINES[algorithm], markersize = 8, linewidth = 2, zorder=3)
yticks = np.arange(0, 110, 10)
plt.xlabel(X_LEGEND, fontsize=legenda_size)
plt.ylabel('Atraso (s)', fontsize=legenda_size)
plt.xlim(50, x_lim)
plt.xticks(TRAFFICS, fontsize=legenda_size)
plt.yticks(yticks, fontsize=legenda_size)
plt.yscale("log")
plt.grid()
plt.legend(numpoints=1, loc=2, fancybox=True)
fig = plt.gcf()
fig.set_size_inches(x_fig, y_fig)
fig.savefig('atraso' + formato, dpi=200, bbox_inches = 'tight', pad_inches = 0.05)
plt.show()
#PACKETS TRANSMITTED
def plot_transmitted():
for algorithm in ALGORITHMS:
transmitted_values = []
confidence_intervals = []
for traffic in TRAFFICS:
values = []
file_input_name = algorithm + "/summary-" + str(traffic) + ".txt"
replication = 0
transmitted = 0
for line in open(file_input_name):
if replication == int(line.split()[0]):
if line.split()[5] != "0":
transmitted += int(line.split()[5])
else:
# CHANGED
if not transmitted == 0:
values.append(transmitted)
transmitted = 0
while replication != int(line.split()[0]):
replication += 1
#values = np.divide(values,traffic)
#values = np.multiply(values,100)
transmitted_values.append(np.mean(values))
confidence_intervals.append(confidence_interval(values))
#print (algorithm, transmitted_values)
plt.errorbar(TRAFFICS, transmitted_values, yerr=confidence_intervals, label=algorithm, color=COLORS[algorithm], marker=MARKS[algorithm], linestyle=LINES[algorithm], markersize = 8, linewidth = 2, zorder=3)
yticks = np.arange(0, 110, 10)
plt.xlabel(X_LEGEND, fontsize=legenda_size)
plt.ylabel('Total de Pacotes Transmitidos', fontsize=legenda_size)
plt.xlim(50, x_lim)
plt.xticks(TRAFFICS, fontsize=legenda_size)
plt.yticks(yticks, fontsize=legenda_size)
plt.yscale("log")
plt.grid()
plt.legend(numpoints=1, loc=2, fancybox=True)
fig = plt.gcf()
fig.set_size_inches(x_fig, y_fig)
fig.savefig('transmitidos' + formato, dpi=200, bbox_inches = 'tight', pad_inches = 0.05)
plt.show()
#COLISIONS
def plot_colisions():
for algorithm in ALGORITHMS:
colisions_values = []
confidence_intervals = []
for traffic in TRAFFICS:
values = []
file_input_name = algorithm + "/summary-" + str(traffic) + ".txt"
replication = 0
colisions = 0
for line in open(file_input_name):
if replication == int(line.split()[0]):
if line.split()[7] != "0":
colisions += int(line.split()[7])
else:
# CHANGED
if not colisions == 0:
values.append(colisions)
colisions = 0
while replication != int(line.split()[0]):
replication += 1
#values = np.divide(values,traffic)
#values = np.multiply(values,100)
colisions_values.append(np.mean(values))
confidence_intervals.append(confidence_interval(values))
#print (algorithm, colisions_values)
plt.errorbar(TRAFFICS, colisions_values, yerr=confidence_intervals, label=algorithm, color=COLORS[algorithm], marker=MARKS[algorithm], linestyle=LINES[algorithm], markersize = 8, linewidth = 2, zorder=3)
yticks = np.arange(0, 20, 1)
plt.xlabel(X_LEGEND, fontsize=legenda_size)
plt.ylabel(u'Número de Colisões', fontsize=legenda_size)
plt.xlim(50, x_lim)
plt.xticks(TRAFFICS, fontsize=legenda_size)
plt.yticks(yticks, fontsize=legenda_size)
plt.yscale("log")
plt.grid()
plt.legend(numpoints=1, loc=2, fancybox=True)
fig = plt.gcf()
fig.set_size_inches(x_fig, y_fig)
fig.savefig('colisoes' + formato, dpi=200, bbox_inches = 'tight', pad_inches = 0.05)
plt.show()
if __name__ == "__main__":
pass
print("Grafico de COBERTURA...")
plot_coverage()
print("Grafico de ATRASO...")
plot_delay()
print("Grafico de PACOTES_TRANSMITIDOS...")
plot_transmitted()
print("Grafico de COLISOES...")
plot_colisions()