• 大小: 4KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-06-03
  • 语言: Matlab
  • 标签: pegasi  leach  MATLAB  

资源简介

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


评论

共有 条评论