Classes | Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes

MoBANCoordinator Class Reference
[mobility - modules handling the mobility of the hostsMoBAN - Classes providing a mobility model for Wireless Body Area Networks]

This is the coordinator module of the MoBAN mobility model. It should be instantiated in the top level simulation network in MiXiM, once per WBAN. The coordinator module is the main module that provides the group mobility and correlation between nodes in a WBAN. In the initialization phase, it reads three user defined input files which are the postures specification file, a configuration file which includes all required parameter for specific distributions, and the previously logged mobility pattern, if it is requested to use a logged pattern. Note that all WBAN instances may use the same input files if they are exactly in the same situation. More...

#include <MoBANCoordinator.h>

Collaboration diagram for MoBANCoordinator:
Collaboration graph
[legend]

List of all members.

Classes

struct  pattern
 Data type for one instance of mobility pattern. More...

Public Member Functions

virtual void initialize (int)
 Initializes the MoBAN mobility model.

Protected Types

enum  posture_sel_type { UNIFORM_RANDOM = 0, MARKOV_BASE }
 

Possible (supported) strategies for posture selection.


typedef struct
MoBANCoordinator::pattern 
Pattern
 Data type for one instance of mobility pattern.

Protected Member Functions

void handleMessage (cMessage *msg)
 Handes self messages and initiate the next message for updateInterval seconds later.
virtual void finish ()
 To be called at the end of simulation run.
void selectPosture ()
 Function to select the next posture considering the current posture and the Markov model.
Coord selectDestination ()
 Function to select the destination in the case of a mobile posture.
double selectSpeed ()
 Select a velocity value within the given velocity range.
simtime_t selectDuration ()
 Select a stay time duration in the specified range for the new posture.
void mainProcess ()
 The main process of the MoBAN mobility model.
void stepMove ()
 Making one step move and publishing the new reference point position to all belonging nodes.
bool isInsideWorld (Coord)
 Checks if all nodes of the WBAN are inside the simulation environment w ith the given position of the logical center.
bool readPostureSpecificationFile ()
 Reading the input postures specification file and making the posture data base.
bool readConfigurationFile ()
 Reads the input configuration file.
bool readMobilityPatternFile ()
 Reads the previously logged mobility pattern and make mobility pattern data base.
void publishToNodes ()
 Publishes the reference point and other information of the posture to the blackboard of the belonging nodes.

Protected Attributes

bool debug
 Debug switch for all other modules.
BaseUtilityutility
 Pointer to the BaseUtility.
BaseWorldUtilityworld
 Pointer to the BaseWorldUtility.
cModule * network
 Pointer to the top level (network).
simtime_t updateInterval
 Interval for updating the move (NED parameter).
cMessage * MoveMsg
 A self message to trigger move step every updateInterval seconds.
unsigned int numNodes
 The number of nodes in the this WBAN.
double speed
 Currently selected speed for the mobile posture.
int index
 Index of this WBAN.
FILE * logfile
 Pointer to the file for logging MoBAN mobility pattern for future use.
unsigned int numPostures
 Number of predefined postures.
std::vector< Posture * > postureList
 The list of all predefined postures (posture data base).
PosturecurrentPosture
 The current selected posture.
simtime_t duration
 The selected duration of the current posture.
simtime_t minDuration
 The minimum value of the duration for stable postures.
simtime_t maxDuration
 The maximum value of the duration for stable postures.
int * nodeIndex
 the index list of nodes belong to this WBAN
Coord logicalCenter
 Current position of the logical center of the group.
int step
 Number of steps already moved.
int numSteps
 Total number of steps of the current move or current posture.
Coord targetPos
 Selected destination for the ongoing move of the logical center.
Coord stepTarget
 The intermediate target of the current move step.
Coord stepSize
 The size of the current move step.
bool useMobilityPattern
 Variable that shows if reusing previously logged mobility pattern is requested. The value is gotten from the parameter of the module.
PatternmobilityPattern
 The mobility pattern data base.
int patternLength
 The number of mobility pattern instances which has been read from the input file (length of mobility pattern data base).
int currentPattern
 The index of the currently applied mobility pattern from.
double ** markovMatrix
 A matrix which maintains the transition probabilities of the Markov Model of posture pattern. To be given through configuration file.
posture_sel_type postureSelStrategy
 The requested strategy for posture selection. To be given through configuration file.
PostureTransitiontransitions
 Class for performing operation for spatial and temporal correlations in posture selection.

Detailed Description

This is the coordinator module of the MoBAN mobility model. It should be instantiated in the top level simulation network in MiXiM, once per WBAN. The coordinator module is the main module that provides the group mobility and correlation between nodes in a WBAN. In the initialization phase, it reads three user defined input files which are the postures specification file, a configuration file which includes all required parameter for specific distributions, and the previously logged mobility pattern, if it is requested to use a logged pattern. Note that all WBAN instances may use the same input files if they are exactly in the same situation.

After the initialization phase, the MoBAN coordinator decides about the posture and the position of the Logical center of the group (WBAN). The absolute position of the reference point of each belonging node is calculated by adding the current position of the logical center by the reference point of that node in the selected posture. The coordinator publish the position of the reference point as well as the speed and the radius of the local movement of nodes to their blackboards.

Author:
Majid Nabi

Definition at line 93 of file MoBANCoordinator.h.


Member Function Documentation

void MoBANCoordinator::finish (  )  [protected, virtual]

To be called at the end of simulation run.

This function is called at the end of simulation run.

Definition at line 326 of file MoBANCoordinator.cc.

References logfile, and MoveMsg.

                              {

  cancelAndDelete(MoveMsg);
  fclose(logfile);

}

void MoBANCoordinator::handleMessage ( cMessage *  msg  )  [protected]

Handes self messages and initiate the next message for updateInterval seconds later.

Handling self message and initiate the next message with the given parameter updateInterval.

Definition at line 114 of file MoBANCoordinator.cc.

References MoveMsg, stepMove(), and updateInterval.

                                                   {
  if (msg == MoveMsg) {
    stepMove();
    scheduleAt(simTime() + updateInterval, msg);
  } else
    error("MoBAN Coordinator: unexpected message!");
}

bool MoBANCoordinator::isInsideWorld ( Coord  tPos  )  [protected]

Checks if all nodes of the WBAN are inside the simulation environment w ith the given position of the logical center.

Checks if all nodes of the WBAN are inside the simulation environment with the given position of the logical center.

Definition at line 310 of file MoBANCoordinator.cc.

References currentPosture, BaseWorldUtility::getPgs(), Posture::getPs(), Posture::getRadius(), Coord::isInBoundary(), numNodes, and world.

Referenced by selectDestination().

                                               {
  Coord absolutePosition;

  for (unsigned int i = 0; i < numNodes; ++i) {
    absolutePosition = tPos + currentPosture->getPs(i)
        + currentPosture->getRadius(i);
    if (!absolutePosition.isInBoundary(Coord(0, 0, 0), world->getPgs()))
      return false;
  }

  return true;
}

void MoBANCoordinator::mainProcess (  )  [protected]

The main process of the MoBAN mobility model.

The main process of the MoBAN mobility model. To be called whenever a destination is reached or the duration of the previous posture expires. It select the behavior of the next movement (the posture and the destination), and prepare the required variables to make the movement. In the case of using a logged mobility pattern, the new posture and other parameters are obtained from the pattern.

Definition at line 159 of file MoBANCoordinator.cc.

References currentPattern, currentPosture, Coord::distance(), duration, BaseWorldUtility::getPgs(), Posture::getPostureID(), Posture::getPostureName(), Coord::getX(), Coord::getY(), Coord::getZ(), index, Coord::info(), Posture::isMobile(), logfile, logicalCenter, mobilityPattern, numSteps, patternLength, postureList, FWMath::round(), selectDestination(), selectDuration(), selectPosture(), selectSpeed(), speed, step, stepSize, stepTarget, targetPos, updateInterval, useMobilityPattern, and world.

Referenced by initialize(), and stepMove().

                                   {
  //select the new posture and set the variable currentPosture as well as the reference points of all nodes within the WBAN.
  if (useMobilityPattern) {
    currentPattern = (currentPattern + 1) % patternLength;
    int postureID = mobilityPattern[currentPattern].postureID;
    currentPosture = postureList[postureID];
  } else
    selectPosture();

  EV<<"New posture is selected:"<<currentPosture->getPostureName() << endl;

  if (currentPosture->isMobile())
  {
    double distance;

    if (useMobilityPattern) {
      targetPos = mobilityPattern[currentPattern].targetPos;
      speed = mobilityPattern[currentPattern].speed;
    }
    else {
      targetPos = selectDestination();
      speed = selectSpeed();
    }

    if (speed==0)
      error("The velocity in a mobile posture should not be zero!");

    distance = logicalCenter.distance(targetPos);
    duration = distance / speed;

    if (duration >= updateInterval)
      numSteps = FWMath::round(duration / updateInterval);
    else
      numSteps = 1; //The selected target position is quite close so that in less than one step, it will be reached with the given velocity.

    stepSize = targetPos - logicalCenter;
    stepSize = stepSize / numSteps;
    stepTarget = logicalCenter + stepSize;
  }
  else
  {
    if (useMobilityPattern)
      duration = mobilityPattern[currentPattern].duration;
    else
      duration = selectDuration();

    if (duration < updateInterval)
      error("The duration of a posture should be bigger than the updateInterval value!");

    numSteps = FWMath::round(duration / updateInterval) ;
  }
  step = 0;

    //show posture name in the graphical interface
  if(ev.isGUI()){
    char dis_str[100];
    sprintf(dis_str,"p=%f,50;i=block/wheelbarrow;is=vs;t=%s Duration:%f",world->getPgs()->getX()+10+(index*30),currentPosture->getPostureName(),duration.dbl());
    setDisplayString(dis_str);
  }

    // write the move step into the output log file
  if (currentPosture->isMobile())
    fprintf(logfile,"%s %d %f %f %f %f \n",currentPosture->getPostureName(),currentPosture->getPostureID(), targetPos.getX(),targetPos.getY(),targetPos.getZ(),speed);
  else
    fprintf(logfile,"%s %d %f \n",currentPosture->getPostureName(),currentPosture->getPostureID(), duration.dbl());


  EV << "New posture : " << currentPosture->getPostureName() << endl;
  EV << "Destination:" << targetPos.info() << " Total Time=" << duration << endl;
}

bool MoBANCoordinator::readConfigurationFile (  )  [protected]

Reads the input configuration file.

Function to read the configuration file which includes the information for configuring and tuning the model for a specific application scenario. The configuration file can provide the Markov model transition matrices, different area types and time domains, and the proper matrix for each time-space combination. However, these are all optional and will b e given just in the case that the space-time correlation are required to be simulated. The function will be called in the initialization phase.

Definition at line 503 of file MoBANCoordinator.cc.

References PostureTransition::addAreaType(), PostureTransition::addCombination(), PostureTransition::addMatrix(), PostureTransition::addSteadyState(), PostureTransition::addTimeDomain(), currentPosture, Coord::info(), logicalCenter, FWMath::max(), maxDuration, minDuration, numPostures, postureList, postureSelStrategy, PostureTransition::setAreaBoundry(), PostureTransition::setTimeBoundry(), Coord::setX(), Coord::setY(), Coord::setZ(), transitions, and updateInterval.

Referenced by initialize().

                                             {
  cXMLElement* xmlConfig = par("configFile").xmlValue();
  if (xmlConfig == 0)
    return false;

  cXMLElementList tagList;
  cXMLElement* tempTag;
  const char* str;
  std::string sstr; //for easier comparison

  /* Reading the initial posture if it is given*/
  int postureID;
  tagList = xmlConfig->getElementsByTagName("initialPosture");

  if (tagList.empty())
    postureID = 0; // no initial posture has been specified. The first one is selected!
  else {
    tempTag = tagList.front();
    str = tempTag->getAttribute("postureID");
    postureID = strtol(str, 0, 0);
  }
  currentPosture = postureList[postureID];
  EV<< "Initial Posture:"<< postureID <<endl;


  /* Reading the initial position of the logical center if it is given */
  tagList = xmlConfig->getElementsByTagName("initialLocation");
  if(tagList.empty())
    logicalCenter=Coord(10,10,5); // no initial location has been specified .
  else
  {
    double x,y,z;
    tempTag= tagList.front();

    str = tempTag->getAttribute("x"); x = strtod(str, 0);
    str = tempTag->getAttribute("y"); y = strtod(str, 0);
    str = tempTag->getAttribute("z"); z = strtod(str, 0);
    logicalCenter = Coord(x,y,z);
  }
  EV << "Initial position of the LC:"<< logicalCenter.info() <<endl;

  /* Reading the given range for duration of stable postures */
  tagList = xmlConfig->getElementsByTagName("durationRange");
  if(tagList.empty())
  {
    // no duration is specified. We assign a value!
    minDuration = updateInterval;
    maxDuration = 100;
  }
  else
  {
    double min,max;
    tempTag= tagList.front();

    str = tempTag->getAttribute("min"); min = strtod(str, 0);
    str = tempTag->getAttribute("max"); max = strtod(str, 0);

    minDuration = FWMath::max(updateInterval.dbl(),min); // the minimum should be bigger than the update interval.
    maxDuration = FWMath::max(min,max);
  }
  EV << "Posture duration range: ("<< minDuration << " , " << maxDuration << ")" << endl;


  transitions = new PostureTransition(numPostures);


  /* Reading the Markov transition matrices, if there are any. */
  tagList = xmlConfig->getElementsByTagName("markovMatrices");

  if(tagList.empty())
  {
    postureSelStrategy = UNIFORM_RANDOM; // no posture selection strategy is required. uniform random is applied
    EV << "Posture Selection strategy: UNIFORM_RANDOM "<< endl;
    return true;
  }

  tempTag = tagList.front();

  cXMLElementList matrixList;
  matrixList = tempTag->getElementsByTagName("MarkovMatrix");

  if(tagList.empty())
  {
    postureSelStrategy = UNIFORM_RANDOM; // no posture selection strategy is required. uniform random is applied
    EV << "Posture Selection strategy: UNIFORM_RANDOM "<< endl;
    return true;
  }

  postureSelStrategy = MARKOV_BASE;

  // make an empty matrix for the Markov Chain
    double** matrix = new double* [numPostures];
  for (unsigned int i=0;i<numPostures;++i)
    matrix[i] = new double [numPostures];

  bool setDefault=false; // variable to remember if the default matrix is defined.
  cXMLElementList::const_iterator matrixTag;
  for(matrixTag = matrixList.begin(); matrixTag != matrixList.end(); matrixTag++)
  {

    cXMLElementList rowList;
    cXMLElementList cellList;
    int i=0,j=0;
    bool thisDefault = false;

    if ( (*matrixTag)->getAttribute("type") != NULL)
    {
      sstr = (*matrixTag)->getAttribute("type");
      if ( sstr == "Default" || sstr == "default" )
      {
        if (setDefault)
          error ("There are more than one default matrix defined in the configuration file!");
        else
          {setDefault = true; thisDefault = true;}
      }
    }


    sstr = (*matrixTag)->getAttribute("name");

    rowList = (*matrixTag)->getElementsByTagName("row");
    if (rowList.size()!= numPostures && rowList.size()!= 1)
      error("Number of rows in  the Markov transition matrix should be equal to either the number"
          " of postures (full Markov matrix) or one (steady state vector).");

    if (rowList.size()!= numPostures && thisDefault )
      error("Dimension of the default Markov matrix should be equal to the number of postures in the configuration file.");

    if ( (rowList.size()== 1) && (!setDefault) )
      error("A default matrix is supposed to be defined before a steady state can be defined in the configuration file.");

    for(cXMLElementList::const_iterator row = rowList.begin(); row != rowList.end(); row++)
    {
      cellList = (*row)->getElementsByTagName("cell");
      if (cellList.size()!= numPostures)
        error("Number of columns in  the Markov transition matrix should be equal to the number of postures.");

      j=0;
      for(cXMLElementList::const_iterator cell = cellList.begin(); cell != cellList.end(); cell++)
      {
        str = (*cell)->getAttribute("value");
        matrix[i][j] = strtod(str, 0);
        j++;
      }

      ++i;
    }

    if (rowList.size() == 1)
      transitions->addSteadyState(sstr, matrix[0]); // steady state
    else
       transitions->addMatrix(sstr, matrix, thisDefault);     // A full Markovian matrix

    EV << "Markov transition matrix "<< sstr << " :" <<endl;
    for (int k=0;k < i ; ++k)
    {
      for (unsigned int f=0; f<numPostures ;++f)
        EV << matrix[k][f]<<" ";
      EV << endl;
    }

  }

  /* Reading the Area types, if there are any. */
  tagList = xmlConfig->getElementsByTagName("areaTypes");

  if( tagList.empty() )
    EV << "No area type is given. So there is no spatial correlation in posture selection." << endl;
  else{

      tempTag = tagList.front();
      cXMLElementList typeList = tempTag->getElementsByTagName("areaType");

      if( typeList.empty() )
        error ("No areaType has been defined in areaTypes!");

      for(cXMLElementList::const_iterator aType = typeList.begin(); aType != typeList.end(); aType++)
      {
        sstr = (*aType)->getAttribute("name");

        EV << "Area type " << sstr << " :" << endl;

        int typeID = transitions->addAreaType(sstr);

        cXMLElementList boundList = (*aType)->getElementsByTagName("boundary");
        if( boundList.empty() )
          error ("No boundary is given for a area type!");

        Coord minBound, maxBound;
        for(cXMLElementList::const_iterator aBound = boundList.begin(); aBound != boundList.end(); aBound++)
        {
          str = (*aBound)->getAttribute("xMin"); minBound.setX(strtod(str, 0));
          str = (*aBound)->getAttribute("yMin"); minBound.setY(strtod(str, 0));
          str = (*aBound)->getAttribute("zMin"); minBound.setZ(strtod(str, 0));

          str = (*aBound)->getAttribute("xMax"); maxBound.setX(strtod(str, 0));
          str = (*aBound)->getAttribute("yMax"); maxBound.setY(strtod(str, 0));
          str = (*aBound)->getAttribute("zMax"); maxBound.setZ(strtod(str, 0));

          transitions->setAreaBoundry(typeID,minBound,maxBound);
          EV << "Low bound: "<< minBound.info() << endl;
          EV << "High bound: "<< maxBound.info() << endl;
        }
      }
    }

  /* Reading the time domains, if there are any. */
  tagList = xmlConfig->getElementsByTagName("timeDomains");

  if( tagList.empty() )
    EV << "No time domain is given. So there is no temporal correlation in posture selection." << endl;
  else{

      tempTag = tagList.front();
      cXMLElementList typeList = tempTag->getElementsByTagName("timeDomain");

      if( typeList.empty() )
        error ("No timeDomain has been defined in timeDomains!");

      for(cXMLElementList::const_iterator aType = typeList.begin(); aType != typeList.end(); aType++)
      {
        sstr = (*aType)->getAttribute("name");

        EV << "Time domain " << sstr << " :" << endl;

        int typeID = transitions->addTimeDomain(sstr);

        cXMLElementList boundList = (*aType)->getElementsByTagName("boundary");
        if( boundList.empty() )
          error ("No boundary is given for a time domain!");

        simtime_t minTime,maxTime;
        for(cXMLElementList::const_iterator aBound = boundList.begin(); aBound != boundList.end(); aBound++)
        {
          str = (*aBound)->getAttribute("tMin"); minTime = strtod(str,0);
          str = (*aBound)->getAttribute("tMax"); maxTime = strtod(str,0);

          transitions->setTimeBoundry(typeID,minTime,maxTime);
          EV << "Low bound: ("<< minTime.dbl() << ", " << maxTime << ")" << endl;
        }
      }
  }

  /* Reading the combinations, if there are any. */
  tagList = xmlConfig->getElementsByTagName("combinations");

  if( tagList.empty() )
    EV << "No combination is given. The default Markov model is then used for the whole time and space!" << endl;
  else{
        tempTag = tagList.front();
      cXMLElementList combList = tempTag->getElementsByTagName("combination");

      if( combList.empty() )
        error ("No combination has been defined in combinations!");

      EV << "Combinations: " << endl;

      for(cXMLElementList::const_iterator aComb = combList.begin(); aComb != combList.end(); aComb++)
      {
        std::string areaName,timeName,matrixName;

        if ((*aComb)->getAttribute("areaType") != NULL)
          areaName = (*aComb)->getAttribute("areaType");
        else
          areaName.clear();

        if ( (*aComb)->getAttribute("timeDomain") != NULL )
          timeName = (*aComb)->getAttribute("timeDomain");
        else
          timeName.clear();

        if ( (*aComb)->getAttribute("matrix") != NULL )
          matrixName = (*aComb)->getAttribute("matrix");
        else
          error("No transition matrix is specified for a combination.");

        transitions->addCombination(areaName, timeName, matrixName);

        EV << "(" << areaName << ", " << timeName << ", " << matrixName << ")" << endl;
      }
    }

  return true;
}

bool MoBANCoordinator::readMobilityPatternFile (  )  [protected]

Reads the previously logged mobility pattern and make mobility pattern data base.

This function reads the input mobility pattern file and make a list of the mobility patterns. It will be called in the initialization phase if the useMobilityPattern parameter is true.

Definition at line 355 of file MoBANCoordinator.cc.

References currentPattern, mobilityPattern, patternLength, and postureList.

Referenced by initialize().

                                               {
  patternLength = 0;
  double x, y, z, s;
  int id;
  char file_name[70];
  char posture_name[50];

  sprintf(file_name, "%s", par("mobilityPatternFile").stringValue());
  FILE *fp = fopen(file_name, "r");
  if (fp == NULL)
    return false;

  //Count number of patterns (lines in the input file)
  int c;
  while ((c = fgetc(fp)) != EOF)
    if (c == '\n')
      patternLength++;
  fclose(fp);

  EV<< "Mobility Pattern Length:" << patternLength << endl;

  mobilityPattern = new Pattern[patternLength];

  fp = fopen(file_name,"r");

  int i=0;
  while (fscanf(fp,"%s %d",posture_name,&id)!= -1) {
    mobilityPattern[i].postureID = id;
    if (postureList[id]->isMobile())
    {
      assert( fscanf(fp,"%le %le %le %le",&x,&y,&z,&s)!=-1 );
      mobilityPattern[i].targetPos = Coord(x,y,z);
      mobilityPattern[i].speed = s;
    }
    else
    {
      assert ( fscanf(fp,"%le",&x)!=-1 );
      mobilityPattern[i].duration = x;
    }
    ++i;
  }

  fclose(fp);

  currentPattern = -1;

  return true;
}

bool MoBANCoordinator::readPostureSpecificationFile (  )  [protected]

Reading the input postures specification file and making the posture data base.

Function to read the specified posture specification input file and make the posture data base. The posture specification includes the specification of a set of possible body postures in the target application. The specification of each posture should provide the speed range of the global movement of the whole WBAN and the relative position of the reference point, movement radius around the reference point and movement velocity of all nodes in the WBAN. The function will be called in the initialization phase.

Definition at line 411 of file MoBANCoordinator.cc.

References numNodes, numPostures, and postureList.

Referenced by initialize().

                                                    {

  cXMLElement* xmlPosture = par("postureSpecFile").xmlValue();
  if (xmlPosture == 0)
    return false;

  const char* str;

  //read the specification of every posture from file and make a list of postures
  cXMLElementList postures;

  postures = xmlPosture->getElementsByTagName("posture");

  //Find the number of defined postures
  numPostures = postures.size();
  if (numPostures == 0)
    error("No posture is defined in the input posture specification file");

  unsigned int postureID;

  cXMLElementList::const_iterator posture;
  for (posture = postures.begin(); posture != postures.end(); posture++)
  {
    str = (*posture)->getAttribute("postureID");
    postureID = strtol(str, 0, 0);
    if ( postureID < 0 || postureID >= numPostures)
      error ("Posture ID in input posture specification file is out of the range.");

    postureList.push_back(new Posture(postureID, numNodes));

    str = (*posture)->getAttribute("name");
    postureList[postureID]->setPostureName(const_cast<char*> (str));

    str = (*posture)->getAttribute("minSpeed");
    double minS = strtod(str, 0);
    str = (*posture)->getAttribute("maxSpeed");
    double maxS = strtod(str, 0);
    postureList[postureID]->setPostureSpeed(minS, maxS);

    int i = 0;
    double x, y, z, s, r;
    cXMLElementList nodeParameters;

    nodeParameters = (*posture)->getElementsByTagName("nodeParameters");
    if (nodeParameters.size() != numNodes)
      error ("Some nodes may not have specified parameters in a posture in input posture specification file.");

    cXMLElementList::const_iterator param;
    for (param = nodeParameters.begin(); param!= nodeParameters.end(); param++)
    {
      str = (*param)->getAttribute("positionX");
      x = strtod(str, 0);

      str = (*param)->getAttribute("positionY");
      y = strtod(str, 0);

      str = (*param)->getAttribute("positionZ");
      z = strtod(str, 0);

      str = (*param)->getAttribute("radius");
      r = strtod(str, 0);

      str = (*param)->getAttribute("speed");
      s = strtod(str, 0);

      postureList[postureID]->setPs(i, Coord(x, y, z));
      postureList[postureID]->setRadius(i, r);
      postureList[postureID]->setSpeed(i, s);

      i++;
    }
  }

  /* Report the obtained specification of the postures. */
  for (unsigned int i = 0; i < numPostures; ++i) {
    EV<< "Information for the posture:"<<i<<" is"<<endl;
    for (unsigned int j=0;j<numNodes;++j)
    EV << "Node "<<j<< " position: "<<postureList[i]->getPs(j).info()<<
    " and radius:"<<postureList[i]->getRadius(j)<<" and speed:"<<postureList[i]->getSpeed(j)<<endl;
  }

  return true;

}

Coord MoBANCoordinator::selectDestination (  )  [protected]

Function to select the destination in the case of a mobile posture.

Select a position inside the simulation area as the destination for the new mobile posture. It is called whenever a new stable posture is selected. It is taken into account that all nodes should be inside the area.

Definition at line 283 of file MoBANCoordinator.cc.

References BaseWorldUtility::getRandomPosition(), Coord::getZ(), isInsideWorld(), logicalCenter, Coord::setZ(), and world.

Referenced by mainProcess().

                                          {
  Coord res;
  res = world->getRandomPosition();
  res.setZ(logicalCenter.getZ()); // the z value remain the same

  //check if it is okay using CoverRadius
  while (!isInsideWorld(res)) {
    res = world->getRandomPosition();
    res.setZ(logicalCenter.getZ());
  }

  return res;
}

simtime_t MoBANCoordinator::selectDuration (  )  [protected]

Select a stay time duration in the specified range for the new posture.

Select a stay time duration in the specified duration range for the new posture. It is called whenever a new stable posture is selected. The selected value should be at least more than the value of updateInterval parameter.

Definition at line 274 of file MoBANCoordinator.cc.

References maxDuration, and minDuration.

Referenced by mainProcess().

                                           {
  return uniform(minDuration, maxDuration);
}

void MoBANCoordinator::selectPosture (  )  [protected]

Function to select the next posture considering the current posture and the Markov model.

Select a new posture randomly or based on the given Markov model. If the requested strategy is not uniform random, A Markov chain will be used. If the strategy is INDIVIDUAL_MARKOV, we should retrieve the transition matrix for the current part of the area. If it is INDIVIDUAL_MARKOV, we have the base transition matrix and a steady state vector for the current part of the area. So the closest transition matrix to the base matrix is calculated which satisfies the required steady state vector. In any case, the next posture is selected considering the current posture and according to the final Markov transition matrix.

Definition at line 239 of file MoBANCoordinator.cc.

References currentPosture, PostureTransition::getMatrix(), Posture::getPostureID(), logicalCenter, markovMatrix, numPostures, postureList, postureSelStrategy, and transitions.

Referenced by mainProcess().

                                     {
  int postureID;

  if (postureSelStrategy == UNIFORM_RANDOM) {
    postureID = floor(uniform(0, numPostures)); // uniformly random posture selection
    currentPosture = postureList[postureID];
    return;
  }

  /* Here we check the area and the time to determine the corresponding posture transition matrix */
  markovMatrix = transitions->getMatrix(simTime(),logicalCenter);

  /* Using transition matrix to select the next posture */
  double randomValue = uniform(0, 1);
  double comp;
  int currentP = currentPosture->getPostureID(); // it determines the column in the matrix

  for (int i = 0; i < static_cast<int>(numPostures); ++i)
  {
    comp += markovMatrix[i][currentP];
    if (randomValue < comp)
    {
      postureID = i;
      break;
    }
  }

  currentPosture = postureList[postureID];
}

double MoBANCoordinator::selectSpeed (  )  [protected]

Select a velocity value within the given velocity range.

Select a velocity value within the given velocity range. It is called whenever a new stable posture is selected. In the case of using a logged mobility pattern, the speed value is retrieved from the pattern.

Definition at line 302 of file MoBANCoordinator.cc.

References currentPosture, Posture::getMaxSpeed(), and Posture::getMinSpeed().

Referenced by mainProcess().

                                     {
  return (uniform(currentPosture->getMinSpeed(),
      currentPosture->getMaxSpeed()));
}

void MoBANCoordinator::stepMove (  )  [protected]

Making one step move and publishing the new reference point position to all belonging nodes.

If the new posture is stable , publish reference points, and then wait for the selected time duration. If the posture is a mobile posture, move the logical center of the WBAN step by step until it reaches the selected destination. To do so, the new position of the reference points are published every "updateInterval" seconds. Then go for another posture selection.

publish info if the posture is mobile or it is the first step after a posture change. So for a stable posture, just one time the information will be published.

Definition at line 128 of file MoBANCoordinator.cc.

References currentPosture, Posture::isMobile(), logicalCenter, mainProcess(), numSteps, publishToNodes(), step, stepSize, and stepTarget.

Referenced by handleMessage().

                                {
  step++;

  if (currentPosture->isMobile()) {
    if (step == numSteps) { // reach the target
      logicalCenter = stepTarget;
      mainProcess();
    } else if (step < numSteps) {
      // step forward
      logicalCenter = stepTarget;
      stepTarget += stepSize;
    } else
      error("step should be less than numSteps");
  } else {
    if (step == numSteps)
      mainProcess();
  }

  if (currentPosture->isMobile() || step == 1)
    publishToNodes();
}


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