hotspotRoaming class More...
#include <hotspotRoaming.h>
Classes | |
struct | Hotspot |
Public Member Functions | |
hotspotRoaming (double areaDimension, double speed, NeighborMap *Neighbors, GlobalCoordinator *coordinator, CollisionList *CollisionRect) | |
virtual | ~hotspotRoaming () |
virtual void | move () |
Defined in subclasses only. | |
Protected Attributes | |
std::vector< Hotspot > | hotspots |
std::vector< Hotspot >::iterator | curHotspot |
simtime_t | hotspotStayTime |
bool | stayInHotspot |
hotspotRoaming class
Simulates nodes roaming an area with hotpots.
Definition at line 34 of file hotspotRoaming.h.
hotspotRoaming::hotspotRoaming | ( | double | areaDimension, | |
double | speed, | |||
NeighborMap * | Neighbors, | |||
GlobalCoordinator * | coordinator, | |||
CollisionList * | CollisionRect | |||
) |
Definition at line 27 of file hotspotRoaming.cc.
00028 :MovementGenerator(areaDimension, speed, Neighbors, coordinator, CollisionRect) 00029 { 00030 double prob = 0; 00031 00032 std::vector<std::string> hotspotvec = cStringTokenizer(coordinator->par("Hotspots"), ";").asVector(); 00033 for( std::vector<std::string>::iterator it = hotspotvec.begin(); it != hotspotvec.end(); ++it ){ 00034 std::vector<std::string> hstr = cStringTokenizer(it->c_str(), ",").asVector(); 00035 if( hstr.size() != 4 ) { 00036 throw( cException("Error parsing Hotspots parameter") ); 00037 } 00038 // parse string, convert to hotspot data 00039 Hotspot h; 00040 h.center.x = convertString<double>( hstr[0] ); 00041 h.center.y = convertString<double>( hstr[1] ); 00042 h.radius = convertString<double>( hstr[2] ); 00043 h.probability = convertString<double>( hstr[3] ); 00044 prob += h.probability; 00045 00046 // check hotspot bounds 00047 if( h.center.x - h.radius < 0 || h.center.y - h.radius < 0 || 00048 h.center.x + h.radius > areaDimension || h.center.y + h.radius > areaDimension ) { 00049 00050 throw( cException("Error: Hotspot is outside the playground!") ); 00051 } 00052 if( prob > 1 ){ 00053 throw( cException("Error: Hotspot probabilities add up to > 1!") ); 00054 } 00055 00056 hotspots.push_back(h); 00057 } 00058 curHotspot = hotspots.end(); 00059 if( (double) coordinator->par("HotspotStayTime") == (double) 0.0 ) { 00060 stayInHotspot = false; 00061 } else { 00062 stayInHotspot = true; 00063 } 00064 target.x = uniform(0.0, areaDimension); 00065 target.y = uniform(0.0, areaDimension); 00066 }
virtual hotspotRoaming::~hotspotRoaming | ( | ) | [inline, virtual] |
Definition at line 48 of file hotspotRoaming.h.
void hotspotRoaming::move | ( | ) | [virtual] |
Defined in subclasses only.
Implements MovementGenerator.
Definition at line 68 of file hotspotRoaming.cc.
00069 { 00070 flock(); 00071 position += direction * speed; 00072 if(testBounds()) { 00073 position += direction * speed * 2; 00074 testBounds(); 00075 } 00076 00077 if(target.distanceSqr(position) < speed * speed) { 00078 // arrived at current destination 00079 00080 // if we are not inside a hotspot, or do not want to 00081 // stay inside the current hotspot (any more) ... 00082 if ( !stayInHotspot || curHotspot == hotspots.end() || 00083 ( hotspotStayTime > 0 && hotspotStayTime < simTime() )) 00084 { 00085 hotspotStayTime = 0; 00086 00087 // ... select next target hotspot 00088 double rnd = uniform(0, 1); 00089 for( curHotspot = hotspots.begin(); curHotspot != hotspots.end(); ++curHotspot ){ 00090 rnd -= curHotspot->probability; 00091 if( rnd <= 0 ) break; 00092 } 00093 00094 } else { 00095 // stay in current hotspot 00096 // start stayTimer if not already done 00097 if ( hotspotStayTime == 0 ) { 00098 hotspotStayTime = simTime() + coordinator->par("HotspotStayTime"); 00099 } 00100 } 00101 00102 // chose target inside hotspot, or random target if no hotspot was selected 00103 if( curHotspot != hotspots.end() ){ 00104 Vector2D dev; 00105 // randomly select point inside the hotspot 00106 double r = uniform( 0, 1 ); 00107 double theta = uniform( 0, 2*M_PI ); 00108 dev.x = sqrt( r ) * cos( theta ); 00109 dev.y = sqrt( r ) * sin( theta ); 00110 00111 target = curHotspot->center + dev*curHotspot->radius; 00112 } else { 00113 target.x = uniform(0.0, areaDimension); 00114 target.y = uniform(0.0, areaDimension); 00115 } 00116 } 00117 }
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 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().