00001 // Copyright 2009-2015 Sandia Corporation. Under the terms 00002 // of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. 00003 // Government retains certain rights in this software. 00004 // 00005 // Copyright (c) 2009-2015, Sandia Corporation 00006 // All rights reserved. 00007 // 00008 // This file is part of the SST software package. For license 00009 // information, see the LICENSE file in the top level directory of the 00010 // distribution. 00011 00012 #ifndef _H_SST_CORE_RNG_EXP 00013 #define _H_SST_CORE_RNG_EXP 00014 00015 #include "math.h" 00016 00017 #include "distrib.h" 00018 #include "mersenne.h" 00019 00020 using namespace SST::RNG; 00021 00022 namespace SST { 00023 namespace RNG { 00024 00025 /** 00026 \class SSTExponentialDistribution expon.h "sst/core/rng/expon.h" 00027 00028 Creates an exponential distribution for use within SST. This distribution is the same across 00029 platforms and compilers. 00030 */ 00031 class SSTExponentialDistribution : public SSTRandomDistribution { 00032 00033 public: 00034 /** 00035 Creates an exponential distribution with a specific lambda 00036 \param mn The lambda of the exponential distribution 00037 */ 00038 SSTExponentialDistribution(const double mn) : 00039 SSTRandomDistribution() { 00040 00041 lambda = mn; 00042 baseDistrib = new MersenneRNG(); 00043 deleteDistrib = true; 00044 } 00045 00046 /** 00047 Creates an exponential distribution with a specific lambda and a base random number generator 00048 \param mn The lambda of the exponential distribution 00049 \param baseDist The base random number generator to take the distribution from. 00050 */ 00051 SSTExponentialDistribution(const double mn, SSTRandom* baseDist) : 00052 SSTRandomDistribution() { 00053 00054 lambda = mn; 00055 baseDistrib = baseDist; 00056 deleteDistrib = false; 00057 } 00058 00059 /** 00060 Destroys the exponential distribution 00061 */ 00062 ~SSTExponentialDistribution() { 00063 if(deleteDistrib) { 00064 delete baseDistrib; 00065 } 00066 } 00067 00068 /** 00069 Gets the next (random) double value in the distribution 00070 \return The next random double from the distribution 00071 */ 00072 double getNextDouble() { 00073 const double next = baseDistrib->nextUniform(); 00074 return log(1 - next) / ( -1 * lambda ); 00075 } 00076 00077 /** 00078 Gets the lambda with which the distribution was created 00079 \return The lambda which the user created the distribution with 00080 */ 00081 double getLambda() { 00082 return lambda; 00083 } 00084 00085 00086 protected: 00087 /** 00088 Sets the lambda of the exponential distribution. 00089 */ 00090 double lambda; 00091 /** 00092 Sets the base random number generator for the distribution. 00093 */ 00094 SSTRandom* baseDistrib; 00095 00096 /** 00097 Controls whether the base distribution should be deleted when this class is destructed. 00098 */ 00099 bool deleteDistrib; 00100 00101 }; 00102 00103 } 00104 } 00105 00106 #endif