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);
45 Histogramm (
Ptr<RandomVariableStream> rndvar,
unsigned int probes,
double precision,
const std::string& title,
bool notcontinous =
false)
47 typedef std::map<double, unsigned int> histogramm_maptype;
48 histogramm_maptype histogramm;
50 for(
unsigned int i = 0; i < probes; ++i)
52 double val = dround ( rndvar->
GetValue (), precision );
62 data.
SetStyle (Gnuplot2dDataset::IMPULSES);
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;
80 gnuplots.SetTerminal (
"pdf enhanced");
84 plot.
SetTitle (
"UniformRandomVariable");
91 plot.
AddDataset ( Histogramm (x, probes, precision,
92 "UniformRandomVariable [0.0 .. 1.0)") );
94 "0 <= x && x <= 1 ? 1.0 : 0") );
96 gnuplots.AddPlot (plot);
101 plot.
SetTitle (
"ExponentialRandomVariable");
103 plot.
AppendExtra (
"ExpDist(x,l) = 1/l * exp(-1/l * x)");
108 plot.
AddDataset ( Histogramm (x1, probes, precision,
109 "ExponentialRandomVariable m=0.5") );
112 "ExpDist(x, 0.5)") );
117 plot.
AddDataset ( Histogramm (x2, probes, precision,
118 "ExponentialRandomVariable m=1") );
121 "ExpDist(x, 1.0)") );
126 plot.
AddDataset ( Histogramm (x3, probes, precision,
127 "ExponentialRandomVariable m=1.5") );
130 "ExpDist(x, 1.5)") );
132 gnuplots.AddPlot (plot);
137 plot.
SetTitle (
"ParetoRandomVariable");
144 plot.
AddDataset ( Histogramm (x1, probes, precision,
145 "ParetoRandomVariable m=1.0 s=1.5") );
151 plot.
AddDataset ( Histogramm (x2, probes, precision,
152 "ParetoRandomVariable m=1.0 s=2.0") );
158 plot.
AddDataset ( Histogramm (x3, probes, precision,
159 "ParetoRandomVariable m=1.0 s=2.5") );
161 gnuplots.AddPlot (plot);
166 plot.
SetTitle (
"WeibullRandomVariable");
173 plot.
AddDataset ( Histogramm (x1, probes, precision,
174 "WeibullRandomVariable m=1.0 s=1.0") );
180 plot.
AddDataset ( Histogramm (x2, probes, precision,
181 "WeibullRandomVariable m=1.0 s=2.0") );
187 plot.
AddDataset ( Histogramm (x3, probes, precision,
188 "WeibullRandomVariable m=1.0 s=3.0") );
190 gnuplots.AddPlot (plot);
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)");
203 plot.
AddDataset ( Histogramm (x1, probes, precision,
204 "NormalRandomVariable m=0.0 v=1.0") );
207 "NormalDist(x,0.0,1.0)") );
213 plot.
AddDataset ( Histogramm (x2, probes, precision,
214 "NormalRandomVariable m=0.0 v=2.0") );
217 "NormalDist(x,0.0,sqrt(2.0))") );
223 plot.
AddDataset ( Histogramm (x3, probes, precision,
224 "NormalRandomVariable m=0.0 v=3.0") );
227 "NormalDist(x,0.0,sqrt(3.0))") );
229 gnuplots.AddPlot (plot);
275 plot.
SetTitle (
"LogNormalRandomVariable");
278 plot.
AppendExtra (
"LogNormalDist(x,m,s) = 1.0/x * NormalDist(log(x), m, s)");
284 plot.
AddDataset ( Histogramm (x1, probes, precision,
285 "LogNormalRandomVariable m=0.0 s=1.0") );
288 "LogNormalDist(x, 0.0, 1.0)") );
294 plot.
AddDataset ( Histogramm (x2, probes, precision,
295 "LogNormalRandomVariable m=0.0 s=0.5") );
301 plot.
AddDataset ( Histogramm (x3, probes, precision,
302 "LogNormalRandomVariable m=0.0 s=0.25") );
305 "LogNormalDist(x, 0.0, 0.25)") );
311 plot.
AddDataset ( Histogramm (x4, probes, precision,
312 "LogNormalRandomVariable m=0.0 s=0.125") );
318 plot.
AddDataset ( Histogramm (x5, probes, precision,
319 "LogNormalRandomVariable m=0.0 s=2.0") );
322 "LogNormalDist(x, 0.0, 2.0)") );
328 plot.
AddDataset ( Histogramm (x6, probes, precision,
329 "LogNormalRandomVariable m=0.0 s=2.5") );
331 gnuplots.AddPlot (plot);
336 plot.
SetTitle (
"TriangularRandomVariable");
344 plot.
AddDataset ( Histogramm (x1, probes, precision,
345 "TriangularRandomVariable [0.0 .. 1.0) m=0.5") );
352 plot.
AddDataset ( Histogramm (x2, probes, precision,
353 "TriangularRandomVariable [0.0 .. 1.0) m=0.4") );
360 plot.
AddDataset ( Histogramm (x3, probes, precision,
361 "TriangularRandomVariable [0.0 .. 1.0) m=0.65") );
363 gnuplots.AddPlot (plot);
368 plot.
SetTitle (
"GammaRandomVariable");
371 plot.
AppendExtra (
"GammaDist(x,a,b) = x**(a-1) * 1/b**a * exp(-x/b) / gamma(a)");
373 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");
379 plot.
AddDataset ( Histogramm (x1, probes, precision,
380 "GammaRandomVariable a=1.0 b=1.0") );
383 "GammaDist(x, 1.0, 1.0)") );
389 plot.
AddDataset ( Histogramm (x2, probes, precision,
390 "GammaRandomVariable a=1.5 b=1.0") );
393 "GammaDist(x, 1.5, 1.0)") );
399 plot.
AddDataset ( Histogramm (x3, probes, precision,
400 "GammaRandomVariable a=2.0 b=1.0") );
403 "GammaDist(x, 2.0, 1.0)") );
409 plot.
AddDataset ( Histogramm (x4, probes, precision,
410 "GammaRandomVariable a=4.0 b=1.0") );
413 "GammaDist(x, 4.0, 1.0)") );
419 plot.
AddDataset ( Histogramm (x5, probes, precision,
420 "GammaRandomVariable a=2.0 b=2.0") );
423 "GammaDist(x, 2.0, 2.0)") );
429 plot.
AddDataset ( Histogramm (x6, probes, precision,
430 "GammaRandomVariable a=2.5 b=3.0") );
433 "GammaDist(x, 2.5, 3.0)") );
439 plot.
AddDataset ( Histogramm (x7, probes, precision,
440 "GammaRandomVariable a=2.5 b=4.5") );
443 "GammaDist(x, 2.5, 4.5)") );
445 gnuplots.AddPlot (plot);
450 plot.
SetTitle (
"ErlangRandomVariable");
452 plot.
AppendExtra (
"ErlangDist(x,k,l) = x**(k-1) * 1/l**k * exp(-x/l) / (k-1)!");
454 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");
460 plot.
AddDataset ( Histogramm (x1, probes, precision,
461 "ErlangRandomVariable k=1 {/Symbol l}=1.0") );
464 "ErlangDist(x, 1, 1.0)") );
470 plot.
AddDataset ( Histogramm (x2, probes, precision,
471 "ErlangRandomVariable k=2 {/Symbol l}=1.0") );
474 "ErlangDist(x, 2, 1.0)") );
480 plot.
AddDataset ( Histogramm (x3, probes, precision,
481 "ErlangRandomVariable k=3 {/Symbol l}=1.0") );
484 "ErlangDist(x, 3, 1.0)") );
490 plot.
AddDataset ( Histogramm (x4, probes, precision,
491 "ErlangRandomVariable k=5 {/Symbol l}=1.0") );
494 "ErlangDist(x, 5, 1.0)") );
500 plot.
AddDataset ( Histogramm (x5, probes, precision,
501 "ErlangRandomVariable k=2 {/Symbol l}=2.0") );
504 "ErlangDist(x, 2, 2.0)") );
510 plot.
AddDataset ( Histogramm (x6, probes, precision,
511 "ErlangRandomVariable k=2 {/Symbol l}=3.0") );
514 "ErlangDist(x, 2, 3.0)") );
520 plot.
AddDataset ( Histogramm (x7, probes, precision,
521 "ErlangRandomVariable k=2 {/Symbol l}=5.0") );
524 "ErlangDist(x, 2, 5.0)") );
526 gnuplots.AddPlot (plot);
529 gnuplots.GenerateOutput (std::cout);
void AppendExtra(const std::string &extra)
Class to represent a 2D points plot. Set the line or points style using SetStyle() and set points usi...
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. for PDF multi-page output term...
void SetTitle(const std::string &title)
void Add(double x, double y)
void SetStyle(enum Style style)
Class to represent a 2D function expression plot.
Hold an floating point type.
void SetAttribute(std::string name, const AttributeValue &value)