Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

BasicMobility Class Reference

#include <BasicMobility.h>

Inheritance diagram for BasicMobility:

BasicModule INotifiable CircleMobility ConstSpeedMobility LinearMobility LineSegmentsMobilityBase MassMobility NullMobility RectangleMobility ANSimMobility BonnMotionMobility RandomWPMobility TurtleMobility List of all members.

Detailed Description

Abstract base class for all mobility modules.

Subclasses are expected to redefine handleSelfMsg() to update the position and schedule the time of the next position update, and initialize() to read parameters and schedule the first position update.

BasicMobility provides random placement of hosts and display updates as well as registering with the ChannelControl module. Change notifications about position changes are also posted to NotificationBoard.

Author:
Daniel Willkomm, Andras Varga


Public Types

enum  BorderPolicy { REFLECT, WRAP, PLACERANDOMLY, RAISEERROR }

Protected Member Functions

void handleMessage (cMessage *msg)
 This modules should only receive self-messages.
virtual void initialize (int)
 Initializes mobility model parameters.
virtual void finish ()
 Delete dynamically allocated objects.
virtual void handleSelfMsg (cMessage *msg)=0
 Called upon arrival of a self messages.
void updatePosition ()
 Update the position information for this node.
double playgroundSizeX () const
 Returns the width of the playground.
double playgroundSizeY () const
 Returns the height of the playground.
virtual Coord getRandomPosition ()
 Get a new random position for the host.
void reflectIfOutside (Coord &targetPos, Coord &step, double &angle)
 Utility function to reflect the node if it goes outside the playground.
void wrapIfOutside (Coord &targetPos)
 Utility function to wrap the node to the opposite edge (torus) if it goes outside the playground.
void placeRandomlyIfOutside (Coord &targetPos)
 Utility function to place the node randomly if it goes outside the playground.
void raiseErrorIfOutside ()
 Utility function to raise an error if the node gets outside the playground.
void handleIfOutside (BorderPolicy policy, Coord &targetPos, Coord &step, double &angle)
 Invokes one of reflectIfOutside(), wrapIfOutside() and placeRandomlyIfOutside(), depending on the given border policy.

Protected Attributes

ChannelControlcc
 Pointer to ChannelControl -- these two must know each other.
ChannelControl::HostRef myHostRef
 Identifies this host in the ChannelControl module.
cModule * hostPtr
 Pointer to host module, to speed up repeated access.
Coord pos
 Stores the actual position of the host.


Member Enumeration Documentation

enum BasicMobility::BorderPolicy
 

Selects how a node should behave if it reaches the edge of the playground.

See also:
handleIfOutside()
Enumeration values:
REFLECT  reflect off the wall
WRAP  reappear at the opposite edge (torus)
PLACERANDOMLY  placed at a randomly chosen position on the blackboard
RAISEERROR  stop the simulation with error
00056                       {
00057         REFLECT,       
00058         WRAP,          
00059         PLACERANDOMLY, 
00060         RAISEERROR     
00061     };


Member Function Documentation

virtual void BasicMobility::finish  )  [inline, protected, virtual]
 

Delete dynamically allocated objects.

00084 {}

Coord BasicMobility::getRandomPosition  )  [protected, virtual]
 

Get a new random position for the host.

You can redefine this function if you want to use another calculation

00116 {
00117     Coord p;
00118     p.x = genk_uniform(0, 0, cc->getPgs()->x);
00119     p.y = genk_uniform(0, 0, cc->getPgs()->y);
00120     return p;
00121 }

void BasicMobility::handleIfOutside BorderPolicy  policy,
Coord targetPos,
Coord step,
double &  angle
[protected]
 

Invokes one of reflectIfOutside(), wrapIfOutside() and placeRandomlyIfOutside(), depending on the given border policy.

00199 {
00200     switch (policy)
00201     {
00202         case REFLECT:       reflectIfOutside(targetPos, step, angle); break;
00203         case WRAP:          wrapIfOutside(targetPos); break;
00204         case PLACERANDOMLY: placeRandomlyIfOutside(targetPos); break;
00205         case RAISEERROR:    raiseErrorIfOutside(); break;
00206     }
00207 }

void BasicMobility::handleMessage cMessage *  msg  )  [protected]
 

This modules should only receive self-messages.

00090 {
00091     if (!msg->isSelfMessage())
00092         error("mobility modules can only receive self messages");
00093 
00094     handleSelfMsg(msg);
00095 }

virtual void BasicMobility::handleSelfMsg cMessage *  msg  )  [protected, pure virtual]
 

Called upon arrival of a self messages.

Implemented in CircleMobility, ConstSpeedMobility, LinearMobility, LineSegmentsMobilityBase, MassMobility, NullMobility, and RectangleMobility.

void BasicMobility::initialize int   )  [protected, virtual]
 

Initializes mobility model parameters.

Reimplemented from BasicModule.

Reimplemented in ANSimMobility, BonnMotionMobility, CircleMobility, ConstSpeedMobility, LinearMobility, LineSegmentsMobilityBase, MassMobility, RandomWPMobility, RectangleMobility, and TurtleMobility.

00040 {
00041     BasicModule::initialize(stage);
00042 
00043     EV << "initializing BasicMobility stage " << stage << endl;
00044 
00045     if (stage == 0)
00046     {
00047         cc = dynamic_cast<ChannelControl *>(simulation.moduleByPath("channelcontrol"));
00048         if (cc == 0)
00049             error("Could not find channelcontrol module");
00050 
00051         // get a pointer to the host
00052         hostPtr = findHost();
00053         myHostRef = cc->registerHost(hostPtr, Coord());
00054     }
00055     else if (stage == 1)
00056     {
00057         // playground size gets set up by ChannelControl in stage==0 (Andras)
00058         // read the playgroundsize from ChannelControl
00059         Coord pgs = cc->getPgs();
00060 
00061         // reading the coordinates from omnetpp.ini makes predefined scenarios a lot easier
00062         // -1 indicates start at display string position, or random position if it's not present
00063         pos.x = pos.y = -1;
00064         if (hasPar("x"))   // not all mobility models have an "x" parameter
00065             pos.x = par("x");
00066         if (pos.x == -1)
00067             pos.x = parseInt(hostPtr->displayString().getTagArg("p",0), -1);
00068         if (pos.x == -1)
00069             pos.x = genk_uniform(0, 0, pgs.x);
00070 
00071         if (hasPar("y")) // not all mobility models have an "y" parameter
00072             pos.y = par("y");
00073         if (pos.y == -1)
00074             pos.y = parseInt(hostPtr->displayString().getTagArg("p",1), -1);
00075         if (pos.y == -1)
00076             pos.y = genk_uniform(0, 0, pgs.y);
00077 
00078         // check validity of position
00079         if (pos.x < 0 || pos.y < 0 || pos.x >= pgs.x || pos.y >= pgs.y)
00080             error("node position (%d,%d) is outside the playground", pos.x, pos.y);
00081 
00082         // adjusting the display string is no longer needed (Andras)
00083 
00084         // print new host position on the screen and update bb info
00085         updatePosition();
00086     }
00087 }

void BasicMobility::placeRandomlyIfOutside Coord targetPos  )  [protected]
 

Utility function to place the node randomly if it goes outside the playground.

Decision is made on pos, but targetPos will also be updated. (Pass a dummy you don't have it).

00180 {
00181     if (pos.x<0 || pos.x>=playgroundSizeX() || pos.y<0 || pos.y>=playgroundSizeY())
00182     {
00183         Coord newPos = getRandomPosition();
00184         targetPos += newPos - pos;
00185         pos = newPos;
00186     }
00187 }

double BasicMobility::playgroundSizeX  )  const [inline, protected]
 

Returns the width of the playground.

00101 {return cc->getPgs()->x;}

double BasicMobility::playgroundSizeY  )  const [inline, protected]
 

Returns the height of the playground.

00104 {return cc->getPgs()->y;}

void BasicMobility::raiseErrorIfOutside  )  [protected]
 

Utility function to raise an error if the node gets outside the playground.

00190 {
00191     if (pos.x<0 || pos.x>=playgroundSizeX() || pos.y<0 || pos.y>=playgroundSizeY())
00192     {
00193         error("node moved outside the playground of size %gx%g (x=%g,y=%g)",
00194               playgroundSizeX(), playgroundSizeY(), pos.x, pos.y);
00195     }
00196 }

void BasicMobility::reflectIfOutside Coord targetPos,
Coord step,
double &  angle
[protected]
 

Utility function to reflect the node if it goes outside the playground.

Decision is made on pos, but the variables passed as args will also be updated. (Pass dummies you don't have some of them).

00124 {
00125     if (pos.x < 0)
00126     {
00127         pos.x = -pos.x;
00128         targetPos.x = -targetPos.x;
00129         step.x = -step.x;
00130         angle = 180 - angle;
00131     }
00132     else if (pos.x >= playgroundSizeX())
00133     {
00134         pos.x = 2*playgroundSizeX() - pos.x;
00135         targetPos.x = 2*playgroundSizeX() - targetPos.x;
00136         step.x = -step.x;
00137         angle = 180 - angle;
00138     }
00139     if (pos.y < 0)
00140     {
00141         pos.y = -pos.y;
00142         targetPos.y = -targetPos.y;
00143         step.y = -step.y;
00144         angle = -angle;
00145     }
00146     else if (pos.y >= playgroundSizeY())
00147     {
00148         pos.y = 2*playgroundSizeY() - pos.y;
00149         targetPos.y = 2*playgroundSizeY() - targetPos.y;
00150         step.y = -step.y;
00151         angle = -angle;
00152     }
00153 }

void BasicMobility::updatePosition  )  [protected]
 

Update the position information for this node.

This function tells NotificationBoard that the position has changed, and it also moves the host's icon to the new position on the screen.

This function has to be called every time the position of the host changes!

00099 {
00100     cc->updateHostPosition(myHostRef, pos);
00101 
00102     double r = cc->getCommunicationRange(myHostRef);
00103     hostPtr->displayString().setTagArg("p", 0, (long) pos.x);
00104     hostPtr->displayString().setTagArg("p", 1, (long) pos.y);
00105     hostPtr->displayString().setTagArg("r", 0, (long) r);
00106 
00107     nb->fireChangeNotification(NF_HOSTPOSITION_UPDATED, &pos);
00108 }

void BasicMobility::wrapIfOutside Coord targetPos  )  [protected]
 

Utility function to wrap the node to the opposite edge (torus) if it goes outside the playground.

Decision is made on pos, but targetPos will also be updated. (Pass a dummy you don't have it).

00156 {
00157     if (pos.x < 0)
00158     {
00159         pos.x += playgroundSizeX();
00160         targetPos.x += playgroundSizeX();
00161     }
00162     else if (pos.x >= playgroundSizeX())
00163     {
00164         pos.x -= playgroundSizeX();
00165         targetPos.x -= playgroundSizeX();
00166     }
00167     if (pos.y < 0)
00168     {
00169         pos.y += playgroundSizeY();
00170         targetPos.y += playgroundSizeY();
00171     }
00172     else if (pos.y >= playgroundSizeY())
00173     {
00174         pos.y -= playgroundSizeY();
00175         targetPos.y -= playgroundSizeY();
00176     }
00177 }


Member Data Documentation

ChannelControl* BasicMobility::cc [protected]
 

Pointer to ChannelControl -- these two must know each other.

cModule* BasicMobility::hostPtr [protected]
 

Pointer to host module, to speed up repeated access.

ChannelControl::HostRef BasicMobility::myHostRef [protected]
 

Identifies this host in the ChannelControl module.

Coord BasicMobility::pos [protected]
 

Stores the actual position of the host.


The documentation for this class was generated from the following files:
Generated on Thu Oct 19 18:22:21 2006 for INET Framework for OMNeT++/OMNEST by  doxygen 1.4.0