INET Framework for OMNeT++/OMNEST
inet::httptools::rdNormal Class Reference

Normal distribution random object. More...

#include <HttpRandom.h>

Inheritance diagram for inet::httptools::rdNormal:
inet::httptools::rdObject

Public Member Functions

 rdNormal (double mean, double sd, bool nonNegative=false)
 
 rdNormal (cXMLAttributeMap attributes)
 
void setMinLimit (double min)
 
void resetMinLimit ()
 
virtual double draw () override
 
- Public Member Functions inherited from inet::httptools::rdObject
virtual ~rdObject ()
 
DISTR_TYPE getType ()
 
std::string typeStr ()
 
virtual std::string toString ()
 

Protected Attributes

double m_mean = NaN
 The mean of the distribution. More...
 
double m_sd = NaN
 The sd of the distribution. More...
 
double m_min = NaN
 The minimum limit . More...
 
bool m_bMinLimit = NaN
 Set if the minimum limit is set. More...
 
bool m_nonNegative = NaN
 Non-negative only – uses the truncnormal function. More...
 
- Protected Attributes inherited from inet::httptools::rdObject
DISTR_TYPE m_type = dt_normal
 

Additional Inherited Members

- Protected Member Functions inherited from inet::httptools::rdObject
bool _hasKey (cXMLAttributeMap attributes, std::string key)
 

Detailed Description

Normal distribution random object.

Wraps the OMNeT++ normal distribution function but adds a minimum limit.

Constructor & Destructor Documentation

inet::httptools::rdNormal::rdNormal ( double  mean,
double  sd,
bool  nonNegative = false 
)
45 {
46  m_type = dt_normal;
47  m_mean = mean;
48  m_sd = sd;
49  m_nonNegative = nonNegative;
50  m_min = 0.0;
51  m_bMinLimit = false;
52 }
double m_sd
The sd of the distribution.
Definition: HttpRandom.h:74
double m_min
The minimum limit .
Definition: HttpRandom.h:75
bool m_nonNegative
Non-negative only – uses the truncnormal function.
Definition: HttpRandom.h:77
Definition: HttpRandom.h:33
double m_mean
The mean of the distribution.
Definition: HttpRandom.h:73
DISTR_TYPE m_type
Definition: HttpRandom.h:49
bool m_bMinLimit
Set if the minimum limit is set.
Definition: HttpRandom.h:76
inet::httptools::rdNormal::rdNormal ( cXMLAttributeMap  attributes)
55 {
56  m_type = dt_normal;
57  if (!_hasKey(attributes, "mean"))
58  throw "Undefined parameter for random distribution. Mean must be defined for a normal distribution";
59  if (!_hasKey(attributes, "sd"))
60  throw "Undefined parameter for random distribution. sd must be defined for a normal distribution";
61  m_mean = atof(attributes["mean"].c_str());
62  m_sd = atof(attributes["sd"].c_str());
63  m_bMinLimit = _hasKey(attributes, "min");
64  if (m_bMinLimit)
65  m_min = atof(attributes["min"].c_str());
66  if (_hasKey(attributes, "nonNegative"))
67  m_nonNegative = strcmp(attributes["nonNegative"].c_str(), "true") == 0;
68  else
69  m_nonNegative = false;
70 }
double m_sd
The sd of the distribution.
Definition: HttpRandom.h:74
double m_min
The minimum limit .
Definition: HttpRandom.h:75
bool m_nonNegative
Non-negative only – uses the truncnormal function.
Definition: HttpRandom.h:77
Definition: HttpRandom.h:33
double m_mean
The mean of the distribution.
Definition: HttpRandom.h:73
DISTR_TYPE m_type
Definition: HttpRandom.h:49
bool m_bMinLimit
Set if the minimum limit is set.
Definition: HttpRandom.h:76
bool _hasKey(cXMLAttributeMap attributes, std::string key)
Definition: HttpRandom.h:52

Member Function Documentation

double inet::httptools::rdNormal::draw ( )
overridevirtual

Implements inet::httptools::rdObject.

73 {
74  double retval = 0.0;
75  do {
76  if (m_nonNegative)
77  retval = RNGCONTEXT truncnormal(m_mean, m_sd);
78  else
79  retval = RNGCONTEXT normal(m_mean, m_sd);
80  } while (m_bMinLimit && retval < m_min);
81 
82  return retval;
83 }
double m_sd
The sd of the distribution.
Definition: HttpRandom.h:74
double m_min
The minimum limit .
Definition: HttpRandom.h:75
bool m_nonNegative
Non-negative only – uses the truncnormal function.
Definition: HttpRandom.h:77
#define RNGCONTEXT
Definition: INETDefs.h:85
double m_mean
The mean of the distribution.
Definition: HttpRandom.h:73
bool m_bMinLimit
Set if the minimum limit is set.
Definition: HttpRandom.h:76
void inet::httptools::rdNormal::resetMinLimit ( )
inline
99 { m_bMinLimit = false; }
bool m_bMinLimit
Set if the minimum limit is set.
Definition: HttpRandom.h:76
void inet::httptools::rdNormal::setMinLimit ( double  min)
inline
94 { m_min = min; m_bMinLimit = true; }
double min(const double a, const double b)
Returns the minimum of a and b.
Definition: SCTPAssociation.h:270
double m_min
The minimum limit .
Definition: HttpRandom.h:75
bool m_bMinLimit
Set if the minimum limit is set.
Definition: HttpRandom.h:76

Member Data Documentation

bool inet::httptools::rdNormal::m_bMinLimit = NaN
protected

Set if the minimum limit is set.

double inet::httptools::rdNormal::m_mean = NaN
protected

The mean of the distribution.

double inet::httptools::rdNormal::m_min = NaN
protected

The minimum limit .

bool inet::httptools::rdNormal::m_nonNegative = NaN
protected

Non-negative only – uses the truncnormal function.

double inet::httptools::rdNormal::m_sd = NaN
protected

The sd of the distribution.


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