author | Raj Bhattacharjea <raj.b@gatech.edu> |
Thu, 22 Mar 2007 16:41:01 -0400 | |
changeset 364 | 9df87117d468 |
parent 360 | 7bffd987426c |
child 396 | 7b4349cd88bc |
permissions | -rw-r--r-- |
346
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
2 |
// |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
3 |
// Copyright (c) 2006 Georgia Tech Research Corporation |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
4 |
// |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
5 |
// This program is free software; you can redistribute it and/or modify |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
6 |
// it under the terms of the GNU General Public License version 2 as |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
7 |
// published by the Free Software Foundation; |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
8 |
// |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
9 |
// This program is distributed in the hope that it will be useful, |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
12 |
// GNU General Public License for more details. |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
13 |
// |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
14 |
// You should have received a copy of the GNU General Public License |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
15 |
// along with this program; if not, write to the Free Software |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
16 |
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
17 |
// |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
18 |
// Author: Rajib Bhattacharjea<raj.b@gatech.edu> |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
19 |
// |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
20 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
21 |
#ifndef __random_variable_h__ |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
22 |
#define __random_variable_h__ |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
23 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
24 |
#include <vector> |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
25 |
#include <algorithm> |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
26 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
27 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
28 |
#define INFINITE_VALUE 1e307 |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
29 |
namespace ns3{ |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
30 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
31 |
class RngStream; |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
32 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
33 |
/** |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
34 |
* \brief Pure virtual base class for RNG seeds |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
35 |
*/ |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
36 |
class Seed { |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
37 |
// Seed is used to seed the random number generator(s) |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
38 |
// This is a base class for RandomSeed and ConstantSeed |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
39 |
public: |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
40 |
virtual ~Seed(); |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
41 |
virtual bool IsRandom() const = 0; |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
42 |
}; |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
43 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
44 |
/** |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
45 |
* \brief random RNG seeds |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
46 |
*/ |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
47 |
class RandomSeed : public Seed { |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
48 |
public: |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
49 |
RandomSeed(); |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
50 |
~RandomSeed(); |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
51 |
bool IsRandom() const; |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
52 |
}; |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
53 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
54 |
/** |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
55 |
* \brief constant RNG seeds |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
56 |
*/ |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
57 |
class ConstantSeed : public Seed |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
58 |
{ |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
59 |
public: |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
60 |
ConstantSeed(uint32_t); // Use six copies of the specified value |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
61 |
ConstantSeed(uint32_t,uint32_t,uint32_t,uint32_t,uint32_t,uint32_t); // Six seeds |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
62 |
bool IsRandom() const; |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
63 |
~ConstantSeed(); |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
64 |
public: |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
65 |
uint32_t seeds[6]; |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
66 |
}; |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
67 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
68 |
/** |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
69 |
* \brief The basic RNG for NS-3. |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
70 |
* |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
71 |
* Note: The underlying random number generation method used |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
72 |
* by NS-3 is the RngStream code by Pierre L'Ecuyer at |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
73 |
* the University of Montreal. |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
74 |
* |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
75 |
* NS-3 has a rich set of random number generators. |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
76 |
* Class RandomVariable defines the base class functionalty |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
77 |
* required for all random number generators. By default, the underlying |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
78 |
* generator is seeded with the time of day, and then deterministically |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
79 |
* creates a sequence of seeds for each subsequent generator that is created. |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
80 |
* The rest of the documentation outlines how to change this behavior. |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
81 |
*/ |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
82 |
class RandomVariable { |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
83 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
84 |
public: |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
85 |
/** |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
86 |
* \brief Constructor for a random number generator with a random seed. |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
87 |
*/ |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
88 |
RandomVariable(); |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
89 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
90 |
/** |
360
7bffd987426c
Fixed major memory bug and docs in RandomVariable
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
346
diff
changeset
|
91 |
* \brief Copy constructor |
7bffd987426c
Fixed major memory bug and docs in RandomVariable
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
346
diff
changeset
|
92 |
*/ |
7bffd987426c
Fixed major memory bug and docs in RandomVariable
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
346
diff
changeset
|
93 |
RandomVariable(const RandomVariable&); |
7bffd987426c
Fixed major memory bug and docs in RandomVariable
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
346
diff
changeset
|
94 |
|
7bffd987426c
Fixed major memory bug and docs in RandomVariable
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
346
diff
changeset
|
95 |
/** |
346
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
96 |
* \brief Destructor for a random number generator with a random seed. |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
97 |
*/ |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
98 |
virtual ~RandomVariable(); |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
99 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
100 |
/** |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
101 |
* \brief Returns a random double from the underlying distribution |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
102 |
* \return A floating point random value |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
103 |
*/ |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
104 |
virtual double GetValue() = 0; |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
105 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
106 |
/** |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
107 |
* \brief Returns a random integer integer from the underlying distribution |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
108 |
* \return Integer cast of ::GetValue() |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
109 |
*/ |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
110 |
virtual uint32_t GetIntValue(); |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
111 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
112 |
/** |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
113 |
* \return A copy of this object |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
114 |
*/ |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
115 |
virtual RandomVariable* Copy() const = 0; |
364
9df87117d468
RandomVariable API in line with Michelle's comments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
360
diff
changeset
|
116 |
|
346
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
117 |
/** |
364
9df87117d468
RandomVariable API in line with Michelle's comments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
360
diff
changeset
|
118 |
* \brief Get the internal state of the RNG |
9df87117d468
RandomVariable API in line with Michelle's comments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
360
diff
changeset
|
119 |
* |
9df87117d468
RandomVariable API in line with Michelle's comments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
360
diff
changeset
|
120 |
* This function is for power users who understand the inner workings |
9df87117d468
RandomVariable API in line with Michelle's comments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
360
diff
changeset
|
121 |
* of the underlying RngStream method used. It returns the internal |
9df87117d468
RandomVariable API in line with Michelle's comments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
360
diff
changeset
|
122 |
* state of the RNG via the input parameter. |
9df87117d468
RandomVariable API in line with Michelle's comments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
360
diff
changeset
|
123 |
* \param seed Output parameter; gets overwritten with the internal state of |
9df87117d468
RandomVariable API in line with Michelle's comments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
360
diff
changeset
|
124 |
* of the RNG. |
346
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
125 |
*/ |
364
9df87117d468
RandomVariable API in line with Michelle's comments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
360
diff
changeset
|
126 |
virtual void GetSeed(uint32_t seed[6]); |
346
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
127 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
128 |
/** |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
129 |
* \brief Set seeding behavior |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
130 |
* |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
131 |
* Specify whether the POSIX device /dev/random is to |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
132 |
* be used for seeding. When this is used, the underlying |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
133 |
* generator is seeded with data from /dev/random instead of |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
134 |
* being seeded based upon the time of day. For this to be effective, |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
135 |
* it must be called before the creation of the first instance of a |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
136 |
* RandomVariable or subclass. Example: |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
137 |
* \code |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
138 |
* RandomVariable::UseDevRandom(); |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
139 |
* UniformVariable x(2,3); //these are seeded randomly |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
140 |
* ExponentialVariable y(120); //etc |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
141 |
* \endcode |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
142 |
* \param udr True if /dev/random desired. |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
143 |
*/ |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
144 |
static void UseDevRandom(bool udr = true); |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
145 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
146 |
/** |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
147 |
* \brief Use the global seed to force precisely reproducible results. |
360
7bffd987426c
Fixed major memory bug and docs in RandomVariable
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
346
diff
changeset
|
148 |
* |
346
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
149 |
* It is often desirable to create a simulation that uses random |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
150 |
* numbers, while at the same time is completely reproducible. |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
151 |
* Specifying this set of six random seeds initializes the |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
152 |
* random number generator with the specified seed. |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
153 |
* Once this is set, all generators will produce fixed output |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
154 |
* from run to run. This is because each time a new generator is created, |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
155 |
* the underlying RngStream deterministically creates a new seed based upon |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
156 |
* the old one, hence a "stream" of RNGs. Example: |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
157 |
* \code |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
158 |
* RandomVariable::UseGlobalSeed(...); |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
159 |
* UniformVariable x(2,3); //these will give the same output everytime |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
160 |
* ExponentialVariable y(120); //as long as the seed stays the same |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
161 |
* \endcode |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
162 |
* \param s |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
163 |
* \return True if seed is valid. |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
164 |
*/ |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
165 |
static void UseGlobalSeed(const Seed& s); |
364
9df87117d468
RandomVariable API in line with Michelle's comments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
360
diff
changeset
|
166 |
|
9df87117d468
RandomVariable API in line with Michelle's comments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
360
diff
changeset
|
167 |
/** |
9df87117d468
RandomVariable API in line with Michelle's comments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
360
diff
changeset
|
168 |
* \brief Set the run number of this simulation |
9df87117d468
RandomVariable API in line with Michelle's comments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
360
diff
changeset
|
169 |
* |
9df87117d468
RandomVariable API in line with Michelle's comments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
360
diff
changeset
|
170 |
* These RNGs have the ability to give independent sets of trials for a fixed |
9df87117d468
RandomVariable API in line with Michelle's comments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
360
diff
changeset
|
171 |
* global seed. For example, suppose one sets up a simulation with |
9df87117d468
RandomVariable API in line with Michelle's comments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
360
diff
changeset
|
172 |
* RandomVariables with a given global seed. Suppose the user wanted to |
9df87117d468
RandomVariable API in line with Michelle's comments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
360
diff
changeset
|
173 |
* retry the same simulation with different random values for validity, |
9df87117d468
RandomVariable API in line with Michelle's comments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
360
diff
changeset
|
174 |
* statistical rigor, etc. The user could either change the global seed and |
9df87117d468
RandomVariable API in line with Michelle's comments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
360
diff
changeset
|
175 |
* re-run the simulation, or could use this facility to increment all of the |
9df87117d468
RandomVariable API in line with Michelle's comments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
360
diff
changeset
|
176 |
* RNGs to a next substream state. This predictably advances the internal |
9df87117d468
RandomVariable API in line with Michelle's comments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
360
diff
changeset
|
177 |
* state of all RandomVariables n steps. This should be called immediately |
9df87117d468
RandomVariable API in line with Michelle's comments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
360
diff
changeset
|
178 |
* after the global seed is set, and before the creation of any |
9df87117d468
RandomVariable API in line with Michelle's comments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
360
diff
changeset
|
179 |
* RandomVariables. For example: |
9df87117d468
RandomVariable API in line with Michelle's comments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
360
diff
changeset
|
180 |
* \code |
9df87117d468
RandomVariable API in line with Michelle's comments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
360
diff
changeset
|
181 |
* RandomVariable::UseGlobalSeed(ConstantSeed(1,2,3,4,5,6)); |
9df87117d468
RandomVariable API in line with Michelle's comments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
360
diff
changeset
|
182 |
* int N = atol(argv[1]); //read in run number from command line |
9df87117d468
RandomVariable API in line with Michelle's comments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
360
diff
changeset
|
183 |
* RandomVariable::SetRunNumber(N); |
9df87117d468
RandomVariable API in line with Michelle's comments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
360
diff
changeset
|
184 |
* UniformVariable x(0,10); |
9df87117d468
RandomVariable API in line with Michelle's comments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
360
diff
changeset
|
185 |
* ExponentialVariable y(2902); |
9df87117d468
RandomVariable API in line with Michelle's comments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
360
diff
changeset
|
186 |
* \endcode |
9df87117d468
RandomVariable API in line with Michelle's comments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
360
diff
changeset
|
187 |
* In this example, N could successivly be equal to 1,2,3, etc. and the user |
9df87117d468
RandomVariable API in line with Michelle's comments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
360
diff
changeset
|
188 |
* would continue to get independent runs out of the single simulation. For |
9df87117d468
RandomVariable API in line with Michelle's comments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
360
diff
changeset
|
189 |
* this simple example, the following might work: |
9df87117d468
RandomVariable API in line with Michelle's comments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
360
diff
changeset
|
190 |
* \code |
9df87117d468
RandomVariable API in line with Michelle's comments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
360
diff
changeset
|
191 |
* ./simulation 0 |
9df87117d468
RandomVariable API in line with Michelle's comments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
360
diff
changeset
|
192 |
* ...Results for run 0:... |
9df87117d468
RandomVariable API in line with Michelle's comments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
360
diff
changeset
|
193 |
* |
9df87117d468
RandomVariable API in line with Michelle's comments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
360
diff
changeset
|
194 |
* ./simulation 1 |
9df87117d468
RandomVariable API in line with Michelle's comments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
360
diff
changeset
|
195 |
* ...Results for run 1:... |
9df87117d468
RandomVariable API in line with Michelle's comments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
360
diff
changeset
|
196 |
* \endcode |
9df87117d468
RandomVariable API in line with Michelle's comments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
360
diff
changeset
|
197 |
*/ |
9df87117d468
RandomVariable API in line with Michelle's comments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
360
diff
changeset
|
198 |
static void SetRunNumber(uint32_t n); |
346
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
199 |
private: |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
200 |
static void Initialize(); // Initialize the RNG system |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
201 |
static void GetRandomSeeds(uint32_t seeds[6]); |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
202 |
private: |
364
9df87117d468
RandomVariable API in line with Michelle's comments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
360
diff
changeset
|
203 |
static bool initialized; // True if package seed is set |
346
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
204 |
static bool useDevRandom; // True if using /dev/random desired |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
205 |
static bool globalSeedSet; // True if global seed has been specified |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
206 |
static int devRandom; // File handle for /dev/random |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
207 |
static uint32_t globalSeed[6]; // The global seed to use |
364
9df87117d468
RandomVariable API in line with Michelle's comments
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
360
diff
changeset
|
208 |
static uint32_t runNumber; |
346
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
209 |
protected: |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
210 |
static unsigned long heuristic_sequence; |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
211 |
RngStream* m_generator; //underlying generator being wrapped |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
212 |
}; |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
213 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
214 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
215 |
/** |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
216 |
* \brief The uniform distribution RNG for NS-3. |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
217 |
*/ |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
218 |
class UniformVariable : public RandomVariable { |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
219 |
public: |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
220 |
/** |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
221 |
* Creates a uniform random number generator in the |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
222 |
* range [0.0 .. 1.0) |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
223 |
*/ |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
224 |
UniformVariable(); |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
225 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
226 |
/** |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
227 |
* Creates a uniform random number generator with the specified range |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
228 |
* \param s Low end of the range |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
229 |
* \param l High end of the range |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
230 |
*/ |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
231 |
UniformVariable(double s, double l); |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
232 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
233 |
UniformVariable(const UniformVariable& c); |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
234 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
235 |
/** |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
236 |
* \return A value between low and high values specified by the constructor |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
237 |
*/ |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
238 |
virtual double GetValue(); |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
239 |
virtual RandomVariable* Copy() const; |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
240 |
private: |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
241 |
double m_min; |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
242 |
double m_max; |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
243 |
}; |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
244 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
245 |
/** |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
246 |
* \brief A random variable that returns a constant |
360
7bffd987426c
Fixed major memory bug and docs in RandomVariable
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
346
diff
changeset
|
247 |
* |
346
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
248 |
* Class ConstantVariable defines a random number generator that |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
249 |
* returns the same value every sample. |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
250 |
*/ |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
251 |
class ConstantVariable : public RandomVariable { |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
252 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
253 |
public: |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
254 |
/** |
360
7bffd987426c
Fixed major memory bug and docs in RandomVariable
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
346
diff
changeset
|
255 |
* Construct a ConstantVariable RNG that returns zero every sample |
346
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
256 |
*/ |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
257 |
ConstantVariable(); |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
258 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
259 |
/** |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
260 |
* Construct a ConstantVariable RNG that returns the specified value |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
261 |
* every sample. |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
262 |
* \param c Unchanging value for this RNG. |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
263 |
*/ |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
264 |
ConstantVariable(double c); |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
265 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
266 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
267 |
ConstantVariable(const ConstantVariable& c) ; |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
268 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
269 |
/** |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
270 |
* \brief Specify a new constant RNG for this generator. |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
271 |
* \param c New constant value for this RNG. |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
272 |
*/ |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
273 |
void NewConstant(double c); |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
274 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
275 |
/** |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
276 |
* \return The constant value specified |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
277 |
*/ |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
278 |
virtual double GetValue(); |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
279 |
virtual uint32_t GetIntValue(); |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
280 |
virtual RandomVariable* Copy() const; |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
281 |
private: |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
282 |
double m_const; |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
283 |
}; |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
284 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
285 |
/** |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
286 |
* \brief Return a sequential list of values |
360
7bffd987426c
Fixed major memory bug and docs in RandomVariable
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
346
diff
changeset
|
287 |
* |
346
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
288 |
* Class SequentialVariable defines a random number generator that |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
289 |
* returns a sequential sequence. The sequence monotonically |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
290 |
* increases for a period, then wraps around to the low value |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
291 |
* and begins monotonicaly increasing again. |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
292 |
*/ |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
293 |
class SequentialVariable : public RandomVariable { |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
294 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
295 |
public: |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
296 |
/** |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
297 |
* \brief Constructor for the SequentialVariable RNG. |
360
7bffd987426c
Fixed major memory bug and docs in RandomVariable
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
346
diff
changeset
|
298 |
* |
346
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
299 |
* The four parameters define the sequence. For example |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
300 |
* SequentialVariable(0,5,1,2) creates a RNG that has the sequence |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
301 |
* 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 0, 0 ... |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
302 |
* \param f First value of the sequence. |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
303 |
* \param l One more than the last value of the sequence. |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
304 |
* \param i Increment between sequence values |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
305 |
* \param c Number of times each member of the sequence is repeated |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
306 |
*/ |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
307 |
SequentialVariable(double f, double l, double i = 1, uint32_t c = 1); |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
308 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
309 |
/** |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
310 |
* \brief Constructor for the SequentialVariable RNG. |
360
7bffd987426c
Fixed major memory bug and docs in RandomVariable
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
346
diff
changeset
|
311 |
* |
346
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
312 |
* Differs from the first only in that the increment parameter is a |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
313 |
* random variable |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
314 |
* \param f First value of the sequence. |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
315 |
* \param l One more than the last value of the sequence. |
360
7bffd987426c
Fixed major memory bug and docs in RandomVariable
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
346
diff
changeset
|
316 |
* \param i Reference to a RandomVariable for the sequence increment |
346
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
317 |
* \param c Number of times each member of the sequence is repeated |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
318 |
*/ |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
319 |
SequentialVariable(double f, double l, const RandomVariable& i, uint32_t c = 1); |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
320 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
321 |
SequentialVariable(const SequentialVariable& c); |
360
7bffd987426c
Fixed major memory bug and docs in RandomVariable
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
346
diff
changeset
|
322 |
|
7bffd987426c
Fixed major memory bug and docs in RandomVariable
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
346
diff
changeset
|
323 |
~SequentialVariable(); |
346
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
324 |
/** |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
325 |
* \return The next value in the Sequence |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
326 |
*/ |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
327 |
virtual double GetValue(); |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
328 |
virtual RandomVariable* Copy() const; |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
329 |
private: |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
330 |
double m_min; |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
331 |
double m_max; |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
332 |
RandomVariable* m_increment; |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
333 |
uint32_t m_consecutive; |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
334 |
double m_current; |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
335 |
uint32_t m_currentConsecutive; |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
336 |
}; |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
337 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
338 |
/** |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
339 |
* \brief Exponentially Distributed random var |
360
7bffd987426c
Fixed major memory bug and docs in RandomVariable
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
346
diff
changeset
|
340 |
* |
346
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
341 |
* ExponentialVariable defines a random variable with an exponential distribution |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
342 |
*/ |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
343 |
class ExponentialVariable : public RandomVariable { |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
344 |
public: |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
345 |
/** |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
346 |
* Constructs an exponential random variable with a mean |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
347 |
* value of 1.0. |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
348 |
*/ |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
349 |
ExponentialVariable(); |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
350 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
351 |
/** |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
352 |
* \brief Constructs an exponential random variable with a specified mean |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
353 |
* \param m Mean value for the random variable |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
354 |
*/ |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
355 |
explicit ExponentialVariable(double m); |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
356 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
357 |
/** |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
358 |
* \brief Constructs an exponential random variable with spefified |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
359 |
* \brief mean and upper limit. |
360
7bffd987426c
Fixed major memory bug and docs in RandomVariable
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
346
diff
changeset
|
360 |
* |
346
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
361 |
* Since exponential distributions can theoretically return unbounded values, |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
362 |
* it is sometimes useful to specify a fixed upper limit. Note however when |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
363 |
* the upper limit is specified, the true mean of the distribution is |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
364 |
* slightly smaller than the mean value specified. |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
365 |
* \param m Mean value of the random variable |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
366 |
* \param b Upper bound on returned values |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
367 |
*/ |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
368 |
ExponentialVariable(double m, double b); |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
369 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
370 |
ExponentialVariable(const ExponentialVariable& c); |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
371 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
372 |
/** |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
373 |
* \return A random value from this exponential distribution |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
374 |
*/ |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
375 |
virtual double GetValue(); |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
376 |
virtual RandomVariable* Copy() const; |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
377 |
private: |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
378 |
double m_mean; // Mean value of RV |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
379 |
double m_bound; // Upper bound on value (if non-zero) |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
380 |
}; |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
381 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
382 |
/** |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
383 |
* \brief ParetoVariable distributed random var |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
384 |
*/ |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
385 |
class ParetoVariable : public RandomVariable { // |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
386 |
public: |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
387 |
/** |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
388 |
* Constructs a pareto random variable with a mean of 1 and a shape |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
389 |
* parameter of 1.5 |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
390 |
*/ |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
391 |
ParetoVariable(); |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
392 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
393 |
/** |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
394 |
* Constructs a pareto random variable with specified mean and shape |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
395 |
* parameter of 1.5 |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
396 |
* \param m Mean value of the distribution |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
397 |
*/ |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
398 |
explicit ParetoVariable(double m); |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
399 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
400 |
/** |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
401 |
* Constructs a pareto random variable with the specified mean value and |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
402 |
* shape parameter. |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
403 |
* \param m Mean value of the distribution |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
404 |
* \param s Shape parameter for the distribution |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
405 |
*/ |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
406 |
ParetoVariable(double m, double s); |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
407 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
408 |
/** |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
409 |
* \brief Constructs a pareto random variable with the specified mean |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
410 |
* \brief value, shape (alpha), and upper bound. |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
411 |
* Since pareto distributions can theoretically return unbounded values, |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
412 |
* it is sometimes useful to specify a fixed upper limit. Note however |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
413 |
* when the upper limit is specified, the true mean of the distribution |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
414 |
* is slightly smaller than the mean value specified. |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
415 |
* \param m Mean value |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
416 |
* \param s Shape parameter |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
417 |
* \param b Upper limit on returned values |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
418 |
*/ |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
419 |
ParetoVariable(double m, double s, double b); |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
420 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
421 |
ParetoVariable(const ParetoVariable& c); |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
422 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
423 |
/** |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
424 |
* \return A random value from this Pareto distribution |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
425 |
*/ |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
426 |
virtual double GetValue(); |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
427 |
virtual RandomVariable* Copy() const; |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
428 |
private: |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
429 |
double m_mean; // Mean value of RV |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
430 |
double m_shape; // Shape parameter |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
431 |
double m_bound; // Upper bound on value (if non-zero) |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
432 |
}; |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
433 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
434 |
/** |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
435 |
* \brief WeibullVariable distributed random var |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
436 |
*/ |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
437 |
class WeibullVariable : public RandomVariable { |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
438 |
public: |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
439 |
/** |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
440 |
* Constructs a weibull random variable with a mean |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
441 |
* value of 1.0 and a shape (alpha) parameter of 1 |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
442 |
*/ |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
443 |
WeibullVariable(); |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
444 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
445 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
446 |
/** |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
447 |
* Constructs a weibull random variable with the specified mean |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
448 |
* value and a shape (alpha) parameter of 1.5. |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
449 |
* \param m mean value of the distribution |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
450 |
*/ |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
451 |
WeibullVariable(double m) ; |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
452 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
453 |
/** |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
454 |
* Constructs a weibull random variable with the specified mean |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
455 |
* value and a shape (alpha). |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
456 |
* \param m Mean value for the distribution. |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
457 |
* \param s Shape (alpha) parameter for the distribution. |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
458 |
*/ |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
459 |
WeibullVariable(double m, double s); |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
460 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
461 |
/** |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
462 |
* \brief Constructs a weibull random variable with the specified mean |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
463 |
* \brief value, shape (alpha), and upper bound. |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
464 |
* Since WeibullVariable distributions can theoretically return unbounded values, |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
465 |
* it is sometimes usefull to specify a fixed upper limit. Note however |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
466 |
* that when the upper limit is specified, the true mean of the distribution |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
467 |
* is slightly smaller than the mean value specified. |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
468 |
* \param m Mean value for the distribution. |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
469 |
* \param s Shape (alpha) parameter for the distribution. |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
470 |
* \param b Upper limit on returned values |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
471 |
*/ |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
472 |
WeibullVariable(double m, double s, double b); |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
473 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
474 |
WeibullVariable(const WeibullVariable& c); |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
475 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
476 |
/** |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
477 |
* \return A random value from this Weibull distribution |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
478 |
*/ |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
479 |
virtual double GetValue(); |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
480 |
virtual RandomVariable* Copy() const; |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
481 |
private: |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
482 |
double m_mean; // Mean value of RV |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
483 |
double m_alpha; // Shape parameter |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
484 |
double m_bound; // Upper bound on value (if non-zero) |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
485 |
}; |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
486 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
487 |
/** |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
488 |
* Class NormalVariable defines a random variable with a |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
489 |
* normal (Gaussian) distribution. |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
490 |
*/ |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
491 |
class NormalVariable : public RandomVariable { // Normally Distributed random var |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
492 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
493 |
public: |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
494 |
/** |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
495 |
* Constructs an normal random variable with a mean |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
496 |
* value of 0 and variance of 1. |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
497 |
*/ |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
498 |
NormalVariable(); |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
499 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
500 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
501 |
/** |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
502 |
* \brief Construct a normal random variable with specified mean and variance |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
503 |
* \param m Mean value |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
504 |
* \param v Variance |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
505 |
* \param b Bound. The NormalVariable is bounded within +-bound. |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
506 |
*/ |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
507 |
NormalVariable(double m, double v, double b = INFINITE_VALUE); |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
508 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
509 |
NormalVariable(const NormalVariable& c); |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
510 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
511 |
/** |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
512 |
* \return A value from this normal distribution |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
513 |
*/ |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
514 |
virtual double GetValue(); |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
515 |
virtual RandomVariable* Copy() const; |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
516 |
private: |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
517 |
double m_mean; // Mean value of RV |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
518 |
double m_variance; // Mean value of RV |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
519 |
double m_bound; // Bound on value (absolute value) |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
520 |
bool m_nextValid; // True if next valid |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
521 |
double m_next; // The algorithm produces two values at a time |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
522 |
}; |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
523 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
524 |
// Value/CDF pair class for Emiprical Distributions |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
525 |
//Doc:ClassXRef |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
526 |
class ValueCDF { |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
527 |
public: |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
528 |
ValueCDF(); |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
529 |
ValueCDF(double v, double c); |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
530 |
ValueCDF(const ValueCDF& c); |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
531 |
double value; |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
532 |
double cdf; |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
533 |
}; |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
534 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
535 |
/** |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
536 |
* \brief EmpiricalVariable distribution random var |
360
7bffd987426c
Fixed major memory bug and docs in RandomVariable
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
346
diff
changeset
|
537 |
* |
346
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
538 |
* Defines a random variable that has a specified, empirical |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
539 |
* distribution. The distribution is specified by a |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
540 |
* series of calls the the CDF member function, specifying a |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
541 |
* value and the probability that the function value is less than |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
542 |
* the specified value. When values are requested, |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
543 |
* a uniform random variable is used to select a probabililty, |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
544 |
* and the return value is interpreted linerarly between the |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
545 |
* two appropriate points in the CDF |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
546 |
*/ |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
547 |
class EmpiricalVariable : public RandomVariable { |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
548 |
public: |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
549 |
/** |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
550 |
* Constructor for the EmpiricalVariable random variables. |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
551 |
*/ |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
552 |
explicit EmpiricalVariable(); |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
553 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
554 |
virtual ~EmpiricalVariable(); |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
555 |
EmpiricalVariable(const EmpiricalVariable& c); |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
556 |
/** |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
557 |
* \return A value from this empirical distribution |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
558 |
*/ |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
559 |
virtual double GetValue(); |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
560 |
virtual RandomVariable* Copy() const; |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
561 |
/** |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
562 |
* \brief Specifies a point in the empirical distribution |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
563 |
* \param v The function value for this point |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
564 |
* \param c Probability that the function is less than or equal to v |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
565 |
*/ |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
566 |
virtual void CDF(double v, double c); // Value, prob <= Value |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
567 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
568 |
private: |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
569 |
virtual void Validate(); // Insure non-decreasing emiprical values |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
570 |
virtual double Interpolate(double, double, double, double, double); |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
571 |
bool validated; // True if non-decreasing validated |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
572 |
std::vector<ValueCDF> emp; // Empicical CDF |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
573 |
}; |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
574 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
575 |
/** |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
576 |
* Defines an empirical distribution where all values are integers. |
360
7bffd987426c
Fixed major memory bug and docs in RandomVariable
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
346
diff
changeset
|
577 |
* Indentical to EmpiricalVariable, but with slightly different |
346
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
578 |
* interpolation between points. |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
579 |
*/ |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
580 |
class IntEmpiricalVariable : public EmpiricalVariable { |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
581 |
public: |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
582 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
583 |
IntEmpiricalVariable(); |
360
7bffd987426c
Fixed major memory bug and docs in RandomVariable
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
346
diff
changeset
|
584 |
|
346
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
585 |
virtual RandomVariable* Copy() const; |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
586 |
/** |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
587 |
* \return An integer value from this empirical distribution |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
588 |
*/ |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
589 |
virtual uint32_t GetIntValue(); |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
590 |
virtual double Interpolate(double, double, double, double, double); |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
591 |
}; |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
592 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
593 |
/** |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
594 |
* Defines a random variable that has a specified, predetermined |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
595 |
* sequence. This would be useful when trying to force |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
596 |
* the RNG to return a known sequence, perhaps to |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
597 |
* compare NS-3 to some other simulator |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
598 |
*/ |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
599 |
class DeterministicVariable : public RandomVariable { |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
600 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
601 |
public: |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
602 |
/** |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
603 |
* \brief Constructor |
360
7bffd987426c
Fixed major memory bug and docs in RandomVariable
Raj Bhattacharjea <raj.b@gatech.edu>
parents:
346
diff
changeset
|
604 |
* |
346
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
605 |
* Creates a generator that returns successive elements of the d array |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
606 |
* on successive calls to ::Value(). Note that the d pointer is copied |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
607 |
* for use by the generator (shallow-copy), not its contents, so the |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
608 |
* contents of the array d points to have to remain unchanged for the use |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
609 |
* of DeterministicVariable to be meaningful. |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
610 |
* \param d Pointer to array of random values to return in sequence |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
611 |
* \param c Number of values in the array |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
612 |
*/ |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
613 |
explicit DeterministicVariable(double* d, uint32_t c); |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
614 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
615 |
virtual ~DeterministicVariable(); |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
616 |
/** |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
617 |
* \return The next value in the deterministic sequence |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
618 |
*/ |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
619 |
virtual double GetValue(); |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
620 |
virtual RandomVariable* Copy() const; |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
621 |
private: |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
622 |
uint32_t count; |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
623 |
uint32_t next; |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
624 |
double* data; |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
625 |
}; |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
626 |
|
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
627 |
}//namespace ns3 |
4a76f247e7dc
Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff
changeset
|
628 |
#endif |