资源简介

内含三色算法的C++环境下的代码和在C++环境下的仿真环境配置。

资源截图

代码片段和文件信息

//-------------------------------------------------------------------
//  file name: application.cpp
// 
//    - contains the implementation of application class
//
//-------------------------------------------------------------------


#include “application.h“


// some constant definitions

// message definitions

#define SEND_BLACK_REQ_NEW { \
cMessage *msg = new cMessage(“BlackRequest“); \
msg->setKind(M_HIGHLOW); \
msg->addPar(“senderPX“)=this->parentModule()->par(“PX“);\
msg->addPar(“senderPY“)=this->parentModule()->par(“PY“);\
msg->addPar(“senderId“)=ID; \
msg->addPar(“nhops“)=0; \
msg->addPar(“preSenderId“)=ID; \
send(msg“lowergate_out“); \
}

#define SEND_GREY_REQ_NEW { \
cMessage *msg = new cMessage(“GreyRequest“); \
msg->addPar(“senderPX“)=this->parentModule()->par(“PX“);\
msg->addPar(“senderPY“)=this->parentModule()->par(“PY“);\
msg->setKind(M_HIGHLOW); \
msg->addPar(“senderId“)=ID; \
msg->addPar(“nhops“)=nhops; \
msg->addPar(“preSenderId“)=preSenderId; \
send(msg“lowergate_out“); \

/*
#define SEND_GREY_REQ_DELAY     { \
cMessage *msg = new cMessage(“GreyRequest“); \
msg->addPar(“senderPX“)=this->parentModule()->par(“PX“);\
msg->addPar(“senderPY“)=this->parentModule()->par(“PY“);\
msg->setKind(M_HIGHLOW); \
msg->addPar(“senderId“)=ID; \
msg->addPar(“nhops“)=nhops; \
msg->addPar(“preSenderId“)=preSenderId; \
sendDelayed(msgtime“lowergate_out“); \

*/
void application::initialize()
{
isreq=-1;
for(int i=0;i neibor[i]=-1;

if (ID==0) // node 0 starts the algorithm
{
isreq=1;
parentModule()->par(“TYPE“)=1;
SEND_BLACK_REQ_NEW;
}
}

void application::finish()
{
int type=parentModule()->par(“TYPE“);
if(type==1)
{
for(int i=0;i if(neibor[i]!=-1)
ev<<“node  “< }
}

void application::handleMessage(cMessage *msg)
{
nhops=msg->par(“nhops“);
preSenderId=msg->par(“preSenderId“);
msg->addPar(“senderPX“)=this->parentModule()->par(“PX“);
msg->addPar(“senderPY“)=this->parentModule()->par(“PY“);

switch(msg->kind())
{
case M_LOWHIGH:
{
if(strcmp(msg->name()“BlackRequest“)==0)
{
processBlackRequest(msg);
break;
}

if(strcmp(msg->name()“GreyRequest“)==0)
{
processGreyRequest(msg);
break;
}

ev << “unknown message received from another node.\n“;
endSimulation();
}

default:
ev << “unknown message received\n“;
endSimulation();
}
}

void application::processBlackRequest(cMessage *msg)
{
if(isreq==1||isreq==0)
{
if(nhops==1)
neibor[preSenderId]=msg->par(“senderId“);


delete msg;
return;
}

else if (isreq==-1)
{
UPDATECOLOR(3);
isreq=0;
parentModule()->par(“TYPE“)=0;

double time=(double)msg->par(“timeout“);
nhops=nhops+1;

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件     818439  2009-02-20 13:30  WSN成簇仿真\[--VC配置第一弹--] VC6环境下的OMNet工程配置 - OMNeT++ - NetForum仿真论坛 - Powered by Discuz!.mht

     文件       3580  2007-06-06 18:53  WSN成簇仿真\three_color\application.cpp

     文件       1136  2007-06-05 11:19  WSN成簇仿真\three_color\application.h

     文件       3120  2004-03-25 06:22  WSN成簇仿真\three_color\bitmaps\application.gif

     文件       6566  2004-03-25 06:22  WSN成簇仿真\three_color\bitmaps\blackboard.gif

    ..A.SHR         9  2007-03-12 14:25  WSN成簇仿真\three_color\bitmaps\Desktop_.ini

     文件       3243  2004-03-25 06:22  WSN成簇仿真\three_color\bitmaps\energy.gif

     文件       3639  2004-03-25 06:22  WSN成簇仿真\three_color\bitmaps\layer0.gif

     文件       3240  2004-03-25 06:22  WSN成簇仿真\three_color\bitmaps\sensor.gif

     文件        919  2004-03-25 06:22  WSN成簇仿真\three_color\bitmaps\snode.gif

     文件        936  2004-03-25 06:22  WSN成簇仿真\three_color\bitmaps\snode_0_0.gif

     文件        926  2004-03-25 06:22  WSN成簇仿真\three_color\bitmaps\snode_0_1.gif

     文件        919  2004-03-25 06:22  WSN成簇仿真\three_color\bitmaps\snode_0_2.gif

     文件        923  2004-03-25 06:22  WSN成簇仿真\three_color\bitmaps\snode_0_3.gif

     文件        936  2004-03-25 06:22  WSN成簇仿真\three_color\bitmaps\snode_10_0.gif

     文件        926  2004-03-25 06:22  WSN成簇仿真\three_color\bitmaps\snode_10_1.gif

     文件        919  2004-03-25 06:22  WSN成簇仿真\three_color\bitmaps\snode_10_2.gif

     文件        923  2004-03-25 06:22  WSN成簇仿真\three_color\bitmaps\snode_10_3.gif

     文件        936  2004-03-25 06:22  WSN成簇仿真\three_color\bitmaps\snode_11_0.gif

     文件        926  2004-03-25 06:22  WSN成簇仿真\three_color\bitmaps\snode_11_1.gif

     文件        919  2004-03-25 06:22  WSN成簇仿真\three_color\bitmaps\snode_11_2.gif

     文件        923  2004-03-25 06:22  WSN成簇仿真\three_color\bitmaps\snode_11_3.gif

     文件        936  2004-03-25 06:22  WSN成簇仿真\three_color\bitmaps\snode_12_0.gif

     文件        926  2004-03-25 06:22  WSN成簇仿真\three_color\bitmaps\snode_12_1.gif

     文件        919  2004-03-25 06:22  WSN成簇仿真\three_color\bitmaps\snode_12_2.gif

     文件        923  2004-03-25 06:22  WSN成簇仿真\three_color\bitmaps\snode_12_3.gif

     文件        936  2004-03-25 06:22  WSN成簇仿真\three_color\bitmaps\snode_13_0.gif

     文件        926  2004-03-25 06:22  WSN成簇仿真\three_color\bitmaps\snode_13_1.gif

     文件        919  2004-03-25 06:22  WSN成簇仿真\three_color\bitmaps\snode_13_2.gif

     文件        923  2004-03-25 06:22  WSN成簇仿真\three_color\bitmaps\snode_13_3.gif

............此处省略66个文件信息

评论

共有 条评论