您现在的位置:首页 >> 网络协议 >> 内容

基于matlab的分簇异构无线传感器网络选举协议

时间:2023/1/3 22:53:28 点击:

  核心提示:A178,包括程序操作录像...

1.完整项目描述和程序获取

>面包多安全交易平台:https://mbd.pub/o/bread/Y52clZlr

>如果链接失效,可以直接打开本站店铺搜索相关店铺:

点击店铺

>如果链接失效,程序调试报错或者项目合作可以加微信或者QQ联系。

2.部分仿真图预览



3.算法概述

       为了进一步均衡网络能耗,延长网络生命周期,提出了一种基于最优分簇的能量异构无线传感器网络路由协议(OCRP)。OCRP协议考虑了最优簇首数K,将待测区域划分为K个固定分区,优化了成簇过程;在簇首选择阶段,充分考虑了节点的剩余能量、整个网络的能量以及节点与基站之间的距离,改进了簇头选举机制。

4.部分源码

。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。

countCHs=0;

%counter for CHs per round

rcountCHs=0;

cluster=1;

t=0;

countCHs;

rcountCHs=rcountCHs+countCHs;

flag_first_dead=0;

for r=0:1:rmax

    r;

  %Election Probability for Normal Nodes

  pnrm=( p/ (1+a*m) );

  %Election Probability for Advanced Nodes

  padv= ( p*(1+a)/(1+a*m) );

  %Operation for heterogeneous epoch

  if(mod(r, round(1/pnrm) )==0)

    for i=1:1:n

        S(i).G=0;

        S(i).cl=0;

    end

  end

 %Operations for sub-epochs

 if(mod(r, round(1/padv) )==0)

    for i=1:1:n

        if(S(i).ENERGY==1)

            S(i).G=0;

            S(i).cl=0;

        end

    end

  end

%hold off;

%Number of dead nodes

dead=0;

%Number of dead Advanced Nodes

dead_a=0;

%Number of dead Normal Nodes

dead_n=0;

%counter for bit transmitted to Bases Station and to Cluster Heads

packets_TO_BS=0;

packets_TO_CH=0;

%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;

for i=1:1:n

    %checking if there is a dead node

    if (S(i).E<=0)

        plot(S(i).xd,S(i).yd,'red .');

        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');

        end

        if (S(i).ENERGY==1)  

        plot(S(i).xd,S(i).yd,'+');

        end

        hold on;

    end

end

plot(S(n+1).xd,S(n+1).yd,'ks');

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

countCHs=0;

cluster=1;

for i=1:1:n

    if(S(i).far~=-1)

    if(S(i).E>0 )

   temp_rand=rand;     

   if ( (S(i).G)<=0)

 %Election of Cluster Heads for normal nodes

 if( ( S(i).ENERGY==0 && ( temp_rand <= ( pnrm / ( 1 - pnrm * mod(r,round(1/pnrm)) )) ) )  )

            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=100;

            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

            distance;

            if (distance>do)

                S(i).E=S(i).E- ( (ETX+EDA)*(4000) + Emp*4000*( distance*distance*distance*distance )); 

            end

            if (distance<=do)

                S(i).E=S(i).E- ( (ETX+EDA)*(4000)  + Efs*4000*( distance * distance )); 

            end

        end     

 %Election of Cluster Heads for Advanced nodes

 if( ( S(i).ENERGY==1 && ( temp_rand <= ( padv / ( 1 - padv * mod(r,round(1/padv)) )) ) )  )

。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。

A178 

作者:我爱C编程 来源:我爱C编程
本站最新成功开发工程项目案例
相关评论
发表我的评论
  • 大名:
  • 内容:
本类固顶
  • 没有
  • FPGA/MATLAB商业/科研类项目合作(www.store718.com) © 2025 版权所有 All Rights Reserved.
  • Email:1480526168@qq.com 站长QQ: 1480526168