21 #include "ns3/simulator.h"
22 #include "ns3/nstime.h"
23 #include "ns3/command-line.h"
24 #include "ns3/random-variable-stream.h"
25 #include "ns3/histogram.h"
65 std::cout <<
"------------------------------" << std::endl;
66 std::cout <<
"Sampling " << mode << std::endl;
68 std::cout << std::endl;
69 std::cout <<
"Binned sample" << std::endl;
70 double value = erv->GetValue ();
71 std::cout <<
"Binned sample: " << value << std::endl;
72 std::cout << std::endl;
74 std::cout <<
"Interpolated sample" << std::endl;
75 erv->SetInterpolate (
true);
76 value = erv->GetValue ();
77 std::cout <<
"Interpolated sample:" << value << std::endl;
78 erv->SetInterpolate (
false);
92 std::cout << std::fixed << std::setprecision (3)
93 << std::setw (10) << std::right << value
94 << std::setw (10) << std::right << count
95 << std::setw (10) << std::right
96 << count /
static_cast<double> (n) * 100.0
112 std::cout << std::endl;
113 std::cout <<
" --------" << std::endl;
114 std::cout <<
" Total "
115 << std::setprecision (3) << std::fixed
116 << std::setw (10) << std::right
117 << sum /
static_cast<double> (n) * 100.0
119 std::cout <<
" Average "
120 << std::setprecision (3) << std::fixed
121 << std::setw (6) << std::right << weighted / n
123 std::cout <<
" Expected "
124 << std::setprecision (3) << std::fixed
125 << std::setw (6) << std::right << expected
141 std::cout << std::endl;
142 std::cout <<
"Sampling " << mode << std::endl;
143 std::map <double, int> counts;
145 for (
long i = 0; i < n; ++i)
147 ++counts[erv->GetValue ()];
151 std::cout << std::endl;
152 std::cout <<
" Value Counts %" << std::endl;
153 std::cout <<
"---------- -------- --------" << std::endl;
154 for (
auto c : counts)
156 long count = c.second;
157 double value = c.first;
159 weighted += value * count;
164 std::cout <<
"Interpolating " << mode << std::endl;
165 erv->SetInterpolate (
true);
167 for (
long i = 0; i < n; ++i)
173 erv->SetInterpolate (
false);
176 std::cout << std::endl;
177 std::cout <<
" Bin Start Counts %" << std::endl;
178 std::cout <<
"---------- -------- --------" << std::endl;
179 for (uint32_t i = 0; i < h.
GetNBins (); ++i)
185 weighted += count * value;
192 int main (
int argc,
char *argv[])
195 bool disableAnti =
false;
198 cmd.AddValue (
"count",
"how many draws to make from the rng", n);
199 cmd.AddValue (
"antithetic",
"disable antithetic sampling", disableAnti);
200 cmd.AddValue (
"single",
"sample a single time", single);
201 cmd.Parse (argc, argv);
202 std::cout << std::endl;
203 std::cout <<
cmd.GetName () << std::endl;
206 std::cout <<
"Sample count: " << n << std::endl;
210 std::cout <<
"Sampling a single time" << std::endl;
214 std::cout <<
"Antithetic sampling disabled" << std::endl;
219 erv->SetInterpolate (
false);
220 erv->CDF ( 0.0, 0.0);
221 erv->CDF ( 5.0, 0.25);
222 erv->CDF (10.0, 1.0);
229 std::cout << std::endl;
230 std::cout <<
"Antithetic" << std::endl;
231 erv->SetAntithetic (
true);
233 erv->SetAntithetic (
false);
236 std::cout << std::endl;
244 erv->SetAntithetic (
true);
246 erv->SetAntithetic (
false);
Parse command-line arguments.
Class used to store data and make an histogram of the data frequency.
uint32_t GetBinCount(uint32_t index)
Get the number of data added to the bin.
double GetBinWidth(uint32_t index) const
Returns the bin width.
uint32_t GetNBins() const
Returns the number of bins in the histogram.
void AddValue(double value)
Add a value to the histogram.
double GetBinStart(uint32_t index)
Returns the bin start, i.e., index*binWidth.
Smart pointer class similar to boost::intrusive_ptr.
void PrintSummary(long sum, long n, double weighted, double expected)
Prints the summary.
void RunBothModes(std::string mode, Ptr< EmpiricalRandomVariable > erv, long n)
Sample the random variable.
void RunSingleSample(std::string mode, Ptr< EmpiricalRandomVariable > erv)
Sample the random variable only once.
void PrintStatsLine(const double value, const long count, const long n)
Prints a stat line.
Every class exported by the ns3 library is enclosed in the ns3 namespace.