SST  13.0.0
StructuralSimulationToolkit
expon.h
1 // Copyright 2009-2023 NTESS. Under the terms
2 // of Contract DE-NA0003525 with NTESS, the U.S.
3 // Government retains certain rights in this software.
4 //
5 // Copyright (c) 2009-2023, NTESS
6 // All rights reserved.
7 //
8 // This file is part of the SST software package. For license
9 // information, see the LICENSE file in the top level directory of the
10 // distribution.
11 
12 #ifndef SST_CORE_RNG_EXPON_H
13 #define SST_CORE_RNG_EXPON_H
14 
15 #include "distrib.h"
16 #include "math.h"
17 #include "mersenne.h"
18 #include "rng.h"
19 
20 using namespace SST::RNG;
21 
22 namespace SST {
23 namespace RNG {
24 
25 /**
26  \class ExponentialDistribution expon.h "sst/core/rng/expon.h"
27 
28  Creates an exponential distribution for use within SST. This distribution is the same across
29  platforms and compilers.
30 */
32 {
33 
34 public:
35  /**
36  Creates an exponential distribution with a specific lambda
37  \param mn The lambda of the exponential distribution
38  */
40  {
41 
42  lambda = mn;
43  baseDistrib = new MersenneRNG();
44  deleteDistrib = true;
45  }
46 
47  /**
48  Creates an exponential distribution with a specific lambda and a base random number generator
49  \param mn The lambda of the exponential distribution
50  \param baseDist The base random number generator to take the distribution from.
51  */
53  {
54 
55  lambda = mn;
56  baseDistrib = baseDist;
57  deleteDistrib = false;
58  }
59 
60  /**
61  Destroys the exponential distribution
62  */
64  {
65  if ( deleteDistrib ) { delete baseDistrib; }
66  }
67 
68  /**
69  Gets the next (random) double value in the distribution
70  \return The next random double from the distribution
71  */
72  double getNextDouble()
73  {
74  const double next = baseDistrib->nextUniform();
75  return log(1 - next) / (-1 * lambda);
76  }
77 
78  /**
79  Gets the lambda with which the distribution was created
80  \return The lambda which the user created the distribution with
81  */
82  double getLambda() { return lambda; }
83 
84 protected:
85  /**
86  Sets the lambda of the exponential distribution.
87  */
88  double lambda;
89  /**
90  Sets the base random number generator for the distribution.
91  */
93 
94  /**
95  Controls whether the base distribution should be deleted when this class is destructed.
96  */
98 };
99 
101 
102 } // namespace RNG
103 } // namespace SST
104 
105 #endif // SST_CORE_RNG_EXPON_H
Implements the base class for random number generators for the SST core.
Definition: rng.h:27
Definition: constant.h:21
double getLambda()
Gets the lambda with which the distribution was created.
Definition: expon.h:82
SST::RNG::Random * baseDistrib
Sets the base random number generator for the distribution.
Definition: expon.h:92
~ExponentialDistribution()
Destroys the exponential distribution.
Definition: expon.h:63
Definition: action.cc:18
ExponentialDistribution(const double mn)
Creates an exponential distribution with a specific lambda.
Definition: expon.h:39
ExponentialDistribution(const double mn, SST::RNG::Random *baseDist)
Creates an exponential distribution with a specific lambda and a base random number generator...
Definition: expon.h:52
Implements a Mersenne-based RNG for use in the SST core or components.
Definition: mersenne.h:34
bool deleteDistrib
Controls whether the base distribution should be deleted when this class is destructed.
Definition: expon.h:97
double lambda
Sets the lambda of the exponential distribution.
Definition: expon.h:88
Base class of statistical distributions in SST.
Definition: distrib.h:22
Creates an exponential distribution for use within SST.
Definition: expon.h:31
double getNextDouble()
Gets the next (random) double value in the distribution.
Definition: expon.h:72