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"
33 double dround (
double number,
double precision)
37 number = std::floor (number + 0.5);
39 number = std::ceil (number - 0.5);
47 typedef std::map<double, unsigned int> histogramm_maptype;
48 histogramm_maptype histogramm;
50 for(
unsigned int i = 0; i < probes; ++i)
65 for(histogramm_maptype::const_iterator hi = histogramm.begin ();
66 hi != histogramm.end (); ++hi)
68 data.
Add (hi->first, (
double)hi->second / (
double)probes / precision);
74 int main (
int argc,
char *argv[])
76 unsigned int probes = 1000000;
77 double precision = 0.01;
84 plot.
SetTitle (
"UniformRandomVariable");
92 "UniformRandomVariable [0.0 .. 1.0)") );
94 "0 <= x && x <= 1 ? 1.0 : 0") );
101 plot.
SetTitle (
"ExponentialRandomVariable");
103 plot.
AppendExtra (
"ExpDist(x,l) = 1/l * exp(-1/l * x)");
109 "ExponentialRandomVariable m=0.5") );
112 "ExpDist(x, 0.5)") );
118 "ExponentialRandomVariable m=1") );
121 "ExpDist(x, 1.0)") );
127 "ExponentialRandomVariable m=1.5") );
130 "ExpDist(x, 1.5)") );
137 plot.
SetTitle (
"ParetoRandomVariable");
145 "ParetoRandomVariable m=1.0 s=1.5") );
152 "ParetoRandomVariable m=1.0 s=2.0") );
159 "ParetoRandomVariable m=1.0 s=2.5") );
166 plot.
SetTitle (
"WeibullRandomVariable");
174 "WeibullRandomVariable m=1.0 s=1.0") );
181 "WeibullRandomVariable m=1.0 s=2.0") );
188 "WeibullRandomVariable m=1.0 s=3.0") );
195 plot.
SetTitle (
"NormalRandomVariable");
197 plot.
AppendExtra (
"NormalDist(x,m,s) = 1 / (s * sqrt(2*pi)) * exp(-1.0 / 2.0 * ((x-m) / s)**2)");
204 "NormalRandomVariable m=0.0 v=1.0") );
207 "NormalDist(x,0.0,1.0)") );
214 "NormalRandomVariable m=0.0 v=2.0") );
217 "NormalDist(x,0.0,sqrt(2.0))") );
224 "NormalRandomVariable m=0.0 v=3.0") );
227 "NormalDist(x,0.0,sqrt(3.0))") );
273 plot.
SetTitle (
"LogNormalRandomVariable");
276 plot.
AppendExtra (
"LogNormalDist(x,m,s) = 1.0/x * NormalDist(log(x), m, s)");
283 "LogNormalRandomVariable m=0.0 s=1.0") );
286 "LogNormalDist(x, 0.0, 1.0)") );
293 "LogNormalRandomVariable m=0.0 s=0.5") );
300 "LogNormalRandomVariable m=0.0 s=0.25") );
303 "LogNormalDist(x, 0.0, 0.25)") );
310 "LogNormalRandomVariable m=0.0 s=0.125") );
317 "LogNormalRandomVariable m=0.0 s=2.0") );
320 "LogNormalDist(x, 0.0, 2.0)") );
327 "LogNormalRandomVariable m=0.0 s=2.5") );
334 plot.
SetTitle (
"TriangularRandomVariable");
343 "TriangularRandomVariable [0.0 .. 1.0) m=0.5") );
351 "TriangularRandomVariable [0.0 .. 1.0) m=0.4") );
359 "TriangularRandomVariable [0.0 .. 1.0) m=0.65") );
366 plot.
SetTitle (
"GammaRandomVariable");
369 plot.
AppendExtra (
"GammaDist(x,a,b) = x**(a-1) * 1/b**a * exp(-x/b) / gamma(a)");
371 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");
378 "GammaRandomVariable a=1.0 b=1.0") );
381 "GammaDist(x, 1.0, 1.0)") );
388 "GammaRandomVariable a=1.5 b=1.0") );
391 "GammaDist(x, 1.5, 1.0)") );
398 "GammaRandomVariable a=2.0 b=1.0") );
401 "GammaDist(x, 2.0, 1.0)") );
408 "GammaRandomVariable a=4.0 b=1.0") );
411 "GammaDist(x, 4.0, 1.0)") );
418 "GammaRandomVariable a=2.0 b=2.0") );
421 "GammaDist(x, 2.0, 2.0)") );
428 "GammaRandomVariable a=2.5 b=3.0") );
431 "GammaDist(x, 2.5, 3.0)") );
438 "GammaRandomVariable a=2.5 b=4.5") );
441 "GammaDist(x, 2.5, 4.5)") );
448 plot.
SetTitle (
"ErlangRandomVariable");
450 plot.
AppendExtra (
"ErlangDist(x,k,l) = x**(k-1) * 1/l**k * exp(-x/l) / (k-1)!");
452 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");
459 "ErlangRandomVariable k=1 {/Symbol l}=1.0") );
462 "ErlangDist(x, 1, 1.0)") );
469 "ErlangRandomVariable k=2 {/Symbol l}=1.0") );
472 "ErlangDist(x, 2, 1.0)") );
479 "ErlangRandomVariable k=3 {/Symbol l}=1.0") );
482 "ErlangDist(x, 3, 1.0)") );
489 "ErlangRandomVariable k=5 {/Symbol l}=1.0") );
492 "ErlangDist(x, 5, 1.0)") );
499 "ErlangRandomVariable k=2 {/Symbol l}=2.0") );
502 "ErlangDist(x, 2, 2.0)") );
509 "ErlangRandomVariable k=2 {/Symbol l}=3.0") );
512 "ErlangDist(x, 2, 3.0)") );
519 "ErlangRandomVariable k=2 {/Symbol l}=5.0") );
522 "ErlangDist(x, 2, 5.0)") );
int main(int argc, char *argv[])
void AppendExtra(const std::string &extra)
Class to represent a 2D points plot.
void SetTitle(const std::string &title)
Change line title.
Abstract class to store a plot line to be used by ns3::Gnuplot.
Hold a signed integer type.
void AddDataset(const GnuplotDataset &dataset)
virtual double GetValue(void)=0
Returns a random double from the underlying 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)
void Add(double x, double y)
void AddPlot(const Gnuplot &plot)
void GenerateOutput(std::ostream &os)
static GnuplotDataset Histogramm(Ptr< RandomVariableStream > rndvar, unsigned int probes, double precision, const std::string &title, bool notcontinous=false)
double dround(double number, double precision)
Round a double number to the given precision.
void SetStyle(enum Style style)
void SetTerminal(const std::string &terminal)
Class to represent a 2D function expression plot.
Hold a floating point type.
void SetAttribute(std::string name, const AttributeValue &value)