SST  14.0.0
StructuralSimulationToolkit
expon.h
1 // Copyright 2009-2024 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-2024, 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() override
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  /**
85  Default constructor. FOR SERIALIZATION ONLY.
86  */
88 
89  /**
90  Serialization function for checkpoint
91  */
93  {
94  ser& lambda;
95  ser& baseDistrib;
96  ser& deleteDistrib;
97  }
98 
99  /**
100  Serialization macro
101  */
102  ImplementSerializable(SST::RNG::ExponentialDistribution)
103 
104 protected:
105  /**
106  Sets the lambda of the exponential distribution.
107  */
108  double lambda;
109  /**
110  Sets the base random number generator for the distribution.
111  */
113 
114  /**
115  Controls whether the base distribution should be deleted when this class is destructed.
116  */
118 };
119 
121 
122 } // namespace RNG
123 } // namespace SST
124 
125 #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:21
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition: serializer.h:35
double getLambda()
Gets the lambda with which the distribution was created.
Definition: expon.h:82
~ExponentialDistribution()
Destroys the exponential distribution.
Definition: expon.h:63
ExponentialDistribution()
Default constructor.
Definition: expon.h:87
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
void serialize_order(SST::Core::Serialization::serializer &ser) override
Serialization function for checkpoint.
Definition: expon.h:92
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:117
double getNextDouble() override
Gets the next (random) double value in the distribution.
Definition: expon.h:72
ImplementSerializable(SST::RNG::ExponentialDistribution) protected SST::RNG::Random * baseDistrib
Serialization macro.
Definition: expon.h:102
Base class of statistical distributions in SST.
Definition: distrib.h:24
Creates an exponential distribution for use within SST.
Definition: expon.h:31