|
|
| 34 |
#include "ns3/string.h" |
34 |
#include "ns3/string.h" |
| 35 |
#include "ns3/integer.h" |
35 |
#include "ns3/integer.h" |
| 36 |
#include "ns3/test.h" |
36 |
#include "ns3/test.h" |
|
|
37 |
#include "ns3/log.h" |
| 37 |
#include "ns3/rng-seed-manager.h" |
38 |
#include "ns3/rng-seed-manager.h" |
| 38 |
#include "ns3/random-variable-stream.h" |
39 |
#include "ns3/random-variable-stream.h" |
| 39 |
|
40 |
|
| 40 |
using namespace ns3; |
41 |
using namespace ns3; |
| 41 |
|
42 |
|
|
|
43 |
NS_LOG_COMPONENT_DEFINE ("RandomVariableStreamGenerators"); |
| 44 |
|
| 42 |
namespace { |
45 |
namespace { |
| 43 |
|
46 |
|
| 44 |
void |
47 |
void |
|
|
| 54 |
} |
57 |
} |
| 55 |
} |
58 |
} |
| 56 |
|
59 |
|
|
|
60 |
bool seedSet = false; |
| 61 |
|
| 62 |
// Over time, this test suite is designed to be run with varying seed |
| 63 |
// values so that the distributions can be evaluated with chi-squared |
| 64 |
// tests. To enable this, normal invocation of this test suite will |
| 65 |
// result in a seed value corresponding to the seconds since epoch |
| 66 |
// (time (0) from ctime). Note: this is not a recommended practice for |
| 67 |
// seeding normal simulations, as described in the ns-3 manual, but |
| 68 |
// suits our purposes here. |
| 69 |
// |
| 70 |
// However, we also want to provide the ability to run this test suite |
| 71 |
// with a repeatable value, such as when the seed or run number is configured |
| 72 |
// to a specific value. Therefore, we adopt the following policy. When |
| 73 |
// the test program is being run with the default global values for seed |
| 74 |
// and run number, this function will instead pick a random, time-based |
| 75 |
// seed for use within this test suite. If the global values for seed or |
| 76 |
// run number have been configured different from the default values, |
| 77 |
// the global seed value will be used instead of the time-based one. |
| 78 |
// |
| 79 |
// For example, this command will cause this test suite to use the |
| 80 |
// deterministic value of seed=3 every time: |
| 81 |
// NS_GLOBAL_VALUE="RngSeed=3" ./test.py -s random-variable-stream-generators |
| 82 |
// or equivalently (to see log output): |
| 83 |
// NS_LOG="RandomVariableStreamGenerators" NS_GLOBAL_VALUE="RngSeed=3" ./waf --run "test-runner --suite=random-variable-stream-generators" |
| 84 |
void |
| 85 |
SetTestSuiteSeed (void) |
| 86 |
{ |
| 87 |
if (seedSet == false) |
| 88 |
{ |
| 89 |
uint32_t seed; |
| 90 |
if (RngSeedManager::GetSeed () == 1 && RngSeedManager::GetRun () == 1) |
| 91 |
{ |
| 92 |
seed = static_cast<uint32_t> (time (0)); |
| 93 |
seedSet = true; |
| 94 |
NS_LOG_DEBUG ("Global seed and run number are default; seeding with time of day: " << seed); |
| 95 |
|
| 96 |
} |
| 97 |
else |
| 98 |
{ |
| 99 |
seed = RngSeedManager::GetSeed (); |
| 100 |
seedSet = true; |
| 101 |
NS_LOG_DEBUG ("Global seed and run number are not default; using the non-default value: " << seed); |
| 102 |
} |
| 103 |
SeedManager::SetSeed (seed); |
| 104 |
} |
| 105 |
} |
| 106 |
|
| 57 |
} // anonymous namespace |
107 |
} // anonymous namespace |
| 58 |
|
108 |
|
| 59 |
// =========================================================================== |
109 |
// =========================================================================== |
|
|
| 125 |
void |
175 |
void |
| 126 |
RandomVariableStreamUniformTestCase::DoRun (void) |
176 |
RandomVariableStreamUniformTestCase::DoRun (void) |
| 127 |
{ |
177 |
{ |
| 128 |
SeedManager::SetSeed (time (0)); |
178 |
SetTestSuiteSeed (); |
| 129 |
|
179 |
|
| 130 |
double sum = 0.; |
180 |
double sum = 0.; |
| 131 |
double maxStatistic = gsl_cdf_chisq_Qinv (0.05, N_BINS); |
181 |
double maxStatistic = gsl_cdf_chisq_Qinv (0.05, N_BINS); |
|
|
| 268 |
void |
318 |
void |
| 269 |
RandomVariableStreamUniformAntitheticTestCase::DoRun (void) |
319 |
RandomVariableStreamUniformAntitheticTestCase::DoRun (void) |
| 270 |
{ |
320 |
{ |
| 271 |
SeedManager::SetSeed (time (0)); |
321 |
SetTestSuiteSeed (); |
| 272 |
|
322 |
|
| 273 |
double sum = 0.; |
323 |
double sum = 0.; |
| 274 |
double maxStatistic = gsl_cdf_chisq_Qinv (0.05, N_BINS); |
324 |
double maxStatistic = gsl_cdf_chisq_Qinv (0.05, N_BINS); |
|
|
| 345 |
void |
395 |
void |
| 346 |
RandomVariableStreamConstantTestCase::DoRun (void) |
396 |
RandomVariableStreamConstantTestCase::DoRun (void) |
| 347 |
{ |
397 |
{ |
| 348 |
SeedManager::SetSeed (time (0)); |
398 |
SetTestSuiteSeed (); |
| 349 |
|
399 |
|
| 350 |
Ptr<ConstantRandomVariable> c = CreateObject<ConstantRandomVariable> (); |
400 |
Ptr<ConstantRandomVariable> c = CreateObject<ConstantRandomVariable> (); |
| 351 |
|
401 |
|
|
|
| 395 |
void |
445 |
void |
| 396 |
RandomVariableStreamSequentialTestCase::DoRun (void) |
446 |
RandomVariableStreamSequentialTestCase::DoRun (void) |
| 397 |
{ |
447 |
{ |
| 398 |
SeedManager::SetSeed (time (0)); |
448 |
SetTestSuiteSeed (); |
| 399 |
|
449 |
|
| 400 |
Ptr<SequentialRandomVariable> s = CreateObject<SequentialRandomVariable> (); |
450 |
Ptr<SequentialRandomVariable> s = CreateObject<SequentialRandomVariable> (); |
| 401 |
|
451 |
|
|
|
| 509 |
void |
559 |
void |
| 510 |
RandomVariableStreamNormalTestCase::DoRun (void) |
560 |
RandomVariableStreamNormalTestCase::DoRun (void) |
| 511 |
{ |
561 |
{ |
| 512 |
SeedManager::SetSeed (time (0)); |
562 |
SetTestSuiteSeed (); |
| 513 |
|
563 |
|
| 514 |
double sum = 0.; |
564 |
double sum = 0.; |
| 515 |
double maxStatistic = gsl_cdf_chisq_Qinv (0.05, N_BINS); |
565 |
double maxStatistic = gsl_cdf_chisq_Qinv (0.05, N_BINS); |
|
|
| 635 |
void |
685 |
void |
| 636 |
RandomVariableStreamNormalAntitheticTestCase::DoRun (void) |
686 |
RandomVariableStreamNormalAntitheticTestCase::DoRun (void) |
| 637 |
{ |
687 |
{ |
| 638 |
SeedManager::SetSeed (time (0)); |
688 |
SetTestSuiteSeed (); |
| 639 |
|
689 |
|
| 640 |
double sum = 0.; |
690 |
double sum = 0.; |
| 641 |
double maxStatistic = gsl_cdf_chisq_Qinv (0.05, N_BINS); |
691 |
double maxStatistic = gsl_cdf_chisq_Qinv (0.05, N_BINS); |
|
|
| 766 |
void |
816 |
void |
| 767 |
RandomVariableStreamExponentialTestCase::DoRun (void) |
817 |
RandomVariableStreamExponentialTestCase::DoRun (void) |
| 768 |
{ |
818 |
{ |
| 769 |
SeedManager::SetSeed (time (0)); |
819 |
SetTestSuiteSeed (); |
| 770 |
|
820 |
|
| 771 |
double sum = 0.; |
821 |
double sum = 0.; |
| 772 |
double maxStatistic = gsl_cdf_chisq_Qinv (0.05, N_BINS); |
822 |
double maxStatistic = gsl_cdf_chisq_Qinv (0.05, N_BINS); |
|
|
| 886 |
void |
936 |
void |
| 887 |
RandomVariableStreamExponentialAntitheticTestCase::DoRun (void) |
937 |
RandomVariableStreamExponentialAntitheticTestCase::DoRun (void) |
| 888 |
{ |
938 |
{ |
| 889 |
SeedManager::SetSeed (time (0)); |
939 |
SetTestSuiteSeed (); |
| 890 |
|
940 |
|
| 891 |
double sum = 0.; |
941 |
double sum = 0.; |
| 892 |
double maxStatistic = gsl_cdf_chisq_Qinv (0.05, N_BINS); |
942 |
double maxStatistic = gsl_cdf_chisq_Qinv (0.05, N_BINS); |
|
|
| 1015 |
void |
1065 |
void |
| 1016 |
RandomVariableStreamParetoTestCase::DoRun (void) |
1066 |
RandomVariableStreamParetoTestCase::DoRun (void) |
| 1017 |
{ |
1067 |
{ |
| 1018 |
SeedManager::SetSeed (time (0)); |
1068 |
SetTestSuiteSeed (); |
| 1019 |
|
1069 |
|
| 1020 |
double sum = 0.; |
1070 |
double sum = 0.; |
| 1021 |
double maxStatistic = gsl_cdf_chisq_Qinv (0.05, N_BINS); |
1071 |
double maxStatistic = gsl_cdf_chisq_Qinv (0.05, N_BINS); |
|
|
| 1149 |
void |
1199 |
void |
| 1150 |
RandomVariableStreamParetoAntitheticTestCase::DoRun (void) |
1200 |
RandomVariableStreamParetoAntitheticTestCase::DoRun (void) |
| 1151 |
{ |
1201 |
{ |
| 1152 |
SeedManager::SetSeed (time (0)); |
1202 |
SetTestSuiteSeed (); |
| 1153 |
|
1203 |
|
| 1154 |
double sum = 0.; |
1204 |
double sum = 0.; |
| 1155 |
double maxStatistic = gsl_cdf_chisq_Qinv (0.05, N_BINS); |
1205 |
double maxStatistic = gsl_cdf_chisq_Qinv (0.05, N_BINS); |
|
|
| 1291 |
void |
1341 |
void |
| 1292 |
RandomVariableStreamWeibullTestCase::DoRun (void) |
1342 |
RandomVariableStreamWeibullTestCase::DoRun (void) |
| 1293 |
{ |
1343 |
{ |
| 1294 |
SeedManager::SetSeed (time (0)); |
1344 |
SetTestSuiteSeed (); |
| 1295 |
|
1345 |
|
| 1296 |
double sum = 0.; |
1346 |
double sum = 0.; |
| 1297 |
double maxStatistic = gsl_cdf_chisq_Qinv (0.05, N_BINS); |
1347 |
double maxStatistic = gsl_cdf_chisq_Qinv (0.05, N_BINS); |
|
|
| 1437 |
void |
1487 |
void |
| 1438 |
RandomVariableStreamWeibullAntitheticTestCase::DoRun (void) |
1488 |
RandomVariableStreamWeibullAntitheticTestCase::DoRun (void) |
| 1439 |
{ |
1489 |
{ |
| 1440 |
SeedManager::SetSeed (time (0)); |
1490 |
SetTestSuiteSeed (); |
| 1441 |
|
1491 |
|
| 1442 |
double sum = 0.; |
1492 |
double sum = 0.; |
| 1443 |
double maxStatistic = gsl_cdf_chisq_Qinv (0.05, N_BINS); |
1493 |
double maxStatistic = gsl_cdf_chisq_Qinv (0.05, N_BINS); |
|
|
| 1590 |
void |
1640 |
void |
| 1591 |
RandomVariableStreamLogNormalTestCase::DoRun (void) |
1641 |
RandomVariableStreamLogNormalTestCase::DoRun (void) |
| 1592 |
{ |
1642 |
{ |
| 1593 |
SeedManager::SetSeed (time (0)); |
1643 |
SetTestSuiteSeed (); |
| 1594 |
|
1644 |
|
| 1595 |
double sum = 0.; |
1645 |
double sum = 0.; |
| 1596 |
double maxStatistic = gsl_cdf_chisq_Qinv (0.05, N_BINS); |
1646 |
double maxStatistic = gsl_cdf_chisq_Qinv (0.05, N_BINS); |
|
|
| 1726 |
void |
1776 |
void |
| 1727 |
RandomVariableStreamLogNormalAntitheticTestCase::DoRun (void) |
1777 |
RandomVariableStreamLogNormalAntitheticTestCase::DoRun (void) |
| 1728 |
{ |
1778 |
{ |
| 1729 |
SeedManager::SetSeed (time (0)); |
1779 |
SetTestSuiteSeed (); |
| 1730 |
|
1780 |
|
| 1731 |
double sum = 0.; |
1781 |
double sum = 0.; |
| 1732 |
double maxStatistic = gsl_cdf_chisq_Qinv (0.05, N_BINS); |
1782 |
double maxStatistic = gsl_cdf_chisq_Qinv (0.05, N_BINS); |
|
|
| 1869 |
void |
1919 |
void |
| 1870 |
RandomVariableStreamGammaTestCase::DoRun (void) |
1920 |
RandomVariableStreamGammaTestCase::DoRun (void) |
| 1871 |
{ |
1921 |
{ |
| 1872 |
SeedManager::SetSeed (time (0)); |
1922 |
SetTestSuiteSeed (); |
| 1873 |
|
1923 |
|
| 1874 |
double sum = 0.; |
1924 |
double sum = 0.; |
| 1875 |
double maxStatistic = gsl_cdf_chisq_Qinv (0.05, N_BINS); |
1925 |
double maxStatistic = gsl_cdf_chisq_Qinv (0.05, N_BINS); |
|
|
| 1998 |
void |
2048 |
void |
| 1999 |
RandomVariableStreamGammaAntitheticTestCase::DoRun (void) |
2049 |
RandomVariableStreamGammaAntitheticTestCase::DoRun (void) |
| 2000 |
{ |
2050 |
{ |
| 2001 |
SeedManager::SetSeed (time (0)); |
2051 |
SetTestSuiteSeed (); |
| 2002 |
|
2052 |
|
| 2003 |
double sum = 0.; |
2053 |
double sum = 0.; |
| 2004 |
double maxStatistic = gsl_cdf_chisq_Qinv (0.05, N_BINS); |
2054 |
double maxStatistic = gsl_cdf_chisq_Qinv (0.05, N_BINS); |
|
|
| 2138 |
void |
2188 |
void |
| 2139 |
RandomVariableStreamErlangTestCase::DoRun (void) |
2189 |
RandomVariableStreamErlangTestCase::DoRun (void) |
| 2140 |
{ |
2190 |
{ |
| 2141 |
SeedManager::SetSeed (time (0)); |
2191 |
SetTestSuiteSeed (); |
| 2142 |
|
2192 |
|
| 2143 |
double sum = 0.; |
2193 |
double sum = 0.; |
| 2144 |
double maxStatistic = gsl_cdf_chisq_Qinv (0.05, N_BINS); |
2194 |
double maxStatistic = gsl_cdf_chisq_Qinv (0.05, N_BINS); |
|
|
| 2270 |
void |
2320 |
void |
| 2271 |
RandomVariableStreamErlangAntitheticTestCase::DoRun (void) |
2321 |
RandomVariableStreamErlangAntitheticTestCase::DoRun (void) |
| 2272 |
{ |
2322 |
{ |
| 2273 |
SeedManager::SetSeed (time (0)); |
2323 |
SetTestSuiteSeed (); |
| 2274 |
|
2324 |
|
| 2275 |
double sum = 0.; |
2325 |
double sum = 0.; |
| 2276 |
double maxStatistic = gsl_cdf_chisq_Qinv (0.05, N_BINS); |
2326 |
double maxStatistic = gsl_cdf_chisq_Qinv (0.05, N_BINS); |
|
|
| 2351 |
void |
2401 |
void |
| 2352 |
RandomVariableStreamZipfTestCase::DoRun (void) |
2402 |
RandomVariableStreamZipfTestCase::DoRun (void) |
| 2353 |
{ |
2403 |
{ |
| 2354 |
SeedManager::SetSeed (time (0)); |
2404 |
SetTestSuiteSeed (); |
| 2355 |
|
2405 |
|
| 2356 |
uint32_t n = 1; |
2406 |
uint32_t n = 1; |
| 2357 |
double alpha = 2.0; |
2407 |
double alpha = 2.0; |
|
|
| 2433 |
void |
2483 |
void |
| 2434 |
RandomVariableStreamZipfAntitheticTestCase::DoRun (void) |
2484 |
RandomVariableStreamZipfAntitheticTestCase::DoRun (void) |
| 2435 |
{ |
2485 |
{ |
| 2436 |
SeedManager::SetSeed (time (0)); |
2486 |
SetTestSuiteSeed (); |
| 2437 |
|
2487 |
|
| 2438 |
uint32_t n = 1; |
2488 |
uint32_t n = 1; |
| 2439 |
double alpha = 2.0; |
2489 |
double alpha = 2.0; |
|
|
| 2518 |
void |
2568 |
void |
| 2519 |
RandomVariableStreamZetaTestCase::DoRun (void) |
2569 |
RandomVariableStreamZetaTestCase::DoRun (void) |
| 2520 |
{ |
2570 |
{ |
| 2521 |
SeedManager::SetSeed (time (0)); |
2571 |
SetTestSuiteSeed (); |
| 2522 |
|
2572 |
|
| 2523 |
double alpha = 5.0; |
2573 |
double alpha = 5.0; |
| 2524 |
double value; |
2574 |
double value; |
|
|
| 2582 |
void |
2632 |
void |
| 2583 |
RandomVariableStreamZetaAntitheticTestCase::DoRun (void) |
2633 |
RandomVariableStreamZetaAntitheticTestCase::DoRun (void) |
| 2584 |
{ |
2634 |
{ |
| 2585 |
SeedManager::SetSeed (time (0)); |
2635 |
SetTestSuiteSeed (); |
| 2586 |
|
2636 |
|
| 2587 |
double alpha = 5.0; |
2637 |
double alpha = 5.0; |
| 2588 |
double value; |
2638 |
double value; |
|
|
| 2651 |
void |
2701 |
void |
| 2652 |
RandomVariableStreamDeterministicTestCase::DoRun (void) |
2702 |
RandomVariableStreamDeterministicTestCase::DoRun (void) |
| 2653 |
{ |
2703 |
{ |
| 2654 |
SeedManager::SetSeed (time (0)); |
2704 |
SetTestSuiteSeed (); |
| 2655 |
|
2705 |
|
| 2656 |
Ptr<DeterministicRandomVariable> s = CreateObject<DeterministicRandomVariable> (); |
2706 |
Ptr<DeterministicRandomVariable> s = CreateObject<DeterministicRandomVariable> (); |
| 2657 |
|
2707 |
|
|
|
| 2726 |
void |
2776 |
void |
| 2727 |
RandomVariableStreamEmpiricalTestCase::DoRun (void) |
2777 |
RandomVariableStreamEmpiricalTestCase::DoRun (void) |
| 2728 |
{ |
2778 |
{ |
| 2729 |
SeedManager::SetSeed (time (0)); |
2779 |
SetTestSuiteSeed (); |
| 2730 |
|
2780 |
|
| 2731 |
// Create the RNG with a uniform distribution between 0 and 10. |
2781 |
// Create the RNG with a uniform distribution between 0 and 10. |
| 2732 |
Ptr<EmpiricalRandomVariable> x = CreateObject<EmpiricalRandomVariable> (); |
2782 |
Ptr<EmpiricalRandomVariable> x = CreateObject<EmpiricalRandomVariable> (); |
|
|
| 2783 |
void |
2833 |
void |
| 2784 |
RandomVariableStreamEmpiricalAntitheticTestCase::DoRun (void) |
2834 |
RandomVariableStreamEmpiricalAntitheticTestCase::DoRun (void) |
| 2785 |
{ |
2835 |
{ |
| 2786 |
SeedManager::SetSeed (time (0)); |
2836 |
SetTestSuiteSeed (); |
| 2787 |
|
2837 |
|
| 2788 |
// Create the RNG with a uniform distribution between 0 and 10. |
2838 |
// Create the RNG with a uniform distribution between 0 and 10. |
| 2789 |
Ptr<EmpiricalRandomVariable> x = CreateObject<EmpiricalRandomVariable> (); |
2839 |
Ptr<EmpiricalRandomVariable> x = CreateObject<EmpiricalRandomVariable> (); |