ConnectivityProbeApp.cc

Go to the documentation of this file.
00001 //
00002 // Copyright (C) 2006 Institut fuer Telematik, Universitaet Karlsruhe (TH)
00003 //
00004 // This program is free software; you can redistribute it and/or
00005 // modify it under the terms of the GNU General Public License
00006 // as published by the Free Software Foundation; either version 2
00007 // of the License, or (at your option) any later version.
00008 //
00009 // This program is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with this program; if not, write to the Free Software
00016 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017 //
00018 
00025 #include "ConnectivityProbeApp.h"
00026 
00027 Define_Module(ConnectivityProbeApp);
00028 
00029 void ConnectivityProbeApp::initialize()
00030 {
00031     globalStatistics = GlobalStatisticsAccess().get();
00032     probeIntervall = par("connectivityProbeIntervall");
00033     probeTimer = new cMessage("probeTimer");
00034 
00035     if(probeIntervall > 0.0) {
00036         scheduleAt(simTime() + probeIntervall, probeTimer);
00037 
00038         cOV_NodeCount.setName("total node count");
00039         cOV_ZeroMissingNeighbors.setName("neighbor-error free nodes");
00040         cOV_AverageMissingNeighbors.setName("average missing neighbors per node");
00041         cOV_MaxMissingNeighbors.setName("largest missing neighbors count");
00042         cOV_AverageDrift.setName("average drift");
00043     }
00044 
00045 }
00046 
00047 void ConnectivityProbeApp::handleMessage(cMessage* msg)
00048 {
00049     // fill topology with all modules
00050     extractTopology();
00051 
00052     if(Topology.size() == 0) {
00053         return;
00054     }
00055 
00056     // catch self timer messages
00057     if(msg->isName("probeTimer")) {
00058         //reset timer
00059         cancelEvent(probeTimer);
00060         scheduleAt(simTime() + probeIntervall, msg);
00061 
00062         int mnMax = 0;
00063         int mnZero = 0;
00064         int driftCount = 0;
00065         double mnAverage = 0.0;
00066         double drift = 0.0;
00067 
00068         for(std::map<NodeHandle, SimpleGameClient*>::iterator itTopology = Topology.begin(); itTopology != Topology.end(); ++itTopology) {
00069             int missing = 0;
00070             Vector2D pos = itTopology->second->getPosition();
00071             double AOIWidth = itTopology->second->getAOI();
00072             for(std::map<NodeHandle, SimpleGameClient*>::iterator itI = Topology.begin(); itI != Topology.end(); ++itI) {
00073                 if(itI != itTopology && pos.distanceSqr(itI->second->getPosition()) <= AOIWidth*AOIWidth) {
00074                     NeighborMap::iterator currentSite = itTopology->second->Neighbors.find(itI->second->getThisNode());
00075                     if(currentSite == itTopology->second->Neighbors.end()) {
00076                         ++missing;
00077                     }
00078                     else {
00079                         drift += sqrt(currentSite->second.position.distanceSqr(itI->second->getPosition()));
00080                         ++driftCount;
00081                     }
00082                 }
00083             }
00084 
00085             mnAverage += missing;
00086             if(mnMax < missing) {
00087                 mnMax = missing;
00088             }
00089             if(missing == 0) {
00090                 ++mnZero;
00091             }
00092         }
00093         mnAverage /= (double)Topology.size();
00094         if(driftCount > 0) {
00095             drift /= (double)driftCount;
00096         }
00097 
00098         cOV_ZeroMissingNeighbors.record((double)mnZero);
00099         RECORD_STATS (
00100             globalStatistics->addStdDev("ConnectivityProbe: percentage zero missing neighbors", (double)mnZero * 100.0 / (double)Topology.size());
00101             globalStatistics->addStdDev("ConnectivityProbe: average drift", drift);
00102         );
00103         cOV_AverageMissingNeighbors.record(mnAverage);
00104         cOV_MaxMissingNeighbors.record((double)mnMax);
00105         cOV_AverageDrift.record(drift);
00106     }
00107     Topology.clear();
00108 }
00109 
00110 void ConnectivityProbeApp::extractTopology()
00111 {
00112     for(int i=0; i<=simulation.getLastModuleId(); i++) {
00113         cModule* module = simulation.getModule(i);
00114         SimpleGameClient* client;
00115         if((client = dynamic_cast<SimpleGameClient*>(module))) {
00116 
00117             if(client->isOverlayReady()) {
00118                 Topology.insert(std::make_pair(client->getThisNode(), client));
00119             }
00120         }
00121     }
00122 }
00123 
00124 ConnectivityProbeApp::~ConnectivityProbeApp()
00125 {
00126     // destroy self timer messages
00127     cancelAndDelete(probeTimer);
00128 }
Generated on Wed May 26 16:21:14 2010 for OverSim by  doxygen 1.6.3