ConnectivityProbeP Class Reference

#include <ConnectivityProbeP.h>

List of all members.


Detailed Description

Definition at line 47 of file ConnectivityProbeP.h.


Public Member Functions

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

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 plotMissing
cMessage * probeTimer
cMessage * plotTimer
PTopology Topology
GlobalStatistics * globalStatistics
cOutVector cOV_NodeCount
cOutVector cOV_MaximumComponent
cOutVector cOV_MaxConnectivity
cOutVector cOV_ZeroMissingNeighbors
cOutVector cOV_AverageMissingNeighbors
cOutVector cOV_MaxMissingNeighbors
cOutVector cOV_AverageDrift

Constructor & Destructor Documentation

ConnectivityProbeP::~ConnectivityProbeP (  ) 

Definition at line 295 of file ConnectivityProbeP.cc.

00296 {
00297     // destroy self timer messages
00298     cancelAndDelete(probeTimer);
00299     cancelAndDelete(plotTimer);
00300 }


Member Function Documentation

void ConnectivityProbeP::initialize (  ) 

Definition at line 39 of file ConnectivityProbeP.cc.

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

void ConnectivityProbeP::handleMessage ( cMessage *  msg  ) 

Definition at line 73 of file ConnectivityProbeP.cc.

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

void ConnectivityProbeP::extractTopology (  )  [private]

Definition at line 259 of file ConnectivityProbeP.cc.

Referenced by handleMessage().

00260 {
00261     for(int i=0; i<=simulation.getLastModuleId(); i++) {
00262         cModule* module = simulation.getModule(i);
00263         if(module && dynamic_cast<QuonP*>(module)) {
00264             QuonP* quonp = check_and_cast<QuonP*>(module);
00265             if(quonp->getState() == QREADY) {
00266                 PTopologyNode temp(i);
00267                 Topology.insert(std::make_pair(quonp->getKey(), temp));
00268             }
00269         }
00270     }
00271 }

void ConnectivityProbeP::resetTopologyNodes (  )  [private]

Definition at line 273 of file ConnectivityProbeP.cc.

Referenced by handleMessage().

00274 {
00275     for(PTopology::iterator itTopology = Topology.begin(); itTopology != Topology.end(); ++itTopology) {
00276         itTopology->second.visited = false;
00277     }
00278 }

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

Definition at line 280 of file ConnectivityProbeP.cc.

Referenced by handleMessage().

00281 {
00282     PTopology::iterator itEntry = Topology.find(key);
00283     if(itEntry != Topology.end() && itEntry->second.visited == false) {
00284         int count = 1;
00285         itEntry->second.visited = true;
00286         QuonP* quonp = itEntry->second.getModule();
00287         for(PSiteMap::iterator itSites = quonp->Sites.begin(); itSites != quonp->Sites.end(); ++itSites) {
00288             count += getComponentSize(itSites->first);
00289         }
00290         return count;
00291     }
00292     return 0;
00293 }


Member Data Documentation

std::fstream ConnectivityProbeP::pltNetwork [private]

Definition at line 55 of file ConnectivityProbeP.h.

Referenced by handleMessage().

std::fstream ConnectivityProbeP::pltData [private]

Definition at line 55 of file ConnectivityProbeP.h.

Referenced by handleMessage().

std::fstream ConnectivityProbeP::pltVector [private]

Definition at line 55 of file ConnectivityProbeP.h.

Referenced by handleMessage().

Definition at line 60 of file ConnectivityProbeP.h.

Referenced by handleMessage(), and initialize().

simtime_t ConnectivityProbeP::plotIntervall [private]

Definition at line 61 of file ConnectivityProbeP.h.

Referenced by handleMessage(), and initialize().

simtime_t ConnectivityProbeP::startPlotTime [private]

Definition at line 62 of file ConnectivityProbeP.h.

Referenced by handleMessage(), and initialize().

simtime_t ConnectivityProbeP::plotPeriod [private]

Definition at line 63 of file ConnectivityProbeP.h.

Referenced by handleMessage(), and initialize().

Definition at line 64 of file ConnectivityProbeP.h.

Referenced by handleMessage(), and initialize().

Definition at line 65 of file ConnectivityProbeP.h.

Referenced by handleMessage(), and initialize().

cMessage* ConnectivityProbeP::probeTimer [private]

Definition at line 66 of file ConnectivityProbeP.h.

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

cMessage* ConnectivityProbeP::plotTimer [private]

Definition at line 67 of file ConnectivityProbeP.h.

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

Definition at line 69 of file ConnectivityProbeP.h.

Referenced by handleMessage(), and initialize().

cOutVector ConnectivityProbeP::cOV_NodeCount [private]

Definition at line 72 of file ConnectivityProbeP.h.

Referenced by handleMessage(), and initialize().

Definition at line 73 of file ConnectivityProbeP.h.

Referenced by handleMessage(), and initialize().

Definition at line 74 of file ConnectivityProbeP.h.

Referenced by handleMessage(), and initialize().

Definition at line 75 of file ConnectivityProbeP.h.

Referenced by handleMessage(), and initialize().

Definition at line 76 of file ConnectivityProbeP.h.

Referenced by handleMessage(), and initialize().

Definition at line 77 of file ConnectivityProbeP.h.

Referenced by handleMessage(), and initialize().

Definition at line 78 of file ConnectivityProbeP.h.

Referenced by handleMessage(), and initialize().


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

Generated on Wed Mar 25 16:32:52 2009 for OverSim by  doxygen 1.5.5