欢迎来到天天文库
浏览记录
ID:69568261
大小:180.50 KB
页数:18页
时间:2021-11-07
《LEACH算法源代码》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、------------------------------------------作者xxxx------------------------------------------日期xxxxLEACH算法源代码【精品文档】/***Createdon:2011-4-17*Author:syj*/#include#include#include#include"bs.h"#include"node.h"#include"cl_msg_m.h"#include"le
2、ach.h"Define_Module(BS);//定义简单模块(1)直接或间接定义一个CSimpleModule的子类;///(2)以define_Module()或define_Module_Like()宏注册之;/******************第一个执行的函数***********************/voidBS::initialize(){inti;cModule*parent=getParentModule();//消息参数的访问调用cModule的par()成员函数可以访问模块指针://cPar&
3、delayPar=par("delay");cPar类是一个存储值的对象,//它支持数据类型,指针值可以这样读:///周围的复合模块可以通过parentModule()成员函数访问:cModule*parent=parentModule();//例如,父模块的参数像这样被访问:doubletimeout=parentModule()->par("tthis->myId=par("id");this->xpos=par("xpos");this->ypos=par("ypos");this->nrNodes=parent-
4、>par("numNodes");//////////????????????????????????????????????????this->nrGates=parent->par("numNodes");//////????????????????????????????????????????????【精品文档】【精品文档】this->nrRounds=parent->par("rounds");this->deadNodes=0;this->roundsDone=0;this->oldDeadNodes=0;t
5、his->nrStatusRec=0;//?????????????????????????????????this->halfDeadCtr=0;//?????????????????????????????????this->halfDead=0;//????????????????????????????????????this->calledEnd=0;//??????????????????????????????????this->P=0.05;//??????????????????????????????
6、????????this->cHeadsRound=0;////每一轮簇头的个数this->roundEnergyLoss=80001.0;//?????????????????????/********************记录图像用的变量的名字******加的***************************/roundVector.setName("round");//轮数deadNodesVector.setName("nodesdead");//死亡的节点olddeadNodesVector.setNam
7、e("alldead");//所有死亡的节点nrheadVector.setName("headnumber");//簇头的个数tVector.setName("T");//运行的时间lastrecVector.setName("lastrec");//最后记录的消息cheadVector.setName("allheadnum");//所有的节点个数for(i=0;i<104;i++){advInfo[i].id=0;advInfo[i].energy=0;advInfo[i].status=0;}//初始化节点信息共
8、103项为什么是103??????????????????????this->setGateSize("out",nrGates+1);//需要设置参数值或门向量大小???????????【精品文档】【精品文档】this->setGateSize("in",nrGates+1);//创建消息cMessage*cmsg
此文档下载收益归作者所有