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"
48 double dround (
double number,
double precision)
52 number = std::floor (number + 0.5);
54 number = std::ceil (number - 0.5);
70 unsigned int probes,
double precision,
71 const std::string& title,
bool impulses =
false)
73 typedef std::map<double, unsigned int> histogram_maptype;
74 histogram_maptype histogram;
76 for(
unsigned int i = 0; i < probes; ++i)
91 for(histogram_maptype::const_iterator hi = histogram.begin ();
92 hi != histogram.end (); ++hi)
94 data.
Add (hi->first, (
double)hi->second / (
double)probes / precision);
103 int main (
int argc,
char *argv[])
105 unsigned int probes = 1000000;
106 double precision = 0.01;
109 gnuplots.SetTerminal (
"pdf enhanced");
113 plot.
SetTitle (
"UniformRandomVariable");
121 "UniformRandomVariable [0.0 .. 1.0)") );
123 "0 <= x && x <= 1 ? 1.0 : 0") );
125 gnuplots.AddPlot (plot);
130 plot.
SetTitle (
"ExponentialRandomVariable");
132 plot.
AppendExtra (
"ExpDist(x,l) = 1/l * exp(-1/l * x)");
138 "ExponentialRandomVariable m=0.5") );
141 "ExpDist(x, 0.5)") );
147 "ExponentialRandomVariable m=1") );
150 "ExpDist(x, 1.0)") );
156 "ExponentialRandomVariable m=1.5") );
159 "ExpDist(x, 1.5)") );
161 gnuplots.AddPlot (plot);
166 plot.
SetTitle (
"ParetoRandomVariable");
174 "ParetoRandomVariable scale=1.0 shape=1.5") );
181 "ParetoRandomVariable scale=1.0 shape=2.0") );
188 "ParetoRandomVariable scale=1.0 shape=2.5") );
190 gnuplots.AddPlot (plot);
195 plot.
SetTitle (
"WeibullRandomVariable");
203 "WeibullRandomVariable scale=1.0 shape=1.0") );
210 "WeibullRandomVariable scale=1.0 shape=2.0") );
217 "WeibullRandomVariable scale=1.0 shape=3.0") );
219 gnuplots.AddPlot (plot);
224 plot.
SetTitle (
"NormalRandomVariable");
226 plot.
AppendExtra (
"NormalDist(x,m,s) = 1 / (s * sqrt(2*pi)) * exp(-1.0 / 2.0 * ((x-m) / s)**2)");
233 "NormalRandomVariable m=0.0 v=1.0") );
236 "NormalDist(x,0.0,1.0)") );
243 "NormalRandomVariable m=0.0 v=2.0") );
246 "NormalDist(x,0.0,sqrt(2.0))") );
253 "NormalRandomVariable m=0.0 v=3.0") );
256 "NormalDist(x,0.0,sqrt(3.0))") );
258 gnuplots.AddPlot (plot);
302 plot.
SetTitle (
"LogNormalRandomVariable");
305 plot.
AppendExtra (
"LogNormalDist(x,m,s) = 1.0/x * NormalDist(log(x), m, s)");
312 "LogNormalRandomVariable m=0.0 s=1.0") );
315 "LogNormalDist(x, 0.0, 1.0)") );
322 "LogNormalRandomVariable m=0.0 s=0.5") );
329 "LogNormalRandomVariable m=0.0 s=0.25") );
332 "LogNormalDist(x, 0.0, 0.25)") );
339 "LogNormalRandomVariable m=0.0 s=0.125") );
346 "LogNormalRandomVariable m=0.0 s=2.0") );
349 "LogNormalDist(x, 0.0, 2.0)") );
356 "LogNormalRandomVariable m=0.0 s=2.5") );
358 gnuplots.AddPlot (plot);
363 plot.
SetTitle (
"TriangularRandomVariable");
372 "TriangularRandomVariable [0.0 .. 1.0) m=0.5") );
380 "TriangularRandomVariable [0.0 .. 1.0) m=0.4") );
388 "TriangularRandomVariable [0.0 .. 1.0) m=0.65") );
390 gnuplots.AddPlot (plot);
395 plot.
SetTitle (
"GammaRandomVariable");
398 plot.
AppendExtra (
"GammaDist(x,a,b) = x**(a-1) * 1/b**a * exp(-x/b) / gamma(a)");
400 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");
407 "GammaRandomVariable a=1.0 b=1.0") );
410 "GammaDist(x, 1.0, 1.0)") );
417 "GammaRandomVariable a=1.5 b=1.0") );
420 "GammaDist(x, 1.5, 1.0)") );
427 "GammaRandomVariable a=2.0 b=1.0") );
430 "GammaDist(x, 2.0, 1.0)") );
437 "GammaRandomVariable a=4.0 b=1.0") );
440 "GammaDist(x, 4.0, 1.0)") );
447 "GammaRandomVariable a=2.0 b=2.0") );
450 "GammaDist(x, 2.0, 2.0)") );
457 "GammaRandomVariable a=2.5 b=3.0") );
460 "GammaDist(x, 2.5, 3.0)") );
467 "GammaRandomVariable a=2.5 b=4.5") );
470 "GammaDist(x, 2.5, 4.5)") );
472 gnuplots.AddPlot (plot);
477 plot.
SetTitle (
"ErlangRandomVariable");
479 plot.
AppendExtra (
"ErlangDist(x,k,l) = x**(k-1) * 1/l**k * exp(-x/l) / (k-1)!");
481 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");
488 "ErlangRandomVariable k=1 {/Symbol l}=1.0") );
491 "ErlangDist(x, 1, 1.0)") );
498 "ErlangRandomVariable k=2 {/Symbol l}=1.0") );
501 "ErlangDist(x, 2, 1.0)") );
508 "ErlangRandomVariable k=3 {/Symbol l}=1.0") );
511 "ErlangDist(x, 3, 1.0)") );
518 "ErlangRandomVariable k=5 {/Symbol l}=1.0") );
521 "ErlangDist(x, 5, 1.0)") );
528 "ErlangRandomVariable k=2 {/Symbol l}=2.0") );
531 "ErlangDist(x, 2, 2.0)") );
538 "ErlangRandomVariable k=2 {/Symbol l}=3.0") );
541 "ErlangDist(x, 2, 3.0)") );
548 "ErlangRandomVariable k=2 {/Symbol l}=5.0") );
551 "ErlangDist(x, 2, 5.0)") );
553 gnuplots.AddPlot (plot);
556 gnuplots.GenerateOutput (std::cout);
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)
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)
void Add(double x, double y)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void SetStyle(enum Style style)
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.