ConnectivityProbe Class Reference

#include <ConnectivityProbe.h>

List of all members.

Public Member Functions

void initialize ()
void handleMessage (cMessage *msg)
 ~ConnectivityProbe ()

Private Member Functions

void extractTopology ()
void resetTopologyNodes ()
unsigned int getComponentSize (OverlayKey key)

Private Attributes

std::fstream pltNetwork
std::fstream pltData
double probeIntervall
double plotIntervall
cMessage * probeTimer
cMessage * plotTimer
VTopology Topology
cOutVector cOV_NodeCount
cOutVector cOV_MaximumComponent
cOutVector cOV_MaxConnectivity
cOutVector cOV_ZeroMissingNeighbors
cOutVector cOV_OneMissingNeighbor
cOutVector cOV_TwoMissingNeighbor
cOutVector cOV_ThreeMissingNeighbor
cOutVector cOV_FourMissingNeighbor
cOutVector cOV_FiveMissingNeighbors
cOutVector cOV_SeveralMissingNeighbors
cOutVector cOV_AverageMissingNeighbors
cOutVector cOV_MaxMissingNeighbors


Constructor & Destructor Documentation

ConnectivityProbe::~ConnectivityProbe (  ) 

00263 {
00264     // destroy self timer messages
00265     cancelAndDelete(probeTimer);
00266     cancelAndDelete(plotTimer);
00267 }


Member Function Documentation

void ConnectivityProbe::initialize (  ) 

00040 {
00041     probeIntervall = par("connectivityProbeIntervall");
00042     plotIntervall = par("visualizeNetworkIntervall");
00043     probeTimer = new cMessage("probeTimer");
00044     plotTimer = new cMessage("plotTimer");
00045 
00046     if(probeIntervall > 0.0) {
00047         scheduleAt(simulation.simTime() + probeIntervall, probeTimer);
00048 
00049         cOV_NodeCount.setName("node count");
00050         cOV_MaximumComponent.setName("largest connected component");
00051         cOV_MaxConnectivity.setName("connectivity");
00052         cOV_ZeroMissingNeighbors.setName("nodes with 0 missing neighbors");
00053         cOV_OneMissingNeighbor.setName("nodes with 1 missing neighbor");
00054         cOV_TwoMissingNeighbor.setName("nodes with 2 missing neighbor");
00055         cOV_ThreeMissingNeighbor.setName("nodes with 3 missing neighbor");
00056         cOV_FourMissingNeighbor.setName("nodes with 4 missing neighbor");
00057         cOV_FiveMissingNeighbors.setName("nodes with 5 missing neighbors");
00058         cOV_SeveralMissingNeighbors.setName("nodes with more than 5 missing neighbors");
00059         cOV_AverageMissingNeighbors.setName("average missing neighbors per node");
00060         cOV_MaxMissingNeighbors.setName("largest missing neighbors count");
00061     }
00062 
00063     if(plotIntervall > 0.0) {
00064         scheduleAt(simulation.simTime() + plotIntervall, plotTimer);
00065     }
00066 }

void ConnectivityProbe::handleMessage ( cMessage *  msg  ) 

00069 {
00070     // fill topology with all VAST modules
00071     extractTopology();
00072 
00073     if(Topology.size() == 0) {
00074         return;
00075     }
00076 
00077     // catch self timer messages
00078     if(msg->isName("probeTimer")) {
00079         //reset timer
00080         cancelEvent(probeTimer);
00081         scheduleAt(simulation.simTime() + probeIntervall, msg);
00082 
00083         unsigned int maxComponent = 0;
00084         unsigned int connectivity = 0;
00085         for(VTopology::iterator itTopology = Topology.begin(); itTopology != Topology.end(); ++itTopology) {
00086             unsigned int count = getComponentSize(itTopology->second.module()->getThisNode().key);
00087             if(count > maxComponent) {
00088                 maxComponent = count;
00089             }
00090             if(count == Topology.size()) {
00091                 ++connectivity;
00092             }
00093             resetTopologyNodes();
00094         }
00095 
00096         cOV_NodeCount.record((double)Topology.size());
00097         cOV_MaximumComponent.record((double)maxComponent);
00098         cOV_MaxConnectivity.record((double)connectivity);
00099 
00100         int mnZero, mnOne, mnTwo, mnThree, mnFour, mnFive, mnSeveral, mnMax;
00101         double mnAverage = 0.0;
00102         double AOIWidthSqr = Topology.begin()->second.module()->getAOI();
00103         AOIWidthSqr *= AOIWidthSqr;
00104         mnZero = mnOne = mnTwo = mnThree = mnFour = mnFive = mnSeveral = mnMax = 0;
00105 
00106         for(VTopology::iterator itTopology = Topology.begin(); itTopology != Topology.end(); ++itTopology) {
00107             NodeSet SiteHandles;
00108             Vector2D vastPosition = itTopology->second.module()->getPosition();
00109             int missing = 0;
00110             for(VTopology::iterator itI = Topology.begin(); itI != Topology.end(); ++itI) {
00111                 if(itI != itTopology && vastPosition.distanceSqr(itI->second.module()->getPosition()) <= AOIWidthSqr) {
00112                     SiteHandles.insert(itI->second.module()->getThisNode());
00113                 }
00114             }
00115 
00116             for(NodeSet::iterator itSiteHandles = SiteHandles.begin(); itSiteHandles != SiteHandles.end(); ++itSiteHandles) {
00117                 if(itTopology->second.module()->getList()->Sites.find(*itSiteHandles) == itTopology->second.module()->getList()->Sites.end()) {
00118                     ++missing;
00119                 }
00120             }
00121 
00122             switch(missing) {
00123                 case 0:
00124                     ++mnZero;
00125                 break;
00126                 case 1:
00127                     ++mnOne;
00128                 break;
00129                 case 2:
00130                     ++mnTwo;
00131                 break;
00132                 case 3:
00133                     ++mnThree;
00134                 break;
00135                 case 4:
00136                     ++mnFour;
00137                 break;
00138                 case 5:
00139                     ++mnFive;
00140                 break;
00141                 default:
00142                     ++mnSeveral;
00143             }
00144             mnAverage += missing;
00145             if(mnMax < missing) {
00146                 mnMax = missing;
00147             }
00148         }
00149         mnAverage /= (double)Topology.size();
00150 
00151         cOV_ZeroMissingNeighbors.record((double)mnZero);
00152         cOV_OneMissingNeighbor.record((double)mnOne);
00153         cOV_TwoMissingNeighbor.record((double)mnTwo);
00154         cOV_ThreeMissingNeighbor.record((double)mnThree);
00155         cOV_FourMissingNeighbor.record((double)mnFour);
00156         cOV_FiveMissingNeighbors.record((double)mnFive);
00157         cOV_SeveralMissingNeighbors.record((double)mnSeveral);
00158         cOV_AverageMissingNeighbors.record(mnAverage);
00159         cOV_MaxMissingNeighbors.record((double)mnMax);
00160     }
00161     else if(msg->isName("plotTimer")) {
00162          //reset timer
00163         cancelEvent(plotTimer);
00164         scheduleAt(simulation.simTime() + plotIntervall, msg);
00165 
00166         int range = par("areaDimension");;
00167         std::stringstream oss;
00168         std::string filename;
00169         int simTime, stellen = 1;
00170         simTime = (int)simulation.simTime();
00171         oss << "plot";
00172         for(int i=0; i<6; i++) {
00173             if(!(simTime / stellen)) {
00174                 oss << "0";
00175             }
00176             stellen *= 10;
00177         }
00178         oss << simTime;
00179 
00180         // write plot file
00181         filename = oss.str() + ".plt";
00182         pltNetwork.open(filename.c_str(), std::ios::out);
00183         pltNetwork << "set noarrow" << endl;
00184         pltNetwork << "set style line 1 linetype 7 linecolor rgb \"red\"" << endl;
00185         pltNetwork << "set style line 2 linetype 7 linecolor rgb \"green\"" << endl;
00186         pltNetwork << "set style line 3 linetype 7 linecolor rgb \"blue\"" << endl;
00187         pltNetwork << "set style line 4 linetype 7 linecolor rgb \"black\"" << endl;
00188         pltNetwork << "set xrange [0:" << range << "]" << endl;
00189         pltNetwork << "set yrange [0:" << range << "]" << endl;
00190         for(VTopology::iterator itTopology = Topology.begin(); itTopology != Topology.end(); ++itTopology) {
00191             for(SiteMap::iterator itSites = itTopology->second.module()->getList()->Sites.begin(); itSites != itTopology->second.module()->getList()->Sites.end(); ++itSites) {
00192                 pltNetwork << "set arrow from " << itTopology->second.module()->getPosition().x << "," << itTopology->second.module()->getPosition().y <<
00193                               " to " << itSites->second.coord.x << "," << itSites->second.coord.y << " ls ";
00194                 if(itSites->second.type & NEIGHBOR) {
00195                     if(itSites->second.type & ENCLOSING) {
00196                         pltNetwork << "3" << endl;
00197                     }
00198                     else {
00199                         pltNetwork << "1" << endl;
00200                     }
00201                 }
00202                 else if(itSites->second.type & BOUNDARY) {
00203                     if(itSites->second.type & ENCLOSING) {
00204                         pltNetwork << "4" << endl;
00205                     }
00206                     else {
00207                         pltNetwork << "2" << endl;
00208                     }
00209                 }
00210             }
00211         }
00212         filename = oss.str() + ".dat";
00213         pltNetwork << "plot '" << filename << "' using 1:2 with points pointtype 7" << endl;
00214         pltNetwork.close();
00215 
00216         // write point data file
00217         pltData.open(filename.c_str(), std::ios::out);
00218         for(VTopology::iterator itTopology = Topology.begin(); itTopology != Topology.end(); ++itTopology) {
00219             pltData << itTopology->second.module()->getPosition().x << "\t" << itTopology->second.module()->getPosition().y << endl;
00220         }
00221         pltData.close();
00222     }
00223     Topology.clear();
00224 }

void ConnectivityProbe::extractTopology (  )  [private]

Referenced by handleMessage().

00227 {
00228     for(int i=0; i<=simulation.lastModuleId(); i++) {
00229         cModule* module = simulation.module(i);
00230         if(module && dynamic_cast<Vast*>(module)) {
00231             Vast* vast = check_and_cast<Vast*>(module);
00232             if(vast->getState() == BaseOverlay::READY) {
00233                 VTopologyNode temp(i);
00234                 Topology.insert(std::make_pair(vast->getThisNode().key, temp));
00235             }
00236         }
00237     }
00238 }

void ConnectivityProbe::resetTopologyNodes (  )  [private]

Referenced by handleMessage().

00241 {
00242     for(VTopology::iterator itTopology = Topology.begin(); itTopology != Topology.end(); ++itTopology) {
00243         itTopology->second.visited = false;
00244     }
00245 }

unsigned int ConnectivityProbe::getComponentSize ( OverlayKey  key  )  [private]

Referenced by handleMessage().

00248 {
00249     VTopology::iterator itEntry = Topology.find(key);
00250     if(itEntry != Topology.end() && itEntry->second.visited == false) {
00251         int count = 1;
00252         itEntry->second.visited = true;
00253         Vast* vast = itEntry->second.module();
00254         for(SiteMap::iterator itSites = vast->getList()->Sites.begin(); itSites != vast->getList()->Sites.end(); ++itSites) {
00255             count += getComponentSize(itSites->first.key);
00256         }
00257         return count;
00258     }
00259     return 0;
00260 }


Member Data Documentation

std::fstream ConnectivityProbe::pltNetwork [private]

Referenced by handleMessage().

std::fstream ConnectivityProbe::pltData [private]

Referenced by handleMessage().

Referenced by handleMessage(), and initialize().

Referenced by handleMessage(), and initialize().

cMessage* ConnectivityProbe::probeTimer [private]

cMessage* ConnectivityProbe::plotTimer [private]

cOutVector ConnectivityProbe::cOV_NodeCount [private]

Referenced by handleMessage(), and initialize().

Referenced by handleMessage(), and initialize().

Referenced by handleMessage(), and initialize().

Referenced by handleMessage(), and initialize().

Referenced by handleMessage(), and initialize().

Referenced by handleMessage(), and initialize().

Referenced by handleMessage(), and initialize().

Referenced by handleMessage(), and initialize().

Referenced by handleMessage(), and initialize().

Referenced by handleMessage(), and initialize().

Referenced by handleMessage(), and initialize().

Referenced by handleMessage(), and initialize().


The documentation for this class was generated from the following files:

Generated on Fri Sep 19 13:05:06 2008 for ITM OverSim by  doxygen 1.5.5