19#include "ns3/command-line.h"
20#include "ns3/double.h"
21#include "ns3/gnuplot.h"
22#include "ns3/integer.h"
24#include "ns3/random-variable-stream.h"
25#include "ns3/string.h"
51dround(
double number,
double precision)
56 number = std::floor(number + 0.5);
60 number = std::ceil(number - 0.5);
79 const std::string& title,
80 bool impulses =
false)
82 typedef std::map<double, unsigned int> histogram_maptype;
83 histogram_maptype histogram;
85 for (
unsigned int i = 0; i < probes; ++i)
97 data.SetStyle(Gnuplot2dDataset::IMPULSES);
100 for (histogram_maptype::const_iterator hi = histogram.begin(); hi != histogram.end(); ++hi)
102 data.Add(hi->first, (
double)hi->second / (
double)probes / precision);
111main(
int argc,
char* argv[])
114 cmd.Parse(argc, argv);
116 unsigned int probes = 1000000;
117 double precision = 0.01;
120 gnuplots.SetTerminal(
"pdf enhanced");
124 plot.
SetTitle(
"UniformRandomVariable");
134 gnuplots.AddPlot(plot);
139 plot.
SetTitle(
"ExponentialRandomVariable");
141 plot.
AppendExtra(
"ExpDist(x,l) = 1/l * exp(-1/l * x)");
164 gnuplots.AddPlot(plot);
169 plot.
SetTitle(
"ParetoRandomVariable");
177 Histogram(x1, probes, precision,
"ParetoRandomVariable scale=1.0 shape=1.5"));
184 Histogram(x2, probes, precision,
"ParetoRandomVariable scale=1.0 shape=2.0"));
191 Histogram(x3, probes, precision,
"ParetoRandomVariable scale=1.0 shape=2.5"));
193 gnuplots.AddPlot(plot);
198 plot.
SetTitle(
"WeibullRandomVariable");
206 Histogram(x1, probes, precision,
"WeibullRandomVariable scale=1.0 shape=1.0"));
213 Histogram(x2, probes, precision,
"WeibullRandomVariable scale=1.0 shape=2.0"));
220 Histogram(x3, probes, precision,
"WeibullRandomVariable scale=1.0 shape=3.0"));
222 gnuplots.AddPlot(plot);
227 plot.
SetTitle(
"NormalRandomVariable");
230 "NormalDist(x,m,s) = 1 / (s * sqrt(2*pi)) * exp(-1.0 / 2.0 * ((x-m) / s)**2)");
239 "NormalDist(x,0.0,1.0)"));
248 "NormalDist(x,0.0,sqrt(2.0))"));
257 "NormalDist(x,0.0,sqrt(3.0))"));
259 gnuplots.AddPlot(plot);
303 plot.
SetTitle(
"LogNormalRandomVariable");
306 plot.
AppendExtra(
"LogNormalDist(x,m,s) = 1.0/x * NormalDist(log(x), m, s)");
330 Gnuplot2dFunction(
"LogNormalDist(x, 0.0, 0.25)",
"LogNormalDist(x, 0.0, 0.25)"));
336 plot.
AddDataset(
Histogram(x4, probes, precision,
"LogNormalRandomVariable m=0.0 s=0.125"));
353 gnuplots.AddPlot(plot);
358 plot.
SetTitle(
"TriangularRandomVariable");
367 Histogram(x1, probes, precision,
"TriangularRandomVariable [0.0 .. 1.0) m=0.5"));
375 Histogram(x2, probes, precision,
"TriangularRandomVariable [0.0 .. 1.0) m=0.4"));
383 Histogram(x3, probes, precision,
"TriangularRandomVariable [0.0 .. 1.0) m=0.65"));
385 gnuplots.AddPlot(plot);
390 plot.
SetTitle(
"GammaRandomVariable");
393 plot.
AppendExtra(
"GammaDist(x,a,b) = x**(a-1) * 1/b**a * exp(-x/b) / gamma(a)");
396 "set label 1 '{/Symbol g}(x,{/Symbol a},{/Symbol b}) = x^{/Symbol a-1} e^{-x {/Symbol "
397 "b}^{-1}} ( {/Symbol b}^{/Symbol a} {/Symbol G}({/Symbol a}) )^{-1}' at 0.7, 0.9");
455 gnuplots.AddPlot(plot);
460 plot.
SetTitle(
"ErlangRandomVariable");
462 plot.
AppendExtra(
"ErlangDist(x,k,l) = x**(k-1) * 1/l**k * exp(-x/l) / (k-1)!");
464 plot.
AppendExtra(
"set label 1 'Erlang(x,k,{/Symbol l}) = x^{k-1} e^{-x {/Symbol l}^{-1}} ( "
465 "{/Symbol l}^k (k-1)! )^{-1}' at 0.7, 0.9");
472 Histogram(x1, probes, precision,
"ErlangRandomVariable k=1 {/Symbol l}=1.0"));
481 Histogram(x2, probes, precision,
"ErlangRandomVariable k=2 {/Symbol l}=1.0"));
490 Histogram(x3, probes, precision,
"ErlangRandomVariable k=3 {/Symbol l}=1.0"));
499 Histogram(x4, probes, precision,
"ErlangRandomVariable k=5 {/Symbol l}=1.0"));
508 Histogram(x5, probes, precision,
"ErlangRandomVariable k=2 {/Symbol l}=2.0"));
517 Histogram(x6, probes, precision,
"ErlangRandomVariable k=2 {/Symbol l}=3.0"));
526 Histogram(x7, probes, precision,
"ErlangRandomVariable k=2 {/Symbol l}=5.0"));
530 gnuplots.AddPlot(plot);
533 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()=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.