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