20#include "ns3/command-line.h"
21#include "ns3/histogram.h"
22#include "ns3/nstime.h"
24#include "ns3/random-variable-stream.h"
25#include "ns3/simulator.h"
62 std::cout <<
"------------------------------" << std::endl;
63 std::cout <<
"Sampling " << mode << std::endl;
65 std::cout << std::endl;
66 std::cout <<
"Binned sample" << std::endl;
67 double value = erv->GetValue();
68 std::cout <<
"Binned sample: " <<
value << std::endl;
69 std::cout << std::endl;
71 std::cout <<
"Interpolated sample" << std::endl;
72 erv->SetInterpolate(
true);
73 value = erv->GetValue();
74 std::cout <<
"Interpolated sample:" <<
value << std::endl;
75 erv->SetInterpolate(
false);
89 std::cout << std::fixed << std::setprecision(3) << std::setw(10) << std::right <<
value
90 << std::setw(10) << std::right << count << std::setw(10) << std::right
91 << count /
static_cast<double>(n) * 100.0 << std::endl;
106 std::cout << std::endl;
107 std::cout <<
" --------" << std::endl;
108 std::cout <<
" Total " << std::setprecision(3) << std::fixed << std::setw(10)
109 << std::right << sum /
static_cast<double>(n) * 100.0 << std::endl;
110 std::cout <<
" Average " << std::setprecision(3) << std::fixed << std::setw(6)
111 << std::right << weighted / n << std::endl;
112 std::cout <<
" Expected " << std::setprecision(3) << std::fixed << std::setw(6)
113 << std::right << expected << std::endl
128 std::cout << std::endl;
129 std::cout <<
"Sampling " << mode << std::endl;
130 std::map<double, int> counts;
132 for (
long i = 0; i < n; ++i)
134 ++counts[erv->GetValue()];
138 std::cout << std::endl;
139 std::cout <<
" Value Counts %" << std::endl;
140 std::cout <<
"---------- -------- --------" << std::endl;
141 for (
auto c : counts)
143 long count = c.second;
144 double value = c.first;
146 weighted +=
value * count;
151 std::cout <<
"Interpolating " << mode << std::endl;
152 erv->SetInterpolate(
true);
154 for (
long i = 0; i < n; ++i)
160 erv->SetInterpolate(
false);
163 std::cout << std::endl;
164 std::cout <<
" Bin Start Counts %" << std::endl;
165 std::cout <<
"---------- -------- --------" << std::endl;
172 weighted += count *
value;
179main(
int argc,
char* argv[])
182 bool disableAnti =
false;
185 cmd.AddValue(
"count",
"how many draws to make from the rng", n);
186 cmd.AddValue(
"antithetic",
"disable antithetic sampling", disableAnti);
187 cmd.AddValue(
"single",
"sample a single time", single);
188 cmd.Parse(argc, argv);
189 std::cout << std::endl;
190 std::cout <<
cmd.GetName() << std::endl;
193 std::cout <<
"Sample count: " << n << std::endl;
197 std::cout <<
"Sampling a single time" << std::endl;
201 std::cout <<
"Antithetic sampling disabled" << std::endl;
206 erv->SetInterpolate(
false);
216 std::cout << std::endl;
217 std::cout <<
"Antithetic" << std::endl;
218 erv->SetAntithetic(
true);
220 erv->SetAntithetic(
false);
223 std::cout << std::endl;
231 erv->SetAntithetic(
true);
233 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.