A Discrete-Event Network Simulator
API
main-random-variable-stream.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2008 Timo Bingmann
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Timo Bingmann <timo.bingmann@student.kit.edu>
19  */
20 #include "ns3/random-variable-stream.h"
21 #include "ns3/ptr.h"
22 #include "ns3/double.h"
23 #include "ns3/string.h"
24 #include "ns3/integer.h"
25 #include "ns3/gnuplot.h"
26 #include <map>
27 #include <cmath>
28 
29 using namespace ns3;
30 
33 double dround (double number, double precision)
34 {
35  number /= precision;
36  if (number >= 0)
37  number = std::floor (number + 0.5);
38  else
39  number = std::ceil (number - 0.5);
40  number *= precision;
41  return number;
42 }
43 
44 static GnuplotDataset
45 Histogramm (Ptr<RandomVariableStream> rndvar, unsigned int probes, double precision, const std::string& title, bool notcontinous = false)
46 {
47  typedef std::map<double, unsigned int> histogramm_maptype;
48  histogramm_maptype histogramm;
49 
50  for(unsigned int i = 0; i < probes; ++i)
51  {
52  double val = dround ( rndvar->GetValue (), precision );
53 
54  ++histogramm[val];
55  }
56 
58  data.SetTitle (title);
59 
60  if (notcontinous)
61  {
63  }
64 
65  for(histogramm_maptype::const_iterator hi = histogramm.begin ();
66  hi != histogramm.end (); ++hi)
67  {
68  data.Add (hi->first, (double)hi->second / (double)probes / precision);
69  }
70 
71  return data;
72 }
73 
74 int main (int argc, char *argv[])
75 {
76  unsigned int probes = 1000000;
77  double precision = 0.01;
78 
79  GnuplotCollection gnuplots ("main-random-variables.pdf");
80  gnuplots.SetTerminal ("pdf enhanced");
81 
82  {
83  Gnuplot plot;
84  plot.SetTitle ("UniformRandomVariable");
85  plot.AppendExtra ("set yrange [0:]");
86 
87  Ptr<UniformRandomVariable> x = CreateObject<UniformRandomVariable> ();
88  x->SetAttribute ("Min", DoubleValue (0.0));
89  x->SetAttribute ("Max", DoubleValue (1.0));
90 
91  plot.AddDataset ( Histogramm (x, probes, precision,
92  "UniformRandomVariable [0.0 .. 1.0)") );
93  plot.AddDataset ( Gnuplot2dFunction ("1.0",
94  "0 <= x && x <= 1 ? 1.0 : 0") );
95 
96  gnuplots.AddPlot (plot);
97  }
98 
99  {
100  Gnuplot plot;
101  plot.SetTitle ("ExponentialRandomVariable");
102  plot.AppendExtra ("set xrange [0:8]");
103  plot.AppendExtra ("ExpDist(x,l) = 1/l * exp(-1/l * x)");
104 
105  Ptr<ExponentialRandomVariable> x1 = CreateObject<ExponentialRandomVariable> ();
106  x1->SetAttribute ("Mean", DoubleValue (0.5));
107 
108  plot.AddDataset ( Histogramm (x1, probes, precision,
109  "ExponentialRandomVariable m=0.5") );
110 
111  plot.AddDataset ( Gnuplot2dFunction ("ExponentialDistribution mean 0.5",
112  "ExpDist(x, 0.5)") );
113 
114  Ptr<ExponentialRandomVariable> x2 = CreateObject<ExponentialRandomVariable> ();
115  x2->SetAttribute ("Mean", DoubleValue (1.0));
116 
117  plot.AddDataset ( Histogramm (x2, probes, precision,
118  "ExponentialRandomVariable m=1") );
119 
120  plot.AddDataset ( Gnuplot2dFunction ("ExponentialDistribution mean 1.0",
121  "ExpDist(x, 1.0)") );
122 
123  Ptr<ExponentialRandomVariable> x3 = CreateObject<ExponentialRandomVariable> ();
124  x3->SetAttribute ("Mean", DoubleValue (1.5));
125 
126  plot.AddDataset ( Histogramm (x3, probes, precision,
127  "ExponentialRandomVariable m=1.5") );
128 
129  plot.AddDataset ( Gnuplot2dFunction ("ExponentialDistribution mean 1.5",
130  "ExpDist(x, 1.5)") );
131 
132  gnuplots.AddPlot (plot);
133  }
134 
135  {
136  Gnuplot plot;
137  plot.SetTitle ("ParetoRandomVariable");
138  plot.AppendExtra ("set xrange [0:2]");
139 
140  Ptr<ParetoRandomVariable> x1 = CreateObject<ParetoRandomVariable> ();
141  x1->SetAttribute ("Mean", DoubleValue (1.0));
142  x1->SetAttribute ("Shape", DoubleValue (1.5));
143 
144  plot.AddDataset ( Histogramm (x1, probes, precision,
145  "ParetoRandomVariable m=1.0 s=1.5") );
146 
147  Ptr<ParetoRandomVariable> x2 = CreateObject<ParetoRandomVariable> ();
148  x2->SetAttribute ("Mean", DoubleValue (1.0));
149  x2->SetAttribute ("Shape", DoubleValue (2.0));
150 
151  plot.AddDataset ( Histogramm (x2, probes, precision,
152  "ParetoRandomVariable m=1.0 s=2.0") );
153 
154  Ptr<ParetoRandomVariable> x3 = CreateObject<ParetoRandomVariable> ();
155  x3->SetAttribute ("Mean", DoubleValue (1.0));
156  x3->SetAttribute ("Shape", DoubleValue (2.5));
157 
158  plot.AddDataset ( Histogramm (x3, probes, precision,
159  "ParetoRandomVariable m=1.0 s=2.5") );
160 
161  gnuplots.AddPlot (plot);
162  }
163 
164  {
165  Gnuplot plot;
166  plot.SetTitle ("WeibullRandomVariable");
167  plot.AppendExtra ("set xrange [0:3]");
168 
169  Ptr<WeibullRandomVariable> x1 = CreateObject<WeibullRandomVariable> ();
170  x1->SetAttribute ("Scale", DoubleValue (1.0));
171  x1->SetAttribute ("Shape", DoubleValue (1.0));
172 
173  plot.AddDataset ( Histogramm (x1, probes, precision,
174  "WeibullRandomVariable m=1.0 s=1.0") );
175 
176  Ptr<WeibullRandomVariable> x2 = CreateObject<WeibullRandomVariable> ();
177  x2->SetAttribute ("Scale", DoubleValue (1.0));
178  x2->SetAttribute ("Shape", DoubleValue (2.0));
179 
180  plot.AddDataset ( Histogramm (x2, probes, precision,
181  "WeibullRandomVariable m=1.0 s=2.0") );
182 
183  Ptr<WeibullRandomVariable> x3 = CreateObject<WeibullRandomVariable> ();
184  x3->SetAttribute ("Scale", DoubleValue (1.0));
185  x3->SetAttribute ("Shape", DoubleValue (3.0));
186 
187  plot.AddDataset ( Histogramm (x3, probes, precision,
188  "WeibullRandomVariable m=1.0 s=3.0") );
189 
190  gnuplots.AddPlot (plot);
191  }
192 
193  {
194  Gnuplot plot;
195  plot.SetTitle ("NormalRandomVariable");
196  plot.AppendExtra ("set xrange [-3:3]");
197  plot.AppendExtra ("NormalDist(x,m,s) = 1 / (s * sqrt(2*pi)) * exp(-1.0 / 2.0 * ((x-m) / s)**2)");
198 
199  Ptr<NormalRandomVariable> x1 = CreateObject<NormalRandomVariable> ();
200  x1->SetAttribute ("Mean", DoubleValue (0.0));
201  x1->SetAttribute ("Variance", DoubleValue (1.0));
202 
203  plot.AddDataset ( Histogramm (x1, probes, precision,
204  "NormalRandomVariable m=0.0 v=1.0") );
205 
206  plot.AddDataset ( Gnuplot2dFunction ("NormalDist {/Symbol m}=0.0 {/Symbol s}=1.0",
207  "NormalDist(x,0.0,1.0)") );
208 
209  Ptr<NormalRandomVariable> x2 = CreateObject<NormalRandomVariable> ();
210  x2->SetAttribute ("Mean", DoubleValue (0.0));
211  x2->SetAttribute ("Variance", DoubleValue (2.0));
212 
213  plot.AddDataset ( Histogramm (x2, probes, precision,
214  "NormalRandomVariable m=0.0 v=2.0") );
215 
216  plot.AddDataset ( Gnuplot2dFunction ("NormalDist {/Symbol m}=0.0 {/Symbol s}=sqrt(2.0)",
217  "NormalDist(x,0.0,sqrt(2.0))") );
218 
219  Ptr<NormalRandomVariable> x3 = CreateObject<NormalRandomVariable> ();
220  x3->SetAttribute ("Mean", DoubleValue (0.0));
221  x3->SetAttribute ("Variance", DoubleValue (3.0));
222 
223  plot.AddDataset ( Histogramm (x3, probes, precision,
224  "NormalRandomVariable m=0.0 v=3.0") );
225 
226  plot.AddDataset ( Gnuplot2dFunction ("NormalDist {/Symbol m}=0.0 {/Symbol s}=sqrt(3.0)",
227  "NormalDist(x,0.0,sqrt(3.0))") );
228 
229  gnuplots.AddPlot (plot);
230  }
231 
233  /*
234  {
235  Gnuplot plot;
236  plot.SetTitle ("EmpiricalRandomVariable");
237  plot.AppendExtra ("set xrange [*:*]");
238 
239  EmpiricalRandomVariable emp1;
240  emp1.CDF (0.0, 0.0 / 15.0);
241  emp1.CDF (0.2, 1.0 / 15.0);
242  emp1.CDF (0.4, 3.0 / 15.0);
243  emp1.CDF (0.6, 6.0 / 15.0);
244  emp1.CDF (0.8, 10.0 / 15.0);
245  emp1.CDF (1.0, 15.0 / 15.0);
246 
247  plot.AddDataset ( Histogramm (emp1, probes, precision,
248  "EmpiricalRandomVariable (Stairs)") );
249 
250  gnuplots.AddPlot (plot);
251  }
252  */
253 
255  /*
256  {
257  Gnuplot plot;
258  plot.SetTitle ("DeterministicRandomVariable");
259  plot.AppendExtra ("set xrange [*:*]");
260 
261  double values[] = { 0.0, 0.2, 0.2, 0.4, 0.2, 0.6, 0.8, 0.8, 1.0 };
262  DeterministicRandomVariable det1 (values, sizeof(values) / sizeof(values[0]));
263 
264  plot.AddDataset ( Histogramm (det1, probes, precision,
265  "DeterministicRandomVariable", true) );
266 
267  gnuplots.AddPlot (plot);
268  }
269  */
270 
271  {
272  Gnuplot plot;
273  plot.SetTitle ("LogNormalRandomVariable");
274  plot.AppendExtra ("set xrange [0:3]");
275 
276  plot.AppendExtra ("LogNormalDist(x,m,s) = 1.0/x * NormalDist(log(x), m, s)");
277 
278  Ptr<LogNormalRandomVariable> x1 = CreateObject<LogNormalRandomVariable> ();
279  x1->SetAttribute ("Mu", DoubleValue (0.0));
280  x1->SetAttribute ("Sigma", DoubleValue (1.0));
281 
282  plot.AddDataset ( Histogramm (x1, probes, precision,
283  "LogNormalRandomVariable m=0.0 s=1.0") );
284 
285  plot.AddDataset ( Gnuplot2dFunction ("LogNormalDist(x, 0.0, 1.0)",
286  "LogNormalDist(x, 0.0, 1.0)") );
287 
288  Ptr<LogNormalRandomVariable> x2 = CreateObject<LogNormalRandomVariable> ();
289  x2->SetAttribute ("Mu", DoubleValue (0.0));
290  x2->SetAttribute ("Sigma", DoubleValue (0.5));
291 
292  plot.AddDataset ( Histogramm (x2, probes, precision,
293  "LogNormalRandomVariable m=0.0 s=0.5") );
294 
295  Ptr<LogNormalRandomVariable> x3 = CreateObject<LogNormalRandomVariable> ();
296  x3->SetAttribute ("Mu", DoubleValue (0.0));
297  x3->SetAttribute ("Sigma", DoubleValue (0.25));
298 
299  plot.AddDataset ( Histogramm (x3, probes, precision,
300  "LogNormalRandomVariable m=0.0 s=0.25") );
301 
302  plot.AddDataset ( Gnuplot2dFunction ("LogNormalDist(x, 0.0, 0.25)",
303  "LogNormalDist(x, 0.0, 0.25)") );
304 
305  Ptr<LogNormalRandomVariable> x4 = CreateObject<LogNormalRandomVariable> ();
306  x4->SetAttribute ("Mu", DoubleValue (0.0));
307  x4->SetAttribute ("Sigma", DoubleValue (0.125));
308 
309  plot.AddDataset ( Histogramm (x4, probes, precision,
310  "LogNormalRandomVariable m=0.0 s=0.125") );
311 
312  Ptr<LogNormalRandomVariable> x5 = CreateObject<LogNormalRandomVariable> ();
313  x5->SetAttribute ("Mu", DoubleValue (0.0));
314  x5->SetAttribute ("Sigma", DoubleValue (2.0));
315 
316  plot.AddDataset ( Histogramm (x5, probes, precision,
317  "LogNormalRandomVariable m=0.0 s=2.0") );
318 
319  plot.AddDataset ( Gnuplot2dFunction ("LogNormalDist(x, 0.0, 2.0)",
320  "LogNormalDist(x, 0.0, 2.0)") );
321 
322  Ptr<LogNormalRandomVariable> x6 = CreateObject<LogNormalRandomVariable> ();
323  x6->SetAttribute ("Mu", DoubleValue (0.0));
324  x6->SetAttribute ("Sigma", DoubleValue (2.5));
325 
326  plot.AddDataset ( Histogramm (x6, probes, precision,
327  "LogNormalRandomVariable m=0.0 s=2.5") );
328 
329  gnuplots.AddPlot (plot);
330  }
331 
332  {
333  Gnuplot plot;
334  plot.SetTitle ("TriangularRandomVariable");
335  plot.AppendExtra ("set xrange [*:*]");
336 
337  Ptr<TriangularRandomVariable> x1 = CreateObject<TriangularRandomVariable> ();
338  x1->SetAttribute ("Min", DoubleValue (0.0));
339  x1->SetAttribute ("Max", DoubleValue (1.0));
340  x1->SetAttribute ("Mean", DoubleValue (0.5));
341 
342  plot.AddDataset ( Histogramm (x1, probes, precision,
343  "TriangularRandomVariable [0.0 .. 1.0) m=0.5") );
344 
345  Ptr<TriangularRandomVariable> x2 = CreateObject<TriangularRandomVariable> ();
346  x2->SetAttribute ("Min", DoubleValue (0.0));
347  x2->SetAttribute ("Max", DoubleValue (1.0));
348  x2->SetAttribute ("Mean", DoubleValue (0.4));
349 
350  plot.AddDataset ( Histogramm (x2, probes, precision,
351  "TriangularRandomVariable [0.0 .. 1.0) m=0.4") );
352 
353  Ptr<TriangularRandomVariable> x3 = CreateObject<TriangularRandomVariable> ();
354  x3->SetAttribute ("Min", DoubleValue (0.0));
355  x3->SetAttribute ("Max", DoubleValue (1.0));
356  x3->SetAttribute ("Mean", DoubleValue (0.65));
357 
358  plot.AddDataset ( Histogramm (x3, probes, precision,
359  "TriangularRandomVariable [0.0 .. 1.0) m=0.65") );
360 
361  gnuplots.AddPlot (plot);
362  }
363 
364  {
365  Gnuplot plot;
366  plot.SetTitle ("GammaRandomVariable");
367  plot.AppendExtra ("set xrange [0:10]");
368  plot.AppendExtra ("set yrange [0:1]");
369  plot.AppendExtra ("GammaDist(x,a,b) = x**(a-1) * 1/b**a * exp(-x/b) / gamma(a)");
370 
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");
372 
373  Ptr<GammaRandomVariable> x1 = CreateObject<GammaRandomVariable> ();
374  x1->SetAttribute ("Alpha", DoubleValue (1.0));
375  x1->SetAttribute ("Beta", DoubleValue (1.0));
376 
377  plot.AddDataset ( Histogramm (x1, probes, precision,
378  "GammaRandomVariable a=1.0 b=1.0") );
379 
380  plot.AddDataset ( Gnuplot2dFunction ("{/Symbol g}(x, 1.0, 1.0)",
381  "GammaDist(x, 1.0, 1.0)") );
382 
383  Ptr<GammaRandomVariable> x2 = CreateObject<GammaRandomVariable> ();
384  x2->SetAttribute ("Alpha", DoubleValue (1.5));
385  x2->SetAttribute ("Beta", DoubleValue (1.0));
386 
387  plot.AddDataset ( Histogramm (x2, probes, precision,
388  "GammaRandomVariable a=1.5 b=1.0") );
389 
390  plot.AddDataset ( Gnuplot2dFunction ("{/Symbol g}(x, 1.5, 1.0)",
391  "GammaDist(x, 1.5, 1.0)") );
392 
393  Ptr<GammaRandomVariable> x3 = CreateObject<GammaRandomVariable> ();
394  x3->SetAttribute ("Alpha", DoubleValue (2.0));
395  x3->SetAttribute ("Beta", DoubleValue (1.0));
396 
397  plot.AddDataset ( Histogramm (x3, probes, precision,
398  "GammaRandomVariable a=2.0 b=1.0") );
399 
400  plot.AddDataset ( Gnuplot2dFunction ("{/Symbol g}(x, 2.0, 1.0)",
401  "GammaDist(x, 2.0, 1.0)") );
402 
403  Ptr<GammaRandomVariable> x4 = CreateObject<GammaRandomVariable> ();
404  x4->SetAttribute ("Alpha", DoubleValue (4.0));
405  x4->SetAttribute ("Beta", DoubleValue (1.0));
406 
407  plot.AddDataset ( Histogramm (x4, probes, precision,
408  "GammaRandomVariable a=4.0 b=1.0") );
409 
410  plot.AddDataset ( Gnuplot2dFunction ("{/Symbol g}(x, 4.0, 1.0)",
411  "GammaDist(x, 4.0, 1.0)") );
412 
413  Ptr<GammaRandomVariable> x5 = CreateObject<GammaRandomVariable> ();
414  x5->SetAttribute ("Alpha", DoubleValue (2.0));
415  x5->SetAttribute ("Beta", DoubleValue (2.0));
416 
417  plot.AddDataset ( Histogramm (x5, probes, precision,
418  "GammaRandomVariable a=2.0 b=2.0") );
419 
420  plot.AddDataset ( Gnuplot2dFunction ("{/Symbol g}(x, 2.0, 2.0)",
421  "GammaDist(x, 2.0, 2.0)") );
422 
423  Ptr<GammaRandomVariable> x6 = CreateObject<GammaRandomVariable> ();
424  x6->SetAttribute ("Alpha", DoubleValue (2.5));
425  x6->SetAttribute ("Beta", DoubleValue (3.0));
426 
427  plot.AddDataset ( Histogramm (x6, probes, precision,
428  "GammaRandomVariable a=2.5 b=3.0") );
429 
430  plot.AddDataset ( Gnuplot2dFunction ("{/Symbol g}(x, 2.5, 3.0)",
431  "GammaDist(x, 2.5, 3.0)") );
432 
433  Ptr<GammaRandomVariable> x7 = CreateObject<GammaRandomVariable> ();
434  x7->SetAttribute ("Alpha", DoubleValue (2.5));
435  x7->SetAttribute ("Beta", DoubleValue (4.5));
436 
437  plot.AddDataset ( Histogramm (x7, probes, precision,
438  "GammaRandomVariable a=2.5 b=4.5") );
439 
440  plot.AddDataset ( Gnuplot2dFunction ("{/Symbol g}(x, 2.5, 4.5)",
441  "GammaDist(x, 2.5, 4.5)") );
442 
443  gnuplots.AddPlot (plot);
444  }
445 
446  {
447  Gnuplot plot;
448  plot.SetTitle ("ErlangRandomVariable");
449  plot.AppendExtra ("set xrange [0:10]");
450  plot.AppendExtra ("ErlangDist(x,k,l) = x**(k-1) * 1/l**k * exp(-x/l) / (k-1)!");
451 
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");
453 
454  Ptr<ErlangRandomVariable> x1 = CreateObject<ErlangRandomVariable> ();
455  x1->SetAttribute ("K", IntegerValue (1));
456  x1->SetAttribute ("Lambda", DoubleValue (1.0));
457 
458  plot.AddDataset ( Histogramm (x1, probes, precision,
459  "ErlangRandomVariable k=1 {/Symbol l}=1.0") );
460 
461  plot.AddDataset ( Gnuplot2dFunction ("Erlang(x, 1, 1.0)",
462  "ErlangDist(x, 1, 1.0)") );
463 
464  Ptr<ErlangRandomVariable> x2 = CreateObject<ErlangRandomVariable> ();
465  x2->SetAttribute ("K", IntegerValue (2));
466  x2->SetAttribute ("Lambda", DoubleValue (1.0));
467 
468  plot.AddDataset ( Histogramm (x2, probes, precision,
469  "ErlangRandomVariable k=2 {/Symbol l}=1.0") );
470 
471  plot.AddDataset ( Gnuplot2dFunction ("Erlang(x, 2, 1.0)",
472  "ErlangDist(x, 2, 1.0)") );
473 
474  Ptr<ErlangRandomVariable> x3 = CreateObject<ErlangRandomVariable> ();
475  x3->SetAttribute ("K", IntegerValue (3));
476  x3->SetAttribute ("Lambda", DoubleValue (1.0));
477 
478  plot.AddDataset ( Histogramm (x3, probes, precision,
479  "ErlangRandomVariable k=3 {/Symbol l}=1.0") );
480 
481  plot.AddDataset ( Gnuplot2dFunction ("Erlang(x, 3, 1.0)",
482  "ErlangDist(x, 3, 1.0)") );
483 
484  Ptr<ErlangRandomVariable> x4 = CreateObject<ErlangRandomVariable> ();
485  x4->SetAttribute ("K", IntegerValue (5));
486  x4->SetAttribute ("Lambda", DoubleValue (1.0));
487 
488  plot.AddDataset ( Histogramm (x4, probes, precision,
489  "ErlangRandomVariable k=5 {/Symbol l}=1.0") );
490 
491  plot.AddDataset ( Gnuplot2dFunction ("Erlang(x, 5, 1.0)",
492  "ErlangDist(x, 5, 1.0)") );
493 
494  Ptr<ErlangRandomVariable> x5 = CreateObject<ErlangRandomVariable> ();
495  x5->SetAttribute ("K", IntegerValue (2));
496  x5->SetAttribute ("Lambda", DoubleValue (2.0));
497 
498  plot.AddDataset ( Histogramm (x5, probes, precision,
499  "ErlangRandomVariable k=2 {/Symbol l}=2.0") );
500 
501  plot.AddDataset ( Gnuplot2dFunction ("Erlang(x, 2, 2.0)",
502  "ErlangDist(x, 2, 2.0)") );
503 
504  Ptr<ErlangRandomVariable> x6 = CreateObject<ErlangRandomVariable> ();
505  x6->SetAttribute ("K", IntegerValue (2));
506  x6->SetAttribute ("Lambda", DoubleValue (3.0));
507 
508  plot.AddDataset ( Histogramm (x6, probes, precision,
509  "ErlangRandomVariable k=2 {/Symbol l}=3.0") );
510 
511  plot.AddDataset ( Gnuplot2dFunction ("Erlang(x, 2, 3.0)",
512  "ErlangDist(x, 2, 3.0)") );
513 
514  Ptr<ErlangRandomVariable> x7 = CreateObject<ErlangRandomVariable> ();
515  x7->SetAttribute ("K", IntegerValue (2));
516  x7->SetAttribute ("Lambda", DoubleValue (5.0));
517 
518  plot.AddDataset ( Histogramm (x7, probes, precision,
519  "ErlangRandomVariable k=2 {/Symbol l}=5.0") );
520 
521  plot.AddDataset ( Gnuplot2dFunction ("Erlang(x, 2, 5.0)",
522  "ErlangDist(x, 2, 5.0)") );
523 
524  gnuplots.AddPlot (plot);
525  }
526 
527  gnuplots.GenerateOutput (std::cout);
528 
529  return 0;
530 }
void AppendExtra(const std::string &extra)
Definition: gnuplot.cc:749
Class to represent a 2D points plot.
Definition: gnuplot.h:113
void SetTitle(const std::string &title)
Change line title.
Definition: gnuplot.cc:141
Abstract class to store a plot line to be used by ns3::Gnuplot.
Definition: gnuplot.h:38
Hold a signed integer type.
Definition: integer.h:44
void AddDataset(const GnuplotDataset &dataset)
Definition: gnuplot.cc:756
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.
Definition: gnuplot.h:367
a simple class to group together multiple gnuplots into one file, e.g.
Definition: gnuplot.h:483
void SetTitle(const std::string &title)
Definition: gnuplot.cc:730
uint8_t data[writeSize]
void Add(double x, double y)
Definition: gnuplot.cc:359
static GnuplotDataset Histogramm(Ptr< RandomVariableStream > rndvar, unsigned int probes, double precision, const std::string &title, bool notcontinous=false)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
double dround(double number, double precision)
Round a double number to the given precision.
void SetStyle(enum Style style)
Definition: gnuplot.cc:342
Class to represent a 2D function expression plot.
Definition: gnuplot.h:239
This class can be used to hold variables of floating point type such as 'double' or 'float'...
Definition: double.h:41
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
Definition: object-base.cc:191