Professional Documents
Culture Documents
ETX=5010-9 ERX=5010-9
Eelec=ETX=ERX
Efs=1010-12 Emp=0.001310-12
EDA=510-9
m=0.5
=1
rmax=100
n=200;%Enter the number of nodes in the space (in the field)
%Energy Model (all values in Joules)
Eo=0.1;%Initial Energy the initial energy of sensor nJ
xm=100;ym=100;%Field Dimensions - x and y maximum (in meters)
x,y value for area plot
sink.x=1.5*xm;sink.y=0.5*ym;%x and y Coordinates of the Sink
p=0.2;%Optimal Election Probability of a node to become CH
ETX=50e-9;ERX=50e-9;%Eelec=Etx=Erx
Efs=10e-12;Emp=0.0013e-12;%Transmit Amplifier types
EDA=53-9;%Data Aggregation Energy Values for Heterogeneity
m=0.5;%Percentage of nodes than are advanced
a=1;%\alpha
rmax=100;%maximum number of rounds (iterations);
Computation of d0:
0 =
= 1,2, . , =
= 0
=
do=sqrt(Efs/Emp);%Computation of do
%Creation of the random Sensor Network
figure(10);
for i=1:1:n
S(i).xd=rand(1,1)*xm;
S(i).yd=rand(1,1)*ym;
S(i).G=0;
S(i).type='N';%initially there are no cluster heads only nodes
Random Election of Normal Nodes:
0 + 1
= {
0 (1 + ) < + 1
0 + 1
={
1 < + 1
+1
=
+1
=
90
80
70
60
50
40
30
Sink
20
10
0
0 50 100 150
figure(1);
%First Iteration
countCHs=0;%counter for CHs
rcountCHs=0;%counter for CHs per round
cluster=1;
rcountCHs=rcountCHs+countCHs;
flag_first_dead=0;
For rmax of rounds:
Operation for epoch
= 0 , = 0 (, (1/) ) = 0
= 1,2, . , =
= 1,2, . , max =
Initially there are no dead nodes, dead advanced nodes, and dead normal
nodes, therefore their counters are reset to zero
Counters for bit transmitted to Bases Station and to Cluster Heads are
reset to zero
Counters per round for bit transmitted to Bases Station and to Cluster
Heads are reset to zero
for r=0:1:rmax
%Operation for epoch
if(mod(r, round(1/p) )==0)
for i=1:1:n
S(i).G=0;
S(i).cl=0;
end
end
hold off;
dead=0;%Number of dead nodes
dead_a=0;%Number of dead Advanced Nodes
dead_n=0;%Number of dead Normal Nodes
packets_TO_BS=0;%counter for bit transmitted to Bases Station
packets_TO_CH=0;%and to Cluster Heads
%counter for bit transmitted to Bases Station and to Cluster
Heads per round
PACKETS_TO_CH(r+1)=0;PACKETS_TO_BS(r+1)=0;
figure(1);
Checking if there is a dead node
0 &
= 0
0 &
= 1
Counters of dead nodes, dead advanced nodes, and dead normal nodes,
will start counting
> 0
> 0 &
= 0 , =
> 0 &
= 1
for i=1:1:n
%checking if there is a dead node
if (S(i).E<=0)
plot(S(i).xd,S(i).yd,'^','LineWidth',1,...
'MarkerEdgeColor','k', 'MarkerFaceColor','y',
'MarkerSize',8);
dead=dead+1;
if(S(i).ENERGY==1)
dead_a=dead_a+1;
end
if(S(i).ENERGY==0)
dead_n=dead_n+1;
end
hold on;
end
if S(i).E>0
S(i).type='N';
if (S(i).ENERGY==0)
plot(S(i).xd,S(i).yd,'o','LineWidth',1,
'MarkerEdgeColor','k',...
'MarkerFaceColor','g', 'MarkerSize',8);
end
if (S(i).ENERGY==1)
plot(S(i).xd,S(i).yd,'+','LineWidth',3,
'MarkerEdgeColor','k',...
'MarkerFaceColor','r', 'MarkerSize',8);
end
hold on;
end
end
plot(S(n+1).xd,S(n+1).yd,'x','LineWidth',1,
'MarkerEdgeColor','k',...
'MarkerFaceColor','r', 'MarkerSize',8);
STATISTICS(r+1).DEAD=dead;
DEAD(r+1)=dead;DEAD_N(r+1)=dead_n;DEAD_A(r+1)=dead_a;
%When the first node dies
if (dead==1)
if(flag_first_dead==0)
first_dead=r;flag_first_dead=1;
end
end
Counter for Cluster Heads are reset to zero starting with cluster number 1
> 0
1
(, ( ))
Counters for bit transmitted to Bases Station and to Cluster Heads start
counting
= , = (1/) 1
countCHs=0;cluster=1;
for i=1:1:n
if(S(i).E>0)
temp_rand=rand;
if ((S(i).G)<=0)
if(temp_rand<= (p/(1-p*mod(r,round(1/p))))) %Election of CHs
countCHs=countCHs+1;
packets_TO_BS=packets_TO_BS+1;
PACKETS_TO_BS(r+1)=packets_TO_BS;
S(i).type='C';S(i).G=round(1/p)-1;
Calculating the cluster head coordinates:
=
=
Calculating the distance between the cluster head and the sink:
2 2
= ( ) + ( )
=
Calculation of Energy dissipated
+1
4000( + + (4 )) > 0
={
4000( + + (2 )) 0
C(cluster).xd=S(i).xd;
C(cluster).yd=S(i).yd;
plot(S(i).xd,S(i).yd,'k*');
distance=sqrt( (S(i).xd-(S(n+1).xd) )^2 +...
(S(i).yd-(S(n+1).yd) )^2 );
C(cluster).distance=distance;
C(cluster).id=i;
X(cluster)=S(i).xd;
Y(cluster)=S(i).yd;
cluster=cluster+1;
%Calculation of Energy dissipated
if (distance>do)
S(i).E=S(i).E- ( (ETX+EDA)*(4000) + Emp*4000*(distance^4));
end
if (distance<=do)
S(i).E=S(i).E- ( (ETX+EDA)*(4000) + Efs*4000*( distance^2));
end
Energy_disp(r+1) = S(i).E;
end
end
end
end
Counting for cluster heads in each cluster
After selecting a cluster head the associated normal nodes will be elected
according to the distance
= , > 0 (Check if the node is normal and not dead)
Also (if cluster-1>=1) to start with the node is next to the cluster head
= 1,2, . , 1 =
4000( + + (4 )) > 0
= {
4000( + + (2 )) 0
Counter for Cluster Heads per rounds (current) = Counter for Cluster Heads per
rounds (pervious) + Counter for Cluster Head
STATISTICS(r+1).CLUSTERHEADS=cluster-1;
CLUSTERHS(r+1)=cluster-1;
0.15
0.145
0.14
Average Energy of Each Node
0.135
0.13
0.125
0.12
0.115
0.11
0 5 10 15 20 25
Round Number
0.16
0.15
0.14
Average Energy of Each Node
0.13
0.12
0.11
0.1
0.09
0.08
0 5 10 15 20 25 30 35 40 45 50
Round Number
0.16
0.14
Average Energy of Each Node
0.12
0.1
0.08
0.06
0.04
0 10 20 30 40 50 60 70 80
Round Number
0.16
0.14
Average Energy of Each Node
0.12
0.1
0.08
0.06
0.04
0.02
0 10 20 30 40 50 60 70 80 90 100
Round Number
0.8
0.6
0.4
Number of Dead Nodes
0.2
-0.2
-0.4
-0.6
-0.8
-1
0 5 10 15 20 25
Round Number
14
12
10
Number of Dead Nodes
0
0 5 10 15 20 25 30 35 40 45 50
Round Number
45
40
35
Number of Dead Nodes
30
25
20
15
10
0
0 10 20 30 40 50 60 70 80
Round Number
80
70
60
Number of Dead Nodes
50
40
30
20
10
0
0 10 20 30 40 50 60 70 80 90 100
Round Number