• PUDN用户
    了解作者
  • Visual C++
    开发工具
  • 44KB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 4
    下载次数
  • 2009-10-31 18:23
    上传日期
该程序时在LEACH协议基础上,对能量模块的改进!
leach_wsn.rar
  • leach_wsn
  • result
  • omnetpp.sca21_600
    6.2KB
  • omnetpp.sca21_1200f10
    2.1KB
  • omnetpp.sca23_2400f10
    2.1KB
  • omnetpp.sca23_1200f10
    2.1KB
  • omnetpp.sca21_2400f10
    2.1KB
  • omnetpp.sca23_200f10
    2.1KB
  • omnetpp.sca22_600
    2.1KB
  • omnetpp.sca24_1200f10
    2.1KB
  • omnetpp.sca25_2400
    2.1KB
  • omnetpp.sca22_2400
    2.1KB
  • omnetpp.sca22_2400f10
    2.1KB
  • omnetpp.sca23_1200
    2.1KB
  • omnetpp.sca25_1200f10
    2.1KB
  • omnetpp.sca23_2400
    2.1KB
  • omnetpp.sca23_600f10
    2.1KB
  • omnetpp.sca21_2400
    2.1KB
  • omnetpp.sca24_200f10
    2.1KB
  • omnetpp.sca25_200f10
    2.1KB
  • omnetpp.sca25_600f10
    2.1KB
  • omnetpp.sca25_2400f10
    2.1KB
  • omnetpp.sca24_2400f10
    2.1KB
  • omnetpp.sca24_2400
    2.1KB
  • omnetpp.sca24_600
    2.1KB
  • omnetpp.sca25_1200
    2.1KB
  • omnetpp.sca22_1200
    2.1KB
  • omnetpp.sca21_200f10
    2.1KB
  • omnetpp.sca21_600f10
    2.1KB
  • omnetpp.sca25_600
    2.1KB
  • omnetpp.sca22_600f10
    2.1KB
  • omnetpp.sca22_1200f10
    2.1KB
  • omnetpp.sca21_1200
    2.1KB
  • omnetpp.sca24_600f10
    2.1KB
  • omnetpp.sca22_200f10
    2.1KB
  • omnetpp.sca23_600
    2.1KB
  • omnetpp.sca24_1200
    2.1KB
  • ini
  • omnetpp.ini22_1200
    1018B
  • omnetpp.ini24_200
    1017B
  • omnetpp.ini21_1200
    1018B
  • omnetpp.ini22_2400
    1018B
  • omnetpp.ini25_600
    1017B
  • omnetpp.ini23_1200
    1018B
  • omnetpp.ini24_2400
    1018B
  • omnetpp.ini25_2400
    1018B
  • omnetpp.ini21_600
    1017B
  • omnetpp.ini21_200
    1017B
  • omnetpp.ini22_200
    1017B
  • omnetpp.ini23_2400
    1018B
  • omnetpp.ini23_200
    1017B
  • omnetpp.ini22_600
    1017B
  • omnetpp.ini25_1200
    1018B
  • omnetpp.ini25_200
    1017B
  • omnetpp.ini24_1200
    1018B
  • omnetpp.ini24_600
    1017B
  • omnetpp.ini23_600
    1017B
  • omnetpp.ini21_2400
    1018B
  • scripts
  • minitopology.pl
    2.6KB
  • parse_data.pl
    1.5KB
  • avg.pl
    537B
  • meta.pl
    1.1KB
  • createtops.pl
    506B
  • topology.pl
    2.6KB
  • parse_results.pl
    1.5KB
  • node.cpp
    23.4KB
  • node.ned
    1017B
  • node.h
    3.4KB
  • RESULTS
    6.2KB
  • bs.ned
    980B
  • nodebase.cpp
    1.8KB
  • cl_msg.msg
    1.8KB
  • solar.ned
    1.7KB
  • solar.h
    3.2KB
  • bs.cpp
    19.6KB
  • bs.h
    2KB
  • nodebase.h
    1.6KB
  • omnetpp.ini
    1005B
内容介绍
// // Copyright (C) 2003 Thiemo Voigt // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, write to the Free Software // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA // #include <stdio.h> #include <string.h> #include <omnetpp.h> #include "node.h" #include "bs.h" #include "cl_msg_m.h" #include "cgate.h" Define_Module(Node); void Node::initialize() { int i; cMessage *cm; cMessage *cm2; cModule *parent = parentModule(); this->initStats(); this->myId = par("id"); this->xpos = par("xpos"); this->ypos = par("ypos"); this->nrGates = (int) parent->par("numNodes") + 3; this->energy = (double) par("energy"); this->myCluster = 0; this->nrNodes = (int) parent->par("numNodes"); this->nrFrames = (int) parent->par("frames"); this->nrRounds = (int) parent->par("rounds"); this->solarOn = (int) parent->par("solarOn"); this->sunDuration = (int) parent->par("sunDuration"); this->sunStart = par("sunstart"); this->sunNodes = (int) parent->par("sunNodes"); this->myData = 0; this->curFrame = 0; this->sentBS = 0; this->wasHead = 0; this->headSun = 0; this->headBatt = 0; // default, set black this->myStatus = STATUS_BATT; this->setDisplayString("p=$xpos,$ypos;o=black"); // schedule SUN //if (this->solarOn) { cm = new cMessage(); cm2 = new cMessage(); cm->setKind(SMSG_CHANGESTATUS); cm2->setKind(SMSG_CHANGESTATUS); int max = this->nrRounds * (this->nrFrames * 30); int endSun = this->sunStart + this->sunDuration; this->repeatTime = (this->nrNodes / this->sunNodes) * this->sunDuration; this->expectedEndTime = (30 * this->nrFrames) * nrRounds; ev << "repeatTime " << this->repeatTime << " expected end " << this-> expectedEndTime << "\n"; if (endSun > max) endSun = max - 100; scheduleAt(simTime() + this->sunStart, cm); // XXXXXXXX scheduleAt(simTime() + endSun, cm2); // XXXXXXXX } ev << this->myId << " energy: " << energy << "status " << this->myStatus << "\n"; { cMessage *cmsg = new cMessage(); cmsg->setKind(SMSG_INIT); scheduleAt(simTime() + INIT_WAIT, cmsg); } } // making the gates on the fly void Node::initNodes() { int i; cModule *parent = parentModule(); cModule *mod; cModule *myMod; // this is my Module int numNodes; int trRange; int delx, dely; int ritems; numNodes = (int) parent->par("numNodes"); ev << "numNodes is: " << numNodes << " energy: " << energy << "\n"; for (i = 1; i <= simulation.lastModuleIndex(); i++) { int x, y, id; //scan the simulation module vector mod = (cModule *) simulation.module(i); // check for nodes in transmission range if ((strcmp(mod->name(), "node") == 0) || (strcmp(mod->name(), "bs") == 0)) { if (strcmp(mod->name(), "node") == 0) { id = ((Node *) mod)->myId; x = ((Node *) mod)->xpos; y = ((Node *) mod)->ypos; nodePtr[id] = ((Node *) mod); } if (strcmp(mod->name(), "bs") == 0) { id = ((BS *) mod)->myId; this->bsId = id; x = ((BS *) mod)->xpos; y = ((BS *) mod)->ypos; this->bsDist = (x / 10 - this->xpos / 10) * (x / 10 - this->xpos / 10) + (y / 10 - this->ypos / 10) * (y / 10 - this->ypos / 10); } if (id != this->myId && id == this->bsId) { cGate *g; char gName[32]; int items; // ev << this->myId << "(" << this->xpos << "," << this->ypos <<") found node with id " << id << " xpos: " << x << " ypos: " << y<< "\n"; if ((((this->ypos - ypos) * (this->ypos - ypos)) + ((this->xpos - xpos) * (this->xpos - xpos))) < 2500 || id == this->bsId) { items = this->gatev.items(); ritems = mod->gatev.items(); // make new gate here sprintf(gName, "O_%d", id); g = new cGate(gName, 'O'); this->gatev.addAt(items, g); // position, element g->setOwnerModule((cModule *) this, items); // make new gate at other side sprintf(gName, "I_%d", this->myId); g = new cGate(gName, 'I'); mod->gatev.addAt(ritems, g); // position, element g->setOwnerModule((cModule *) mod, ritems); //CHANNEL cLinkType *etere = findLink("etere"); connect((cModule *) this, items, (cLinkType *) etere, (cModule *) mod, ritems); //draw the link g = this->gate(items); //g->setDisplayString( g->displayString(), true); } } } } // send energy and solar status to BS ev << "call send2BS\n"; send2BS(this->myId, this->bsId, this->energy, this->myStatus, this->myCluster, this->xpos, this->ypos); } void Node::handleMessage(cMessage * msg) { if (!msg->isSelfMessage()) { // // BS announces head with this message // broadcasted to all nodes by BS // if (((ClusterMessage *) msg)->getProto() == CL_TOHEAD) { int head; // cluster head of the cluster // reduce energy for packet reception of header energyReceive(25 * 8); head = ((ClusterHeadMessage *) msg)->getCHead(this->myId); ev << this->myId << " my head is " << head << "\n"; if (head != this->myId) { // setup connection to host cGate *g; char gName[32]; int items; int xpos, ypos; cModule *mod; int ritems; ; this->cHead = 0; this->headId = head; if (myStatus == STATUS_SUN) this->setDisplayString("p=$xpos,$ypos;o=yellow"); else this->setDisplayString("p=$xpos,$ypos;o=black"); xpos = nodePtr[head]->xpos; ypos = nodePtr[head]->ypos; mod = (Node *) nodePtr[head]; items = this->gatev.items(); ritems = mod->gatev.items(); // make new gate here sprintf(gName, "O_%d", head); g = new cGate(gName, 'O'); this->gatev.addAt(items, g); // position, element g->setOwnerModule((cModule *) this, items); // make new gate at other side sprintf(gName, "I_%d", this->myId); g = new cGate(g
评论
    相关推荐
    • WSN-LEACH.zip
      无线传感器网络分层协议中的LEACH算法,简单易懂的描述了LEACH协议的概念,模型,过程,流程图,优缺点等,快速了解LEACH的可以下载看看。
    • LEACH.zip
      使用matlab模拟仿真LEACH协议。
    • leach.zip
      leach 完整源码,部分附中文注释。供大家参考学习
    • LEACH.rar
      Leach算法的Matlab编程实现.一个小小的程序,可以帮助很多初学wsn的学者
    • matlab__leach.zip
      基于matlab的无线传感器网络leach路由协议仿真
    • LEACH.zip
      适用于无线传感器网络MATLAB环境下的用于路由的仿真源代码
    • LEACH.zip
      matlab下的leach协议 可以获得更好的生存时间
    • LEACH:WSNLEACH 路由协议-matlab开发
      这是 WSNLEACH(低能耗自适应聚类层次)路由协议。 它创建了一个 100 节点的网络,在 100 平方米的场地中具有随机位置。 在设置阶段,它根据 LEACH 的簇头选举概率“p”选择簇头,该概率包含在“阈值”参数中。 ...
    • leach:WSN LEACH 协议的 ns3 实现
      基于 LEACH 的无线传感器网络 WSN 的集群和能量分布在中的模拟,保持低能量足迹以延长集群的寿命,从而延长网络的寿命。 #####如何? 下载项目并将其解压到您的 ns3 根 src 目录中,然后通过运行来执行构建 $...
    • wsn.rar
      WSN代码可运行,供初学者学习参考。代码可运行,有注释