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 "ns3/command-line.h"
27 #include <map>
28 #include <cmath>
29 
37 using namespace ns3;
38 
39 namespace {
40 
49 double dround (double number, double precision)
50 {
51  number /= precision;
52  if (number >= 0)
53  number = std::floor (number + 0.5);
54  else
55  number = std::ceil (number - 0.5);
56  number *= precision;
57  return number;
58 }
59 
69 static GnuplotDataset
71  unsigned int probes, double precision,
72  const std::string& title, bool impulses = false)
73 {
74  typedef std::map<double, unsigned int> histogram_maptype;
75  histogram_maptype histogram;
76 
77  for(unsigned int i = 0; i < probes; ++i)
78  {
79  double val = dround ( rndvar->GetValue (), precision );
80 
81  ++histogram[val];
82  }
83 
85  data.SetTitle (title);
86 
87  if (impulses)
88  {
90  }
91 
92  for(histogram_maptype::const_iterator hi = histogram.begin ();
93  hi != histogram.end (); ++hi)
94  {
95  data.Add (hi->first, (double)hi->second / (double)probes / precision);
96  }
97 
98  return data;
99 }
100 
101 } // unnamed namespace
102 
103 
104 int main (int argc, char *argv[])
105 {
107  cmd.Parse(argc, argv);
108 
109  unsigned int probes = 1000000;
110  double precision = 0.01;
111 
112  GnuplotCollection gnuplots ("main-random-variables.pdf");
113  gnuplots.SetTerminal ("pdf enhanced");
114 
115  {
116  Gnuplot plot;
117  plot.SetTitle ("UniformRandomVariable");
118  plot.AppendExtra ("set yrange [0:]");
119 
120  Ptr<UniformRandomVariable> x = CreateObject<UniformRandomVariable> ();
121  x->SetAttribute ("Min", DoubleValue (0.0));
122  x->SetAttribute ("Max", DoubleValue (1.0));
123 
124  plot.AddDataset ( Histogram (x, probes, precision,
125  "UniformRandomVariable [0.0 .. 1.0)") );
126  plot.AddDataset ( Gnuplot2dFunction ("1.0",
127  "0 <= x && x <= 1 ? 1.0 : 0") );
128 
129  gnuplots.AddPlot (plot);
130  }
131 
132  {
133  Gnuplot plot;
134  plot.SetTitle ("ExponentialRandomVariable");
135  plot.AppendExtra ("set xrange [0:8]");
136  plot.AppendExtra ("ExpDist(x,l) = 1/l * exp(-1/l * x)");
137 
138  Ptr<ExponentialRandomVariable> x1 = CreateObject<ExponentialRandomVariable> ();
139  x1->SetAttribute ("Mean", DoubleValue (0.5));
140 
141  plot.AddDataset ( Histogram (x1, probes, precision,
142  "ExponentialRandomVariable m=0.5") );
143 
144  plot.AddDataset ( Gnuplot2dFunction ("ExponentialDistribution mean 0.5",
145  "ExpDist(x, 0.5)") );
146 
147  Ptr<ExponentialRandomVariable> x2 = CreateObject<ExponentialRandomVariable> ();
148  x2->SetAttribute ("Mean", DoubleValue (1.0));
149 
150  plot.AddDataset ( Histogram (x2, probes, precision,
151  "ExponentialRandomVariable m=1") );
152 
153  plot.AddDataset ( Gnuplot2dFunction ("ExponentialDistribution mean 1.0",
154  "ExpDist(x, 1.0)") );
155 
156  Ptr<ExponentialRandomVariable> x3 = CreateObject<ExponentialRandomVariable> ();
157  x3->SetAttribute ("Mean", DoubleValue (1.5));
158 
159  plot.AddDataset ( Histogram (x3, probes, precision,
160  "ExponentialRandomVariable m=1.5") );
161 
162  plot.AddDataset ( Gnuplot2dFunction ("ExponentialDistribution mean 1.5",
163  "ExpDist(x, 1.5)") );
164 
165  gnuplots.AddPlot (plot);
166  }
167 
168  {
169  Gnuplot plot;
170  plot.SetTitle ("ParetoRandomVariable");
171  plot.AppendExtra ("set xrange [0:2]");
172 
173  Ptr<ParetoRandomVariable> x1 = CreateObject<ParetoRandomVariable> ();
174  x1->SetAttribute ("Scale", DoubleValue (1.0));
175  x1->SetAttribute ("Shape", DoubleValue (1.5));
176 
177  plot.AddDataset ( Histogram (x1, probes, precision,
178  "ParetoRandomVariable scale=1.0 shape=1.5") );
179 
180  Ptr<ParetoRandomVariable> x2 = CreateObject<ParetoRandomVariable> ();
181  x2->SetAttribute ("Scale", DoubleValue (1.0));
182  x2->SetAttribute ("Shape", DoubleValue (2.0));
183 
184  plot.AddDataset ( Histogram (x2, probes, precision,
185  "ParetoRandomVariable scale=1.0 shape=2.0") );
186 
187  Ptr<ParetoRandomVariable> x3 = CreateObject<ParetoRandomVariable> ();
188  x3->SetAttribute ("Scale", DoubleValue (1.0));
189  x3->SetAttribute ("Shape", DoubleValue (2.5));
190 
191  plot.AddDataset ( Histogram (x3, probes, precision,
192  "ParetoRandomVariable scale=1.0 shape=2.5") );
193 
194  gnuplots.AddPlot (plot);
195  }
196 
197  {
198  Gnuplot plot;
199  plot.SetTitle ("WeibullRandomVariable");
200  plot.AppendExtra ("set xrange [0:3]");
201 
202  Ptr<WeibullRandomVariable> x1 = CreateObject<WeibullRandomVariable> ();
203  x1->SetAttribute ("Scale", DoubleValue (1.0));
204  x1->SetAttribute ("Shape", DoubleValue (1.0));
205 
206  plot.AddDataset ( Histogram (x1, probes, precision,
207  "WeibullRandomVariable scale=1.0 shape=1.0") );
208 
209  Ptr<WeibullRandomVariable> x2 = CreateObject<WeibullRandomVariable> ();
210  x2->SetAttribute ("Scale", DoubleValue (1.0));
211  x2->SetAttribute ("Shape", DoubleValue (2.0));
212 
213  plot.AddDataset ( Histogram (x2, probes, precision,
214  "WeibullRandomVariable scale=1.0 shape=2.0") );
215 
216  Ptr<WeibullRandomVariable> x3 = CreateObject<WeibullRandomVariable> ();
217  x3->SetAttribute ("Scale", DoubleValue (1.0));
218  x3->SetAttribute ("Shape", DoubleValue (3.0));
219 
220  plot.AddDataset ( Histogram (x3, probes, precision,
221  "WeibullRandomVariable scale=1.0 shape=3.0") );
222 
223  gnuplots.AddPlot (plot);
224  }
225 
226  {
227  Gnuplot plot;
228  plot.SetTitle ("NormalRandomVariable");
229  plot.AppendExtra ("set xrange [-3:3]");
230  plot.AppendExtra ("NormalDist(x,m,s) = 1 / (s * sqrt(2*pi)) * exp(-1.0 / 2.0 * ((x-m) / s)**2)");
231 
232  Ptr<NormalRandomVariable> x1 = CreateObject<NormalRandomVariable> ();
233  x1->SetAttribute ("Mean", DoubleValue (0.0));
234  x1->SetAttribute ("Variance", DoubleValue (1.0));
235 
236  plot.AddDataset ( Histogram (x1, probes, precision,
237  "NormalRandomVariable m=0.0 v=1.0") );
238 
239  plot.AddDataset ( Gnuplot2dFunction ("NormalDist {/Symbol m}=0.0 {/Symbol s}=1.0",
240  "NormalDist(x,0.0,1.0)") );
241 
242  Ptr<NormalRandomVariable> x2 = CreateObject<NormalRandomVariable> ();
243  x2->SetAttribute ("Mean", DoubleValue (0.0));
244  x2->SetAttribute ("Variance", DoubleValue (2.0));
245 
246  plot.AddDataset ( Histogram (x2, probes, precision,
247  "NormalRandomVariable m=0.0 v=2.0") );
248 
249  plot.AddDataset ( Gnuplot2dFunction ("NormalDist {/Symbol m}=0.0 {/Symbol s}=sqrt(2.0)",
250  "NormalDist(x,0.0,sqrt(2.0))") );
251 
252  Ptr<NormalRandomVariable> x3 = CreateObject<NormalRandomVariable> ();
253  x3->SetAttribute ("Mean", DoubleValue (0.0));
254  x3->SetAttribute ("Variance", DoubleValue (3.0));
255 
256  plot.AddDataset ( Histogram (x3, probes, precision,
257  "NormalRandomVariable m=0.0 v=3.0") );
258 
259  plot.AddDataset ( Gnuplot2dFunction ("NormalDist {/Symbol m}=0.0 {/Symbol s}=sqrt(3.0)",
260  "NormalDist(x,0.0,sqrt(3.0))") );
261 
262  gnuplots.AddPlot (plot);
263  }
264 
266  /*
267  {
268  Gnuplot plot;
269  plot.SetTitle ("EmpiricalRandomVariable");
270  plot.AppendExtra ("set xrange [*:*]");
271 
272  EmpiricalRandomVariable emp1;
273  emp1.CDF (0.0, 0.0 / 15.0);
274  emp1.CDF (0.2, 1.0 / 15.0);
275  emp1.CDF (0.4, 3.0 / 15.0);
276  emp1.CDF (0.6, 6.0 / 15.0);
277  emp1.CDF (0.8, 10.0 / 15.0);
278  emp1.CDF (1.0, 15.0 / 15.0);
279 
280  plot.AddDataset ( Histogram (emp1, probes, precision,
281  "EmpiricalRandomVariable (Stairs)") );
282 
283  gnuplots.AddPlot (plot);
284  }
285  */
286 
288  /*
289  {
290  Gnuplot plot;
291  plot.SetTitle ("DeterministicRandomVariable");
292  plot.AppendExtra ("set xrange [*:*]");
293 
294  double values[] = { 0.0, 0.2, 0.2, 0.4, 0.2, 0.6, 0.8, 0.8, 1.0 };
295  DeterministicRandomVariable det1 (values, sizeof(values) / sizeof(values[0]));
296 
297  plot.AddDataset ( Histogram (det1, probes, precision,
298  "DeterministicRandomVariable", true) );
299 
300  gnuplots.AddPlot (plot);
301  }
302  */
303 
304  {
305  Gnuplot plot;
306  plot.SetTitle ("LogNormalRandomVariable");
307  plot.AppendExtra ("set xrange [0:3]");
308 
309  plot.AppendExtra ("LogNormalDist(x,m,s) = 1.0/x * NormalDist(log(x), m, s)");
310 
311  Ptr<LogNormalRandomVariable> x1 = CreateObject<LogNormalRandomVariable> ();
312  x1->SetAttribute ("Mu", DoubleValue (0.0));
313  x1->SetAttribute ("Sigma", DoubleValue (1.0));
314 
315  plot.AddDataset ( Histogram (x1, probes, precision,
316  "LogNormalRandomVariable m=0.0 s=1.0") );
317 
318  plot.AddDataset ( Gnuplot2dFunction ("LogNormalDist(x, 0.0, 1.0)",
319  "LogNormalDist(x, 0.0, 1.0)") );
320 
321  Ptr<LogNormalRandomVariable> x2 = CreateObject<LogNormalRandomVariable> ();
322  x2->SetAttribute ("Mu", DoubleValue (0.0));
323  x2->SetAttribute ("Sigma", DoubleValue (0.5));
324 
325  plot.AddDataset ( Histogram (x2, probes, precision,
326  "LogNormalRandomVariable m=0.0 s=0.5") );
327 
328  Ptr<LogNormalRandomVariable> x3 = CreateObject<LogNormalRandomVariable> ();
329  x3->SetAttribute ("Mu", DoubleValue (0.0));
330  x3->SetAttribute ("Sigma", DoubleValue (0.25));
331 
332  plot.AddDataset ( Histogram (x3, probes, precision,
333  "LogNormalRandomVariable m=0.0 s=0.25") );
334 
335  plot.AddDataset ( Gnuplot2dFunction ("LogNormalDist(x, 0.0, 0.25)",
336  "LogNormalDist(x, 0.0, 0.25)") );
337 
338  Ptr<LogNormalRandomVariable> x4 = CreateObject<LogNormalRandomVariable> ();
339  x4->SetAttribute ("Mu", DoubleValue (0.0));
340  x4->SetAttribute ("Sigma", DoubleValue (0.125));
341 
342  plot.AddDataset ( Histogram (x4, probes, precision,
343  "LogNormalRandomVariable m=0.0 s=0.125") );
344 
345  Ptr<LogNormalRandomVariable> x5 = CreateObject<LogNormalRandomVariable> ();
346  x5->SetAttribute ("Mu", DoubleValue (0.0));
347  x5->SetAttribute ("Sigma", DoubleValue (2.0));
348 
349  plot.AddDataset ( Histogram (x5, probes, precision,
350  "LogNormalRandomVariable m=0.0 s=2.0") );
351 
352  plot.AddDataset ( Gnuplot2dFunction ("LogNormalDist(x, 0.0, 2.0)",
353  "LogNormalDist(x, 0.0, 2.0)") );
354 
355  Ptr<LogNormalRandomVariable> x6 = CreateObject<LogNormalRandomVariable> ();
356  x6->SetAttribute ("Mu", DoubleValue (0.0));
357  x6->SetAttribute ("Sigma", DoubleValue (2.5));
358 
359  plot.AddDataset ( Histogram (x6, probes, precision,
360  "LogNormalRandomVariable m=0.0 s=2.5") );
361 
362  gnuplots.AddPlot (plot);
363  }
364 
365  {
366  Gnuplot plot;
367  plot.SetTitle ("TriangularRandomVariable");
368  plot.AppendExtra ("set xrange [*:*]");
369 
370  Ptr<TriangularRandomVariable> x1 = CreateObject<TriangularRandomVariable> ();
371  x1->SetAttribute ("Min", DoubleValue (0.0));
372  x1->SetAttribute ("Max", DoubleValue (1.0));
373  x1->SetAttribute ("Mean", DoubleValue (0.5));
374 
375  plot.AddDataset ( Histogram (x1, probes, precision,
376  "TriangularRandomVariable [0.0 .. 1.0) m=0.5") );
377 
378  Ptr<TriangularRandomVariable> x2 = CreateObject<TriangularRandomVariable> ();
379  x2->SetAttribute ("Min", DoubleValue (0.0));
380  x2->SetAttribute ("Max", DoubleValue (1.0));
381  x2->SetAttribute ("Mean", DoubleValue (0.4));
382 
383  plot.AddDataset ( Histogram (x2, probes, precision,
384  "TriangularRandomVariable [0.0 .. 1.0) m=0.4") );
385 
386  Ptr<TriangularRandomVariable> x3 = CreateObject<TriangularRandomVariable> ();
387  x3->SetAttribute ("Min", DoubleValue (0.0));
388  x3->SetAttribute ("Max", DoubleValue (1.0));
389  x3->SetAttribute ("Mean", DoubleValue (0.65));
390 
391  plot.AddDataset ( Histogram (x3, probes, precision,
392  "TriangularRandomVariable [0.0 .. 1.0) m=0.65") );
393 
394  gnuplots.AddPlot (plot);
395  }
396 
397  {
398  Gnuplot plot;
399  plot.SetTitle ("GammaRandomVariable");
400  plot.AppendExtra ("set xrange [0:10]");
401  plot.AppendExtra ("set yrange [0:1]");
402  plot.AppendExtra ("GammaDist(x,a,b) = x**(a-1) * 1/b**a * exp(-x/b) / gamma(a)");
403 
404  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");
405 
406  Ptr<GammaRandomVariable> x1 = CreateObject<GammaRandomVariable> ();
407  x1->SetAttribute ("Alpha", DoubleValue (1.0));
408  x1->SetAttribute ("Beta", DoubleValue (1.0));
409 
410  plot.AddDataset ( Histogram (x1, probes, precision,
411  "GammaRandomVariable a=1.0 b=1.0") );
412 
413  plot.AddDataset ( Gnuplot2dFunction ("{/Symbol g}(x, 1.0, 1.0)",
414  "GammaDist(x, 1.0, 1.0)") );
415 
416  Ptr<GammaRandomVariable> x2 = CreateObject<GammaRandomVariable> ();
417  x2->SetAttribute ("Alpha", DoubleValue (1.5));
418  x2->SetAttribute ("Beta", DoubleValue (1.0));
419 
420  plot.AddDataset ( Histogram (x2, probes, precision,
421  "GammaRandomVariable a=1.5 b=1.0") );
422 
423  plot.AddDataset ( Gnuplot2dFunction ("{/Symbol g}(x, 1.5, 1.0)",
424  "GammaDist(x, 1.5, 1.0)") );
425 
426  Ptr<GammaRandomVariable> x3 = CreateObject<GammaRandomVariable> ();
427  x3->SetAttribute ("Alpha", DoubleValue (2.0));
428  x3->SetAttribute ("Beta", DoubleValue (1.0));
429 
430  plot.AddDataset ( Histogram (x3, probes, precision,
431  "GammaRandomVariable a=2.0 b=1.0") );
432 
433  plot.AddDataset ( Gnuplot2dFunction ("{/Symbol g}(x, 2.0, 1.0)",
434  "GammaDist(x, 2.0, 1.0)") );
435 
436  Ptr<GammaRandomVariable> x4 = CreateObject<GammaRandomVariable> ();
437  x4->SetAttribute ("Alpha", DoubleValue (4.0));
438  x4->SetAttribute ("Beta", DoubleValue (1.0));
439 
440  plot.AddDataset ( Histogram (x4, probes, precision,
441  "GammaRandomVariable a=4.0 b=1.0") );
442 
443  plot.AddDataset ( Gnuplot2dFunction ("{/Symbol g}(x, 4.0, 1.0)",
444  "GammaDist(x, 4.0, 1.0)") );
445 
446  Ptr<GammaRandomVariable> x5 = CreateObject<GammaRandomVariable> ();
447  x5->SetAttribute ("Alpha", DoubleValue (2.0));
448  x5->SetAttribute ("Beta", DoubleValue (2.0));
449 
450  plot.AddDataset ( Histogram (x5, probes, precision,
451  "GammaRandomVariable a=2.0 b=2.0") );
452 
453  plot.AddDataset ( Gnuplot2dFunction ("{/Symbol g}(x, 2.0, 2.0)",
454  "GammaDist(x, 2.0, 2.0)") );
455 
456  Ptr<GammaRandomVariable> x6 = CreateObject<GammaRandomVariable> ();
457  x6->SetAttribute ("Alpha", DoubleValue (2.5));
458  x6->SetAttribute ("Beta", DoubleValue (3.0));
459 
460  plot.AddDataset ( Histogram (x6, probes, precision,
461  "GammaRandomVariable a=2.5 b=3.0") );
462 
463  plot.AddDataset ( Gnuplot2dFunction ("{/Symbol g}(x, 2.5, 3.0)",
464  "GammaDist(x, 2.5, 3.0)") );
465 
466  Ptr<GammaRandomVariable> x7 = CreateObject<GammaRandomVariable> ();
467  x7->SetAttribute ("Alpha", DoubleValue (2.5));
468  x7->SetAttribute ("Beta", DoubleValue (4.5));
469 
470  plot.AddDataset ( Histogram (x7, probes, precision,
471  "GammaRandomVariable a=2.5 b=4.5") );
472 
473  plot.AddDataset ( Gnuplot2dFunction ("{/Symbol g}(x, 2.5, 4.5)",
474  "GammaDist(x, 2.5, 4.5)") );
475 
476  gnuplots.AddPlot (plot);
477  }
478 
479  {
480  Gnuplot plot;
481  plot.SetTitle ("ErlangRandomVariable");
482  plot.AppendExtra ("set xrange [0:10]");
483  plot.AppendExtra ("ErlangDist(x,k,l) = x**(k-1) * 1/l**k * exp(-x/l) / (k-1)!");
484 
485  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");
486 
487  Ptr<ErlangRandomVariable> x1 = CreateObject<ErlangRandomVariable> ();
488  x1->SetAttribute ("K", IntegerValue (1));
489  x1->SetAttribute ("Lambda", DoubleValue (1.0));
490 
491  plot.AddDataset ( Histogram (x1, probes, precision,
492  "ErlangRandomVariable k=1 {/Symbol l}=1.0") );
493 
494  plot.AddDataset ( Gnuplot2dFunction ("Erlang(x, 1, 1.0)",
495  "ErlangDist(x, 1, 1.0)") );
496 
497  Ptr<ErlangRandomVariable> x2 = CreateObject<ErlangRandomVariable> ();
498  x2->SetAttribute ("K", IntegerValue (2));
499  x2->SetAttribute ("Lambda", DoubleValue (1.0));
500 
501  plot.AddDataset ( Histogram (x2, probes, precision,
502  "ErlangRandomVariable k=2 {/Symbol l}=1.0") );
503 
504  plot.AddDataset ( Gnuplot2dFunction ("Erlang(x, 2, 1.0)",
505  "ErlangDist(x, 2, 1.0)") );
506 
507  Ptr<ErlangRandomVariable> x3 = CreateObject<ErlangRandomVariable> ();
508  x3->SetAttribute ("K", IntegerValue (3));
509  x3->SetAttribute ("Lambda", DoubleValue (1.0));
510 
511  plot.AddDataset ( Histogram (x3, probes, precision,
512  "ErlangRandomVariable k=3 {/Symbol l}=1.0") );
513 
514  plot.AddDataset ( Gnuplot2dFunction ("Erlang(x, 3, 1.0)",
515  "ErlangDist(x, 3, 1.0)") );
516 
517  Ptr<ErlangRandomVariable> x4 = CreateObject<ErlangRandomVariable> ();
518  x4->SetAttribute ("K", IntegerValue (5));
519  x4->SetAttribute ("Lambda", DoubleValue (1.0));
520 
521  plot.AddDataset ( Histogram (x4, probes, precision,
522  "ErlangRandomVariable k=5 {/Symbol l}=1.0") );
523 
524  plot.AddDataset ( Gnuplot2dFunction ("Erlang(x, 5, 1.0)",
525  "ErlangDist(x, 5, 1.0)") );
526 
527  Ptr<ErlangRandomVariable> x5 = CreateObject<ErlangRandomVariable> ();
528  x5->SetAttribute ("K", IntegerValue (2));
529  x5->SetAttribute ("Lambda", DoubleValue (2.0));
530 
531  plot.AddDataset ( Histogram (x5, probes, precision,
532  "ErlangRandomVariable k=2 {/Symbol l}=2.0") );
533 
534  plot.AddDataset ( Gnuplot2dFunction ("Erlang(x, 2, 2.0)",
535  "ErlangDist(x, 2, 2.0)") );
536 
537  Ptr<ErlangRandomVariable> x6 = CreateObject<ErlangRandomVariable> ();
538  x6->SetAttribute ("K", IntegerValue (2));
539  x6->SetAttribute ("Lambda", DoubleValue (3.0));
540 
541  plot.AddDataset ( Histogram (x6, probes, precision,
542  "ErlangRandomVariable k=2 {/Symbol l}=3.0") );
543 
544  plot.AddDataset ( Gnuplot2dFunction ("Erlang(x, 2, 3.0)",
545  "ErlangDist(x, 2, 3.0)") );
546 
547  Ptr<ErlangRandomVariable> x7 = CreateObject<ErlangRandomVariable> ();
548  x7->SetAttribute ("K", IntegerValue (2));
549  x7->SetAttribute ("Lambda", DoubleValue (5.0));
550 
551  plot.AddDataset ( Histogram (x7, probes, precision,
552  "ErlangRandomVariable k=2 {/Symbol l}=5.0") );
553 
554  plot.AddDataset ( Gnuplot2dFunction ("Erlang(x, 2, 5.0)",
555  "ErlangDist(x, 2, 5.0)") );
556 
557  gnuplots.AddPlot (plot);
558  }
559 
560  gnuplots.GenerateOutput (std::cout);
561 
562  return 0;
563 }
void AppendExtra(const std::string &extra)
Definition: gnuplot.cc:749
Class to represent a 2D points plot.
Definition: gnuplot.h:117
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
cmd
Definition: second.py:35
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.
Definition: gnuplot.h:371
a simple class to group together multiple gnuplots into one file, e.g.
Definition: gnuplot.h:487
void SetTitle(const std::string &title)
Definition: gnuplot.cc:730
uint8_t data[writeSize]
Parse command-line arguments.
Definition: command-line.h:213
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Class to represent a 2D function expression plot.
Definition: gnuplot.h:243
This class can be used to hold variables of floating point type such as &#39;double&#39; or &#39;float&#39;...
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:185
Class used to store data and make an histogram of the data frequency.
Definition: histogram.h:45