20 #include "ns3/random-variable-stream.h" 22 #include "ns3/double.h" 23 #include "ns3/string.h" 24 #include "ns3/integer.h" 25 #include "ns3/gnuplot.h" 26 #include "ns3/command-line.h" 49 double dround (
double number,
double precision)
53 number = std::floor (number + 0.5);
55 number = std::ceil (number - 0.5);
71 unsigned int probes,
double precision,
72 const std::string& title,
bool impulses =
false)
74 typedef std::map<double, unsigned int> histogram_maptype;
75 histogram_maptype histogram;
77 for(
unsigned int i = 0; i < probes; ++i)
85 data.SetTitle (title);
92 for(histogram_maptype::const_iterator hi = histogram.begin ();
93 hi != histogram.end (); ++hi)
95 data.Add (hi->first, (
double)hi->second / (
double)probes / precision);
104 int main (
int argc,
char *argv[])
107 cmd.Parse(argc, argv);
109 unsigned int probes = 1000000;
110 double precision = 0.01;
113 gnuplots.SetTerminal (
"pdf enhanced");
117 plot.
SetTitle (
"UniformRandomVariable");
125 "UniformRandomVariable [0.0 .. 1.0)") );
127 "0 <= x && x <= 1 ? 1.0 : 0") );
129 gnuplots.AddPlot (plot);
134 plot.
SetTitle (
"ExponentialRandomVariable");
136 plot.
AppendExtra (
"ExpDist(x,l) = 1/l * exp(-1/l * x)");
142 "ExponentialRandomVariable m=0.5") );
145 "ExpDist(x, 0.5)") );
151 "ExponentialRandomVariable m=1") );
154 "ExpDist(x, 1.0)") );
160 "ExponentialRandomVariable m=1.5") );
163 "ExpDist(x, 1.5)") );
165 gnuplots.AddPlot (plot);
170 plot.
SetTitle (
"ParetoRandomVariable");
178 "ParetoRandomVariable scale=1.0 shape=1.5") );
185 "ParetoRandomVariable scale=1.0 shape=2.0") );
192 "ParetoRandomVariable scale=1.0 shape=2.5") );
194 gnuplots.AddPlot (plot);
199 plot.
SetTitle (
"WeibullRandomVariable");
207 "WeibullRandomVariable scale=1.0 shape=1.0") );
214 "WeibullRandomVariable scale=1.0 shape=2.0") );
221 "WeibullRandomVariable scale=1.0 shape=3.0") );
223 gnuplots.AddPlot (plot);
228 plot.
SetTitle (
"NormalRandomVariable");
230 plot.
AppendExtra (
"NormalDist(x,m,s) = 1 / (s * sqrt(2*pi)) * exp(-1.0 / 2.0 * ((x-m) / s)**2)");
237 "NormalRandomVariable m=0.0 v=1.0") );
240 "NormalDist(x,0.0,1.0)") );
247 "NormalRandomVariable m=0.0 v=2.0") );
250 "NormalDist(x,0.0,sqrt(2.0))") );
257 "NormalRandomVariable m=0.0 v=3.0") );
260 "NormalDist(x,0.0,sqrt(3.0))") );
262 gnuplots.AddPlot (plot);
306 plot.
SetTitle (
"LogNormalRandomVariable");
309 plot.
AppendExtra (
"LogNormalDist(x,m,s) = 1.0/x * NormalDist(log(x), m, s)");
316 "LogNormalRandomVariable m=0.0 s=1.0") );
319 "LogNormalDist(x, 0.0, 1.0)") );
326 "LogNormalRandomVariable m=0.0 s=0.5") );
333 "LogNormalRandomVariable m=0.0 s=0.25") );
336 "LogNormalDist(x, 0.0, 0.25)") );
343 "LogNormalRandomVariable m=0.0 s=0.125") );
350 "LogNormalRandomVariable m=0.0 s=2.0") );
353 "LogNormalDist(x, 0.0, 2.0)") );
360 "LogNormalRandomVariable m=0.0 s=2.5") );
362 gnuplots.AddPlot (plot);
367 plot.
SetTitle (
"TriangularRandomVariable");
376 "TriangularRandomVariable [0.0 .. 1.0) m=0.5") );
384 "TriangularRandomVariable [0.0 .. 1.0) m=0.4") );
392 "TriangularRandomVariable [0.0 .. 1.0) m=0.65") );
394 gnuplots.AddPlot (plot);
399 plot.
SetTitle (
"GammaRandomVariable");
402 plot.
AppendExtra (
"GammaDist(x,a,b) = x**(a-1) * 1/b**a * exp(-x/b) / gamma(a)");
404 plot.
AppendExtra (
"set label 1 '{/Symbol g}(x,{/Symbol a},{/Symbol b}) = x^{/Symbol a-1} e^{-x {/Symbol b}^{-1}} ( {/Symbol b}^{/Symbol a} {/Symbol G}({/Symbol a}) )^{-1}' at 0.7, 0.9");
411 "GammaRandomVariable a=1.0 b=1.0") );
414 "GammaDist(x, 1.0, 1.0)") );
421 "GammaRandomVariable a=1.5 b=1.0") );
424 "GammaDist(x, 1.5, 1.0)") );
431 "GammaRandomVariable a=2.0 b=1.0") );
434 "GammaDist(x, 2.0, 1.0)") );
441 "GammaRandomVariable a=4.0 b=1.0") );
444 "GammaDist(x, 4.0, 1.0)") );
451 "GammaRandomVariable a=2.0 b=2.0") );
454 "GammaDist(x, 2.0, 2.0)") );
461 "GammaRandomVariable a=2.5 b=3.0") );
464 "GammaDist(x, 2.5, 3.0)") );
471 "GammaRandomVariable a=2.5 b=4.5") );
474 "GammaDist(x, 2.5, 4.5)") );
476 gnuplots.AddPlot (plot);
481 plot.
SetTitle (
"ErlangRandomVariable");
483 plot.
AppendExtra (
"ErlangDist(x,k,l) = x**(k-1) * 1/l**k * exp(-x/l) / (k-1)!");
485 plot.
AppendExtra (
"set label 1 'Erlang(x,k,{/Symbol l}) = x^{k-1} e^{-x {/Symbol l}^{-1}} ( {/Symbol l}^k (k-1)! )^{-1}' at 0.7, 0.9");
492 "ErlangRandomVariable k=1 {/Symbol l}=1.0") );
495 "ErlangDist(x, 1, 1.0)") );
502 "ErlangRandomVariable k=2 {/Symbol l}=1.0") );
505 "ErlangDist(x, 2, 1.0)") );
512 "ErlangRandomVariable k=3 {/Symbol l}=1.0") );
515 "ErlangDist(x, 3, 1.0)") );
522 "ErlangRandomVariable k=5 {/Symbol l}=1.0") );
525 "ErlangDist(x, 5, 1.0)") );
532 "ErlangRandomVariable k=2 {/Symbol l}=2.0") );
535 "ErlangDist(x, 2, 2.0)") );
542 "ErlangRandomVariable k=2 {/Symbol l}=3.0") );
545 "ErlangDist(x, 2, 3.0)") );
552 "ErlangRandomVariable k=2 {/Symbol l}=5.0") );
555 "ErlangDist(x, 2, 5.0)") );
557 gnuplots.AddPlot (plot);
560 gnuplots.GenerateOutput (std::cout);
void AppendExtra(const std::string &extra)
Class to represent a 2D points plot.
Abstract class to store a plot line to be used by ns3::Gnuplot.
Hold a signed integer type.
void AddDataset(const GnuplotDataset &dataset)
static double dround(double number, double precision)
Round a double number to the given precision.
virtual double GetValue(void)=0
Get the next random value as a double drawn from the distribution.
a simple class to generate gnuplot-ready plotting commands from a set of datasets.
a simple class to group together multiple gnuplots into one file, e.g.
void SetTitle(const std::string &title)
Parse command-line arguments.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Class to represent a 2D function expression plot.
This class can be used to hold variables of floating point type such as 'double' or 'float'...
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
Class used to store data and make an histogram of the data frequency.