23#include "ns3/boolean.h"
24#include "ns3/double.h"
25#include "ns3/integer.h"
27#include "ns3/random-variable-stream.h"
28#include "ns3/rng-seed-manager.h"
29#include "ns3/shuffle.h"
30#include "ns3/string.h"
36#include <gsl/gsl_cdf.h>
37#include <gsl/gsl_histogram.h>
38#include <gsl/gsl_randist.h>
39#include <gsl/gsl_sf_zeta.h>
51namespace RandomVariable
97 bool underflow =
true,
98 bool overflow =
true)
const
101 std::size_t nBins = gsl_histogram_bins(h);
102 double increment = (end - start) / (nBins - 1.);
105 std::vector<double> range(nBins + 1);
107 for (
auto& r : range)
114 range[0] = -std::numeric_limits<double>::max();
118 range[nBins] = std::numeric_limits<double>::max();
121 gsl_histogram_set_ranges(h, range.data(), nBins + 1);
136 double value = rng->GetValue();
159 template <
typename RNG>
175 auto rng = CreateObject<RNG>();
201 const std::vector<double>& expected,
206 "Histogram and expected vector have different sizes.");
211 double value = rng->GetValue();
212 gsl_histogram_increment(h, value);
216 double chiSquared = 0;
217 std::size_t nBins = gsl_histogram_bins(h);
218 for (std::size_t i = 0; i < nBins; ++i)
220 double hbin = gsl_histogram_get(h, i);
221 double tmp = hbin - expected[i];
278 for (std::size_t i = 0; i < nRuns; ++i)
280 auto rng = generator->
Create();
326 seed =
static_cast<uint32_t>(time(
nullptr));
329 "Special run number value of zero; seeding with time of day: " << seed);
363 void DoRun()
override;
367 :
TestCaseBase(
"Uniform Random Variable Stream Generator")
374 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
378 gsl_histogram_set_ranges_uniform(h, 0., 1.);
382 double chiSquared =
ChiSquared(h, expected, rng);
383 gsl_histogram_free(h);
393 double confidence = 0.99;
394 double maxStatistic = gsl_cdf_chisq_Pinv(confidence, (
N_BINS - 1));
396 <<
" bins is " << maxStatistic);
398 double result = maxStatistic;
405 if (result < maxStatistic)
429 value = x->GetValue();
435 static const uint32_t UNIFORM_INTEGER_MIN{0};
436 static const uint32_t UNIFORM_INTEGER_MAX{4294967295U};
439 intValue = x->GetInteger(UNIFORM_INTEGER_MIN, UNIFORM_INTEGER_MIN);
442 intValue = x->GetInteger(UNIFORM_INTEGER_MAX, UNIFORM_INTEGER_MAX);
446 for (
int i = 0; i < 20; i++)
448 intValue += x->GetInteger(UNIFORM_INTEGER_MIN, UNIFORM_INTEGER_MIN + 1);
454 for (
int i = 0; i < 20; i++)
456 intValue = x->GetInteger(UNIFORM_INTEGER_MAX - 1, UNIFORM_INTEGER_MAX);
457 if (intValue == UNIFORM_INTEGER_MAX)
465 intValue = x->GetInteger(UNIFORM_INTEGER_MIN, UNIFORM_INTEGER_MAX);
466 uint32_t intValue2 = x->GetInteger(UNIFORM_INTEGER_MIN, UNIFORM_INTEGER_MAX);
485 void DoRun()
override;
489 :
TestCaseBase(
"Antithetic Uniform Random Variable Stream Generator")
496 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
500 gsl_histogram_set_ranges_uniform(h, 0., 1.);
504 double chiSquared =
ChiSquared(h, expected, rng);
505 gsl_histogram_free(h);
517 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
539 value = x->GetValue();
557 void DoRun()
override;
564 :
TestCaseBase(
"Constant Random Variable Stream Generator")
580 c->SetAttribute(
"Constant",
DoubleValue(constant));
586 constant = c->GetValue();
592 "Constant value changed in loop");
608 void DoRun()
override;
615 :
TestCaseBase(
"Sequential Random Variable Stream Generator")
633 s->SetAttribute(
"Increment",
StringValue(
"ns3::UniformRandomVariable[Min=3.0|Max=3.0]"));
639 value = s->GetValue();
641 value = s->GetValue();
643 value = s->GetValue();
645 value = s->GetValue();
647 value = s->GetValue();
649 value = s->GetValue();
668 void DoRun()
override;
675 :
TestCaseBase(
"Normal Random Variable Stream Generator")
682 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
685 std::vector<double> expected(
N_BINS);
692 for (std::size_t i = 0; i <
N_BINS; ++i)
694 expected[i] = gsl_cdf_gaussian_P(range[i + 1], sigma) - gsl_cdf_gaussian_P(range[i], sigma);
698 double chiSquared =
ChiSquared(h, expected, rng);
699 gsl_histogram_free(h);
710 auto rng = generator.Create();
713 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
717 double variance = 2.0;
722 x->SetAttribute(
"Variance",
DoubleValue(variance));
729 double expectedMean = mean;
736 "Wrong mean value.");
754 void DoRun()
override;
761 :
TestCaseBase(
"Antithetic Normal Random Variable Stream Generator")
768 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
771 std::vector<double> expected(
N_BINS);
778 for (std::size_t i = 0; i <
N_BINS; ++i)
780 expected[i] = gsl_cdf_gaussian_P(range[i + 1], sigma) - gsl_cdf_gaussian_P(range[i], sigma);
784 double chiSquared =
ChiSquared(h, expected, rng);
786 gsl_histogram_free(h);
798 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
802 double variance = 2.0;
807 x->SetAttribute(
"Variance",
DoubleValue(variance));
817 double expectedMean = mean;
824 "Wrong mean value.");
842 void DoRun()
override;
849 :
TestCaseBase(
"Exponential Random Variable Stream Generator")
856 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
859 std::vector<double> expected(
N_BINS);
865 for (std::size_t i = 0; i <
N_BINS; ++i)
867 expected[i] = gsl_cdf_exponential_P(range[i + 1], mu) - gsl_cdf_exponential_P(range[i], mu);
871 double chiSquared =
ChiSquared(h, expected, rng);
873 gsl_histogram_free(h);
885 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
898 double expectedMean = mean;
905 "Wrong mean value.");
923 void DoRun()
override;
930 :
TestCaseBase(
"Antithetic Exponential Random Variable Stream Generator")
937 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
940 std::vector<double> expected(
N_BINS);
946 for (std::size_t i = 0; i <
N_BINS; ++i)
948 expected[i] = gsl_cdf_exponential_P(range[i + 1], mu) - gsl_cdf_exponential_P(range[i], mu);
952 double chiSquared =
ChiSquared(h, expected, rng);
954 gsl_histogram_free(h);
966 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
982 double expectedMean = mean;
989 "Wrong mean value.");
1007 void DoRun()
override;
1017 :
TestCaseBase(
"Pareto Random Variable Stream Generator")
1024 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
1027 std::vector<double> expected(
N_BINS);
1032 for (std::size_t i = 0; i <
N_BINS; ++i)
1035 gsl_cdf_pareto_P(range[i + 1], shape, scale) - gsl_cdf_pareto_P(range[i], shape, scale);
1039 double chiSquared =
ChiSquared(h, expected, rng);
1041 gsl_histogram_free(h);
1053 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
1065 double valueMean =
Average(x);
1076 double expectedMean = (shape * scale) / (shape - 1.0);
1082 "Wrong mean value.");
1100 void DoRun()
override;
1110 :
TestCaseBase(
"Antithetic Pareto Random Variable Stream Generator")
1117 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
1120 std::vector<double> expected(
N_BINS);
1125 for (std::size_t i = 0; i <
N_BINS; ++i)
1128 gsl_cdf_pareto_P(range[i + 1], shape, scale) - gsl_cdf_pareto_P(range[i], shape, scale);
1132 double chiSquared =
ChiSquared(h, expected, rng);
1134 gsl_histogram_free(h);
1146 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
1161 double valueMean =
Average(x);
1173 double expectedMean = (shape * scale) / (shape - 1.0);
1179 "Wrong mean value.");
1197 void DoRun()
override;
1207 :
TestCaseBase(
"Weibull Random Variable Stream Generator")
1214 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
1217 std::vector<double> expected(
N_BINS);
1225 for (std::size_t i = 0; i <
N_BINS; ++i)
1227 expected[i] = gsl_cdf_weibull_P(range[i + 1], a, b) - gsl_cdf_weibull_P(range[i], a, b);
1232 double chiSquared =
ChiSquared(h, expected, rng);
1234 gsl_histogram_free(h);
1246 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
1258 double valueMean =
Average(x);
1282 double expectedMean = scale;
1288 "Wrong mean value.");
1306 void DoRun()
override;
1316 :
TestCaseBase(
"Antithetic Weibull Random Variable Stream Generator")
1323 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
1326 std::vector<double> expected(
N_BINS);
1334 for (std::size_t i = 0; i <
N_BINS; ++i)
1336 expected[i] = gsl_cdf_weibull_P(range[i + 1], a, b) - gsl_cdf_weibull_P(range[i], a, b);
1340 double chiSquared =
ChiSquared(h, expected, rng);
1342 gsl_histogram_free(h);
1354 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
1369 double valueMean =
Average(x);
1393 double expectedMean = scale;
1399 "Wrong mean value.");
1417 void DoRun()
override;
1427 :
TestCaseBase(
"Log-Normal Random Variable Stream Generator")
1434 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
1437 std::vector<double> expected(
N_BINS);
1445 for (std::size_t i = 0; i <
N_BINS; ++i)
1448 gsl_cdf_lognormal_P(range[i + 1], mu, sigma) - gsl_cdf_lognormal_P(range[i], mu, sigma);
1452 double chiSquared =
ChiSquared(h, expected, rng);
1454 gsl_histogram_free(h);
1466 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
1479 double valueMean =
Average(x);
1488 double expectedMean = std::exp(mu + sigma * sigma / 2.0);
1501 "Wrong mean value.");
1519 void DoRun()
override;
1529 :
TestCaseBase(
"Antithetic Log-Normal Random Variable Stream Generator")
1536 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
1539 std::vector<double> expected(
N_BINS);
1547 for (std::size_t i = 0; i <
N_BINS; ++i)
1550 gsl_cdf_lognormal_P(range[i + 1], mu, sigma) - gsl_cdf_lognormal_P(range[i], mu, sigma);
1554 double chiSquared =
ChiSquared(h, expected, rng);
1556 gsl_histogram_free(h);
1568 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
1583 double valueMean =
Average(x);
1592 double expectedMean = std::exp(mu + sigma * sigma / 2.0);
1605 "Wrong mean value.");
1623 void DoRun()
override;
1633 :
TestCaseBase(
"Gamma Random Variable Stream Generator")
1640 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
1643 std::vector<double> expected(
N_BINS);
1651 for (std::size_t i = 0; i <
N_BINS; ++i)
1654 gsl_cdf_gamma_P(range[i + 1], alpha, beta) - gsl_cdf_gamma_P(range[i], alpha, beta);
1658 double chiSquared =
ChiSquared(h, expected, rng);
1660 gsl_histogram_free(h);
1672 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
1684 double valueMean =
Average(x);
1691 double expectedMean = alpha * beta;
1697 "Wrong mean value.");
1715 void DoRun()
override;
1725 :
TestCaseBase(
"Antithetic Gamma Random Variable Stream Generator")
1732 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
1735 std::vector<double> expected(
N_BINS);
1743 for (std::size_t i = 0; i <
N_BINS; ++i)
1746 gsl_cdf_gamma_P(range[i + 1], alpha, beta) - gsl_cdf_gamma_P(range[i], alpha, beta);
1750 double chiSquared =
ChiSquared(h, expected, rng);
1752 gsl_histogram_free(h);
1764 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
1780 double valueMean =
Average(x);
1787 double expectedMean = alpha * beta;
1793 "Wrong mean value.");
1811 void DoRun()
override;
1821 :
TestCaseBase(
"Erlang Random Variable Stream Generator")
1828 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
1831 std::vector<double> expected(
N_BINS);
1837 double lambda = 1.0;
1842 for (std::size_t i = 0; i <
N_BINS; ++i)
1845 gsl_cdf_gamma_P(range[i + 1], k, lambda) - gsl_cdf_gamma_P(range[i], k, lambda);
1849 double chiSquared =
ChiSquared(h, expected, rng);
1851 gsl_histogram_free(h);
1863 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
1867 double lambda = 2.0;
1875 double valueMean =
Average(x);
1882 double expectedMean = k * lambda;
1888 "Wrong mean value.");
1906 void DoRun()
override;
1916 :
TestCaseBase(
"Antithetic Erlang Random Variable Stream Generator")
1923 gsl_histogram* h = gsl_histogram_alloc(
N_BINS);
1926 std::vector<double> expected(
N_BINS);
1932 double lambda = 1.0;
1937 for (std::size_t i = 0; i <
N_BINS; ++i)
1940 gsl_cdf_gamma_P(range[i + 1], k, lambda) - gsl_cdf_gamma_P(range[i], k, lambda);
1944 double chiSquared =
ChiSquared(h, expected, rng);
1946 gsl_histogram_free(h);
1958 double maxStatistic = gsl_cdf_chisq_Qinv(0.05,
N_BINS);
1962 double lambda = 2.0;
1974 double valueMean =
Average(x);
1981 double expectedMean = k * lambda;
1987 "Wrong mean value.");
2002 void DoRun()
override;
2012 :
TestCaseBase(
"Zipf Random Variable Stream Generator")
2031 double valueMean =
Average(x);
2061 double expectedMean = 1.0;
2067 "Wrong mean value.");
2082 void DoRun()
override;
2092 :
TestCaseBase(
"Antithetic Zipf Random Variable Stream Generator")
2114 double valueMean =
Average(x);
2144 double expectedMean = 1.0;
2150 "Wrong mean value.");
2165 void DoRun()
override;
2175 :
TestCaseBase(
"Zeta Random Variable Stream Generator")
2192 double valueMean =
Average(x);
2206 double expectedMean =
2207 gsl_sf_zeta_int(
static_cast<int>(alpha - 1)) / gsl_sf_zeta_int(
static_cast<int>(alpha));
2213 "Wrong mean value.");
2228 void DoRun()
override;
2238 :
TestCaseBase(
"Antithetic Zeta Random Variable Stream Generator")
2258 double valueMean =
Average(x);
2272 double expectedMean =
2273 gsl_sf_zeta_int(
static_cast<int>(alpha) - 1) / gsl_sf_zeta_int(
static_cast<int>(alpha));
2279 "Wrong mean value.");
2294 void DoRun()
override;
2301 :
TestCaseBase(
"Deterministic Random Variable Stream Generator")
2317 double array1[] = {4, 4, 7, 7, 10, 10};
2318 std::size_t count1 = 6;
2319 s->SetValueArray(array1, count1);
2324 value = s->GetValue();
2326 value = s->GetValue();
2328 value = s->GetValue();
2330 value = s->GetValue();
2332 value = s->GetValue();
2334 value = s->GetValue();
2341 double array2[] = {1000, 2000, 3000, 4000};
2342 std::size_t count2 = 4;
2343 s->SetValueArray(array2, count2);
2346 value = s->GetValue();
2348 value = s->GetValue();
2350 value = s->GetValue();
2352 value = s->GetValue();
2354 value = s->GetValue();
2369 void DoRun()
override;
2379 :
TestCaseBase(
"Empirical Random Variable Stream Generator")
2391 x->SetInterpolate(
false);
2399 double value = x->GetValue();
2402 "Incorrect value returned, expected only 5 or 10.");
2406 double valueMean =
Average(x);
2418 double expectedMean = 8.75;
2422 "Wrong mean value.");
2425 x->SetInterpolate(
true);
2440 expectedMean = 6.25;
2446 "Wrong mean value.");
2450 y->SetInterpolate(
false);
2469 void DoRun()
override;
2479 :
TestCaseBase(
"EmpiricalAntithetic Random Variable Stream Generator")
2491 x->SetInterpolate(
false);
2502 double value = x->GetValue();
2505 "Incorrect value returned, expected only 5 or 10.");
2509 double valueMean =
Average(x);
2512 double expectedMean = 8.75;
2516 "Wrong mean value.");
2519 x->SetInterpolate(
true);
2527 expectedMean = 6.25;
2533 "Wrong mean value.");
2548 void DoRun()
override;
2552 :
TestCaseBase(
"NormalRandomVariable caching of parameters")
2563 double v1 = n->GetValue(-10, 1, 10);
2564 double v2 = n->GetValue(10, 1, 10);
2585 void DoRun()
override;
2592 :
TestCaseBase(
"Bernoulli Random Variable Stream Generator")
2599 gsl_histogram* h = gsl_histogram_alloc(2);
2605 double chiSquared =
ChiSquared(h, expected, rng);
2607 gsl_histogram_free(h);
2619 double maxStatistic = gsl_cdf_chisq_Qinv(0.05, 1);
2622 double probability = 0.5;
2626 x->SetAttribute(
"Probability",
DoubleValue(probability));
2629 double mean = probability;
2630 double valueMean =
Average(x);
2631 double expectedMean = mean;
2638 "Wrong mean value.");
2656 void DoRun()
override;
2663 :
TestCaseBase(
"Antithetic Bernoulli Random Variable Stream Generator")
2670 gsl_histogram* h = gsl_histogram_alloc(2);
2676 double chiSquared =
ChiSquared(h, expected, rng);
2678 gsl_histogram_free(h);
2690 double maxStatistic = gsl_cdf_chisq_Qinv(0.05, 1);
2693 double probability = 0.5;
2697 x->SetAttribute(
"Probability",
DoubleValue(probability));
2703 double mean = probability;
2704 double valueMean =
Average(x);
2705 double expectedMean = mean;
2712 "Wrong mean value.");
2730 void DoRun()
override;
2737 :
TestCaseBase(
"Binomial Random Variable Stream Generator")
2745 double probability = 0.5;
2747 gsl_histogram* h = gsl_histogram_alloc(trials + 1);
2750 std::vector<double> expected(trials + 1);
2751 for (std::size_t i = 0; i < trials + 1; ++i)
2753 expected[i] =
N_MEASUREMENTS * gsl_ran_binomial_pdf(i, probability, trials);
2756 double chiSquared =
ChiSquared(h, expected, rng);
2758 gsl_histogram_free(h);
2769 double probability = 0.5;
2773 double maxStatistic = gsl_cdf_chisq_Qinv(0.05, trials);
2779 x->SetAttribute(
"Probability",
DoubleValue(probability));
2782 double mean = trials * probability;
2783 double valueMean =
Average(x);
2784 double expectedMean = mean;
2791 "Wrong mean value.");
2809 void DoRun()
override;
2816 :
TestCaseBase(
"Antithetic Binomial Random Variable Stream Generator")
2824 double probability = 0.5;
2826 gsl_histogram* h = gsl_histogram_alloc(trials + 1);
2829 std::vector<double> expected(trials + 1);
2830 for (std::size_t i = 0; i < trials + 1; ++i)
2832 expected[i] =
N_MEASUREMENTS * gsl_ran_binomial_pdf(i, probability, trials);
2835 double chiSquared =
ChiSquared(h, expected, rng);
2837 gsl_histogram_free(h);
2848 double probability = 0.5;
2852 double maxStatistic = gsl_cdf_chisq_Qinv(0.05, trials);
2858 x->SetAttribute(
"Probability",
DoubleValue(probability));
2864 double mean = trials * probability;
2865 double valueMean =
Average(x);
2866 double expectedMean = mean;
2873 "Wrong mean value.");
2890 void DoRun()
override;
2894 :
TestCase(
"Check correct operation of the Shuffle function")
2904 auto rv = CreateObject<UniformRandomVariable>();
2908 std::vector<uint8_t> vec{};
2910 Shuffle(vec.begin(), vec.end(), rv);
2917 Shuffle(vec.begin(), vec.end(), rv);
2924 Shuffle(vec.begin(), vec.end(), rv);
2934 Shuffle(vec.begin(), vec.end(), rv);
2938 "Expected vector {4, 1, 9, 3, 2, 7}");
2954 :
TestSuite(
"random-variable-stream-generators",
Type::UNIT)
Simple average, min, max and std.
AttributeValue implementation for Boolean.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Hold a signed integer type.
Smart pointer class similar to boost::intrusive_ptr.
static void SetRun(uint64_t run)
Set the run number of simulation.
static void SetSeed(uint32_t seed)
Set the seed.
static uint64_t GetRun()
Get the current run number.
static uint32_t GetSeed()
Get the current seed value which will be used by all subsequently instantiated RandomVariableStream o...
Hold variables of type string.
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Test case for antithetic bernoulli distribution random variable stream generator.
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation, in rms.
BernoulliAntitheticTestCase()
void DoRun() override
Implementation to actually run this TestCase.
double ChiSquaredTest(Ptr< RandomVariableStream > rng) const override
Compute the chi square value from a random variable.
Test case for bernoulli distribution random variable stream generator.
double ChiSquaredTest(Ptr< RandomVariableStream > rng) const override
Compute the chi square value from a random variable.
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation, in rms.
void DoRun() override
Implementation to actually run this TestCase.
Test case for antithetic binomial distribution random variable stream generator.
void DoRun() override
Implementation to actually run this TestCase.
double ChiSquaredTest(Ptr< RandomVariableStream > rng) const override
Compute the chi square value from a random variable.
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation, in rms.
BinomialAntitheticTestCase()
Test case for binomial distribution random variable stream generator.
void DoRun() override
Implementation to actually run this TestCase.
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation, in rms.
double ChiSquaredTest(Ptr< RandomVariableStream > rng) const override
Compute the chi square value from a random variable.
Test case for constant random variable stream generator.
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation.
void DoRun() override
Implementation to actually run this TestCase.
Test case for deterministic random variable stream generator.
void DoRun() override
Implementation to actually run this TestCase.
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation.
Test case for antithetic empirical distribution random variable stream generator.
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation, as a fraction of mean value.
void DoRun() override
Implementation to actually run this TestCase.
EmpiricalAntitheticTestCase()
Test case for empirical distribution random variable stream generator.
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation, as a fraction of mean value.
void DoRun() override
Implementation to actually run this TestCase.
Test case for antithetic Erlang distribution random variable stream generator.
void DoRun() override
Implementation to actually run this TestCase.
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation, as a fraction of mean value.
double ChiSquaredTest(Ptr< RandomVariableStream > rng) const override
Compute the chi square value from a random variable.
ErlangAntitheticTestCase()
Test case for Erlang distribution random variable stream generator.
double ChiSquaredTest(Ptr< RandomVariableStream > rng) const override
Compute the chi square value from a random variable.
void DoRun() override
Implementation to actually run this TestCase.
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation, as a fraction of mean value.
Test case for antithetic exponential distribution random variable stream generator.
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation, in rms.
void DoRun() override
Implementation to actually run this TestCase.
double ChiSquaredTest(Ptr< RandomVariableStream > rng) const override
Compute the chi square value from a random variable.
ExponentialAntitheticTestCase()
Test case for exponential distribution random variable stream generator.
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation, in rms.
void DoRun() override
Implementation to actually run this TestCase.
double ChiSquaredTest(Ptr< RandomVariableStream > rng) const override
Compute the chi square value from a random variable.
Test case for antithetic gamma distribution random variable stream generator.
double ChiSquaredTest(Ptr< RandomVariableStream > rng) const override
Compute the chi square value from a random variable.
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation, as a fraction of mean value.
GammaAntitheticTestCase()
void DoRun() override
Implementation to actually run this TestCase.
Test case for gamma distribution random variable stream generator.
double ChiSquaredTest(Ptr< RandomVariableStream > rng) const override
Compute the chi square value from a random variable.
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation, as a fraction of mean value.
void DoRun() override
Implementation to actually run this TestCase.
Test case for antithetic log-normal distribution random variable stream generator.
void DoRun() override
Implementation to actually run this TestCase.
double ChiSquaredTest(Ptr< RandomVariableStream > rng) const override
Compute the chi square value from a random variable.
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation, as a fraction of mean value.
LogNormalAntitheticTestCase()
Test case for log-normal distribution random variable stream generator.
double ChiSquaredTest(Ptr< RandomVariableStream > rng) const override
Compute the chi square value from a random variable.
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation, as a fraction of mean value.
void DoRun() override
Implementation to actually run this TestCase.
Test case for antithetic normal distribution random variable stream generator.
NormalAntitheticTestCase()
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation, in rms.
void DoRun() override
Implementation to actually run this TestCase.
double ChiSquaredTest(Ptr< RandomVariableStream > rng) const override
Compute the chi square value from a random variable.
Test case for caching of Normal RV parameters (see issue #302)
void DoRun() override
Implementation to actually run this TestCase.
Test case for normal distribution random variable stream generator.
double ChiSquaredTest(Ptr< RandomVariableStream > rng) const override
Compute the chi square value from a random variable.
void DoRun() override
Implementation to actually run this TestCase.
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation, in rms.
Test case for antithetic Pareto distribution random variable stream generator.
double ChiSquaredTest(Ptr< RandomVariableStream > rng) const override
Compute the chi square value from a random variable.
ParetoAntitheticTestCase()
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation, as a fraction of mean value.
void DoRun() override
Implementation to actually run this TestCase.
Test case for Pareto distribution random variable stream generator.
void DoRun() override
Implementation to actually run this TestCase.
double ChiSquaredTest(Ptr< RandomVariableStream > rng) const override
Compute the chi square value from a random variable.
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation, as a fraction of mean value.
RandomVariableStream test suite, covering all random number variable stream generator types.
Test case for sequential random variable stream generator.
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation.
void DoRun() override
Implementation to actually run this TestCase.
Test the Shuffle function.
void DoRun() override
Implementation to actually run this TestCase.
A factory base class to create new instances of a random variable.
virtual Ptr< RandomVariableStream > Create() const =0
Create a new instance of a random variable stream.
Factory class to create new instances of a particular random variable stream.
Ptr< RandomVariableStream > Create() const override
Create a new instance of a random variable stream.
bool m_anti
Whether to create antithetic random variable streams.
RngGenerator(bool anti=false)
Constructor.
Base class for RandomVariableStream test suites.
double ChiSquared(gsl_histogram *h, const std::vector< double > &expected, Ptr< RandomVariableStream > rng) const
Compute the chi squared value of a sampled distribution compared to the expected distribution.
static const uint32_t N_MEASUREMENTS
Number of samples to draw when populating the distributions.
void SetTestSuiteSeed()
Set the seed used for this test suite.
double ChiSquaredsAverage(const RngGeneratorBase *generator, std::size_t nRuns) const
Average the chi squared value over some number of runs, each run with a new instance of the random nu...
std::vector< double > UniformHistogramBins(gsl_histogram *h, double start, double end, bool underflow=true, bool overflow=true) const
Configure a GSL histogram with uniform bins, with optional under/over-flow bins.
virtual double ChiSquaredTest(Ptr< RandomVariableStream > rng) const
Compute the chi square value from a random variable.
static const uint32_t N_BINS
Number of bins for sampling the distributions.
bool m_seedSet
true if we've already set the seed the correctly.
TestCaseBase(std::string name)
Constructor.
static const uint32_t N_RUNS
Number of retry attempts to pass a chi-square test.
double Average(Ptr< RandomVariableStream > rng) const
Compute the average of a random variable.
Test case for antithetic Weibull distribution random variable stream generator.
double ChiSquaredTest(Ptr< RandomVariableStream > rng) const override
Compute the chi square value from a random variable.
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation, as a fraction of mean value.
void DoRun() override
Implementation to actually run this TestCase.
WeibullAntitheticTestCase()
Test case for Weibull distribution random variable stream generator.
double ChiSquaredTest(Ptr< RandomVariableStream > rng) const override
Compute the chi square value from a random variable.
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation, as a fraction of mean value.
void DoRun() override
Implementation to actually run this TestCase.
Test case for antithetic Zeta distribution random variable stream generator.
void DoRun() override
Implementation to actually run this TestCase.
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation, as a fraction of mean value.
Test case for Zeta distribution random variable stream generator.
void DoRun() override
Implementation to actually run this TestCase.
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation, as a fraction of mean value.
Test case for antithetic Zipf distribution random variable stream generator.
void DoRun() override
Implementation to actually run this TestCase.
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation, as a fraction of mean value.
Test case for Zipf distribution random variable stream generator.
static constexpr double TOLERANCE
Tolerance for testing rng values against expectation, as a fraction of mean value.
void DoRun() override
Implementation to actually run this TestCase.
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
#define NS_TEST_ASSERT_MSG_LT(actual, limit, msg)
Test that an actual value is less than a limit and report and abort if not.
#define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report and abort if not.
#define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg)
Test that an actual and expected (limit) value are equal and report if not.
#define NS_TEST_ASSERT_MSG_NE(actual, limit, msg)
Test that an actual and expected (limit) value are not equal and report and abort if not.
#define NS_TEST_ASSERT_MSG_GT(actual, limit, msg)
Test that an actual value is greater than a limit and report and abort if not.
#define NS_TEST_ASSERT_MSG_EQ_TOL(actual, limit, tol, msg)
Test that actual and expected (limit) values are equal to plus or minus some tolerance and report and...
static RandomVariableSuite randomVariableSuite
Static variable for test initialization.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void Shuffle(RND_ACCESS_ITER first, RND_ACCESS_ITER last, Ptr< UniformRandomVariable > rv)
Shuffle the elements in the range first to last.
-ns3 Test suite for the ns3 wrapper script