ConnectivityProbeQuon.cc
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00025 #include "ConnectivityProbeQuon.h"
00026
00027 Define_Module(ConnectivityProbeQuon);
00028
00029 QuonTopologyNode::QuonTopologyNode(int moduleID)
00030 {
00031 this->moduleID = moduleID;
00032 visited = false;
00033 }
00034
00035 Quon* QuonTopologyNode::getModule() const
00036 {
00037 return check_and_cast<Quon*>(simulation.getModule(moduleID));
00038 }
00039
00040 void ConnectivityProbeQuon::initialize()
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 }
00074
00075 void ConnectivityProbeQuon::handleMessage(cMessage* msg)
00076 {
00077
00078 extractTopology();
00079
00080 if(Topology.size() == 0) {
00081 return;
00082 }
00083
00084
00085 if(msg->isName("probeTimer")) {
00086
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
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
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
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
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
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
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 }
00264
00265 void ConnectivityProbeQuon::extractTopology()
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 }
00278
00279 void ConnectivityProbeQuon::resetTopologyNodes()
00280 {
00281 for(QuonTopology::iterator itTopology = Topology.begin(); itTopology != Topology.end(); ++itTopology) {
00282 itTopology->second.visited = false;
00283 }
00284 }
00285
00286 unsigned int ConnectivityProbeQuon::getComponentSize(OverlayKey key)
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 }
00300
00301 ConnectivityProbeQuon::~ConnectivityProbeQuon()
00302 {
00303
00304 cancelAndDelete(probeTimer);
00305 cancelAndDelete(plotTimer);
00306 }