OverSim
hotspotRoaming Class Reference

hotspotRoaming class More...

#include <hotspotRoaming.h>

Inheritance diagram for hotspotRoaming:
MovementGenerator

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.
- Public Member Functions inherited from MovementGenerator
 MovementGenerator (double areaDimension, double speed, NeighborMap *Neighbors, GlobalCoordinator *coordinator, CollisionList *CollisionRect)
 Initialize the generator with the movement area dimensions and node movement speed.
virtual ~MovementGenerator ()
Vector2D getPosition ()
 Get the nodes current position.

Protected Attributes

std::vector< Hotspothotspots
std::vector< Hotspot >::iterator curHotspot
simtime_t hotspotStayTime
bool stayInHotspot
- Protected Attributes inherited from MovementGenerator
double areaDimension
double speed
Vector2D direction
Vector2D position
Vector2D target
NeighborMapNeighbors
NeighborMap::iterator itNeighbors
GlobalCoordinatorcoordinator
CollisionListCollisionRect

Additional Inherited Members

- Protected Member Functions inherited from MovementGenerator
bool testBounds ()
 Prevents the node from leaving the defined area and checks for obstacle hits.
void flock ()
 Simple flocking algorithm.
void generateScenery (unsigned int seed)
 Generates scenery objects.

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.

{
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);
}
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 ( )
inlinevirtual

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();
if(testBounds()) {
position += direction * speed * 2;
}
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() ))
{
// ... 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().

bool hotspotRoaming::stayInHotspot
protected

Definition at line 45 of file hotspotRoaming.h.

Referenced by hotspotRoaming(), and move().


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