Public Member Functions | Private Member Functions | Private Attributes

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
bool plotMissing
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 293 of file ConnectivityProbe.cc.

{
    // destroy self timer messages
    cancelAndDelete(probeTimer);
    cancelAndDelete(plotTimer);
}


Member Function Documentation

void ConnectivityProbe::extractTopology (  )  [private]

Definition at line 257 of file ConnectivityProbe.cc.

Referenced by handleMessage().

{
    for(int i=0; i<=simulation.getLastModuleId(); i++) {
        cModule* module = simulation.getModule(i);
        if(module && dynamic_cast<Vast*>(module)) {
            Vast* vast = check_and_cast<Vast*>(module);
            if(vast->getState() == BaseOverlay::READY) {
                VTopologyNode temp(i);
                Topology.insert(std::make_pair(vast->getHandle().getKey(), temp));
            }
        }
    }
}

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

Definition at line 278 of file ConnectivityProbe.cc.

Referenced by handleMessage().

{
    VTopology::iterator itEntry = Topology.find(key);
    if(itEntry != Topology.end() && itEntry->second.visited == false) {
        int count = 1;
        itEntry->second.visited = true;
        Vast* vast = itEntry->second.getModule();
        for(SiteMap::iterator itSites = vast->Sites.begin(); itSites != vast->Sites.end(); ++itSites) {
            count += getComponentSize(itSites->first.getKey());
        }
        return count;
    }
    return 0;
}

void ConnectivityProbe::handleMessage ( cMessage *  msg  ) 

Definition at line 66 of file ConnectivityProbe.cc.

{
    // fill topology with all VAST modules
    extractTopology();

    if(Topology.size() == 0) {
        return;
    }

    // catch self timer messages
    if(msg->isName("probeTimer")) {
        //reset timer
        cancelEvent(probeTimer);
        scheduleAt(simTime() + probeIntervall, msg);

        unsigned int maxComponent = 0;
        for(VTopology::iterator itTopology = Topology.begin(); itTopology != Topology.end(); ++itTopology) {
            unsigned int count = getComponentSize(itTopology->second.getModule()->getHandle().getKey());
            if(count > maxComponent) {
                maxComponent = count;
            }
            resetTopologyNodes();
            if(count == Topology.size()) {
                break;
            }
        }

        cOV_NodeCount.record((double)Topology.size());
        cOV_MaximumComponent.record((double)maxComponent);
        cOV_MaxConnectivity.record((double)maxComponent * 100.0 / (double)Topology.size());
        RECORD_STATS (
            globalStatistics->addStdDev("ConnectivityProbe: max connectivity", (double)maxComponent * 100.0 / (double)Topology.size());
        );

        int mnMax = 0;
        int mnZero = 0;
        int driftCount = 0;
        double mnAverage = 0.0;
        double drift = 0.0;

        for(VTopology::iterator itTopology = Topology.begin(); itTopology != Topology.end(); ++itTopology) {
            double AOIWidthSqr = itTopology->second.getModule()->getAOI();
            AOIWidthSqr *= AOIWidthSqr;
            Vector2D vastPosition = itTopology->second.getModule()->getPosition();
            int missing = 0;
            for(VTopology::iterator itI = Topology.begin(); itI != Topology.end(); ++itI) {
                if(itI != itTopology && vastPosition.distanceSqr(itI->second.getModule()->getPosition()) <= AOIWidthSqr) {
                    SiteMap::iterator currentSite = itTopology->second.getModule()->Sites.find(itI->second.getModule()->getHandle());
                    if(currentSite == itTopology->second.getModule()->Sites.end()) {
                        ++missing;
                    }
                    else {
                        drift += sqrt(currentSite->second->coord.distanceSqr(itI->second.getModule()->getPosition()));
                        ++driftCount;
                    }
                }
            }

            mnAverage += missing;
            if(mnMax < missing) {
                mnMax = missing;
            }
            if(missing == 0) {
                ++mnZero;
            }
        }
        mnAverage /= (double)Topology.size();
        if(driftCount > 0) {
            drift /= (double)driftCount;
        }

        cOV_ZeroMissingNeighbors.record((double)mnZero);
        RECORD_STATS (
            globalStatistics->addStdDev("ConnectivityProbe: percentage zero missing neighbors", (double)mnZero * 100.0 / (double)Topology.size());
            globalStatistics->addStdDev("ConnectivityProbe: average drift", drift);
        );
        cOV_AverageMissingNeighbors.record(mnAverage);
        cOV_MaxMissingNeighbors.record((double)mnMax);
        cOV_AverageDrift.record(drift);
    }
    else if(msg->isName("plotTimer")) {
        //reset timer
        cancelEvent(plotTimer);
        scheduleAt(simTime() + plotIntervall, msg);

        bool missingFound = false;
        if(plotMissing) {
            for(VTopology::iterator itTopology = Topology.begin(); itTopology != Topology.end(); ++itTopology) {
                double AOIWidthSqr = itTopology->second.getModule()->getAOI();
                AOIWidthSqr *= AOIWidthSqr;
                Vector2D vastPosition = itTopology->second.getModule()->getPosition();
                for(VTopology::iterator itI = Topology.begin(); itI != Topology.end(); ++itI) {
                    if(itI != itTopology && vastPosition.distanceSqr(itI->second.getModule()->getPosition()) <= AOIWidthSqr) {
                        SiteMap::iterator currentSite = itTopology->second.getModule()->Sites.find(itI->second.getModule()->getHandle());
                        if(currentSite == itTopology->second.getModule()->Sites.end()) {
                            missingFound=true;
                        }
                    }
                }
            }
        }

        if(!plotMissing || missingFound) {

            int range = (int)Topology.begin()->second.getModule()->getAreaDimension();
            std::stringstream oss;
            std::string filename;
            int simTimeInt, stellen = 1;
            simTimeInt = (int)SIMTIME_DBL(simTime());
            oss << "plot";
            for(int i=0; i<6; i++) {
                if(!(simTimeInt / stellen)) {
                    oss << "0";
                }
                stellen *= 10;
            }
            oss << simTimeInt;

            // open/ write plot file
            filename = oss.str() + ".plot";
            pltNetwork.open(filename.c_str(), std::ios::out);
            pltNetwork << "set xrange [0:" << range << "]" << endl;
            pltNetwork << "set yrange [0:" << range << "]" << endl;
            pltNetwork << "set nokey" << endl;

            // open point file
            filename = oss.str() + ".point";
            pltData.open(filename.c_str(), std::ios::out);

            pltNetwork << "plot '" << filename << "' using 1:2 with points pointtype 7,\\" << endl;

            // open vector file
            filename = oss.str() + ".arrow";
            pltVector.open(filename.c_str(), std::ios::out);

            pltNetwork << "     '" << filename << "' using 1:2:3:4 with vectors linetype 1" << endl;
            pltNetwork.close();

            // write point data file
            for(VTopology::iterator itTopology = Topology.begin(); itTopology != Topology.end(); ++itTopology) {
                pltData << itTopology->second.getModule()->getPosition().x << "\t" << itTopology->second.getModule()->getPosition().y << endl;
            }
            pltData.close();

            //write arrow data file
            if(!plotMissing) {
                for(VTopology::iterator itTopology = Topology.begin(); itTopology != Topology.end(); ++itTopology) {
                    for(SiteMap::iterator itSites = itTopology->second.getModule()->Sites.begin(); itSites != itTopology->second.getModule()->Sites.end(); ++itSites) {
                        if(plotConnections) {
                            VTopology::iterator destNode = Topology.find(itSites->second->addr.getKey());
                            if(destNode != Topology.end()) {
                                Vector2D relPos = destNode->second.getModule()->getPosition() - itTopology->second.getModule()->getPosition();
                                pltVector << itTopology->second.getModule()->getPosition().x << "\t" << itTopology->second.getModule()->getPosition().y << "\t"
                                    << relPos.x << "\t" << relPos.y << endl;
                            }
                        }
                        else {
                            Vector2D relPos = itSites->second->coord - itTopology->second.getModule()->getPosition();
                            pltVector << itTopology->second.getModule()->getPosition().x << "\t" << itTopology->second.getModule()->getPosition().y << "\t"
                                << relPos.x << "\t" << relPos.y << endl;
                        }
                    }
                }
            } else {
                for(VTopology::iterator itTopology = Topology.begin(); itTopology != Topology.end(); ++itTopology) {
                    double AOIWidthSqr = itTopology->second.getModule()->getAOI();
                    AOIWidthSqr *= AOIWidthSqr;
                    Vector2D vastPosition = itTopology->second.getModule()->getPosition();
                    for(VTopology::iterator itI = Topology.begin(); itI != Topology.end(); ++itI) {
                        if(itI != itTopology && vastPosition.distanceSqr(itI->second.getModule()->getPosition()) <= AOIWidthSqr) {
                            SiteMap::iterator currentSite = itTopology->second.getModule()->Sites.find(itI->second.getModule()->getHandle());
                            if(currentSite == itTopology->second.getModule()->Sites.end()) {
                                Vector2D relPos = itI->second.getModule()->getPosition() - itTopology->second.getModule()->getPosition();
                                pltVector << itTopology->second.getModule()->getPosition().x << "\t"
                                          << itTopology->second.getModule()->getPosition().y << "\t"
                                          << relPos.x << "\t" << relPos.y <<  "\t"
                                          << itTopology->second.getModule()->getParentModule()->getParentModule()->getFullName() << ":"
                                          << itTopology->second.getModule()->thisSite.addr.getKey().toString(16) << "\t"
                                          << itI->second.getModule()->getParentModule()->getParentModule()->getFullName() << ":"
                                          << itI->second.getModule()->thisSite.addr.getKey().toString(16) << endl;
                            }
                        }
                    }
                }
            }
            pltVector.close();
        }
    }
    Topology.clear();
}

void ConnectivityProbe::initialize (  ) 

Definition at line 39 of file ConnectivityProbe.cc.

{
    globalStatistics = GlobalStatisticsAccess().get();
    probeIntervall = par("connectivityProbeIntervall");
    plotIntervall = par("visualizeNetworkIntervall");
    probeTimer = new cMessage("probeTimer");
    plotTimer = new cMessage("plotTimer");
    plotConnections = par("plotConnections");
    plotMissing= par("plotMissing");

    if(probeIntervall > 0.0) {
        scheduleAt(simTime() + probeIntervall, probeTimer);

        cOV_NodeCount.setName("total node count");
        cOV_MaximumComponent.setName("largest connected component");
        cOV_MaxConnectivity.setName("connectivity in percent");
        cOV_ZeroMissingNeighbors.setName("neighbor-error free nodes");
        cOV_AverageMissingNeighbors.setName("average missing neighbors per node");
        cOV_MaxMissingNeighbors.setName("largest missing neighbors count");
        cOV_AverageDrift.setName("average drift");
    }

    if(plotIntervall > 0.0) {
        scheduleAt(simTime() + plotIntervall, plotTimer);
    }
}

void ConnectivityProbe::resetTopologyNodes (  )  [private]

Definition at line 271 of file ConnectivityProbe.cc.

Referenced by handleMessage().

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


Member Data Documentation

Definition at line 79 of file ConnectivityProbe.h.

Referenced by handleMessage(), and initialize().

Definition at line 77 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 74 of file ConnectivityProbe.h.

Referenced by handleMessage(), and initialize().

Definition at line 78 of file ConnectivityProbe.h.

Referenced by handleMessage(), and initialize().

cOutVector ConnectivityProbe::cOV_NodeCount [private]

Definition at line 73 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 70 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().

Definition at line 66 of file ConnectivityProbe.h.

Referenced by handleMessage(), and initialize().

cMessage* ConnectivityProbe::plotTimer [private]

Definition at line 68 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 67 of file ConnectivityProbe.h.

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


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