ConnectivityProbeQuon Class Reference

#include <ConnectivityProbeQuon.h>

List of all members.

Public Member Functions

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

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
simtime_t startPlotTime
simtime_t plotPeriod
bool plotConnections
bool plotBindings
bool plotMissing
cMessage * probeTimer
cMessage * plotTimer
QuonTopology 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 48 of file ConnectivityProbeQuon.h.


Constructor & Destructor Documentation

ConnectivityProbeQuon::~ConnectivityProbeQuon (  ) 

Definition at line 301 of file ConnectivityProbeQuon.cc.

00302 {
00303     // destroy self timer messages
00304     cancelAndDelete(probeTimer);
00305     cancelAndDelete(plotTimer);
00306 }


Member Function Documentation

void ConnectivityProbeQuon::extractTopology (  )  [private]

Definition at line 265 of file ConnectivityProbeQuon.cc.

Referenced by handleMessage().

00266 {
00267     for(int i=0; i<=simulation.getLastModuleId(); i++) {
00268         cModule* module = simulation.getModule(i);
00269         if(module && dynamic_cast<Quon*>(module)) {
00270             Quon* quonp = check_and_cast<Quon*>(module);
00271             if(quonp->getState() == QREADY) {
00272                 QuonTopologyNode temp(i);
00273                 Topology.insert(std::make_pair(quonp->getKey(), temp));
00274             }
00275         }
00276     }
00277 }

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

Definition at line 286 of file ConnectivityProbeQuon.cc.

Referenced by handleMessage().

00287 {
00288     QuonTopology::iterator itEntry = Topology.find(key);
00289     if(itEntry != Topology.end() && itEntry->second.visited == false) {
00290         int count = 1;
00291         itEntry->second.visited = true;
00292         Quon* quonp = itEntry->second.getModule();
00293         for(QuonSiteMap::iterator itSites = quonp->Sites.begin(); itSites != quonp->Sites.end(); ++itSites) {
00294             count += getComponentSize(itSites->first);
00295         }
00296         return count;
00297     }
00298     return 0;
00299 }

void ConnectivityProbeQuon::handleMessage ( cMessage *  msg  ) 

Definition at line 75 of file ConnectivityProbeQuon.cc.

00076 {
00077     // fill topology with all QUONP modules
00078     extractTopology();
00079 
00080     if(Topology.size() == 0) {
00081         return;
00082     }
00083 
00084     // catch self timer messages
00085     if(msg->isName("probeTimer")) {
00086         //reset timer
00087         cancelEvent(probeTimer);
00088         scheduleAt(simTime() + probeIntervall, msg);
00089 
00090         unsigned int maxComponent = 0;
00091         for(QuonTopology::iterator itTopology = Topology.begin(); itTopology != Topology.end(); ++itTopology) {
00092             unsigned int count = getComponentSize(itTopology->second.getModule()->getKey());
00093             if(count > maxComponent) {
00094                 maxComponent = count;
00095             }
00096             resetTopologyNodes();
00097             if(count == Topology.size()) {
00098                 break;
00099             }
00100         }
00101 
00102         cOV_NodeCount.record((double)Topology.size());
00103         cOV_MaximumComponent.record((double)maxComponent);
00104         cOV_MaxConnectivity.record((double)maxComponent * 100.0 / (double)Topology.size());
00105         RECORD_STATS (
00106             globalStatistics->addStdDev("ConnectivityProbe: max connectivity", (double)maxComponent * 100.0 / (double)Topology.size());
00107         );
00108 
00109         int mnMax = 0;
00110         int mnZero = 0;
00111         int driftCount = 0;
00112         double mnAverage = 0.0;
00113         double drift = 0.0;
00114 
00115         for(QuonTopology::iterator itTopology = Topology.begin(); itTopology != Topology.end(); ++itTopology) {
00116             QuonAOI AOI(itTopology->second.getModule()->getPosition(), itTopology->second.getModule()->getAOI());
00117             int missing = 0;
00118             for(QuonTopology::iterator itI = Topology.begin(); itI != Topology.end(); ++itI) {
00119                 if(itI != itTopology && AOI.collide(itI->second.getModule()->getPosition())) {
00120                     QuonSiteMap::iterator currentSite = itTopology->second.getModule()->Sites.find(itI->second.getModule()->getKey());
00121                     if(currentSite == itTopology->second.getModule()->Sites.end()) {
00122                         ++missing;
00123                     }
00124                     else {
00125                         drift += sqrt(currentSite->second->position.distanceSqr(itI->second.getModule()->getPosition()));
00126                         ++driftCount;
00127                     }
00128                 }
00129             }
00130 
00131             mnAverage += missing;
00132             if(mnMax < missing) {
00133                 mnMax = missing;
00134             }
00135             if(missing == 0) {
00136                 ++mnZero;
00137             }
00138         }
00139         mnAverage /= (double)Topology.size();
00140         if(driftCount > 0) {
00141             drift /= (double)driftCount;
00142         }
00143 
00144         cOV_ZeroMissingNeighbors.record((double)mnZero);
00145         RECORD_STATS (
00146             globalStatistics->addStdDev("ConnectivityProbe: percentage zero missing neighbors", (double)mnZero * 100.0 / (double)Topology.size());
00147             globalStatistics->addStdDev("ConnectivityProbe: average drift", drift);
00148         );
00149         cOV_AverageMissingNeighbors.record(mnAverage);
00150         cOV_MaxMissingNeighbors.record((double)mnMax);
00151         cOV_AverageDrift.record(drift);
00152     }
00153     else if(msg->isName("plotTimer")) {
00154         //reset timer
00155         cancelEvent(plotTimer);
00156         if(plotPeriod == 0.0 || simTime() <= startPlotTime + plotPeriod) {
00157             scheduleAt(simTime() + plotIntervall, msg);
00158         }
00159 
00160         bool missingFound = false;
00161         if(plotMissing) {
00162             for(QuonTopology::iterator itTopology = Topology.begin(); itTopology != Topology.end(); ++itTopology) {
00163                 QuonAOI AOI(itTopology->second.getModule()->getPosition(), itTopology->second.getModule()->getAOI());
00164                 for(QuonTopology::iterator itI = Topology.begin(); itI != Topology.end(); ++itI) {
00165                     if(itI != itTopology && AOI.collide(itI->second.getModule()->getPosition())) {
00166                         QuonSiteMap::iterator currentSite = itTopology->second.getModule()->Sites.find(itI->second.getModule()->getKey());
00167                         if(currentSite == itTopology->second.getModule()->Sites.end()) {
00168                             missingFound = true;
00169                         }
00170                     }
00171                 }
00172             }
00173         }
00174 
00175         if(!plotMissing || missingFound) {
00176             int range = (int)Topology.begin()->second.getModule()->getAreaDimension();
00177             std::stringstream oss;
00178             std::string filename;
00179             int simTimeInt, stellen = 1;
00180             simTimeInt = (int)SIMTIME_DBL(simTime());
00181             oss << "plot";
00182             for(int i=0; i<6; i++) {
00183                 if(!(simTimeInt / stellen)) {
00184                     oss << "0";
00185                 }
00186                 stellen *= 10;
00187             }
00188             oss << simTimeInt;
00189 
00190             // open / write plot file
00191             filename = oss.str() + ".plot";
00192             pltNetwork.open(filename.c_str(), std::ios::out);
00193             pltNetwork << "set xrange [0:" << range << "]" << endl;
00194             pltNetwork << "set yrange [0:" << range << "]" << endl;
00195             pltNetwork << "set nokey" << endl;
00196 
00197             // open point file
00198             filename = oss.str() + ".point";
00199             pltData.open(filename.c_str(), std::ios::out);
00200 
00201             pltNetwork << "plot '" << filename << "' using 1:2 with points pointtype 7,\\" << endl;
00202 
00203             // open vector file
00204             filename = oss.str() + ".arrow";
00205             pltVector.open(filename.c_str(), std::ios::out);
00206 
00207             pltNetwork << "     '" << filename << "' using 1:2:3:4 with vectors linetype 1" << endl;
00208             pltNetwork.close();
00209 
00210             // write point data file
00211             for(QuonTopology::iterator itTopology = Topology.begin(); itTopology != Topology.end(); ++itTopology) {
00212                 pltData << itTopology->second.getModule()->getPosition().x << "\t" << itTopology->second.getModule()->getPosition().y << endl;
00213             }
00214             pltData.close();
00215 
00216             //write arrow data file
00217             if(!plotMissing) {
00218                 for(QuonTopology::iterator itTopology = Topology.begin(); itTopology != Topology.end(); ++itTopology) {
00219                     for(QuonSiteMap::iterator itSites = itTopology->second.getModule()->Sites.begin(); itSites != itTopology->second.getModule()->Sites.end(); ++itSites) {
00220                         if(plotBindings && itSites->second->type != QBINDING && !itSites->second->softNeighbor) {
00221                             continue;
00222                         }
00223                         if(plotConnections) {
00224                             QuonTopology::iterator destNode = Topology.find(itSites->second->address.getKey());
00225                             if(destNode != Topology.end()) {
00226                                 Vector2D relPos = destNode->second.getModule()->getPosition() - itTopology->second.getModule()->getPosition();
00227                                 pltVector << itTopology->second.getModule()->getPosition().x << "\t" << itTopology->second.getModule()->getPosition().y << "\t"
00228                                         << relPos.x << "\t" << relPos.y << endl;
00229                             }
00230                         }
00231                         else {
00232                             Vector2D relPos = itSites->second->position - itTopology->second.getModule()->getPosition();
00233                             pltVector << itTopology->second.getModule()->getPosition().x << "\t" << itTopology->second.getModule()->getPosition().y << "\t"
00234                                     << relPos.x << "\t" << relPos.y << endl;
00235                         }
00236                     }
00237                 }
00238             }
00239             else {
00240                 for(QuonTopology::iterator itTopology = Topology.begin(); itTopology != Topology.end(); ++itTopology) {
00241                     QuonAOI AOI(itTopology->second.getModule()->getPosition(), itTopology->second.getModule()->getAOI());
00242                     for(QuonTopology::iterator itI = Topology.begin(); itI != Topology.end(); ++itI) {
00243                         if(itI != itTopology && AOI.collide(itI->second.getModule()->getPosition())) {
00244                             QuonSiteMap::iterator currentSite = itTopology->second.getModule()->Sites.find(itI->second.getModule()->getKey());
00245                             if(currentSite == itTopology->second.getModule()->Sites.end()) {
00246                                 Vector2D relPos = itI->second.getModule()->getPosition() - itTopology->second.getModule()->getPosition();
00247                                 pltVector << itTopology->second.getModule()->getPosition().x << "\t"
00248                                           << itTopology->second.getModule()->getPosition().y << "\t"
00249                                           << relPos.x << "\t" << relPos.y <<  "\t"
00250                                           << itTopology->second.getModule()->getParentModule()->getParentModule()->getFullName() << ":"
00251                                           << itTopology->second.getModule()->getKey().toString(16) << "\t"
00252                                           << itI->second.getModule()->getParentModule()->getParentModule()->getFullName() << ":"
00253                                           << itI->second.getModule()->getKey().toString(16) << endl;
00254                             }
00255                         }
00256                     }
00257                 }
00258             }
00259             pltVector.close();
00260         }
00261     }
00262     Topology.clear();
00263 }

void ConnectivityProbeQuon::initialize (  ) 

Definition at line 40 of file ConnectivityProbeQuon.cc.

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

void ConnectivityProbeQuon::resetTopologyNodes (  )  [private]

Definition at line 279 of file ConnectivityProbeQuon.cc.

Referenced by handleMessage().

00280 {
00281     for(QuonTopology::iterator itTopology = Topology.begin(); itTopology != Topology.end(); ++itTopology) {
00282         itTopology->second.visited = false;
00283     }
00284 }


Member Data Documentation

Definition at line 80 of file ConnectivityProbeQuon.h.

Referenced by handleMessage(), and initialize().

Definition at line 78 of file ConnectivityProbeQuon.h.

Referenced by handleMessage(), and initialize().

Definition at line 76 of file ConnectivityProbeQuon.h.

Referenced by handleMessage(), and initialize().

Definition at line 75 of file ConnectivityProbeQuon.h.

Referenced by handleMessage(), and initialize().

Definition at line 79 of file ConnectivityProbeQuon.h.

Referenced by handleMessage(), and initialize().

Definition at line 74 of file ConnectivityProbeQuon.h.

Referenced by handleMessage(), and initialize().

Definition at line 77 of file ConnectivityProbeQuon.h.

Referenced by handleMessage(), and initialize().

Definition at line 71 of file ConnectivityProbeQuon.h.

Referenced by handleMessage(), and initialize().

Definition at line 66 of file ConnectivityProbeQuon.h.

Referenced by handleMessage(), and initialize().

Definition at line 65 of file ConnectivityProbeQuon.h.

Referenced by handleMessage(), and initialize().

Definition at line 62 of file ConnectivityProbeQuon.h.

Referenced by handleMessage(), and initialize().

Definition at line 67 of file ConnectivityProbeQuon.h.

Referenced by handleMessage(), and initialize().

simtime_t ConnectivityProbeQuon::plotPeriod [private]

Definition at line 64 of file ConnectivityProbeQuon.h.

Referenced by handleMessage(), and initialize().

cMessage* ConnectivityProbeQuon::plotTimer [private]

Definition at line 69 of file ConnectivityProbeQuon.h.

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

std::fstream ConnectivityProbeQuon::pltData [private]

Definition at line 56 of file ConnectivityProbeQuon.h.

Referenced by handleMessage().

std::fstream ConnectivityProbeQuon::pltNetwork [private]

Definition at line 56 of file ConnectivityProbeQuon.h.

Referenced by handleMessage().

std::fstream ConnectivityProbeQuon::pltVector [private]

Definition at line 56 of file ConnectivityProbeQuon.h.

Referenced by handleMessage().

Definition at line 61 of file ConnectivityProbeQuon.h.

Referenced by handleMessage(), and initialize().

cMessage* ConnectivityProbeQuon::probeTimer [private]

Definition at line 68 of file ConnectivityProbeQuon.h.

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

Definition at line 63 of file ConnectivityProbeQuon.h.

Referenced by handleMessage(), and initialize().


The documentation for this class was generated from the following files:
Generated on Wed May 26 16:21:17 2010 for OverSim by  doxygen 1.6.3