目录
1 概述
2 运行结果
3 参考文献
4 Matlab代码
无线传感器网络(Wireless Sensor Networks, WSN)是一种分布式传感网络,它的末梢是可以感知和检查外部世界的传感器。WSN中的传感器通过无线方式通信,因此网络设置灵活,设备位置可以随时更改,还可以跟互联网进行有线或无线方式的连接。通过无线通信方式形成的一个多跳自组织网络。
[1]王福豹,史龙,任丰原.无线传感器网络中的自身定位系统和算法[J].软件学报,2005(05):857-868.
主函数部分代码:
clear;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% PARAMETERS %%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Field Dimensions - x and y maximum (in meters)
xm=100;
ym=100;
%x and y Coordinates of the Sink
sink.x=1.5*xm;
sink.y=0.5*ym;
%Number of Nodes in the field
n=200
%Optimal Election Probability of a node
%to become cluster head
p=0.2;
%Energy Model (all values in Joules)
%Initial Energy
Eo=0.1;
%Eelec=Etx=Erx
ETX=50*0.000000001;
ERX=50*0.000000001;
%Transmit Amplifier types
Efs=10*0.000000000001;
Emp=0.0013*0.000000000001;
%Data Aggregation Energy
EDA=5*0.000000001;
%Values for Hetereogeneity
%Percentage of nodes than are advanced
m=0.0;
%\alpha
a=1;
%maximum number of rounds
rmax=100
%%%%%%%%%%%%%%%%%%%%%%%%% END OF PARAMETERS %%%%%%%%%%%%%%%%%%%%%%%%
%Computation of do
do=sqrt(Efs/Emp);
%Creation of the random Sensor Network
figure(1);
hold off;
for i=1:1:n
S(i).xd=rand(1,1)*xm;
XR(i)=S(i).xd;
S(i).yd=rand(1,1)*ym;
YR(i)=S(i).yd;
S(i).G=0;
%initially there are no cluster heads only nodes
S(i).type='N';
temp_rnd0=i;
%Random Election of Normal Nodes
if (temp_rnd0>=m*n+1)
S(i).E=Eo;
S(i).ENERGY=0;
% plot(S(i).xd,S(i).yd,'o');
hold on;
end
%Random Election of Advanced Nodes
if (temp_rnd0
S(i).ENERGY=1;
% plot(S(i).xd,S(i).yd,'+');
hold on;
end
end
S(n+1).xd=sink.x;
S(n+1).yd=sink.y;
%plot(S(n+1).xd,S(n+1).yd,'x');
%First Iteration
figure(1);
%counter for CHs
countCHs=0;
%counter for CHs per round
rcountCHs=0;
cluster=1;
countCHs;
rcountCHs=rcountCHs+countCHs;
flag_first_dead=0;
for r=0:1:rmax
r
%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