A Discrete-Event Network Simulator
API
 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 
36 class RngStream;
37 
58 {
59 public:
60  static TypeId GetTypeId (void);
62  virtual ~RandomVariableStream();
63 
68  void SetStream (int64_t stream);
69 
74  int64_t GetStream(void) const;
75 
81  void SetAntithetic(bool isAntithetic);
82 
88  bool IsAntithetic(void) const;
89 
94  virtual double GetValue (void) = 0;
95 
100  virtual uint32_t GetInteger (void) = 0;
101 
102 protected:
106  RngStream *Peek(void) const;
107 
108 private:
109  // you can't copy these objects.
110  // Theoretically, it is possible to give them good copy semantics
111  // but not enough time to iron out the details.
114 
117 
120 
122  int64_t m_stream;
123 };
124 
154 {
155 public:
156  static TypeId GetTypeId (void);
157 
162 
167  double GetMin (void) const;
168 
173  double GetMax (void) const;
174 
194  double GetValue (double min, double max);
195 
215  uint32_t GetInteger (uint32_t min, uint32_t max);
216 
239  virtual double GetValue (void);
240 
258  virtual uint32_t GetInteger (void);
259 private:
261  double m_min;
262 
264  double m_max;
265 };
266 
274 {
275 public:
276  static TypeId GetTypeId (void);
277 
282 
287  double GetConstant (void) const;
288 
293  double GetValue (double constant);
298  uint32_t GetInteger (uint32_t constant);
299 
304  virtual double GetValue (void);
305 
310  virtual uint32_t GetInteger (void);
311 
312 private:
314  double m_constant;
315 };
316 
328 {
329 public:
330  static TypeId GetTypeId (void);
331 
336 
341  double GetMin (void) const;
342 
347  double GetMax (void) const;
348 
354 
359  uint32_t GetConsecutive (void) const;
360 
374  virtual double GetValue (void);
375 
380  virtual uint32_t GetInteger (void);
381 
382 private:
384  double m_min;
385 
387  double m_max;
388 
391 
393  uint32_t m_consecutive;
394 
396  double m_current;
397 
400 
403 
404 };
405 
441 {
442 public:
443  static TypeId GetTypeId (void);
444 
450 
455  double GetMean (void) const;
456 
461  double GetBound (void) const;
462 
487  double GetValue (double mean, double bound);
488 
513  uint32_t GetInteger (uint32_t mean, uint32_t bound);
514 
542  virtual double GetValue (void);
543 
566  virtual uint32_t GetInteger (void);
567 
568 private:
570  double m_mean;
571 
573  double m_bound;
574 };
575 
621 {
622 public:
623  static TypeId GetTypeId (void);
624 
630 
635  double GetMean (void) const;
636 
641  double GetShape (void) const;
642 
647  double GetBound (void) const;
648 
680  double GetValue (double mean, double shape, double bound);
681 
713  uint32_t GetInteger (uint32_t mean, uint32_t shape, uint32_t bound);
714 
748  virtual double GetValue (void);
749 
778  virtual uint32_t GetInteger (void);
779 
780 private:
782  double m_mean;
783 
785  double m_shape;
786 
788  double m_bound;
789 };
790 
845 {
846 public:
847  static TypeId GetTypeId (void);
848 
854 
859  double GetScale (void) const;
860 
865  double GetShape (void) const;
866 
871  double GetBound (void) const;
872 
898  double GetValue (double scale, double shape, double bound);
899 
925  uint32_t GetInteger (uint32_t scale, uint32_t shape, uint32_t bound);
926 
954  virtual double GetValue (void);
955 
978  virtual uint32_t GetInteger (void);
979 
980 private:
982  double m_scale;
983 
985  double m_shape;
986 
988  double m_bound;
989 };
990 
1025 {
1026 public:
1027  static const double INFINITE_VALUE;
1028 
1029  static TypeId GetTypeId (void);
1030 
1036 
1041  double GetMean (void) const;
1042 
1047  double GetVariance (void) const;
1048 
1053  double GetBound (void) const;
1054 
1091  double GetValue (double mean, double variance, double bound = NormalRandomVariable::INFINITE_VALUE);
1092 
1129  uint32_t GetInteger (uint32_t mean, uint32_t variance, uint32_t bound);
1130 
1169  virtual double GetValue (void);
1170 
1204  virtual uint32_t GetInteger (void);
1205 
1206 private:
1208  double m_mean;
1209 
1211  double m_variance;
1212 
1214  double m_bound;
1215 
1218 
1220  double m_next;
1221 };
1222 
1267 {
1268 public:
1269  static TypeId GetTypeId (void);
1270 
1276 
1281  double GetMu (void) const;
1282 
1287  double GetSigma (void) const;
1288 
1322  double GetValue (double mu, double sigma);
1323 
1357  uint32_t GetInteger (uint32_t mu, uint32_t sigma);
1358 
1395  virtual double GetValue (void);
1396 
1428  virtual uint32_t GetInteger (void);
1429 
1430 private:
1432  double m_mu;
1433 
1435  double m_sigma;
1436 };
1437 
1470 {
1471 public:
1472  static TypeId GetTypeId (void);
1473 
1479 
1484  double GetAlpha (void) const;
1485 
1490  double GetBeta (void) const;
1491 
1505  double GetValue (double alpha, double beta);
1506 
1520  uint32_t GetInteger (uint32_t alpha, uint32_t beta);
1521 
1538  virtual double GetValue (void);
1539 
1551  virtual uint32_t GetInteger (void);
1552 
1553 private:
1590  double GetNormalValue (double mean, double variance, double bound);
1591 
1593  double m_alpha;
1594 
1596  double m_beta;
1597 
1600 
1602  double m_next;
1603 
1604 };
1605 
1642 {
1643 public:
1644  static TypeId GetTypeId (void);
1645 
1651 
1656  uint32_t GetK (void) const;
1657 
1662  double GetLambda (void) const;
1663 
1677  double GetValue (uint32_t k, double lambda);
1678 
1692  uint32_t GetInteger (uint32_t k, uint32_t lambda);
1693 
1710  virtual double GetValue (void);
1711 
1723  virtual uint32_t GetInteger (void);
1724 
1725 private:
1750  double GetExponentialValue (double mean, double bound);
1751 
1753  uint32_t m_k;
1754 
1756  double m_lambda;
1757 
1758 };
1759 
1789 {
1790 public:
1791  static TypeId GetTypeId (void);
1792 
1798 
1803  double GetMean (void) const;
1804 
1809  double GetMin (void) const;
1810 
1815  double GetMax (void) const;
1816 
1855  double GetValue (double mean, double min, double max);
1856 
1895  uint32_t GetInteger (uint32_t mean, uint32_t min, uint32_t max);
1896 
1937  virtual double GetValue (void);
1938 
1974  virtual uint32_t GetInteger (void);
1975 
1976 private:
1978  double m_mean;
1979 
1981  double m_min;
1982 
1984  double m_max;
1985 
1988  double m_mode;
1989 };
1990 
2050 {
2051 public:
2052  static TypeId GetTypeId (void);
2053 
2058  ZipfRandomVariable ();
2059 
2064  uint32_t GetN (void) const;
2065 
2070  double GetAlpha (void) const;
2071 
2085  double GetValue (uint32_t n, double alpha);
2086 
2100  uint32_t GetInteger (uint32_t n, uint32_t alpha);
2101 
2118  virtual double GetValue (void);
2119 
2131  virtual uint32_t GetInteger (void);
2132 
2133 private:
2135  uint32_t m_n;
2136 
2138  double m_alpha;
2139 
2141  double m_c;
2142 };
2143 
2184 {
2185 public:
2186  static TypeId GetTypeId (void);
2187 
2192  ZetaRandomVariable ();
2193 
2198  double GetAlpha (void) const;
2199 
2212  double GetValue (double alpha);
2213 
2226  uint32_t GetInteger (uint32_t alpha);
2227 
2244  virtual double GetValue (void);
2245 
2257  virtual uint32_t GetInteger (void);
2258 
2259 private:
2261  double m_alpha;
2262 
2264  double m_b;
2265 };
2266 
2298 {
2299 public:
2300  static TypeId GetTypeId (void);
2301 
2307  virtual ~DeterministicRandomVariable ();
2308 
2317  void SetValueArray (double* values, uint64_t length);
2318 
2323  virtual double GetValue (void);
2324 
2329  virtual uint32_t GetInteger (void);
2330 
2331 private:
2333  uint64_t m_count;
2334 
2336  uint64_t m_next;
2337 
2339  double* m_data;
2340 };
2341 
2374 {
2375 public:
2376  static TypeId GetTypeId (void);
2377 
2383 
2389  void CDF (double v, double c); // Value, prob <= Value
2390 
2402  virtual double GetValue (void);
2403 
2415  virtual uint32_t GetInteger (void);
2416 
2417 private:
2418  class ValueCDF
2419  {
2420 public:
2421  ValueCDF ();
2422  ValueCDF (double v, double c);
2423  ValueCDF (const ValueCDF& c);
2424  double value;
2425  double cdf;
2426  };
2427  virtual void Validate (); // Insure non-decreasing emiprical values
2428  virtual double Interpolate (double, double, double, double, double);
2429  bool validated; // True if non-decreasing validated
2430  std::vector<ValueCDF> emp; // Empicical CDF
2431 };
2432 
2433 } // namespace ns3
2434 
2435 #endif /* RANDOM_VARIABLE_STREAM_H */