SST  15.1.0
StructuralSimulationToolkit
expon.h
1 // Copyright 2009-2025 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-2025, 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 namespace SST::RNG {
21 
22 /**
23  \class ExponentialDistribution expon.h "sst/core/rng/expon.h"
24 
25  Creates an exponential distribution for use within SST. This distribution is the same across
26  platforms and compilers.
27 */
29 {
30 
31 public:
32  /**
33  Creates an exponential distribution with a specific lambda
34  \param mn The lambda of the exponential distribution
35  */
36  explicit ExponentialDistribution(const double mn) :
38  {
39 
40  lambda = mn;
41  baseDistrib = new MersenneRNG();
42  deleteDistrib = true;
43  }
44 
45  /**
46  Creates an exponential distribution with a specific lambda and a base random number generator
47  \param mn The lambda of the exponential distribution
48  \param baseDist The base random number generator to take the distribution from.
49  */
50  ExponentialDistribution(const double mn, Random* baseDist) :
52  {
53 
54  lambda = mn;
55  baseDistrib = baseDist;
56  deleteDistrib = false;
57  }
58 
59  /**
60  Destroys the exponential distribution
61  */
63  {
64  if ( deleteDistrib ) {
65  delete baseDistrib;
66  }
67  }
68 
69  /**
70  Gets the next (random) double value in the distribution
71  \return The next random double from the distribution
72  */
73  double getNextDouble() override
74  {
75  const double next = baseDistrib->nextUniform();
76  return log(1 - next) / (-1 * lambda);
77  }
78 
79  /**
80  Gets the lambda with which the distribution was created
81  \return The lambda which the user created the distribution with
82  */
83  double getLambda() { return lambda; }
84 
85  /**
86  Default constructor. FOR SERIALIZATION ONLY.
87  */
90  {}
91 
92  /**
93  Serialization function for checkpoint
94  */
96  {
97  SST_SER(lambda);
98  SST_SER(baseDistrib);
99  SST_SER(deleteDistrib);
100  }
101 
102  /**
103  Serialization macro
104  */
105  ImplementSerializable(SST::RNG::ExponentialDistribution)
106 
107 protected:
108  /**
109  Sets the lambda of the exponential distribution.
110  */
111  double lambda;
112  /**
113  Sets the base random number generator for the distribution.
114  */
116 
117  /**
118  Controls whether the base distribution should be deleted when this class is destructed.
119  */
121 };
122 
123 } // namespace SST::RNG
124 
126 
127 #endif // SST_CORE_RNG_EXPON_H
Implements the base class for random number generators for the SST core.
Definition: rng.h:29
Definition: constant.h:18
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition: serializer.h:42
double getLambda()
Gets the lambda with which the distribution was created.
Definition: expon.h:83
~ExponentialDistribution()
Destroys the exponential distribution.
Definition: expon.h:62
ImplementSerializable(SST::RNG::ExponentialDistribution) protected Random * baseDistrib
Serialization macro.
Definition: expon.h:105
ExponentialDistribution()
Default constructor.
Definition: expon.h:88
ExponentialDistribution(const double mn)
Creates an exponential distribution with a specific lambda.
Definition: expon.h:36
void serialize_order(SST::Core::Serialization::serializer &ser) override
Serialization function for checkpoint.
Definition: expon.h:95
Implements a Mersenne-based RNG for use in the SST core or components.
Definition: mersenne.h:34
ExponentialDistribution(const double mn, Random *baseDist)
Creates an exponential distribution with a specific lambda and a base random number generator...
Definition: expon.h:50
bool deleteDistrib
Controls whether the base distribution should be deleted when this class is destructed.
Definition: expon.h:120
double getNextDouble() override
Gets the next (random) double value in the distribution.
Definition: expon.h:73
Base class of statistical distributions in SST.
Definition: distrib.h:23
Creates an exponential distribution for use within SST.
Definition: expon.h:28