28 #include <sys/types.h>
116 : m_variable (o.m_variable->
Copy ())
120 : m_variable (variable.
Copy ())
187 double GetMin (
void)
const;
188 double GetMax (
void)
const;
198 virtual double GetValue (
double s,
double l);
254 return s + generator->
RandU01 () * (l -
s);
290 return static_cast<uint32_t
> (
GetValue (s, l + 1) );
451 m_currentConsecutive (0)
462 m_currentConsecutive (0)
471 m_increment (c.m_increment),
472 m_consecutive (c.m_consecutive),
473 m_current (c.m_current),
474 m_currentConsecutive (c.m_currentConsecutive)
711 : m_scale (0.5 / 1.5),
719 : m_scale (m * 0.5 / 1.5),
727 : m_scale (m * (s - 1.0) / s),
735 : m_scale (m * (s - 1.0) / s),
743 : m_scale (params.
first),
744 m_shape (params.second),
751 : m_scale (params.
first),
752 m_shape (params.second),
916 double exponent = 1.0 /
m_alpha;
919 double r =
m_mean * std::pow ( -std::log (generator->
RandU01 ()), exponent);
1004 m_bound (INFINITE_VALUE),
1022 m_variance (c.m_variance),
1023 m_bound (c.m_bound),
1042 double u1 = generator->
RandU01 ();
1043 double u2 = generator->
RandU01 ();
1044 double v1 = 2 * u1 - 1;
1045 double v2 = 2 * u2 - 1;
1046 double w = v1 * v1 + v2 * v2;
1049 double y = std::sqrt ((-2 * std::log (w)) / w);
1136 virtual void CDF (
double v,
double c);
1149 virtual double Interpolate (
double,
double,
double,
double,
double);
1186 validated (c.validated),
1202 if (
emp.size () == 0)
1210 double r = generator->
RandU01 ();
1211 if (r <=
emp.front ().cdf)
1213 return emp.front ().value;
1215 if (r >=
emp.back ().cdf)
1217 return emp.back ().value;
1220 std::vector<ValueCDF>::size_type bottom = 0;
1221 std::vector<ValueCDF>::size_type top =
emp.size () - 1;
1224 std::vector<ValueCDF>::size_type c = (top + bottom) / 2;
1225 if (r >=
emp[c].cdf && r <
emp[c + 1].cdf)
1228 emp[c].value,
emp[c + 1].value,
1260 for (std::vector<ValueCDF>::size_type i = 0; i <
emp.size (); ++i)
1265 std::cerr <<
"Empirical Dist error,"
1266 <<
" current value " << current.
value
1267 <<
" prior value " << prior.
value
1268 <<
" current cdf " << current.
cdf
1269 <<
" prior cdf " << prior.
cdf << std::endl;
1278 double v1,
double v2,
double r)
1281 return (v1 + ((v2 - v1) / (c2 - c1)) * (r - c1));
1319 virtual double Interpolate (
double,
double,
double,
double,
double);
1341 double v1,
double v2,
double r)
1344 return std::ceil (v1 + ((v2 - v1) / (c2 - c1)) * (r - c1));
1490 double u, v, r2,
normal, z;
1496 u = -1 + 2 * generator->
RandU01 ();
1497 v = -1 + 2 * generator->
RandU01 ();
1502 while (r2 > 1.0 || r2 == 0);
1504 normal = u * std::sqrt (-2.0 * std::log (r2) / r2);
1539 double GetValue (
double alpha,
double beta);
1594 double u = generator->
RandU01 ();
1595 return GetValue (1.0 + alpha, beta) * std::pow (u, 1.0 / alpha);
1599 double d = alpha - 1.0 / 3.0;
1600 double c = (1.0 / 3.0) / std::sqrt (d);
1613 if (u < 1 - 0.0331 * x * x * x * x)
1617 if (std::log (u) < 0.5 * x * x + d * (1 - v + std::log (v)))
1623 return beta * d * v;
1673 double GetValue (
unsigned int k,
double lambda);
1724 for (
unsigned int i = 0; i < k; ++i)
1804 m_mode (3.0 * mean - s - l)
1822 double u = generator->
RandU01 ();
1903 for (
int i = 1; i <= n; i++)
1905 m_c += (1.0 / std::pow ((
double)i, alpha));
1916 double u = generator->
RandU01 ();
1917 double sum_prob = 0,zipf_value = 0;
1918 for (
int i = 1; i <=
m_n; i++)
1920 sum_prob +=
m_c / std::pow ((
double)i,
m_alpha);
1980 m_b (std::pow (2.0, 2.14))
1988 m_b (std::pow (2.0, alpha - 1.0))
2012 X = floor (std::pow (u, -1.0 / (
m_alpha - 1.0)));
2013 T = std::pow (1.0 + 1.0 / X,
m_alpha - 1.0);
2014 test = v * X * (T - 1.0) / (
m_b - 1.0);
2016 while ( test > (T /
m_b) );
2040 os <<
"Constant:" << constant->
GetValue ();
2046 os <<
"Uniform:" << uniform->
GetMin () <<
":" << uniform->
GetMax ();
2053 double bound = normal->
GetBound ();
2061 os.setstate (std::ios_base::badbit);
2068 std::string::size_type tmp;
2069 tmp = value.find (
":");
2070 if (tmp == std::string::npos)
2072 is.setstate (std::ios_base::badbit);
2075 std::string type = value.substr (0, tmp);
2076 value = value.substr (tmp + 1, value.npos);
2077 if (type ==
"Constant")
2079 std::istringstream iss (value);
2084 else if (type ==
"Uniform")
2086 if (value.size () == 0)
2092 tmp = value.find (
":");
2093 if (tmp == value.npos)
2097 std::istringstream issA (value.substr (0, tmp));
2098 std::istringstream issB (value.substr (tmp + 1, value.npos));
2105 else if (type ==
"Normal")
2107 if (value.size () == 0)
2113 tmp = value.find (
":");
2114 if (tmp == value.npos)
2118 std::string::size_type tmp2;
2119 std::string sub = value.substr (tmp + 1, value.npos);
2120 tmp2 = sub.find (
":");
2121 if (tmp2 == value.npos)
2123 std::istringstream issA (value.substr (0, tmp));
2124 std::istringstream issB (sub);
2132 std::istringstream issA (value.substr (0, tmp));
2133 std::istringstream issB (sub.substr (0, tmp2));
2134 std::istringstream issC (sub.substr (tmp2 + 1, value.npos));
2145 NS_FATAL_ERROR (
"RandomVariable deserialization not implemented for " << type);
RandomVariableBase * Peek(void) const
virtual RandomVariableBase * Copy(void) const
virtual double GetValue()
ExponentialVariableImpl()
Constructs an exponential random variable with a mean value of 1.0.
std::istream & operator>>(std::istream &is, Angles &a)
initialize a struct Angles from input
TriangularVariable()
Creates a triangle distribution random number generator in the range [0.0 .
#define NS_LOG_FUNCTION(parameters)
ErlangVariable()
Constructs an Erlang random variable with k = 1 and lambda = 1.0.
A random variable that returns a constantClass ConstantVariable defines a random number generator tha...
NS_LOG_COMPONENT_DEFINE("GrantedTimeWindowMpiInterface")
virtual uint32_t GetInteger()
virtual uint32_t GetInteger()
virtual ~RandomVariableBase()
virtual double GetValue()
GammaVariable()
Constructs a gamma random variable with alpha = 1.0 and beta = 1.0.
WeibullVariableImpl()
Constructs a weibull random variable with a mean value of 1.0 and a shape (alpha) parameter of 1...
#define NS_ASSERT(condition)
virtual RandomVariableBase * Copy(void) const
uint32_t m_currentConsecutive
virtual double GetValue()
virtual RandomVariableBase * Copy() const
virtual RandomVariableBase * Copy(void) const
virtual double GetValue()
virtual double GetValue()
virtual double GetValue()
ATTRIBUTE_CHECKER_IMPLEMENT(Callback)
Attribute checker.
virtual RandomVariableBase * Copy(void) const
#define NS_FATAL_ERROR(msg)
fatal error handling
static uint64_t GetRun(void)
void NewConstant(double c)
Specify a new constant RNG for this generator.
ExponentialVariable()
Constructs an exponential random variable with a mean value of 1.0.
ZipfVariable()
Constructs a Zipf random variable with N=1 and alpha=0.
NormalVariable()
Constructs an normal random variable with a mean value of 0 and variance of 1.
Class NormalVariable defines a random variable with a normal (Gaussian) distribution.
virtual double Interpolate(double, double, double, double, double)
Combined Multiple-Recursive Generator MRG32k3a.
virtual RandomVariableBase * Copy(void) const
TriangularVariableImpl()
Creates a triangle distribution random number generator in the range [0.0 .
RandomVariable & operator=(const RandomVariable &o)
SequentialVariableImpl(double f, double l, double i=1, uint32_t c=1)
Constructor for the SequentialVariableImpl RNG.
virtual double GetValue()
DeterministicVariable(double *d, uint32_t c)
Constructor.
WeibullVariable()
Constructs a weibull random variable with a mean value of 1.0 and a shape (alpha) parameter of 1...
LogNormalVariableImpl(double mu, double sigma)
double GetValue(void) const
call RandomVariable::GetValue
virtual ~DeterministicVariableImpl()
SequentialVariable(double f, double l, double i=1, uint32_t c=1)
Constructor for the SequentialVariable RNG.
virtual RandomVariableBase * Copy(void) const =0
virtual RandomVariableBase * Copy(void) const
ErlangVariableImpl(unsigned int k, double lambda)
ParetoVariableImpl()
Constructs a pareto random variable with a mean of 1 and a shape parameter of 1.5.
std::ostream & operator<<(std::ostream &os, const Angles &a)
print a struct Angles to output
LogNormalVariable(double mu, double sigma)
RandomVariableBase * m_variable
virtual RandomVariableBase * Copy(void) const
ZipfVariableImpl()
zipf variable with N=1 and alpha=0
virtual double GetValue()
std::vector< ValueCDF > emp
RngStream * GetStream(void)
virtual RandomVariableBase * Copy(void) const
virtual RandomVariableBase * Copy(void) const
virtual void CDF(double v, double c)
Specifies a point in the empirical distribution.
NormalVariableImpl()
Constructs an normal random variable with a mean value of 0 and variance of 1.
virtual double GetValue()
Exponentially Distributed random varThis class supports the creation of objects that return random nu...
double RandU01(void)
Generate the next random number for this stream.
virtual RandomVariableBase * Copy(void) const
static uint32_t GetSeed(void)
Get the seed value.
virtual RandomVariableBase * Copy(void) const
RandomVariable m_increment
ATTRIBUTE_VALUE_IMPLEMENT(RandomVariable)
double GetValue(void) const
call RandomVariable::GetValue
ZetaVariableImpl()
zipf variable with alpha=1.1
virtual RandomVariableBase * Copy(void) const
double GetMean(void) const
void CDF(double v, double c)
Specifies a point in the empirical distribution.
virtual double GetValue()
EmpiricalVariable()
Constructor for the EmpiricalVariable random variables.
virtual double GetValue()=0
virtual ~EmpiricalVariableImpl()
IntEmpiricalVariableImpl()
virtual double GetValue()
virtual uint32_t GetInteger()
ZetaVariable()
Constructs a Zeta random variable with alpha=3.14.
GammaVariableImpl(double alpha, double beta)
static const double INFINITE_VALUE
ConstantVariableImpl()
Construct a ConstantVariableImpl RNG that returns zero every sample.
virtual double GetValue()
double GetBound(void) const
DeterministicVariableImpl(double *d, uint32_t c)
Constructor.
double GetVariance(void) const
EmpiricalVariable distribution random varDefines a random variable that has a specified, empirical distribution.
static uint64_t GetNextStreamIndex(void)
EmpiricalVariableImpl()
Constructor for the EmpiricalVariableImpl random variables.
ConstantVariable()
Construct a ConstantVariable RNG that returns zero every sample.
double GetValue(void) const
Returns a random double from the underlying distribution.
uint32_t GetInteger(void) const
Returns a random integer integer from the underlying distribution.
virtual double Interpolate(double, double, double, double, double)
virtual RandomVariableBase * Copy(void) const
virtual RandomVariableBase * Copy(void) const
void SetConstant(double c)
Specify a new constant RNG for this generator.
Ptr< T > Copy(Ptr< T > object)
~SequentialVariableImpl()
ParetoVariable()
Constructs a pareto random variable with a mean of 1 and a shape parameter of 1.5.
virtual double GetValue()
virtual double GetValue()