9#include "ns3/command-line.h"
10#include "ns3/histogram.h"
11#include "ns3/nstime.h"
13#include "ns3/random-variable-stream.h"
14#include "ns3/simulator.h"
55 std::cout <<
"------------------------------" << std::endl;
56 std::cout <<
"Sampling " << mode << std::endl;
58 std::cout << std::endl;
59 std::cout <<
"Binned sample" << std::endl;
60 double value = erv->GetValue();
61 std::cout <<
"Binned sample: " << value << std::endl;
62 std::cout << std::endl;
64 std::cout <<
"Interpolated sample" << std::endl;
65 erv->SetInterpolate(
true);
66 value = erv->GetValue();
67 std::cout <<
"Interpolated sample:" << value << std::endl;
68 erv->SetInterpolate(
false);
82PrintStatsLine(
const double value,
const long count,
const long n,
const long sum)
84 std::cout << std::fixed << std::setprecision(3) << std::setw(10) << std::right << value
85 << std::setw(10) << std::right << count << std::setw(10) << std::right
86 << count /
static_cast<double>(n) * 100.0 << std::setw(10) << std::right
87 << sum /
static_cast<double>(n) * 100.0 << std::endl;
102 std::cout << std::endl;
103 std::cout <<
" --------" << std::endl;
104 std::cout <<
" Total " << std::setprecision(3) << std::fixed << std::setw(10)
105 << std::right << sum /
static_cast<double>(n) * 100.0 << std::endl;
106 std::cout <<
" Average " << std::setprecision(3) << std::fixed << std::setw(6)
107 << std::right << weighted / n << std::endl;
108 std::cout <<
" Expected " << std::setprecision(3) << std::fixed << std::setw(6)
109 << std::right << expected << std::endl
124 std::cout << std::endl;
125 std::cout <<
"Sampling " << mode << std::endl;
126 std::map<double, int> counts;
128 for (
long i = 0; i < n; ++i)
130 ++counts[erv->GetValue()];
134 std::cout << std::endl;
135 std::cout <<
" Value Counts % % CDF" << std::endl;
136 std::cout <<
"---------- -------- -------- --------" << std::endl;
137 for (
auto c : counts)
139 long count = c.second;
140 double value = c.first;
142 weighted += value * count;
147 std::cout <<
"Interpolating " << mode << std::endl;
148 erv->SetInterpolate(
true);
150 for (
long i = 0; i < n; ++i)
156 erv->SetInterpolate(
false);
159 std::cout << std::endl;
160 std::cout <<
" Bin Start Counts % % CDF" << std::endl;
161 std::cout <<
"---------- -------- -------- --------" << std::endl;
168 weighted += count * value;
175main(
int argc,
char* argv[])
178 bool disableAnti =
false;
181 cmd.AddValue(
"count",
"how many draws to make from the rng", n);
182 cmd.AddValue(
"antithetic",
"disable antithetic sampling", disableAnti);
183 cmd.AddValue(
"single",
"sample a single time", single);
184 cmd.Parse(argc, argv);
185 std::cout << std::endl;
186 std::cout <<
cmd.GetName() << std::endl;
189 std::cout <<
"Sample count: " << n << std::endl;
193 std::cout <<
"Sampling a single time" << std::endl;
197 std::cout <<
"Antithetic sampling disabled" << std::endl;
204 erv->CDF(0.0, 0.0 / 15.0);
205 erv->CDF(0.2, 1.0 / 15.0);
206 erv->CDF(0.4, 3.0 / 15.0);
207 erv->CDF(0.6, 4.0 / 15.0);
208 erv->CDF(0.8, 7.0 / 15.0);
209 erv->CDF(1.0, 9.0 / 15.0);
210 erv->CDF(1.0, 15.0 / 15.0);
217 std::cout << std::endl;
218 std::cout <<
"Antithetic" << std::endl;
219 erv->SetAntithetic(
true);
221 erv->SetAntithetic(
false);
224 std::cout << std::endl;
232 erv->SetAntithetic(
true);
234 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.
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Every class exported by the ns3 library is enclosed in the ns3 namespace.