-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcalculateAverageResults.m
148 lines (106 loc) · 4.65 KB
/
calculateAverageResults.m
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
function [] = calculateAverageResults(N, N_Increase, N_Count, Rnet, Rnet_Increase, Rnet_Count, Average_Count, mode)
%CALCULATEAVERAGERESULTS Summary of this function goes here
% Detailed explanation goes here
close all;
if mode==0
%% Figure-1 Minimum Hop Count.
f1=figure('Name','Minimum Hop Count.');
ylim([0 100]);
xlim([N-1 N+N_Increase*(N_Count-1)+1]);
title('Minimum Hop Count');
%% Figure-2 Decrease in network lifetime when the minimum hop count is enforced.
f2=figure('Name','Decrease in network lifetime when the minimum hop count is enforced.');
ylim([0 100]);
xlim([N-1 N+N_Increase*(N_Count-1)+1]);
title('Decrease in network lifetime when the minimum hop count is enforced');
%% Figure-3 Hop Count increase to achieve the maximum lifetime.
f3=figure('Name','Hop Count increase to achieve the maximum lifetime.');
title('Hop Count increase to achieve the maximum lifetime');
legendString=strings(Rnet_Count,1);
for r=1:Rnet_Count
numberOfNodes=zeros(N_Count,1);
maxLifeTimePercent=zeros(N_Count,1);
minHopCounts=zeros(N_Count,1);
hopCountPercent=zeros(N_Count,1);
rnet=Rnet+Rnet_Increase*(r-1);
for i=1:N_Count
numberOfNodes(i)=N+N_Increase*(i-1);
minHopCounts(i)=0;
maxLifeTimePercent(i)=0;
hopCountPercent(i)=0;
for j=1:Average_Count
filename1=strcat('..\results\',num2str(r),'\',num2str(i),'\',num2str(j));
filename2=strcat('results\',num2str(r),'\',num2str(i),'\',num2str(j));
[minHopCountsTmp, pathsWithMinHop, lifeTimeWithMinHop,...
hopCountWithMaxLifeTime, pathsWithMaxLifeTime, maxLifeTime]=...
calculateNetwork(filename2);
hopCountPercentTmp=(hopCountWithMaxLifeTime/minHopCountsTmp)*100-100;
maxLifeTimePercentTmp=100*((maxLifeTime-lifeTimeWithMinHop)/(maxLifeTime));
minHopCounts(i)=minHopCounts(i)+minHopCountsTmp;
maxLifeTimePercent(i)=maxLifeTimePercent(i)+maxLifeTimePercentTmp;
hopCountPercent(i)=hopCountPercent(i)+hopCountPercentTmp;
end
minHopCounts(i)=minHopCounts(i)/Average_Count;
maxLifeTimePercent(i)=maxLifeTimePercent(i)/Average_Count;
hopCountPercent(i)=hopCountPercent(i)/Average_Count;
end
figure(f1);
plot(numberOfNodes,minHopCounts,'-o');
hold on;
figure(f2);
plot(numberOfNodes,maxLifeTimePercent,'-o');
hold on;
figure(f3);
plot(numberOfNodes,hopCountPercent,'-o');
hold on;
legendString(r)=strcat('Rnet=',num2str(rnet));
end
figure(f1);
grid;
legend(legendString);
xlabel('Number of Nodes');
ylabel('Minimum Hop Count');
figure(f2);
grid;
legend(legendString);
ylim([0 100]);
xlim([N-1 N+N_Increase*(N_Count-1)+1]);
xlabel('Number of Nodes');
ylabel('Lifetime Decrease(%)');
figure(f3);
grid;
legend(legendString);
ylim([0 100]);
xlim([N-1 N+N_Increase*(N_Count-1)+1]);
xlabel('Number of Nodes');
ylabel('Hop Count increase(%)');
else
for r=1:Rnet_Count
rnet=Rnet+Rnet_Increase*(r-1);
figure('Name','Network lifetime-Hop count.');
legendString=strings(N_Count,1);
numberOfNodes=zeros(N_Count,1);
for i=1:N_Count
numberOfNodes(i)=N+N_Increase*(i-1);
lifeTimeDecreaseTmp=zeros(8,1);
for j=1:Average_Count
filename1=strcat('..\results2\',num2str(r),'\',num2str(i),'\',num2str(j));
filename2=strcat('results2\',num2str(r),'\',num2str(i),'\',num2str(j));
[lifeTime, maxLifeTime]=...
calculateLifetimeNetwork(filename2);
lifeTimeDecreaseTmp=lifeTimeDecreaseTmp+100*((maxLifeTime-lifeTime(:,1))/(maxLifeTime));
end
lifeTimeDecrease=lifeTimeDecreaseTmp/Average_Count;
hopCountIncrease=[0;5; 10; 15; 20; 25; 30; 35];
plot(hopCountIncrease,lifeTimeDecrease,'-o');
hold on;
legendString(i)=strcat(num2str(numberOfNodes(i)),' nodes');
end
legend(legendString);
xlabel('Hop Count Increase(%)');
ylabel('Lifetime Decrease(%)');
xlim([-3 38]);
title(strcat('Network lifetime-Hop count R=',num2str(rnet)));
end
end
end