资源简介
matlab运行环境下,基于pegasis和leach协议的无线路由算法,其中含有对比leach和deec算法,源码
代码片段和文件信息
clear
xm=100;
ym=100;
sink.x=0.5*xm;
sink.y=0.5*ym;
n=100
p=0.05;
P=0.05;
Eo=0.5;
%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;
a=1;
rmax=5000
do=sqrt(Efs/Emp);
Et=0;
for i=1:1:n
S1(i).xd=rand(11)*xm;
S2(i).xd=S1(i).xd;
S3(i).xd=S1(i).xd;
S4(i).xd=S3(i).xd;
XR4(i)=S4(i).xd;
XR3(i)=S3(i).xd;
XR2(i)=S2(i).xd;
XR1(i)=S1(i).xd;
S1(i).yd=rand(11)*ym;
S2(i).yd=S1(i).yd;
S3(i).yd=S1(i).yd;
S4(i).yd=S3(i).yd;
YR4(i)=S4(i).yd;
S4(i).G=0;
YR3(i)=S3(i).yd;
S3(i).G=0;
YR2(i)=S2(i).yd;
YR1(i)=S1(i).yd;
S1(i).G=0;
S2(i).G=0;
S1(i).E=Eo*(1+rand*a);
S2(i).E=S1(i).E;
S3(i).E=S1(i).E;
S4(i).E=S3(i).E;
E3(i)= S3(i).E;
E4(i)= S4(i).E;
Et=Et+E3(i);
%initially there are no cluster heads only nodes
S1(i).type=‘N‘;
S2(i).type=‘N‘;
S3(i).type=‘N‘;
S4(i).type=‘N‘;
end
S1(n+1).xd=sink.x;
S1(n+1).yd=sink.y;
S2(n+1).xd=sink.x;
S2(n+1).yd=sink.y;
countCHs1=0;
cluster1=1;
flag_first_dead1=0;
flag_teenth_dead1=0;
flag_all_dead1=0;
dead1=0;
first_dead1=0;
teenth_dead1=0;
all_dead1=0;
allive1=n;
%counter for bit transmitted to bases Station and to Cluster Heads
packets_TO_BS1=0;
packets_TO_CH1=0;
for r=0:1:rmax
r
if(mod(r round(1/p) )==0)
for i=1:1:n
S1(i).G=0;
S1(i).cl=0;
end
end
dead1=0;
for i=1:1:n
if (S1(i).E<=0)
dead1=dead1+1;
if (dead1==1)
if(flag_first_dead1==0)
first_dead1=r;
flag_first_dead1=1;
end
end
if(dead1==0.1*n)
if(flag_teenth_dead1==0)
teenth_dead1=r;
flag_teenth_dead1=1;
end
end
if(dead1==n)
if(flag_all_dead1==0)
all_dead1=r;
flag_all_dead1=1;
end
end
end
if S1(i).E>0
S1(i).type=‘N‘;
end
end
STATISTICS.DEAD1(r+1)=dead1;
STATISTICS.ALLIVE1(r+1)=allive1-dead1;
countCHs1=0;
cluster1=1;
for i=1:1:n
if(S1(i).E>0)
temp_rand=rand;
if ( (S1(i).G)<=0)
if(temp_rand<= (p/(1-p*mod(rround(1/p)))))
countCHs1=countCHs1+1;
packets_TO_BS1=packets_TO_BS1+1;
PACKETS_TO_BS1(r+1)=packets_TO_BS1;
S1(i).type=‘C‘;
S1(i).G=round(1/p)-1;
C1(cluster1).xd=S1(i).xd;
C1(cluster1).yd=S1(i).yd;
distance=sqrt( (S1(i).xd-(S1(n+1).xd) )^2 + (S1(i).yd-(S1(n+1).yd) )^2 );
C1(cluster1).distance=distance;
C1(cluster1).id=i;
X1(cluster1)=S1(i).xd;
Y1(clus
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 2729 2009-11-09 15:34 pegasis.m
文件 20471 2012-04-14 21:56 leachvsdeec.m
----------- --------- ---------- ----- ----
23200 2
- 上一篇:matlab变分模态分解VMD
- 下一篇:moead优化算法
相关资源
- matlab变分模态分解VMD
- 随机森林回归matlab代码
- QPSK与OQPSK数字调制方式MATLAB代码
- 计算光谱夹角的matlab代码,内有注释
- matlab实现人工鱼群算法测试函数
- 熵权法求权重 matlab程序
- 自动控制原理课程设计--用MATLAB进行控
- MD5算法_matlab版
- 多AUV目标搜素与围捕.zip
- 基于DS证据理论的信息融合代码
- 变分模态分解matlab
- 六种数字调制信号识别的matlab程序
- 滤波反投影fbp算法matlab
- 电弧炉MATLAB模型
- matlab中kdtree调用,搜索点云数据近邻
- 演化博弈matlab源代码
- matlab 一致性算法
- 机器学习及其matlab实现—从基础到实
- 聚束SAR,PFA算法matlab仿真
- 图像/水下图像质量评价指标介绍含
- 直流微网模型matlab
- 经典去雾算法matlab实现
- 三维重建八点算法MATLAB代码
- 中继放大转发的matlab代码
- matlab 光学衍射模拟
- MIT-BIH ECG 心电数据+matlab绘图详解
- 从三维数组中提取出任意二维的数据
- MATLAB源程序代码分享:MATLAB实现四阶
- poissonmatlab 一维和二维 有限元程序
- MTI的matlab仿真
评论
共有 条评论