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 PrintStatsLine(
const double value,
const long count,
const long n,
const long sum)
91 std::cout << std::fixed << std::setprecision(3) << std::setw(10) << std::right << value
92 << std::setw(10) << std::right << count << std::setw(10) << std::right
93 << count /
static_cast<double>(n) * 100.0 << std::setw(10) << std::right
94 << sum /
static_cast<double>(n) * 100.0 << std::endl;
109 std::cout << std::endl;
110 std::cout <<
" --------" << std::endl;
111 std::cout <<
" Total " << std::setprecision(3) << std::fixed << std::setw(10)
112 << std::right << sum /
static_cast<double>(n) * 100.0 << std::endl;
113 std::cout <<
" Average " << std::setprecision(3) << std::fixed << std::setw(6)
114 << std::right << weighted / n << std::endl;
115 std::cout <<
" Expected " << std::setprecision(3) << std::fixed << std::setw(6)
116 << std::right << expected << std::endl
131 std::cout << std::endl;
132 std::cout <<
"Sampling " << mode << std::endl;
133 std::map<double, int> counts;
135 for (
long i = 0; i < n; ++i)
137 ++counts[erv->GetValue()];
141 std::cout << std::endl;
142 std::cout <<
" Value Counts % % CDF" << std::endl;
143 std::cout <<
"---------- -------- -------- --------" << std::endl;
144 for (
auto c : counts)
146 long count = c.second;
147 double value = c.first;
149 weighted += value * count;
154 std::cout <<
"Interpolating " << mode << std::endl;
155 erv->SetInterpolate(
true);
157 for (
long i = 0; i < n; ++i)
163 erv->SetInterpolate(
false);
166 std::cout << std::endl;
167 std::cout <<
" Bin Start Counts % % CDF" << std::endl;
168 std::cout <<
"---------- -------- -------- --------" << std::endl;
169 for (uint32_t i = 0; i < h.
GetNBins(); ++i)
175 weighted += count * value;
182 main(
int argc,
char* argv[])
185 bool disableAnti =
false;
188 cmd.AddValue(
"count",
"how many draws to make from the rng", n);
189 cmd.AddValue(
"antithetic",
"disable antithetic sampling", disableAnti);
190 cmd.AddValue(
"single",
"sample a single time", single);
191 cmd.Parse(argc, argv);
192 std::cout << std::endl;
193 std::cout <<
cmd.GetName() << std::endl;
196 std::cout <<
"Sample count: " << n << std::endl;
200 std::cout <<
"Sampling a single time" << std::endl;
204 std::cout <<
"Antithetic sampling disabled" << std::endl;
211 erv->CDF(0.0, 0.0 / 15.0);
212 erv->CDF(0.2, 1.0 / 15.0);
213 erv->CDF(0.4, 3.0 / 15.0);
214 erv->CDF(0.6, 4.0 / 15.0);
215 erv->CDF(0.8, 7.0 / 15.0);
216 erv->CDF(1.0, 9.0 / 15.0);
217 erv->CDF(1.0, 15.0 / 15.0);
224 std::cout << std::endl;
225 std::cout <<
"Antithetic" << std::endl;
226 erv->SetAntithetic(
true);
228 erv->SetAntithetic(
false);
231 std::cout << std::endl;
239 erv->SetAntithetic(
true);
241 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.