A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
random-variable-stream.h
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2006 Georgia Tech Research Corporation
4
* Copyright (c) 2011 Mathieu Lacage
5
*
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License version 2 as
8
* published by the Free Software Foundation;
9
*
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
14
*
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
*
19
* Authors: Rajib Bhattacharjea<raj.b@gatech.edu>
20
* Hadi Arbabi<marbabi@cs.odu.edu>
21
* Mathieu Lacage <mathieu.lacage@gmail.com>
22
*
23
* Modified by Mitch Watrous <watrous@u.washington.edu>
24
*
25
*/
26
#ifndef RANDOM_VARIABLE_STREAM_H
27
#define RANDOM_VARIABLE_STREAM_H
28
29
#include "
type-id.h
"
30
#include "
object.h
"
31
#include "
attribute-helper.h
"
32
#include <stdint.h>
33
34
namespace
ns3 {
35
66
class
RngStream;
67
87
class
RandomVariableStream
:
public
Object
88
{
89
public
:
90
static
TypeId
GetTypeId
(
void
);
91
RandomVariableStream
();
92
virtual
~RandomVariableStream
();
93
98
void
SetStream
(int64_t stream);
99
104
int64_t
GetStream
(
void
)
const
;
105
111
void
SetAntithetic
(
bool
isAntithetic);
112
118
bool
IsAntithetic
(
void
)
const
;
119
124
virtual
double
GetValue
(
void
) = 0;
125
130
virtual
uint32_t
GetInteger
(
void
) = 0;
131
132
protected
:
136
RngStream
*
Peek
(
void
)
const
;
137
138
private
:
139
// you can't copy these objects.
140
// Theoretically, it is possible to give them good copy semantics
141
// but not enough time to iron out the details.
142
RandomVariableStream
(
const
RandomVariableStream
&o);
143
RandomVariableStream
&
operator =
(
const
RandomVariableStream
&o);
144
146
RngStream
*
m_rng
;
147
149
bool
m_isAntithetic
;
150
152
int64_t
m_stream
;
153
};
154
183
class
UniformRandomVariable
:
public
RandomVariableStream
184
{
185
public
:
186
static
TypeId
GetTypeId
(
void
);
187
191
UniformRandomVariable
();
192
197
double
GetMin
(
void
)
const
;
198
203
double
GetMax
(
void
)
const
;
204
224
double
GetValue
(
double
min,
double
max);
225
245
uint32_t
GetInteger
(uint32_t min, uint32_t max);
246
269
virtual
double
GetValue
(
void
);
270
288
virtual
uint32_t
GetInteger
(
void
);
289
private
:
291
double
m_min
;
292
294
double
m_max
;
295
};
296
303
class
ConstantRandomVariable
:
public
RandomVariableStream
304
{
305
public
:
306
static
TypeId
GetTypeId
(
void
);
307
311
ConstantRandomVariable
();
312
317
double
GetConstant
(
void
)
const
;
318
323
double
GetValue
(
double
constant);
328
uint32_t
GetInteger
(uint32_t constant);
329
334
virtual
double
GetValue
(
void
);
335
340
virtual
uint32_t
GetInteger
(
void
);
341
342
private
:
344
double
m_constant
;
345
};
346
357
class
SequentialRandomVariable
:
public
RandomVariableStream
358
{
359
public
:
360
static
TypeId
GetTypeId
(
void
);
361
365
SequentialRandomVariable
();
366
371
double
GetMin
(
void
)
const
;
372
377
double
GetMax
(
void
)
const
;
378
383
Ptr<RandomVariableStream>
GetIncrement
(
void
)
const
;
384
389
uint32_t
GetConsecutive
(
void
)
const
;
390
404
virtual
double
GetValue
(
void
);
405
410
virtual
uint32_t
GetInteger
(
void
);
411
412
private
:
414
double
m_min
;
415
417
double
m_max
;
418
420
Ptr<RandomVariableStream>
m_increment
;
421
423
uint32_t
m_consecutive
;
424
426
double
m_current
;
427
429
uint32_t
m_currentConsecutive
;
430
432
bool
m_isCurrentSet
;
433
434
};
435
470
class
ExponentialRandomVariable
:
public
RandomVariableStream
471
{
472
public
:
473
static
TypeId
GetTypeId
(
void
);
474
479
ExponentialRandomVariable
();
480
485
double
GetMean
(
void
)
const
;
486
491
double
GetBound
(
void
)
const
;
492
517
double
GetValue
(
double
mean,
double
bound);
518
543
uint32_t
GetInteger
(uint32_t mean, uint32_t bound);
544
572
virtual
double
GetValue
(
void
);
573
596
virtual
uint32_t
GetInteger
(
void
);
597
598
private
:
600
double
m_mean
;
601
603
double
m_bound
;
604
};
605
650
class
ParetoRandomVariable
:
public
RandomVariableStream
651
{
652
public
:
653
static
TypeId
GetTypeId
(
void
);
654
659
ParetoRandomVariable
();
660
665
double
GetMean
(
void
)
const
;
666
671
double
GetShape
(
void
)
const
;
672
677
double
GetBound
(
void
)
const
;
678
710
double
GetValue
(
double
mean,
double
shape,
double
bound);
711
743
uint32_t
GetInteger
(uint32_t mean, uint32_t shape, uint32_t bound);
744
778
virtual
double
GetValue
(
void
);
779
808
virtual
uint32_t
GetInteger
(
void
);
809
810
private
:
812
double
m_mean
;
813
815
double
m_shape
;
816
818
double
m_bound
;
819
};
820
874
class
WeibullRandomVariable
:
public
RandomVariableStream
875
{
876
public
:
877
static
TypeId
GetTypeId
(
void
);
878
883
WeibullRandomVariable
();
884
889
double
GetScale
(
void
)
const
;
890
895
double
GetShape
(
void
)
const
;
896
901
double
GetBound
(
void
)
const
;
902
928
double
GetValue
(
double
scale,
double
shape,
double
bound);
929
955
uint32_t
GetInteger
(uint32_t scale, uint32_t shape, uint32_t bound);
956
984
virtual
double
GetValue
(
void
);
985
1008
virtual
uint32_t
GetInteger
(
void
);
1009
1010
private
:
1012
double
m_scale
;
1013
1015
double
m_shape
;
1016
1018
double
m_bound
;
1019
};
1020
1054
class
NormalRandomVariable
:
public
RandomVariableStream
1055
{
1056
public
:
1057
static
const
double
INFINITE_VALUE
;
1058
1059
static
TypeId
GetTypeId
(
void
);
1060
1065
NormalRandomVariable
();
1066
1071
double
GetMean
(
void
)
const
;
1072
1077
double
GetVariance
(
void
)
const
;
1078
1083
double
GetBound
(
void
)
const
;
1084
1121
double
GetValue
(
double
mean,
double
variance,
double
bound =
NormalRandomVariable::INFINITE_VALUE
);
1122
1159
uint32_t
GetInteger
(uint32_t mean, uint32_t variance, uint32_t bound);
1160
1199
virtual
double
GetValue
(
void
);
1200
1234
virtual
uint32_t
GetInteger
(
void
);
1235
1236
private
:
1238
double
m_mean
;
1239
1241
double
m_variance
;
1242
1244
double
m_bound
;
1245
1247
bool
m_nextValid
;
1248
1250
double
m_next
;
1251
};
1252
1296
class
LogNormalRandomVariable
:
public
RandomVariableStream
1297
{
1298
public
:
1299
static
TypeId
GetTypeId
(
void
);
1300
1305
LogNormalRandomVariable
();
1306
1311
double
GetMu
(
void
)
const
;
1312
1317
double
GetSigma
(
void
)
const
;
1318
1352
double
GetValue
(
double
mu,
double
sigma);
1353
1387
uint32_t
GetInteger
(uint32_t mu, uint32_t sigma);
1388
1425
virtual
double
GetValue
(
void
);
1426
1458
virtual
uint32_t
GetInteger
(
void
);
1459
1460
private
:
1462
double
m_mu
;
1463
1465
double
m_sigma
;
1466
};
1467
1499
class
GammaRandomVariable
:
public
RandomVariableStream
1500
{
1501
public
:
1502
static
TypeId
GetTypeId
(
void
);
1503
1508
GammaRandomVariable
();
1509
1514
double
GetAlpha
(
void
)
const
;
1515
1520
double
GetBeta
(
void
)
const
;
1521
1535
double
GetValue
(
double
alpha,
double
beta);
1536
1550
uint32_t
GetInteger
(uint32_t alpha, uint32_t beta);
1551
1568
virtual
double
GetValue
(
void
);
1569
1581
virtual
uint32_t
GetInteger
(
void
);
1582
1583
private
:
1620
double
GetNormalValue
(
double
mean,
double
variance,
double
bound);
1621
1623
double
m_alpha
;
1624
1626
double
m_beta
;
1627
1629
bool
m_nextValid
;
1630
1632
double
m_next
;
1633
1634
};
1635
1671
class
ErlangRandomVariable
:
public
RandomVariableStream
1672
{
1673
public
:
1674
static
TypeId
GetTypeId
(
void
);
1675
1680
ErlangRandomVariable
();
1681
1686
uint32_t
GetK
(
void
)
const
;
1687
1692
double
GetLambda
(
void
)
const
;
1693
1707
double
GetValue
(uint32_t k,
double
lambda);
1708
1722
uint32_t
GetInteger
(uint32_t k, uint32_t lambda);
1723
1740
virtual
double
GetValue
(
void
);
1741
1753
virtual
uint32_t
GetInteger
(
void
);
1754
1755
private
:
1780
double
GetExponentialValue
(
double
mean,
double
bound);
1781
1783
uint32_t
m_k
;
1784
1786
double
m_lambda
;
1787
1788
};
1789
1818
class
TriangularRandomVariable
:
public
RandomVariableStream
1819
{
1820
public
:
1821
static
TypeId
GetTypeId
(
void
);
1822
1827
TriangularRandomVariable
();
1828
1833
double
GetMean
(
void
)
const
;
1834
1839
double
GetMin
(
void
)
const
;
1840
1845
double
GetMax
(
void
)
const
;
1846
1885
double
GetValue
(
double
mean,
double
min,
double
max);
1886
1925
uint32_t
GetInteger
(uint32_t mean, uint32_t min, uint32_t max);
1926
1967
virtual
double
GetValue
(
void
);
1968
2004
virtual
uint32_t
GetInteger
(
void
);
2005
2006
private
:
2008
double
m_mean
;
2009
2011
double
m_min
;
2012
2014
double
m_max
;
2015
2018
double
m_mode
;
2019
};
2020
2079
class
ZipfRandomVariable
:
public
RandomVariableStream
2080
{
2081
public
:
2082
static
TypeId
GetTypeId
(
void
);
2083
2088
ZipfRandomVariable
();
2089
2094
uint32_t
GetN
(
void
)
const
;
2095
2100
double
GetAlpha
(
void
)
const
;
2101
2115
double
GetValue
(uint32_t n,
double
alpha);
2116
2130
uint32_t
GetInteger
(uint32_t n, uint32_t alpha);
2131
2148
virtual
double
GetValue
(
void
);
2149
2161
virtual
uint32_t
GetInteger
(
void
);
2162
2163
private
:
2165
uint32_t
m_n
;
2166
2168
double
m_alpha
;
2169
2171
double
m_c
;
2172
};
2173
2213
class
ZetaRandomVariable
:
public
RandomVariableStream
2214
{
2215
public
:
2216
static
TypeId
GetTypeId
(
void
);
2217
2222
ZetaRandomVariable
();
2223
2228
double
GetAlpha
(
void
)
const
;
2229
2242
double
GetValue
(
double
alpha);
2243
2256
uint32_t
GetInteger
(uint32_t alpha);
2257
2274
virtual
double
GetValue
(
void
);
2275
2287
virtual
uint32_t
GetInteger
(
void
);
2288
2289
private
:
2291
double
m_alpha
;
2292
2294
double
m_b
;
2295
};
2296
2327
class
DeterministicRandomVariable
:
public
RandomVariableStream
2328
{
2329
public
:
2330
static
TypeId
GetTypeId
(
void
);
2331
2336
DeterministicRandomVariable
();
2337
virtual
~DeterministicRandomVariable
();
2338
2347
void
SetValueArray
(
double
* values, uint64_t length);
2348
2353
virtual
double
GetValue
(
void
);
2354
2359
virtual
uint32_t
GetInteger
(
void
);
2360
2361
private
:
2363
uint64_t
m_count
;
2364
2366
uint64_t
m_next
;
2367
2369
double
*
m_data
;
2370
};
2371
2403
class
EmpiricalRandomVariable
:
public
RandomVariableStream
2404
{
2405
public
:
2406
static
TypeId
GetTypeId
(
void
);
2407
2412
EmpiricalRandomVariable
();
2413
2419
void
CDF
(
double
v,
double
c);
// Value, prob <= Value
2420
2432
virtual
double
GetValue
(
void
);
2433
2445
virtual
uint32_t
GetInteger
(
void
);
2446
2447
private
:
2448
class
ValueCDF
2449
{
2450
public
:
2451
ValueCDF
();
2452
ValueCDF
(
double
v,
double
c);
2453
ValueCDF
(
const
ValueCDF
& c);
2454
double
value
;
2455
double
cdf
;
2456
};
2457
virtual
void
Validate
();
// Insure non-decreasing emiprical values
2458
virtual
double
Interpolate
(
double
,
double
,
double
,
double
,
double
);
2459
bool
validated
;
// True if non-decreasing validated
2460
std::vector<ValueCDF>
emp
;
// Empicical CDF
2461
};
2462
2463
}
// namespace ns3
2464
2465
#endif
/* RANDOM_VARIABLE_STREAM_H */
src
core
model
random-variable-stream.h
Generated on Fri Aug 30 2013 01:42:47 for ns-3 by
1.8.1.2