Classes | Public Member Functions | Protected Attributes

hotspotRoaming Class Reference

hotspotRoaming class More...

#include <hotspotRoaming.h>

Inheritance diagram for hotspotRoaming:
MovementGenerator

List of all members.

Classes

struct  Hotspot

Public Member Functions

 hotspotRoaming (double areaDimension, double speed, NeighborMap *Neighbors, GlobalCoordinator *coordinator, CollisionList *CollisionRect)
double getDistanceFromHotspot ()
virtual ~hotspotRoaming ()
virtual void move ()
 Defined in subclasses only.

Protected Attributes

std::vector< Hotspothotspots
std::vector< Hotspot >::iterator curHotspot
simtime_t hotspotStayTime
bool stayInHotspot

Detailed Description

hotspotRoaming class

Simulates nodes roaming an area with hotpots.

Definition at line 34 of file hotspotRoaming.h.


Constructor & Destructor Documentation

hotspotRoaming::hotspotRoaming ( double  areaDimension,
double  speed,
NeighborMap Neighbors,
GlobalCoordinator coordinator,
CollisionList CollisionRect 
)

Definition at line 27 of file hotspotRoaming.cc.

              :MovementGenerator(areaDimension, speed, Neighbors, coordinator, CollisionRect)
{
    double prob = 0;

    std::vector<std::string> hotspotvec = cStringTokenizer(coordinator->par("Hotspots"), ";").asVector();
    for( std::vector<std::string>::iterator it = hotspotvec.begin(); it != hotspotvec.end(); ++it ){
        std::vector<std::string> hstr = cStringTokenizer(it->c_str(), ",").asVector();
        if( hstr.size() != 4 ) {
            throw( cException("Error parsing Hotspots parameter") );
        }
        // parse string, convert to hotspot data
        Hotspot h;
        h.center.x = convertString<double>( hstr[0] );
        h.center.y = convertString<double>( hstr[1] );
        h.radius = convertString<double>( hstr[2] );
        h.probability = convertString<double>( hstr[3] );
        prob += h.probability;

        // check hotspot bounds
        if( h.center.x - h.radius < 0 || h.center.y - h.radius < 0 ||
                h.center.x + h.radius > areaDimension || h.center.y + h.radius > areaDimension ) {
         
            throw( cException("Error: Hotspot is outside the playground!") );
        }
        if( prob > 1 ){
            throw( cException("Error: Hotspot probabilities add up to > 1!") );
        }

        hotspots.push_back(h);
    }
    curHotspot = hotspots.end();
    if( (double) coordinator->par("HotspotStayTime") == (double) 0.0 ) {
        stayInHotspot = false;
    } else {
        stayInHotspot = true;
    }
    target.x = uniform(0.0, areaDimension);
    target.y = uniform(0.0, areaDimension);
}

virtual hotspotRoaming::~hotspotRoaming (  )  [inline, virtual]

Definition at line 49 of file hotspotRoaming.h.

{}


Member Function Documentation

double hotspotRoaming::getDistanceFromHotspot (  ) 

Definition at line 68 of file hotspotRoaming.cc.

{
    double minDist=areaDimension;
    for( std::vector<Hotspot>::iterator it = hotspots.begin(); it != hotspots.end(); ++it) {
        double dist = sqrt(position.distanceSqr( it->center )) - it->radius;
        if( dist < minDist ) minDist = dist;
    }

    return minDist;
}

void hotspotRoaming::move (  )  [virtual]

Defined in subclasses only.

Implements MovementGenerator.

Definition at line 79 of file hotspotRoaming.cc.

{
    flock();
    position += direction * speed;
    if(testBounds()) {
        position += direction * speed * 2;
        testBounds();
    }

    if(target.distanceSqr(position) < speed * speed) {
        // arrived at current destination
        
        // if we are not inside a hotspot, or do not want to
        // stay inside the current hotspot (any more) ...
        if ( !stayInHotspot || curHotspot == hotspots.end() ||
                  ( hotspotStayTime > 0 && hotspotStayTime < simTime() ))
        {
            hotspotStayTime = 0;
            
            // ... select next target hotspot
            double rnd = uniform(0, 1);
            for( curHotspot = hotspots.begin(); curHotspot != hotspots.end(); ++curHotspot ){
                rnd -= curHotspot->probability;
                if( rnd <= 0 ) break;
            }

        } else {
            // stay in current hotspot
            // start stayTimer if not already done
            if ( hotspotStayTime == 0 ) {
                hotspotStayTime = simTime() + coordinator->par("HotspotStayTime");
            }
        }

        // chose target inside hotspot, or random target if no hotspot was selected
        if( curHotspot != hotspots.end() ){
            Vector2D dev;
            // randomly select point inside the hotspot
            double r = uniform( 0, 1 );
            double theta = uniform( 0, 2*M_PI );
            dev.x = sqrt( r ) * cos( theta );
            dev.y = sqrt( r ) * sin( theta );

            target = curHotspot->center + dev*curHotspot->radius;
        } else {
            target.x = uniform(0.0, areaDimension);
            target.y = uniform(0.0, areaDimension);
        }
    }
}


Member Data Documentation

std::vector<Hotspot>::iterator hotspotRoaming::curHotspot [protected]

Definition at line 43 of file hotspotRoaming.h.

Referenced by hotspotRoaming(), and move().

std::vector<Hotspot> hotspotRoaming::hotspots [protected]

Definition at line 42 of file hotspotRoaming.h.

Referenced by getDistanceFromHotspot(), hotspotRoaming(), and move().

simtime_t hotspotRoaming::hotspotStayTime [protected]

Definition at line 44 of file hotspotRoaming.h.

Referenced by move().

Definition at line 45 of file hotspotRoaming.h.

Referenced by hotspotRoaming(), and move().


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