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
std::fstream pltVector
simtime_t probeIntervall
simtime_t plotIntervall
bool plotConnections
cMessage * probeTimer
cMessage * plotTimer
VTopology Topology
GlobalStatisticsglobalStatistics
cOutVector cOV_NodeCount
cOutVector cOV_MaximumComponent
cOutVector cOV_MaxConnectivity
cOutVector cOV_ZeroMissingNeighbors
cOutVector cOV_AverageMissingNeighbors
cOutVector cOV_MaxMissingNeighbors
cOutVector cOV_AverageDrift


Detailed Description

Definition at line 50 of file ConnectivityProbe.h.


Constructor & Destructor Documentation

ConnectivityProbe::~ConnectivityProbe (  ) 

Definition at line 249 of file ConnectivityProbe.cc.

00250 {
00251     // destroy self timer messages
00252     cancelAndDelete(probeTimer);
00253     cancelAndDelete(plotTimer);
00254 }


Member Function Documentation

void ConnectivityProbe::extractTopology (  )  [private]

Definition at line 213 of file ConnectivityProbe.cc.

Referenced by handleMessage().

00214 {
00215     for(int i=0; i<=simulation.getLastModuleId(); i++) {
00216         cModule* module = simulation.getModule(i);
00217         if(module && dynamic_cast<Vast*>(module)) {
00218             Vast* vast = check_and_cast<Vast*>(module);
00219             if(vast->getState() == BaseOverlay::READY) {
00220                 VTopologyNode temp(i);
00221                 Topology.insert(std::make_pair(vast->getHandle().getKey(), temp));
00222             }
00223         }
00224     }
00225 }

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

Definition at line 234 of file ConnectivityProbe.cc.

Referenced by handleMessage().

00235 {
00236     VTopology::iterator itEntry = Topology.find(key);
00237     if(itEntry != Topology.end() && itEntry->second.visited == false) {
00238         int count = 1;
00239         itEntry->second.visited = true;
00240         Vast* vast = itEntry->second.getModule();
00241         for(SiteMap::iterator itSites = vast->Sites.begin(); itSites != vast->Sites.end(); ++itSites) {
00242             count += getComponentSize(itSites->first.getKey());
00243         }
00244         return count;
00245     }
00246     return 0;
00247 }

void ConnectivityProbe::handleMessage ( cMessage *  msg  ) 

Definition at line 65 of file ConnectivityProbe.cc.

00066 {
00067     // fill topology with all VAST modules
00068     extractTopology();
00069 
00070     if(Topology.size() == 0) {
00071         return;
00072     }
00073 
00074     // catch self timer messages
00075     if(msg->isName("probeTimer")) {
00076         //reset timer
00077         cancelEvent(probeTimer);
00078         scheduleAt(simTime() + probeIntervall, msg);
00079 
00080         unsigned int maxComponent = 0;
00081         for(VTopology::iterator itTopology = Topology.begin(); itTopology != Topology.end(); ++itTopology) {
00082             unsigned int count = getComponentSize(itTopology->second.getModule()->getHandle().getKey());
00083             if(count > maxComponent) {
00084                 maxComponent = count;
00085             }
00086             resetTopologyNodes();
00087             if(count == Topology.size()) {
00088                 break;
00089             }
00090         }
00091 
00092         cOV_NodeCount.record((double)Topology.size());
00093         cOV_MaximumComponent.record((double)maxComponent);
00094         cOV_MaxConnectivity.record((double)maxComponent * 100.0 / (double)Topology.size());
00095         RECORD_STATS (
00096             globalStatistics->addStdDev("ConnectivityProbe: max connectivity", (double)maxComponent * 100.0 / (double)Topology.size());
00097         );
00098 
00099         int mnMax = 0;
00100         int mnZero = 0;
00101         int driftCount = 0;
00102         double mnAverage = 0.0;
00103         double drift = 0.0;
00104 
00105         for(VTopology::iterator itTopology = Topology.begin(); itTopology != Topology.end(); ++itTopology) {
00106             double AOIWidthSqr = itTopology->second.getModule()->getAOI();
00107             AOIWidthSqr *= AOIWidthSqr;
00108             Vector2D vastPosition = itTopology->second.getModule()->getPosition();
00109             int missing = 0;
00110             for(VTopology::iterator itI = Topology.begin(); itI != Topology.end(); ++itI) {
00111                 if(itI != itTopology && vastPosition.distanceSqr(itI->second.getModule()->getPosition()) <= AOIWidthSqr) {
00112                     SiteMap::iterator currentSite = itTopology->second.getModule()->Sites.find(itI->second.getModule()->getHandle());
00113                     if(currentSite == itTopology->second.getModule()->Sites.end()) {
00114                         ++missing;
00115                     }
00116                     else {
00117                         drift += sqrt(currentSite->second->coord.distanceSqr(itI->second.getModule()->getPosition()));
00118                         ++driftCount;
00119                     }
00120                 }
00121             }
00122 
00123             mnAverage += missing;
00124             if(mnMax < missing) {
00125                 mnMax = missing;
00126             }
00127             if(missing == 0) {
00128                 ++mnZero;
00129             }
00130         }
00131         mnAverage /= (double)Topology.size();
00132         if(driftCount > 0) {
00133             drift /= (double)driftCount;
00134         }
00135 
00136         cOV_ZeroMissingNeighbors.record((double)mnZero);
00137         RECORD_STATS (
00138             globalStatistics->addStdDev("ConnectivityProbe: percentage zero missing neighbors", (double)mnZero * 100.0 / (double)Topology.size());
00139             globalStatistics->addStdDev("ConnectivityProbe: average drift", drift);
00140         );
00141         cOV_AverageMissingNeighbors.record(mnAverage);
00142         cOV_MaxMissingNeighbors.record((double)mnMax);
00143         cOV_AverageDrift.record(drift);
00144     }
00145     else if(msg->isName("plotTimer")) {
00146          //reset timer
00147         cancelEvent(plotTimer);
00148         scheduleAt(simTime() + plotIntervall, msg);
00149 
00150         int range = (int)Topology.begin()->second.getModule()->getAreaDimension();
00151         std::stringstream oss;
00152         std::string filename;
00153         int simTimeInt, stellen = 1;
00154         simTimeInt = (int)SIMTIME_DBL(simTime());
00155         oss << "plot";
00156         for(int i=0; i<6; i++) {
00157             if(!(simTimeInt / stellen)) {
00158                 oss << "0";
00159             }
00160             stellen *= 10;
00161         }
00162         oss << simTimeInt;
00163 
00164         // open/ write plot file
00165         filename = oss.str() + ".plot";
00166         pltNetwork.open(filename.c_str(), std::ios::out);
00167         pltNetwork << "set xrange [0:" << range << "]" << endl;
00168         pltNetwork << "set yrange [0:" << range << "]" << endl;
00169         pltNetwork << "set nokey" << endl;
00170 
00171         // open point file
00172         filename = oss.str() + ".point";
00173         pltData.open(filename.c_str(), std::ios::out);
00174 
00175         pltNetwork << "plot '" << filename << "' using 1:2 with points pointtype 7,\\" << endl;
00176 
00177         // open vector file
00178         filename = oss.str() + ".arrow";
00179         pltVector.open(filename.c_str(), std::ios::out);
00180 
00181         pltNetwork << "     '" << filename << "' using 1:2:3:4 with vectors linetype 1" << endl;
00182         pltNetwork.close();
00183 
00184         // write point data file
00185         for(VTopology::iterator itTopology = Topology.begin(); itTopology != Topology.end(); ++itTopology) {
00186             pltData << itTopology->second.getModule()->getPosition().x << "\t" << itTopology->second.getModule()->getPosition().y << endl;
00187         }
00188         pltData.close();
00189 
00190         //write arrow data file
00191         for(VTopology::iterator itTopology = Topology.begin(); itTopology != Topology.end(); ++itTopology) {
00192             for(SiteMap::iterator itSites = itTopology->second.getModule()->Sites.begin(); itSites != itTopology->second.getModule()->Sites.end(); ++itSites) {
00193                 if(plotConnections) {
00194                     VTopology::iterator destNode = Topology.find(itSites->second->addr.getKey());
00195                     if(destNode != Topology.end()) {
00196                         Vector2D relPos = destNode->second.getModule()->getPosition() - itTopology->second.getModule()->getPosition();
00197                         pltVector << itTopology->second.getModule()->getPosition().x << "\t" << itTopology->second.getModule()->getPosition().y << "\t"
00198                                   << relPos.x << "\t" << relPos.y << endl;
00199                     }
00200                 }
00201                 else {
00202                     Vector2D relPos = itSites->second->coord - itTopology->second.getModule()->getPosition();
00203                     pltVector << itTopology->second.getModule()->getPosition().x << "\t" << itTopology->second.getModule()->getPosition().y << "\t"
00204                               << relPos.x << "\t" << relPos.y << endl;
00205                 }
00206             }
00207         }
00208         pltVector.close();
00209     }
00210     Topology.clear();
00211 }

void ConnectivityProbe::initialize (  ) 

Definition at line 39 of file ConnectivityProbe.cc.

00040 {
00041     globalStatistics = GlobalStatisticsAccess().get();
00042     probeIntervall = par("connectivityProbeIntervall");
00043     plotIntervall = par("visualizeNetworkIntervall");
00044     probeTimer = new cMessage("probeTimer");
00045     plotTimer = new cMessage("plotTimer");
00046     plotConnections = par("plotConnections");
00047 
00048     if(probeIntervall > 0.0) {
00049         scheduleAt(simTime() + probeIntervall, probeTimer);
00050 
00051         cOV_NodeCount.setName("total node count");
00052         cOV_MaximumComponent.setName("largest connected component");
00053         cOV_MaxConnectivity.setName("connectivity in percent");
00054         cOV_ZeroMissingNeighbors.setName("neighbor-error free nodes");
00055         cOV_AverageMissingNeighbors.setName("average missing neighbors per node");
00056         cOV_MaxMissingNeighbors.setName("largest missing neighbors count");
00057         cOV_AverageDrift.setName("average drift");
00058     }
00059 
00060     if(plotIntervall > 0.0) {
00061         scheduleAt(simTime() + plotIntervall, plotTimer);
00062     }
00063 }

void ConnectivityProbe::resetTopologyNodes (  )  [private]

Definition at line 227 of file ConnectivityProbe.cc.

Referenced by handleMessage().

00228 {
00229     for(VTopology::iterator itTopology = Topology.begin(); itTopology != Topology.end(); ++itTopology) {
00230         itTopology->second.visited = false;
00231     }
00232 }


Member Data Documentation

Definition at line 78 of file ConnectivityProbe.h.

Referenced by handleMessage(), and initialize().

Definition at line 76 of file ConnectivityProbe.h.

Referenced by handleMessage(), and initialize().

Definition at line 74 of file ConnectivityProbe.h.

Referenced by handleMessage(), and initialize().

Definition at line 73 of file ConnectivityProbe.h.

Referenced by handleMessage(), and initialize().

Definition at line 77 of file ConnectivityProbe.h.

Referenced by handleMessage(), and initialize().

cOutVector ConnectivityProbe::cOV_NodeCount [private]

Definition at line 72 of file ConnectivityProbe.h.

Referenced by handleMessage(), and initialize().

Definition at line 75 of file ConnectivityProbe.h.

Referenced by handleMessage(), and initialize().

Definition at line 69 of file ConnectivityProbe.h.

Referenced by handleMessage(), and initialize().

Definition at line 65 of file ConnectivityProbe.h.

Referenced by handleMessage(), and initialize().

simtime_t ConnectivityProbe::plotIntervall [private]

Definition at line 64 of file ConnectivityProbe.h.

Referenced by handleMessage(), and initialize().

cMessage* ConnectivityProbe::plotTimer [private]

Definition at line 67 of file ConnectivityProbe.h.

Referenced by handleMessage(), initialize(), and ~ConnectivityProbe().

std::fstream ConnectivityProbe::pltData [private]

Definition at line 58 of file ConnectivityProbe.h.

Referenced by handleMessage().

std::fstream ConnectivityProbe::pltNetwork [private]

Definition at line 58 of file ConnectivityProbe.h.

Referenced by handleMessage().

std::fstream ConnectivityProbe::pltVector [private]

Definition at line 58 of file ConnectivityProbe.h.

Referenced by handleMessage().

simtime_t ConnectivityProbe::probeIntervall [private]

Definition at line 63 of file ConnectivityProbe.h.

Referenced by handleMessage(), and initialize().

cMessage* ConnectivityProbe::probeTimer [private]

Definition at line 66 of file ConnectivityProbe.h.

Referenced by handleMessage(), initialize(), and ~ConnectivityProbe().


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

Generated on Tue Sep 8 17:26:57 2009 for OverSim by  doxygen 1.5.8