Leach协议性能分析(2)

1.复制leach_test为leach-c_test,修改里面的文件夹和输出文件名。并且手动建立相应的文件夹。

很多教程说只修改文件名,没提到修改文件夹,如果同时运行两个协议会覆盖一部分实验结果的,而且是并行的就更难分解出是哪个协议的实验数据了。所以还是分开较好。


2.添加到test文件最后,后台运行的,需要等待。


3.写脚本分析实验数据。

  1. #计算不同时间剩余节点的数量 
  2.  
  3. BEGIN { 
  4.  
  5.   countcyl=0; 
  6.   totalleft=0; 
  7.  
  8.   lasttime=0; 
  9.   time[0]=0; 
  10.   node=0; 
  11.   total[0]=100; 
  12.  
  13. simtime              = $1; 
  14. nodeid               = $2; 
  15. statenode            = $3; 
  16.  
  17. if (simtime>lasttime ) { 
  18.     countcyl++; 
  19.     lasttime=simtime; 
  20.     time[countcyl]=simtime; 
  21.     totalleft=0; 
  22.       } 
  23.  
  24. if (statenode==1) 
  25.      totalleft++; 
  26.      total[countcyl]=totalleft; 
  27. END { 
  28. for(i=0;i<=countcyl;i++) 
  29. printf( "%f %d\n",time[i],total[i]); 
#计算不同时间剩余节点的数量

BEGIN {

  countcyl=0;
  totalleft=0;

  lasttime=0;
  time[0]=0;
  node=0;
  total[0]=100;
}
{

simtime              = $1;
nodeid               = $2;
statenode            = $3;

if (simtime>lasttime ) {
    countcyl++;
    lasttime=simtime;
    time[countcyl]=simtime;
    totalleft=0;
      }

if (statenode==1)
     totalleft++;
     total[countcyl]=totalleft;
}
END {
for(i=0;i<=countcyl;i++)
printf( "%f %d\n",time[i],total[i]);
}

  1. BEGIN { 
  2.  
  3. countcyl=0; 
  4.     packetsum=0;                       #当前时间发包且接收的总数 
  5.  
  6. lasttime=0; 
  7.     time[0]=0; 
  8.     sum[0]=0; 
  9.  
  10. simtime              = $1; 
  11. nodeid               = $2; 
  12. packet               = $3;             #读取当前时间,当前节点的发包且被成功接收的数目 
  13.  
  14. if (simtime>lasttime ) {                                #具体算法 
  15.      packtsum=0; 
  16.     countcyl++; 
  17.     lasttime=simtime; 
  18.     time[countcyl]=simtime; 
  19.  
  20. if (simtime==lasttime ) { 
  21.    packetsum=packetsum+packet; 
  22.    sum[countcyl]=packetsum; 
  23. END {                                                        #对应时段,打印发包总量。 
  24. for(i=0;i<=countcyl;i++) 
  25. printf ( "%f %f\n",time[i],sum[i]); 
BEGIN {

countcyl=0;
    packetsum=0;                       #当前时间发包且接收的总数

lasttime=0;
    time[0]=0;
    sum[0]=0;
}
{

simtime              = $1;
nodeid               = $2;
packet               = $3;             #读取当前时间,当前节点的发包且被成功接收的数目

if (simtime>lasttime ) {                                #具体算法
     packtsum=0;
    countcyl++;
    lasttime=simtime;
    time[countcyl]=simtime;
}

if (simtime==lasttime ) {
   packetsum=packetsum+packet;
   sum[countcyl]=packetsum;
}
}
END {                                                        #对应时段,打印发包总量。
for(i=0;i<=countcyl;i++)
printf ( "%f %f\n",time[i],sum[i]);
}

  1. BEGIN { 
  2.  
  3. countcyl=0;                           #计数器,用来记录当前的轮数 或者当前的时段数 
  4. energysum=0;                      #用来暂时储存当前时段的节点消耗能量总和 
  5.  
  6. lasttime=0;                           #记录当前最后的时间 
  7. time[0]=0;                             #存储各(轮)分段的时间 
  8. sum[0]=0;                             #存储各分段时间对应的消耗的能量 
  9.  
  10. simtime              = $1;                      #文件中第一字段的值,当前时间 
  11. nodeid               = $2;                      #。。。第二字段的值,节点ID 
  12. nodeenergy            = $3;               #。。。第三字段的值,当前节点使用的能量 
  13.  
  14. if (simtime>lasttime ) {     #这里就是一个简单的方法来提取每个时间段,节点总共消耗了多少能量 
  15.    energysum=0; 
  16.     countcyl++; 
  17.     lasttime=simtime; 
  18.     time[countcyl]=simtime; 
  19.  
  20. if (simtime==lasttime ) { 
  21.     if (nodeenergy<2.0) { 
  22.    energysum=energysum+nodeenergy; 
  23.    sum[countcyl]=energysum; 
  24. else if (nodeenergy>=2.0) {         #节点初始的总能量为2 
  25.    energysum=energysum+2.0; 
  26.    sum[countcyl]=energysum; 
  27. END {                                          #对应时间段,得出能量消耗量并打印 
  28. for(i=0;i<=countcyl;i++) 
  29. printf ( "%f %f\n",time[i],sum[i]); 
BEGIN {

countcyl=0;                           #计数器,用来记录当前的轮数 或者当前的时段数
energysum=0;                      #用来暂时储存当前时段的节点消耗能量总和

lasttime=0;                           #记录当前最后的时间
time[0]=0;                             #存储各(轮)分段的时间
sum[0]=0;                             #存储各分段时间对应的消耗的能量
}
{

simtime              = $1;                      #文件中第一字段的值,当前时间
nodeid               = $2;                      #。。。第二字段的值,节点ID
nodeenergy            = $3;               #。。。第三字段的值,当前节点使用的能量

if (simtime>lasttime ) {     #这里就是一个简单的方法来提取每个时间段,节点总共消耗了多少能量
   energysum=0;
    countcyl++;
    lasttime=simtime;
    time[countcyl]=simtime;
}

if (simtime==lasttime ) {
    if (nodeenergy<2.0) {
   energysum=energysum+nodeenergy;
   sum[countcyl]=energysum;
}
else if (nodeenergy>=2.0) {         #节点初始的总能量为2
   energysum=energysum+2.0;
   sum[countcyl]=energysum;
}
}
}
END {                                          #对应时间段,得出能量消耗量并打印
for(i=0;i<=countcyl;i++)
printf ( "%f %f\n",time[i],sum[i]);
}


4.gnuplot来画图

  1. set multiplot 
  2. set origin 0.0,0.5                         
  3. set size 0.5,0.5                          
  4. plot 'leach.alive.rst' with linespoint,'leach-c.alive.rst' with linespoint       
  5. set origin 0.5,0.5 
  6. set size 0.5,0.5 
  7. plot 'leach.data.rst' with linespoint,'leach-c.data.rst' with linespoint 
  8. set origin 0.33,0.0 
  9. set size 0.5,0.5 
  10. plot 'leach.energy.rst' with linespoint,'leach-c.energy.rst' with linespoint 
set multiplot
set origin 0.0,0.5                        
set size 0.5,0.5                         
plot 'leach.alive.rst' with linespoint,'leach-c.alive.rst' with linespoint      
set origin 0.5,0.5
set size 0.5,0.5
plot 'leach.data.rst' with linespoint,'leach-c.data.rst' with linespoint
set origin 0.33,0.0
set size 0.5,0.5
plot 'leach.energy.rst' with linespoint,'leach-c.energy.rst' with linespoint

得到如下图:


明显实验结果说明leach-c死亡节点比较早,虽然bs收到数据量大,但是能量消耗是leach协议更关心的问题。

修改bs坐标为(0,0),再次计算得到如下结果:


从各方面来说c都比leach更优,有人说若bs在节点区域内部,则leach更优,若在外部则leach-c更优!

想知道为什么还需要看懂这两个协议喽。

接下来代码和理论分析。

This is a simulation of LEACH (Low-Energy Adaptive Clustering Hierarchy), a well-known cluster-based protocol for sensor networks with an extension to make it solar-aware. This simulation was created for the following paper: Thiemo Voigt, Hartmut Ritter, Jochen Schiller, Adam Dunkels, and Juan Alonso. Solar-aware Clustering in Wireless Sensor Networks. In Proceedings of the Ninth IEEE Symposium on Computers and Communications, June 2004. http://www.sics.se/~thiemo/iscc2004Final.pdf Abstract: "Energy conservation plays a crucial in wireless sensor networks since such networks are designed to be placed in hostile and non-accessible areas. While battery-driven sensors will run out of battery sooner or later, the use of renewable energy sources such as solar power or gravitation may extend the lifetime of a sensor network. We propose to utilize solar power in wireless sensor networks and extend LEACH, a well-known cluster-based protocol for sensor networks to become solar-aware. The presented simulation results show that making LEACH solar-aware significantly extends the lifetime of sensor networks." The code contains two directories: one is a distributed LEACH version, the other one a centralized where the base station (assumed to know everything) chooses the optimal cluster head. The "optimal" is in the code approximated via rules that include some kind of geopgraphical criteria among others. In solar.h you choose if you want to have solar turned on or not and also set some other parameters. To compile on Linux: opp_makemake -f -N make On Windows with Visual C++: opp_nmakemake -f -N nmake -f Makefile.vc Hope you find the model useful. Thiemo Voigt (thiemo@sics.se) (model packaged by Andras Varga)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值