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" 55 std::cout <<
"------------------------------" << std::endl;
56 std::cout <<
"Sampling " << mode << std::endl;
58 std::cout << std::endl;
59 std::cout <<
"Binned sample" << std::endl;
61 std::cout <<
"Binned sample: " << value << std::endl;
62 std::cout << std::endl;
64 std::cout <<
"Interpolated sample" << std::endl;
67 std::cout <<
"Interpolated sample:" << value << std::endl;
74 std::cout << std::fixed << std::setprecision (3)
75 << std::setw (10) << std::right << value
76 << std::setw (10) << std::right << count
77 << std::setw (10) << std::right
78 << count /
static_cast<double> (
n) * 100.0
85 std::cout << std::endl;
86 std::cout <<
" --------" << std::endl;
87 std::cout <<
" Total " 88 << std::setprecision (3) << std::fixed
89 << std::setw (10) << std::right
90 << sum /
static_cast<double> (
n) * 100.0
92 std::cout <<
" Average " 93 << std::setprecision (3) << std::fixed
94 << std::setw (6) << std::right << weighted /
n 96 std::cout <<
" Expected " 97 << std::setprecision (3) << std::fixed
98 << std::setw (6) << std::right << expected
106 std::cout << std::endl;
107 std::cout <<
"Sampling " << mode << std::endl;
108 std::map <double, int> counts;
110 for (
long i = 0; i <
n; ++i)
116 std::cout << std::endl;
117 std::cout <<
" Value Counts %" << std::endl;
118 std::cout <<
"---------- -------- --------" << std::endl;
119 for (
auto c : counts)
121 long count = c.second;
122 double value = c.first;
124 weighted += value * count;
129 std::cout <<
"Interpolating " << mode << std::endl;
132 for (
long i = 0; i <
n; ++i)
141 std::cout << std::endl;
142 std::cout <<
" Bin Start Counts %" << std::endl;
143 std::cout <<
"---------- -------- --------" << std::endl;
144 for (uint32_t i = 0; i < h.
GetNBins (); ++i)
150 weighted += count * value;
157 int main (
int argc,
char *argv[])
160 bool disableAnti =
false;
163 cmd.AddValue (
"count",
"how many draws to make from the rng",
n);
164 cmd.AddValue (
"antithetic",
"disable antithetic sampling", disableAnti);
165 cmd.AddValue (
"single",
"sample a single time", single);
166 cmd.Parse (argc, argv);
167 std::cout << std::endl;
168 std::cout <<
cmd.GetName () << std::endl;
171 std::cout <<
"Sample count: " <<
n << std::endl;
175 std::cout <<
"Sampling a single time" << std::endl;
179 std::cout <<
"Antithetic sampling disabled" << std::endl;
185 erv->
CDF ( 0.0, 0.0);
186 erv->
CDF ( 5.0, 0.25);
187 erv->
CDF (10.0, 1.0);
194 std::cout << std::endl;
195 std::cout <<
"Antithetic" << std::endl;
201 std::cout << std::endl;
void PrintStatsLine(const double value, const long count, const long n)
void SetAntithetic(bool isAntithetic)
Specify whether antithetic values should be generated.
virtual double GetValue(void)
Returns the next value in the empirical distribution.
Smart pointer class similar to boost::intrusive_ptr.
uint32_t GetNBins() const
Returns the number of bins in the histogram.
void RunSingleSample(std::string mode, Ptr< EmpiricalRandomVariable > erv)
void CDF(double v, double c)
Specifies a point in the empirical distribution.
Parse command-line arguments.
bool SetInterpolate(bool interpolate)
Switch the mode between sampling the CDF and interpolating.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void RunBothModes(std::string mode, Ptr< EmpiricalRandomVariable > erv, long n)
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.
double GetBinStart(uint32_t index)
Returns the bin start, i.e., index*binWidth.
void PrintSummary(long sum, long n, double weighted, double expected)
void AddValue(double value)
Add a value to the histogram.
Class used to store data and make an histogram of the data frequency.