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))") );
234 plot.
SetTitle (
"EmpiricalRandomVariable");
238 emp1->
CDF (0.0, 0.0 / 15.0);
239 emp1->
CDF (0.2, 1.0 / 15.0);
240 emp1->
CDF (0.4, 3.0 / 15.0);
241 emp1->
CDF (0.6, 6.0 / 15.0);
242 emp1->
CDF (0.8, 10.0 / 15.0);
243 emp1->
CDF (1.0, 15.0 / 15.0);
246 "EmpiricalRandomVariable (Stairs)") );
253 plot.
SetTitle (
"DeterministicRandomVariable");
256 double values[] = { 0.0, 0.2, 0.2, 0.4, 0.2, 0.6, 0.8, 0.8, 1.0 };
259 det1->
SetValueArray (values,
sizeof(values) /
sizeof(values[0]));
262 "DeterministicRandomVariable",
true) );
269 plot.
SetTitle (
"LogNormalRandomVariable");
272 plot.
AppendExtra (
"LogNormalDist(x,m,s) = 1.0/x * NormalDist(log(x), m, s)");
279 "LogNormalRandomVariable m=0.0 s=1.0") );
282 "LogNormalDist(x, 0.0, 1.0)") );
289 "LogNormalRandomVariable m=0.0 s=0.5") );
296 "LogNormalRandomVariable m=0.0 s=0.25") );
299 "LogNormalDist(x, 0.0, 0.25)") );
306 "LogNormalRandomVariable m=0.0 s=0.125") );
313 "LogNormalRandomVariable m=0.0 s=2.0") );
316 "LogNormalDist(x, 0.0, 2.0)") );
323 "LogNormalRandomVariable m=0.0 s=2.5") );
330 plot.
SetTitle (
"TriangularRandomVariable");
339 "TriangularRandomVariable [0.0 .. 1.0) m=0.5") );
347 "TriangularRandomVariable [0.0 .. 1.0) m=0.4") );
355 "TriangularRandomVariable [0.0 .. 1.0) m=0.65") );
362 plot.
SetTitle (
"GammaRandomVariable");
365 plot.
AppendExtra (
"GammaDist(x,a,b) = x**(a-1) * 1/b**a * exp(-x/b) / gamma(a)");
367 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");
374 "GammaRandomVariable a=1.0 b=1.0") );
377 "GammaDist(x, 1.0, 1.0)") );
384 "GammaRandomVariable a=1.5 b=1.0") );
387 "GammaDist(x, 1.5, 1.0)") );
394 "GammaRandomVariable a=2.0 b=1.0") );
397 "GammaDist(x, 2.0, 1.0)") );
404 "GammaRandomVariable a=4.0 b=1.0") );
407 "GammaDist(x, 4.0, 1.0)") );
414 "GammaRandomVariable a=2.0 b=2.0") );
417 "GammaDist(x, 2.0, 2.0)") );
424 "GammaRandomVariable a=2.5 b=3.0") );
427 "GammaDist(x, 2.5, 3.0)") );
434 "GammaRandomVariable a=2.5 b=4.5") );
437 "GammaDist(x, 2.5, 4.5)") );
444 plot.
SetTitle (
"ErlangRandomVariable");
446 plot.
AppendExtra (
"ErlangDist(x,k,l) = x**(k-1) * 1/l**k * exp(-x/l) / (k-1)!");
448 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");
455 "ErlangRandomVariable k=1 {/Symbol l}=1.0") );
458 "ErlangDist(x, 1, 1.0)") );
465 "ErlangRandomVariable k=2 {/Symbol l}=1.0") );
468 "ErlangDist(x, 2, 1.0)") );
475 "ErlangRandomVariable k=3 {/Symbol l}=1.0") );
478 "ErlangDist(x, 3, 1.0)") );
485 "ErlangRandomVariable k=5 {/Symbol l}=1.0") );
488 "ErlangDist(x, 5, 1.0)") );
495 "ErlangRandomVariable k=2 {/Symbol l}=2.0") );
498 "ErlangDist(x, 2, 2.0)") );
505 "ErlangRandomVariable k=2 {/Symbol l}=3.0") );
508 "ErlangDist(x, 2, 3.0)") );
515 "ErlangRandomVariable k=2 {/Symbol l}=5.0") );
518 "ErlangDist(x, 2, 5.0)") );