SST  9.0.0
StructuralSimulationToolkit
expon.h
1 // Copyright 2009-2019 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-2019, 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 _H_SST_CORE_RNG_EXP
13 #define _H_SST_CORE_RNG_EXP
14 
15 #include "math.h"
16 
17 #include "distrib.h"
18 #include "mersenne.h"
19 
20 using namespace SST::RNG;
21 
22 namespace SST {
23 namespace RNG {
24 
25 /**
26  \class SSTExponentialDistribution 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  public:
34  /**
35  Creates an exponential distribution with a specific lambda
36  \param mn The lambda of the exponential distribution
37  */
38  SSTExponentialDistribution(const double mn) :
40 
41  lambda = mn;
42  baseDistrib = new MersenneRNG();
43  deleteDistrib = true;
44  }
45 
46  /**
47  Creates an exponential distribution with a specific lambda and a base random number generator
48  \param mn The lambda of the exponential distribution
49  \param baseDist The base random number generator to take the distribution from.
50  */
51  SSTExponentialDistribution(const double mn, SSTRandom* baseDist) :
53 
54  lambda = mn;
55  baseDistrib = baseDist;
56  deleteDistrib = false;
57  }
58 
59  /**
60  Destroys the exponential distribution
61  */
63  if(deleteDistrib) {
64  delete baseDistrib;
65  }
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  const double next = baseDistrib->nextUniform();
74  return log(1 - next) / ( -1 * lambda );
75  }
76 
77  /**
78  Gets the lambda with which the distribution was created
79  \return The lambda which the user created the distribution with
80  */
81  double getLambda() {
82  return lambda;
83  }
84 
85 
86  protected:
87  /**
88  Sets the lambda of the exponential distribution.
89  */
90  double lambda;
91  /**
92  Sets the base random number generator for the distribution.
93  */
95 
96  /**
97  Controls whether the base distribution should be deleted when this class is destructed.
98  */
100 
101 };
102 
103 }
104 }
105 
106 #endif
Base class of statistical distributions in SST.
Definition: distrib.h:24
SSTRandom * baseDistrib
Sets the base random number generator for the distribution.
Definition: expon.h:94
double getNextDouble()
Gets the next (random) double value in the distribution.
Definition: expon.h:72
Implements a Mersenne-based RNG for use in the SST core or components.
Definition: mersenne.h:34
SSTExponentialDistribution(const double mn, SSTRandom *baseDist)
Creates an exponential distribution with a specific lambda and a base random number generator...
Definition: expon.h:51
double getLambda()
Gets the lambda with which the distribution was created.
Definition: expon.h:81
SSTExponentialDistribution(const double mn)
Creates an exponential distribution with a specific lambda.
Definition: expon.h:38
bool deleteDistrib
Controls whether the base distribution should be deleted when this class is destructed.
Definition: expon.h:99
Implements the base class for random number generators for the SST core.
Definition: sstrng.h:27
double lambda
Sets the lambda of the exponential distribution.
Definition: expon.h:90
~SSTExponentialDistribution()
Destroys the exponential distribution.
Definition: expon.h:62
Creates an exponential distribution for use within SST.
Definition: expon.h:31