INET Framework for OMNeT++/OMNEST
inet::PostureTransition Class Reference

Class to provide spatial and temporal correlation in the posture selection process of the MoBAN mobility model. More...

#include <PostureTransition.h>

Classes

struct  AreaBound
 Data type for one instance of the area (space) boundary. More...
 
struct  AreaType
 Data type for one instance of area type. More...
 
struct  CombinationType
 Data type for one instance of space-time combination. More...
 
struct  TimeBound
 Data type for one instance of the time boundary. More...
 
struct  TimeDomainType
 Data type for one instance of time domain. More...
 
struct  TransMatrix
 Data type for one instance of Markov transition matrix. More...
 

Public Member Functions

 PostureTransition (int)
 Construct a posture transition object. More...
 
 ~PostureTransition ()
 
int addMatrix (std::string, double **, bool)
 Receives a transition matrix and add to the list. More...
 
int addSteadyState (std::string, double *)
 Receives a steady state vector, extracts the corresponding transition matrix considering the default matrix, and add to the list of given matrices. More...
 
int addAreaType (std::string)
 Adds a area type to the list with the given name and returns the index of this area type in the list. More...
 
bool setAreaBoundry (int, Coord, Coord)
 Adds the given boundary to the existing area type specified by the given ID . More...
 
int addTimeDomain (std::string)
 Adds a time domain to the list with the given name and returns the index of the this time domain in the list. More...
 
bool setTimeBoundry (int, simtime_t, simtime_t)
 Adds the given boundary to the existing time domain specified by the given ID . More...
 
bool addCombination (std::string, std::string, std::string)
 Adds a space-time combination to the list. More...
 
double ** getMatrix (simtime_t, Coord)
 Gets a time and location, and returns the corresponding Markov transition matrix. More...
 

Protected Types

typedef std::vector< TransMatrix * > TransMatrixList
 Data type for a list of Markov transition matrices. More...
 
typedef std::vector< AreaType * > AreaTypeList
 Data type for the list of area types. More...
 
typedef std::vector< TimeDomainType * > TimeDomainList
 Data type for the list of time domains. More...
 
typedef std::vector< CombinationType * > CombinationList
 Data type for the list of space-time combinations. More...
 

Protected Member Functions

double ** extractMatrixFromSteadyState (double *)
 Gets a steady state vector and return a matrix which is as close as posible to the default matrix and satisfies the given steady state. More...
 
int findTimeDomain (simtime_t)
 Gets a time and finds the ID of the containing time domain if there is. More...
 
int findAreaType (Coord)
 Gets a location and finds the ID of the containing area type if there is. More...
 
bool isMarkovian (double **)
 Checks if a matrix can be a Markov transition matrix. More...
 
bool isMarkovian (double *)
 Checks if a vector can be the steady state of a Markov chain. More...
 
void multMatrix (double **, double **, double **)
 Multiplies two matrices with dimension numPos*numPose . More...
 
void addMatrix (double **, double **, double **)
 Adds two matrices with dimension numPos*numPose . More...
 
void subtractMatrix (double **, double **, double **)
 Subtracts two matrices with dimension numPos*numPose . More...
 
void multVector (double *, double **)
 Multiply a vector of size numPos with its transpose. More...
 

Protected Attributes

int numPos
 Number of postures. More...
 
int defaultMatrixID
 The index of the default (base) transition matrix. More...
 
TransMatrixList matrixList
 The list of all given transition matrices. More...
 
AreaTypeList areaTypeList
 The list of all defined area types. More...
 
TimeDomainList timeDomainList
 The list of all defined time domains. More...
 
CombinationList combinationList
 The list of all given space-time combinations. More...
 

Detailed Description

Class to provide spatial and temporal correlation in the posture selection process of the MoBAN mobility model.

This class obtains and stores Markovian transition matrices. There is also the possibility to get a steady state vector. In this case, the closest transition matrix to the default Makov matrix is extracted which satisfies the given steady state vector. The class also receives the defined area types and time domains as well as given space-time domains during the initialization phase. During the simulation run, the class provide a functions to return the corresponding markov matrix for a given time and location. It will be used whenever a new posture is going to be selected.

Author
Majid Nabi

Member Typedef Documentation

typedef std::vector<AreaType *> inet::PostureTransition::AreaTypeList
protected

Data type for the list of area types.

Data type for the list of space-time combinations.

typedef std::vector<TimeDomainType *> inet::PostureTransition::TimeDomainList
protected

Data type for the list of time domains.

typedef std::vector<TransMatrix *> inet::PostureTransition::TransMatrixList
protected

Data type for a list of Markov transition matrices.

Constructor & Destructor Documentation

inet::PostureTransition::PostureTransition ( int  numPosture)

Construct a posture transition object.

Constructor function of the class.

The parameter is the number of postures which is the dimension of all matrices

It sets the value for t he number of posture. It also suppose the first given transition matrix as default. However, during parsing the xml configuration file, if a matrix has attribute type with value "default", it will be considered as the default (base) transition matrix.

58 {
59  numPos = numPosture;
60  defaultMatrixID = 0; // if no default matrix found, the first one will be supposed as the default matrix.
61 }
int defaultMatrixID
The index of the default (base) transition matrix.
Definition: PostureTransition.h:77
int numPos
Number of postures.
Definition: PostureTransition.h:71
inet::PostureTransition::~PostureTransition ( )
64 {
65  for (auto comb: combinationList) {
66  delete comb;
67  }
68  for (auto mat: matrixList) {
69  for (int i = 0; i < numPos; ++i)
70  delete [] mat->matrix[i];
71  delete [] mat->matrix;
72  delete mat;
73  }
74  for (auto areaType: areaTypeList) {
75  for (auto bound: areaType->boundries)
76  delete bound;
77  delete areaType;
78  }
79  for (auto timeDomain: timeDomainList) {
80  for (auto bound: timeDomain->boundries)
81  delete bound;
82  delete timeDomain;
83  }
84 }
TransMatrixList matrixList
The list of all given transition matrices.
Definition: PostureTransition.h:90
TimeDomainList timeDomainList
The list of all defined time domains.
Definition: PostureTransition.h:130
CombinationList combinationList
The list of all given space-time combinations.
Definition: PostureTransition.h:144
AreaTypeList areaTypeList
The list of all defined area types.
Definition: PostureTransition.h:110
int numPos
Number of postures.
Definition: PostureTransition.h:71

Member Function Documentation

int inet::PostureTransition::addAreaType ( std::string  name)

Adds a area type to the list with the given name and returns the index of this area type in the list.

Creates a new area type instance and adds it to the list.

The boundaries of the area type is empty now. It will be filled later. The function returns the index of the new area type in the list as its output.

Referenced by inet::MoBANCoordinator::readConfigurationFile().

168 {
169  //Check if the name is repetitive
170  AreaTypeList::const_iterator areaIt;
171  for (areaIt = areaTypeList.begin(); areaIt != areaTypeList.end(); areaIt++) {
172  if ((*areaIt)->name == name) {
173  std::string str = "There are multiple area types with the same name: " + name + " in the configuration file!";
174  throw cRuntimeError(str.c_str());
175  }
176  }
177 
178  AreaType *area = new AreaType;
179  area->name = name;
180  areaTypeList.push_back(area);
181  return areaTypeList.size() - 1;
182 }
AreaTypeList areaTypeList
The list of all defined area types.
Definition: PostureTransition.h:110
bool inet::PostureTransition::addCombination ( std::string  areaName,
std::string  timeName,
std::string  matrixName 
)

Adds a space-time combination to the list.

This function creates a new space-time combination instance and adds it to the combinations list.

It checks if the given names for area type, time domain, and matrix are previously defined and exist in the corresponding lists. Note that at least area type or time domain should have been specified for a combination. Otherwise the combination is not meaningful. if for example a combination has no area type and just has specified time domain, it means that for the whole simulation area, it will be the same and the proper matrix is selected based on the time.

Referenced by inet::MoBANCoordinator::readConfigurationFile().

240 {
241  int thisID;
242  CombinationType *comb = new CombinationType;
243  comb->areaID = -1;
244  comb->timeID = -1;
245  comb->matrixID = -1;
246 
247  // look for matching area type name.
248  thisID = 0;
249  AreaTypeList::const_iterator areaIt;
250  for (areaIt = areaTypeList.begin(); areaIt != areaTypeList.end(); areaIt++) {
251  if (areaName == (*areaIt)->name) {
252  comb->areaID = thisID;
253  break;
254  }
255  ++thisID;
256  }
257 
258  // in the input name is empty, it means that no area type is specified for this combination.
259  if (comb->areaID == -1 && !areaName.empty()) {
260  std::string str = "Undefined area type name is given in a combinations: " + areaName + ", " + timeName + ", " + matrixName;
261  throw cRuntimeError(str.c_str());
262  }
263 
264  // look for matching time domain name.
265  thisID = 0;
266  TimeDomainList::const_iterator timeIt;
267  for (timeIt = timeDomainList.begin(); timeIt != timeDomainList.end(); timeIt++) {
268  if (timeName == (*timeIt)->name) {
269  comb->timeID = thisID;
270  break;
271  }
272  ++thisID;
273  }
274  if (comb->timeID == -1 && !timeName.empty()) {
275  std::string str = "Undefined time domain name is given in a combinations: " + areaName + ", " + timeName + ", " + matrixName;
276  throw cRuntimeError(str.c_str());
277  }
278 
279  if (comb->areaID == -1 && comb->timeID == -1)
280  throw cRuntimeError("Both area type and time domain is unspecified in a combination.");
281 
282  // look for matching transition matrix name.
283  thisID = 0;
284  TransMatrixList::const_iterator matrixIt;
285  for (matrixIt = matrixList.begin(); matrixIt != matrixList.end(); matrixIt++) {
286  if (matrixName == (*matrixIt)->name) {
287  comb->matrixID = thisID;
288  break;
289  }
290  ++thisID;
291  }
292  if (comb->matrixID == -1)
293  throw cRuntimeError("Undefined matrix name is given in the combinations");
294 
295  combinationList.push_back(comb);
296 
297  return true;
298 }
TransMatrixList matrixList
The list of all given transition matrices.
Definition: PostureTransition.h:90
TimeDomainList timeDomainList
The list of all defined time domains.
Definition: PostureTransition.h:130
CombinationList combinationList
The list of all given space-time combinations.
Definition: PostureTransition.h:144
AreaTypeList areaTypeList
The list of all defined area types.
Definition: PostureTransition.h:110
void inet::PostureTransition::addMatrix ( double **  mat1,
double **  mat2,
double **  res 
)
protected

Adds two matrices with dimension numPos*numPose .

Function to add two matrix with the known dimensions as number of postures.

Referenced by extractMatrixFromSteadyState(), and inet::MoBANCoordinator::readConfigurationFile().

431 {
432  int i, j;
433  for (i = 0; i < numPos; i++) {
434  for (j = 0; j < numPos; j++)
435  res[i][j] = mat1[i][j] + mat2[i][j];
436  }
437 }
int numPos
Number of postures.
Definition: PostureTransition.h:71
int inet::PostureTransition::addMatrix ( std::string  name,
double **  matrix,
bool  thisDefault 
)

Receives a transition matrix and add to the list.

This function initiates a new instance of markov matrix with the given matrix.

Note that it copies the matrix into the created matrix. The function first verifies if the given matrix can be a Markov transition matrix.

92 {
93  //check if the name is repetitive
94  TransMatrixList::const_iterator matrixIt;
95  for (matrixIt = matrixList.begin(); matrixIt != matrixList.end(); matrixIt++) {
96  if ((*matrixIt)->name == name) {
97  std::string str = "There are multiple matrices with the same name: " + name + " in the configuration file!";
98  throw cRuntimeError(str.c_str());
99  }
100  }
101 
102  // verify if the given matrix is Markovian
103  if (!isMarkovian(matrix)) {
104  std::string str = "Given transition matrix " + name + " is not Markovian!";
105  throw cRuntimeError(str.c_str());
106  }
107 
108  TransMatrix *mat = new TransMatrix;
109 
110  mat->name = name;
111  mat->matrix = new double *[numPos];
112  for (int i = 0; i < numPos; ++i) {
113  mat->matrix[i] = new double[numPos];
114  for (int j = 0; j < numPos; ++j)
115  mat->matrix[i][j] = matrix[i][j];
116  }
117 
118  matrixList.push_back(mat);
119 
120  if (thisDefault)
121  defaultMatrixID = matrixList.size() - 1;
122 
123  return 0;
124 }
TransMatrixList matrixList
The list of all given transition matrices.
Definition: PostureTransition.h:90
int defaultMatrixID
The index of the default (base) transition matrix.
Definition: PostureTransition.h:77
bool isMarkovian(double **)
Checks if a matrix can be a Markov transition matrix.
Definition: PostureTransition.cc:375
int numPos
Number of postures.
Definition: PostureTransition.h:71
int inet::PostureTransition::addSteadyState ( std::string  name,
double *  iVector 
)

Receives a steady state vector, extracts the corresponding transition matrix considering the default matrix, and add to the list of given matrices.

This function creates a new instance of markov matrix to be filled with a derived matrix from the given steady state vector.

The function first verifies if the given vector can be a steady state vector. Then extracts a markov matrix based on that and adds it to the list of given matrices.

Referenced by inet::MoBANCoordinator::readConfigurationFile().

132 {
133  //check if the name is repetitive
134  TransMatrixList::const_iterator matrixIt;
135  for (matrixIt = matrixList.begin(); matrixIt != matrixList.end(); matrixIt++) {
136  if ((*matrixIt)->name == name) {
137  std::string str = "There are multiple matrices with the same name: " + name + " in the configuration file!";
138  throw cRuntimeError(str.c_str());
139  }
140  }
141 
142  // check if the given matrix is Markovian
143  if (!isMarkovian(iVector)) {
144  std::string str = "Given steady state vector " + name + " cannot be true!";
145  throw cRuntimeError(str.c_str());
146  }
147 
148  // make a local copy of the input steady state vector
149  double *steady = new double[numPos];
150  for (int i = 0; i < numPos; ++i)
151  steady[i] = iVector[i];
152 
153  TransMatrix *mat = new TransMatrix;
154  mat->name = name;
155  mat->matrix = extractMatrixFromSteadyState(steady);
156  delete [] steady;
157 
158  matrixList.push_back(mat);
159 
160  return 0;
161 }
TransMatrixList matrixList
The list of all given transition matrices.
Definition: PostureTransition.h:90
double ** extractMatrixFromSteadyState(double *)
Gets a steady state vector and return a matrix which is as close as posible to the default matrix and...
Definition: PostureTransition.cc:467
bool isMarkovian(double **)
Checks if a matrix can be a Markov transition matrix.
Definition: PostureTransition.cc:375
int numPos
Number of postures.
Definition: PostureTransition.h:71
int inet::PostureTransition::addTimeDomain ( std::string  name)

Adds a time domain to the list with the given name and returns the index of the this time domain in the list.

Creates a new time domain instance and adds it to the list.

The boundaries of the time domain is empty now. It will be filled later. The function returns the index of the time domain in the list as its output.

Referenced by inet::MoBANCoordinator::readConfigurationFile().

203 {
204  //Check if the name is repetitive
205  TimeDomainList::const_iterator timeIt;
206  for (timeIt = timeDomainList.begin(); timeIt != timeDomainList.end(); timeIt++) {
207  if ((*timeIt)->name == name) {
208  std::string str = "There are multiple time domains with the same name: " + name + " in the configuration file!";
209  throw cRuntimeError(str.c_str());
210  }
211  }
212 
213  TimeDomainType *time = new TimeDomainType;
214  time->name = name;
215  timeDomainList.push_back(time);
216  return timeDomainList.size() - 1;
217 }
TimeDomainList timeDomainList
The list of all defined time domains.
Definition: PostureTransition.h:130
double ** inet::PostureTransition::extractMatrixFromSteadyState ( double *  vec)
protected

Gets a steady state vector and return a matrix which is as close as posible to the default matrix and satisfies the given steady state.

This function receives a steady state vector and extracts a Markovian matrix which is as close as possible to the default markov matrix and satisfies the given steady state vector.

Referenced by addSteadyState().

468 {
469  int i, j;
470  double **dafaultMat;
471 
472  //make output matrix and an identity matrix and a temp
473  double **mat = new double *[numPos];
474  double **temp1 = new double *[numPos];
475  double **temp2 = new double *[numPos];
476  double **temp3 = new double *[numPos];
477  double **identity = new double *[numPos];
478  int **change = new int *[numPos];
479  for (int i = 0; i < numPos; ++i) {
480  mat[i] = new double[numPos];
481  temp1[i] = new double[numPos];
482  temp2[i] = new double[numPos];
483  temp3[i] = new double[numPos];
484  identity[i] = new double[numPos];
485  change[i] = new int[numPos];
486  }
487 
488  for (i = 0; i < numPos; i++)
489  for (j = 0; j < numPos; j++)
490  if (i == j)
491  identity[i][j] = 1;
492  else
493  identity[i][j] = 0;
494 
495  double *sum = new double[numPos];
496  int *changeSum = new int[numPos];
497 
498  dafaultMat = matrixList.at(defaultMatrixID)->matrix;
499 
500  for (int numTry = 0; numTry < 400; ++numTry) {
501  subtractMatrix(identity, dafaultMat, temp1);
502  multVector(vec, temp2);
503  multMatrix(temp1, temp2, temp3);
504  addMatrix(dafaultMat, temp3, mat);
505 
506  //remember if it has not changed
507  for (i = 0; i < numPos; i++)
508  for (j = 0; j < numPos; j++)
509  change[i][j] = 1;
510 
511 
512  for (j = 0; j < numPos; j++)
513  for (i = 0; i < numPos; i++) {
514  if (mat[i][j] < 0) {
515  mat[i][j] = 0;
516  change[i][j] = 0;
517  }
518  if (mat[i][j] > 1) {
519  mat[i][j] = 1;
520  change[i][j] = 0;
521  }
522  }
523 
524  for (j = 0; j < numPos; j++) {
525  sum[j] = 0;
526  changeSum[j] = 0;
527  for (i = 0; i < numPos; i++) {
528  sum[j] += mat[i][j];
529  changeSum[j] += change[i][j];
530  }
531  }
532 
533  for (j = 0; j < numPos; j++)
534  for (i = 0; i < numPos; i++) {
535  if (change[i][j] == 1)
536  mat[i][j] = mat[i][j] + (1 - sum[j]) / changeSum[j];
537  }
538 
539  dafaultMat = mat;
540  }
541 
542  for (j = 0; j < numPos; j++)
543  for (i = 0; i < numPos; i++) {
544  if (mat[i][j] < 0)
545  mat[i][j] = 0;
546  if (mat[i][j] > 1)
547  mat[i][j] = 1;
548  }
549 
550  EV_DEBUG << "Generated Markov matrix from the steady state: " << endl;
551  for (int k = 0; k < numPos; ++k) {
552  for (int f = 0; f < numPos; ++f)
553  EV_DEBUG << mat[k][f] << " ";
554  EV_DEBUG << endl;
555  }
556 
557  for (int i = 0; i < numPos; ++i) {
558  delete [] temp1[i];
559  delete [] temp2[i];
560  delete [] temp3[i];
561  delete [] identity[i];
562  delete [] change[i];
563  }
564  delete [] temp1;
565  delete [] temp2;
566  delete [] temp3;
567  delete [] identity;
568  delete [] change;
569  delete [] sum;
570  delete [] changeSum;
571 
572  return mat;
573 }
TransMatrixList matrixList
The list of all given transition matrices.
Definition: PostureTransition.h:90
void subtractMatrix(double **, double **, double **)
Subtracts two matrices with dimension numPos*numPose .
Definition: PostureTransition.cc:442
int defaultMatrixID
The index of the default (base) transition matrix.
Definition: PostureTransition.h:77
void multVector(double *, double **)
Multiply a vector of size numPos with its transpose.
Definition: PostureTransition.cc:454
void addMatrix(double **, double **, double **)
Adds two matrices with dimension numPos*numPose .
Definition: PostureTransition.cc:430
const double k
Definition: QAM16Modulation.cc:24
int numPos
Number of postures.
Definition: PostureTransition.h:71
void multMatrix(double **, double **, double **)
Multiplies two matrices with dimension numPos*numPose .
Definition: PostureTransition.cc:415
int inet::PostureTransition::findAreaType ( Coord  iLocation)
protected

Gets a location and finds the ID of the containing area type if there is.

Looks for the first containing area type for the given location.

If not, return -1.

It return the Id of the found area type. If no area type is found which contains the given location, it returns -1.

Referenced by getMatrix().

354 {
355  int locationID = 0;
356  AreaTypeList::const_iterator areaIt;
357  for (areaIt = areaTypeList.begin(); areaIt != areaTypeList.end(); areaIt++) {
358  std::vector<AreaBound *> boundList = (*areaIt)->boundries;
359 
360  std::vector<AreaBound *>::const_iterator bound;
361  for (bound = boundList.begin(); bound != boundList.end(); bound++) {
362  if (iLocation.isInBoundary((*bound)->low, (*bound)->high))
363  return locationID;
364  }
365  ++locationID;
366  }
367  EV_DEBUG << "Area Type not found" << endl;
368  return -1;
369 }
AreaTypeList areaTypeList
The list of all defined area types.
Definition: PostureTransition.h:110
int inet::PostureTransition::findTimeDomain ( simtime_t  iTime)
protected

Gets a time and finds the ID of the containing time domain if there is.

Looks for the first containing time domain for the given time instance.

If not, return -1.

It return the Id of the found time domain. If no time domain is found which contains the given time instance, it returns -1.

Referenced by getMatrix().

332 {
333  int timeID = 0;
334  TimeDomainList::const_iterator timeIt;
335  for (timeIt = timeDomainList.begin(); timeIt != timeDomainList.end(); timeIt++) {
336  std::vector<TimeBound *> boundList = (*timeIt)->boundries;
337 
338  std::vector<TimeBound *>::const_iterator bound;
339  for (bound = boundList.begin(); bound != boundList.end(); bound++) {
340  if (iTime >= (*bound)->low && iTime < (*bound)->high)
341  return timeID;
342  }
343  ++timeID;
344  }
345  EV_DEBUG << "Time domain not found" << endl;
346  return -1;
347 }
TimeDomainList timeDomainList
The list of all defined time domains.
Definition: PostureTransition.h:130
double ** inet::PostureTransition::getMatrix ( simtime_t  iTime,
Coord  iLocation 
)

Gets a time and location, and returns the corresponding Markov transition matrix.

This function is actually the main usage of this class.

It gets a time instance and a location within the simulation area, and then looks for the first fitting combination. If found, it returns the specified Markov transition matrix for that combination as its output. If no combination is found, it returns the default matrix.

Referenced by inet::MoBANCoordinator::selectPosture().

306 {
307  int timeID, locationID, matrixID;
308 
309  timeID = findTimeDomain(iTime);
310  locationID = findAreaType(iLocation);
311 
312  matrixID = defaultMatrixID;
313 
314  CombinationList::const_iterator combIt;
315  for (combIt = combinationList.begin(); combIt != combinationList.end(); combIt++) {
316  if ((*combIt)->timeID == timeID && (*combIt)->areaID == locationID) {
317  matrixID = (*combIt)->matrixID;
318  break;
319  }
320  }
321 
322  EV_DEBUG << "The corresponding Markov matrix for time" << iTime.dbl() << " and location " << iLocation.info() << " is: " << matrixList.at(matrixID)->name << endl;
323 
324  return matrixList.at(matrixID)->matrix;
325 }
TransMatrixList matrixList
The list of all given transition matrices.
Definition: PostureTransition.h:90
CombinationList combinationList
The list of all given space-time combinations.
Definition: PostureTransition.h:144
int defaultMatrixID
The index of the default (base) transition matrix.
Definition: PostureTransition.h:77
int findTimeDomain(simtime_t)
Gets a time and finds the ID of the containing time domain if there is.
Definition: PostureTransition.cc:331
int findAreaType(Coord)
Gets a location and finds the ID of the containing area type if there is.
Definition: PostureTransition.cc:353
bool inet::PostureTransition::isMarkovian ( double **  matrix)
protected

Checks if a matrix can be a Markov transition matrix.

Verifies if a matrix can be a Markovian transition matrix.

All elements should be in the range [0,1] and elements of each column of the matrix should add up to 1.

Each element of the matrix should be in the range [0 1]. Further, all elements of each column should adds up to one.

Referenced by addMatrix(), and addSteadyState().

376 {
377  double sumCol;
378  for (int j = 0; j < numPos; ++j) {
379  sumCol = 0;
380  for (int i = 0; i < numPos; ++i) {
381  if (matrix[i][j] < 0 || matrix[i][j] > 1)
382  return false;
383  sumCol += matrix[i][j];
384  }
385 
386  if (!math::close(sumCol, 1.0))
387  return false;
388  }
389 
390  return true;
391 }
bool close(double one, double two)
Tests whether two doubles are close enough to be declared equal.
Definition: INETMath.h:135
int numPos
Number of postures.
Definition: PostureTransition.h:71
bool inet::PostureTransition::isMarkovian ( double *  vec)
protected

Checks if a vector can be the steady state of a Markov chain.

Verifies if a vector can be the steady state of a Markov model.

All elements should be in the range [0,1] and the sum of elements should be 1.

Each element of the matrix should be in the range [0 1]. Further, the sum of all elements should be one.

398 {
399  double sumCol = 0;
400  for (int i = 0; i < numPos; ++i) {
401  if (vec[i] < 0 || vec[i] > 1)
402  return false;
403  sumCol += vec[i];
404  }
405 
406  if (!math::close(sumCol, 1.0))
407  return false;
408  else
409  return true;
410 }
bool close(double one, double two)
Tests whether two doubles are close enough to be declared equal.
Definition: INETMath.h:135
int numPos
Number of postures.
Definition: PostureTransition.h:71
void inet::PostureTransition::multMatrix ( double **  mat1,
double **  mat2,
double **  res 
)
protected

Multiplies two matrices with dimension numPos*numPose .

Function to multiply two matrix with the known dimensions as number of postures.

Referenced by extractMatrixFromSteadyState().

416 {
417  int i, j, l;
418  for (i = 0; i < numPos; i++) {
419  for (j = 0; j < numPos; j++) {
420  res[i][j] = 0;
421  for (l = 0; l < numPos; l++)
422  res[i][j] += mat1[i][l] * mat2[l][j];
423  }
424  }
425 }
int numPos
Number of postures.
Definition: PostureTransition.h:71
void inet::PostureTransition::multVector ( double *  vec,
double **  res 
)
protected

Multiply a vector of size numPos with its transpose.

Function to multiply a vector by its transpose (pi .

pi^T). The size in equal to the number of postures.

Referenced by extractMatrixFromSteadyState().

455 {
456  int i, j;
457  for (i = 0; i < numPos; i++) {
458  for (j = 0; j < numPos; j++)
459  res[i][j] = vec[i] * vec[j];
460  }
461 }
int numPos
Number of postures.
Definition: PostureTransition.h:71
bool inet::PostureTransition::setAreaBoundry ( int  id,
Coord  lowBound,
Coord  highBound 
)

Adds the given boundary to the existing area type specified by the given ID .

This function gets an index of an existing area type and adds the given boundary to the boundary list of that area type.

Referenced by inet::MoBANCoordinator::readConfigurationFile().

188 {
189  AreaBound *bound = new AreaBound;
190  bound->low = lowBound;
191  bound->high = highBound;
192 
193  areaTypeList.at(id)->boundries.push_back(bound);
194 
195  return true;
196 }
AreaTypeList areaTypeList
The list of all defined area types.
Definition: PostureTransition.h:110
bool inet::PostureTransition::setTimeBoundry ( int  id,
simtime_t  lowBound,
simtime_t  highBound 
)

Adds the given boundary to the existing time domain specified by the given ID .

This function gets an index of an existing time domain and adds the given boundary to the boundary list of that time domain.

Referenced by inet::MoBANCoordinator::readConfigurationFile().

223 {
224  TimeBound *bound = new TimeBound;
225  bound->low = lowBound;
226  bound->high = highBound;
227 
228  timeDomainList.at(id)->boundries.push_back(bound);
229 
230  return true;
231 }
TimeDomainList timeDomainList
The list of all defined time domains.
Definition: PostureTransition.h:130
void inet::PostureTransition::subtractMatrix ( double **  mat1,
double **  mat2,
double **  res 
)
protected

Subtracts two matrices with dimension numPos*numPose .

Function to subtract two matrix with the known dimensions as number of postures.

Referenced by extractMatrixFromSteadyState().

443 {
444  int i, j;
445  for (i = 0; i < numPos; i++) {
446  for (j = 0; j < numPos; j++)
447  res[i][j] = mat1[i][j] - mat2[i][j];
448  }
449 }
int numPos
Number of postures.
Definition: PostureTransition.h:71

Member Data Documentation

AreaTypeList inet::PostureTransition::areaTypeList
protected

The list of all defined area types.

Referenced by addAreaType(), addCombination(), findAreaType(), setAreaBoundry(), and ~PostureTransition().

CombinationList inet::PostureTransition::combinationList
protected

The list of all given space-time combinations.

Referenced by addCombination(), getMatrix(), and ~PostureTransition().

int inet::PostureTransition::defaultMatrixID
protected

The index of the default (base) transition matrix.

If no default is set, the first matrix is supposed as the default. Default matrix is used for the cases that a time or space domain does not lie in any given area types or time domains. It is also used for generating the transition matrix in the case that a steady state vector is given for a space-time domain.

Referenced by addMatrix(), extractMatrixFromSteadyState(), getMatrix(), and PostureTransition().

TransMatrixList inet::PostureTransition::matrixList
protected

The list of all given transition matrices.

Referenced by addCombination(), addMatrix(), addSteadyState(), extractMatrixFromSteadyState(), getMatrix(), and ~PostureTransition().

int inet::PostureTransition::numPos
protected
TimeDomainList inet::PostureTransition::timeDomainList
protected

The list of all defined time domains.

Referenced by addCombination(), addTimeDomain(), findTimeDomain(), setTimeBoundry(), and ~PostureTransition().


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