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"
66 std::cout <<
"------------------------------" << std::endl;
67 std::cout <<
"Sampling " << mode << std::endl;
69 std::cout << std::endl;
70 std::cout <<
"Binned sample" << std::endl;
71 double value = erv->GetValue();
72 std::cout <<
"Binned sample: " << value << std::endl;
73 std::cout << std::endl;
75 std::cout <<
"Interpolated sample" << std::endl;
76 erv->SetInterpolate(
true);
77 value = erv->GetValue();
78 std::cout <<
"Interpolated sample:" << value << std::endl;
79 erv->SetInterpolate(
false);
93PrintStatsLine(
const double value,
const long count,
const long n,
const long sum)
95 std::cout << std::fixed << std::setprecision(3) << std::setw(10) << std::right << value
96 << std::setw(10) << std::right << count << std::setw(10) << std::right
97 << count /
static_cast<double>(n) * 100.0 << std::setw(10) << std::right
98 << sum /
static_cast<double>(n) * 100.0 << std::endl;
113 std::cout << std::endl;
114 std::cout <<
" --------" << std::endl;
115 std::cout <<
" Total " << std::setprecision(3) << std::fixed << std::setw(10)
116 << std::right << sum /
static_cast<double>(n) * 100.0 << std::endl;
117 std::cout <<
" Average " << std::setprecision(3) << std::fixed << std::setw(6)
118 << std::right << weighted / n << std::endl;
119 std::cout <<
" Expected " << std::setprecision(3) << std::fixed << std::setw(6)
120 << std::right << expected << std::endl
135 std::cout << std::endl;
136 std::cout <<
"Sampling " << mode << std::endl;
137 std::map<double, int> counts;
139 for (
long i = 0; i < n; ++i)
141 ++counts[erv->GetValue()];
145 std::cout << std::endl;
146 std::cout <<
" Value Counts % % CDF" << std::endl;
147 std::cout <<
"---------- -------- -------- --------" << std::endl;
148 for (
auto c : counts)
150 long count = c.second;
151 double value = c.first;
153 weighted += value * count;
158 std::cout <<
"Interpolating " << mode << std::endl;
159 erv->SetInterpolate(
true);
161 for (
long i = 0; i < n; ++i)
167 erv->SetInterpolate(
false);
170 std::cout << std::endl;
171 std::cout <<
" Bin Start Counts % % CDF" << std::endl;
172 std::cout <<
"---------- -------- -------- --------" << std::endl;
179 weighted += count * value;
186main(
int argc,
char* argv[])
189 bool disableAnti =
false;
192 cmd.AddValue(
"count",
"how many draws to make from the rng", n);
193 cmd.AddValue(
"antithetic",
"disable antithetic sampling", disableAnti);
194 cmd.AddValue(
"single",
"sample a single time", single);
195 cmd.Parse(argc, argv);
196 std::cout << std::endl;
197 std::cout <<
cmd.GetName() << std::endl;
200 std::cout <<
"Sample count: " << n << std::endl;
204 std::cout <<
"Sampling a single time" << std::endl;
208 std::cout <<
"Antithetic sampling disabled" << std::endl;
215 erv->CDF(0.0, 0.0 / 15.0);
216 erv->CDF(0.2, 1.0 / 15.0);
217 erv->CDF(0.4, 3.0 / 15.0);
218 erv->CDF(0.6, 4.0 / 15.0);
219 erv->CDF(0.8, 7.0 / 15.0);
220 erv->CDF(1.0, 9.0 / 15.0);
221 erv->CDF(1.0, 15.0 / 15.0);
228 std::cout << std::endl;
229 std::cout <<
"Antithetic" << std::endl;
230 erv->SetAntithetic(
true);
232 erv->SetAntithetic(
false);
235 std::cout << std::endl;
243 erv->SetAntithetic(
true);
245 erv->SetAntithetic(
false);
Parse command-line arguments.
Class used to store data and make an histogram of the data frequency.
double GetBinWidth(uint32_t index) const
Returns the bin width.
uint32_t GetBinCount(uint32_t index) const
Get the number of data added to the bin.
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) const
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, const long sum)
Prints a stat line.
Every class exported by the ns3 library is enclosed in the ns3 namespace.