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)
54 number = std::floor (number + 0.5);
58 number = std::ceil (number - 0.5);
75 unsigned int probes,
double precision,
76 const std::string& title,
bool impulses =
false)
78 typedef std::map<double, unsigned int> histogram_maptype;
79 histogram_maptype histogram;
81 for (
unsigned int i = 0; i < probes; ++i)
89 data.SetTitle (title);
96 for (histogram_maptype::const_iterator hi = histogram.begin ();
97 hi != histogram.end (); ++hi)
99 data.Add (hi->first, (
double)hi->second / (
double)probes / precision);
108 int main (
int argc,
char *argv[])
111 cmd.Parse (argc, argv);
113 unsigned int probes = 1000000;
114 double precision = 0.01;
117 gnuplots.SetTerminal (
"pdf enhanced");
121 plot.
SetTitle (
"UniformRandomVariable");
129 "UniformRandomVariable [0.0 .. 1.0)") );
131 "0 <= x && x <= 1 ? 1.0 : 0") );
133 gnuplots.AddPlot (plot);
138 plot.
SetTitle (
"ExponentialRandomVariable");
140 plot.
AppendExtra (
"ExpDist(x,l) = 1/l * exp(-1/l * x)");
146 "ExponentialRandomVariable m=0.5") );
149 "ExpDist(x, 0.5)") );
155 "ExponentialRandomVariable m=1") );
158 "ExpDist(x, 1.0)") );
164 "ExponentialRandomVariable m=1.5") );
167 "ExpDist(x, 1.5)") );
169 gnuplots.AddPlot (plot);
174 plot.
SetTitle (
"ParetoRandomVariable");
182 "ParetoRandomVariable scale=1.0 shape=1.5") );
189 "ParetoRandomVariable scale=1.0 shape=2.0") );
196 "ParetoRandomVariable scale=1.0 shape=2.5") );
198 gnuplots.AddPlot (plot);
203 plot.
SetTitle (
"WeibullRandomVariable");
211 "WeibullRandomVariable scale=1.0 shape=1.0") );
218 "WeibullRandomVariable scale=1.0 shape=2.0") );
225 "WeibullRandomVariable scale=1.0 shape=3.0") );
227 gnuplots.AddPlot (plot);
232 plot.
SetTitle (
"NormalRandomVariable");
234 plot.
AppendExtra (
"NormalDist(x,m,s) = 1 / (s * sqrt(2*pi)) * exp(-1.0 / 2.0 * ((x-m) / s)**2)");
241 "NormalRandomVariable m=0.0 v=1.0") );
244 "NormalDist(x,0.0,1.0)") );
251 "NormalRandomVariable m=0.0 v=2.0") );
254 "NormalDist(x,0.0,sqrt(2.0))") );
261 "NormalRandomVariable m=0.0 v=3.0") );
264 "NormalDist(x,0.0,sqrt(3.0))") );
266 gnuplots.AddPlot (plot);
310 plot.
SetTitle (
"LogNormalRandomVariable");
313 plot.
AppendExtra (
"LogNormalDist(x,m,s) = 1.0/x * NormalDist(log(x), m, s)");
320 "LogNormalRandomVariable m=0.0 s=1.0") );
323 "LogNormalDist(x, 0.0, 1.0)") );
330 "LogNormalRandomVariable m=0.0 s=0.5") );
337 "LogNormalRandomVariable m=0.0 s=0.25") );
340 "LogNormalDist(x, 0.0, 0.25)") );
347 "LogNormalRandomVariable m=0.0 s=0.125") );
354 "LogNormalRandomVariable m=0.0 s=2.0") );
357 "LogNormalDist(x, 0.0, 2.0)") );
364 "LogNormalRandomVariable m=0.0 s=2.5") );
366 gnuplots.AddPlot (plot);
371 plot.
SetTitle (
"TriangularRandomVariable");
380 "TriangularRandomVariable [0.0 .. 1.0) m=0.5") );
388 "TriangularRandomVariable [0.0 .. 1.0) m=0.4") );
396 "TriangularRandomVariable [0.0 .. 1.0) m=0.65") );
398 gnuplots.AddPlot (plot);
403 plot.
SetTitle (
"GammaRandomVariable");
406 plot.
AppendExtra (
"GammaDist(x,a,b) = x**(a-1) * 1/b**a * exp(-x/b) / gamma(a)");
408 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");
415 "GammaRandomVariable a=1.0 b=1.0") );
418 "GammaDist(x, 1.0, 1.0)") );
425 "GammaRandomVariable a=1.5 b=1.0") );
428 "GammaDist(x, 1.5, 1.0)") );
435 "GammaRandomVariable a=2.0 b=1.0") );
438 "GammaDist(x, 2.0, 1.0)") );
445 "GammaRandomVariable a=4.0 b=1.0") );
448 "GammaDist(x, 4.0, 1.0)") );
455 "GammaRandomVariable a=2.0 b=2.0") );
458 "GammaDist(x, 2.0, 2.0)") );
465 "GammaRandomVariable a=2.5 b=3.0") );
468 "GammaDist(x, 2.5, 3.0)") );
475 "GammaRandomVariable a=2.5 b=4.5") );
478 "GammaDist(x, 2.5, 4.5)") );
480 gnuplots.AddPlot (plot);
485 plot.
SetTitle (
"ErlangRandomVariable");
487 plot.
AppendExtra (
"ErlangDist(x,k,l) = x**(k-1) * 1/l**k * exp(-x/l) / (k-1)!");
489 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");
496 "ErlangRandomVariable k=1 {/Symbol l}=1.0") );
499 "ErlangDist(x, 1, 1.0)") );
506 "ErlangRandomVariable k=2 {/Symbol l}=1.0") );
509 "ErlangDist(x, 2, 1.0)") );
516 "ErlangRandomVariable k=3 {/Symbol l}=1.0") );
519 "ErlangDist(x, 3, 1.0)") );
526 "ErlangRandomVariable k=5 {/Symbol l}=1.0") );
529 "ErlangDist(x, 5, 1.0)") );
536 "ErlangRandomVariable k=2 {/Symbol l}=2.0") );
539 "ErlangDist(x, 2, 2.0)") );
546 "ErlangRandomVariable k=2 {/Symbol l}=3.0") );
549 "ErlangDist(x, 2, 3.0)") );
556 "ErlangRandomVariable k=2 {/Symbol l}=5.0") );
559 "ErlangDist(x, 2, 5.0)") );
561 gnuplots.AddPlot (plot);
564 gnuplots.GenerateOutput (std::cout);
Parse command-line arguments.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Class to represent a 2D points plot.
Class to represent a 2D function expression plot.
a simple class to group together multiple gnuplots into one file, e.g.
Abstract class to store a plot line to be used by ns3::Gnuplot.
a simple class to generate gnuplot-ready plotting commands from a set of datasets.
void AddDataset(const GnuplotDataset &dataset)
void AppendExtra(const std::string &extra)
void SetTitle(const std::string &title)
Class used to store data and make an histogram of the data frequency.
Hold a signed integer type.
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
virtual double GetValue(void)=0
Get the next random value as a double drawn from the distribution.
static double dround(double number, double precision)
Round a double number to the given precision.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
list x
Random number samples.