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 
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 
262  /*
263  {
264  Gnuplot plot;
265  plot.SetTitle ("EmpiricalRandomVariable");
266  plot.AppendExtra ("set xrange [*:*]");
267 
268  EmpiricalRandomVariable emp1;
269  emp1.CDF (0.0, 0.0 / 15.0);
270  emp1.CDF (0.2, 1.0 / 15.0);
271  emp1.CDF (0.4, 3.0 / 15.0);
272  emp1.CDF (0.6, 6.0 / 15.0);
273  emp1.CDF (0.8, 10.0 / 15.0);
274  emp1.CDF (1.0, 15.0 / 15.0);
275 
276  plot.AddDataset ( Histogram (emp1, probes, precision,
277  "EmpiricalRandomVariable (Stairs)") );
278 
279  gnuplots.AddPlot (plot);
280  }
281  */
282 
284  /*
285  {
286  Gnuplot plot;
287  plot.SetTitle ("DeterministicRandomVariable");
288  plot.AppendExtra ("set xrange [*:*]");
289 
290  double values[] = { 0.0, 0.2, 0.2, 0.4, 0.2, 0.6, 0.8, 0.8, 1.0 };
291  DeterministicRandomVariable det1 (values, sizeof(values) / sizeof(values[0]));
292 
293  plot.AddDataset ( Histogram (det1, probes, precision,
294  "DeterministicRandomVariable", true) );
295 
296  gnuplots.AddPlot (plot);
297  }
298  */
299 
300  {
301  Gnuplot plot;
302  plot.SetTitle ("LogNormalRandomVariable");
303  plot.AppendExtra ("set xrange [0:3]");
304 
305  plot.AppendExtra ("LogNormalDist(x,m,s) = 1.0/x * NormalDist(log(x), m, s)");
306 
307  Ptr<LogNormalRandomVariable> x1 = CreateObject<LogNormalRandomVariable> ();
308  x1->SetAttribute ("Mu", DoubleValue (0.0));
309  x1->SetAttribute ("Sigma", DoubleValue (1.0));
310 
311  plot.AddDataset ( Histogram (x1, probes, precision,
312  "LogNormalRandomVariable m=0.0 s=1.0") );
313 
314  plot.AddDataset ( Gnuplot2dFunction ("LogNormalDist(x, 0.0, 1.0)",
315  "LogNormalDist(x, 0.0, 1.0)") );
316 
317  Ptr<LogNormalRandomVariable> x2 = CreateObject<LogNormalRandomVariable> ();
318  x2->SetAttribute ("Mu", DoubleValue (0.0));
319  x2->SetAttribute ("Sigma", DoubleValue (0.5));
320 
321  plot.AddDataset ( Histogram (x2, probes, precision,
322  "LogNormalRandomVariable m=0.0 s=0.5") );
323 
324  Ptr<LogNormalRandomVariable> x3 = CreateObject<LogNormalRandomVariable> ();
325  x3->SetAttribute ("Mu", DoubleValue (0.0));
326  x3->SetAttribute ("Sigma", DoubleValue (0.25));
327 
328  plot.AddDataset ( Histogram (x3, probes, precision,
329  "LogNormalRandomVariable m=0.0 s=0.25") );
330 
331  plot.AddDataset ( Gnuplot2dFunction ("LogNormalDist(x, 0.0, 0.25)",
332  "LogNormalDist(x, 0.0, 0.25)") );
333 
334  Ptr<LogNormalRandomVariable> x4 = CreateObject<LogNormalRandomVariable> ();
335  x4->SetAttribute ("Mu", DoubleValue (0.0));
336  x4->SetAttribute ("Sigma", DoubleValue (0.125));
337 
338  plot.AddDataset ( Histogram (x4, probes, precision,
339  "LogNormalRandomVariable m=0.0 s=0.125") );
340 
341  Ptr<LogNormalRandomVariable> x5 = CreateObject<LogNormalRandomVariable> ();
342  x5->SetAttribute ("Mu", DoubleValue (0.0));
343  x5->SetAttribute ("Sigma", DoubleValue (2.0));
344 
345  plot.AddDataset ( Histogram (x5, probes, precision,
346  "LogNormalRandomVariable m=0.0 s=2.0") );
347 
348  plot.AddDataset ( Gnuplot2dFunction ("LogNormalDist(x, 0.0, 2.0)",
349  "LogNormalDist(x, 0.0, 2.0)") );
350 
351  Ptr<LogNormalRandomVariable> x6 = CreateObject<LogNormalRandomVariable> ();
352  x6->SetAttribute ("Mu", DoubleValue (0.0));
353  x6->SetAttribute ("Sigma", DoubleValue (2.5));
354 
355  plot.AddDataset ( Histogram (x6, probes, precision,
356  "LogNormalRandomVariable m=0.0 s=2.5") );
357 
358  gnuplots.AddPlot (plot);
359  }
360 
361  {
362  Gnuplot plot;
363  plot.SetTitle ("TriangularRandomVariable");
364  plot.AppendExtra ("set xrange [*:*]");
365 
366  Ptr<TriangularRandomVariable> x1 = CreateObject<TriangularRandomVariable> ();
367  x1->SetAttribute ("Min", DoubleValue (0.0));
368  x1->SetAttribute ("Max", DoubleValue (1.0));
369  x1->SetAttribute ("Mean", DoubleValue (0.5));
370 
371  plot.AddDataset ( Histogram (x1, probes, precision,
372  "TriangularRandomVariable [0.0 .. 1.0) m=0.5") );
373 
374  Ptr<TriangularRandomVariable> x2 = CreateObject<TriangularRandomVariable> ();
375  x2->SetAttribute ("Min", DoubleValue (0.0));
376  x2->SetAttribute ("Max", DoubleValue (1.0));
377  x2->SetAttribute ("Mean", DoubleValue (0.4));
378 
379  plot.AddDataset ( Histogram (x2, probes, precision,
380  "TriangularRandomVariable [0.0 .. 1.0) m=0.4") );
381 
382  Ptr<TriangularRandomVariable> x3 = CreateObject<TriangularRandomVariable> ();
383  x3->SetAttribute ("Min", DoubleValue (0.0));
384  x3->SetAttribute ("Max", DoubleValue (1.0));
385  x3->SetAttribute ("Mean", DoubleValue (0.65));
386 
387  plot.AddDataset ( Histogram (x3, probes, precision,
388  "TriangularRandomVariable [0.0 .. 1.0) m=0.65") );
389 
390  gnuplots.AddPlot (plot);
391  }
392 
393  {
394  Gnuplot plot;
395  plot.SetTitle ("GammaRandomVariable");
396  plot.AppendExtra ("set xrange [0:10]");
397  plot.AppendExtra ("set yrange [0:1]");
398  plot.AppendExtra ("GammaDist(x,a,b) = x**(a-1) * 1/b**a * exp(-x/b) / gamma(a)");
399 
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");
401 
402  Ptr<GammaRandomVariable> x1 = CreateObject<GammaRandomVariable> ();
403  x1->SetAttribute ("Alpha", DoubleValue (1.0));
404  x1->SetAttribute ("Beta", DoubleValue (1.0));
405 
406  plot.AddDataset ( Histogram (x1, probes, precision,
407  "GammaRandomVariable a=1.0 b=1.0") );
408 
409  plot.AddDataset ( Gnuplot2dFunction ("{/Symbol g}(x, 1.0, 1.0)",
410  "GammaDist(x, 1.0, 1.0)") );
411 
412  Ptr<GammaRandomVariable> x2 = CreateObject<GammaRandomVariable> ();
413  x2->SetAttribute ("Alpha", DoubleValue (1.5));
414  x2->SetAttribute ("Beta", DoubleValue (1.0));
415 
416  plot.AddDataset ( Histogram (x2, probes, precision,
417  "GammaRandomVariable a=1.5 b=1.0") );
418 
419  plot.AddDataset ( Gnuplot2dFunction ("{/Symbol g}(x, 1.5, 1.0)",
420  "GammaDist(x, 1.5, 1.0)") );
421 
422  Ptr<GammaRandomVariable> x3 = CreateObject<GammaRandomVariable> ();
423  x3->SetAttribute ("Alpha", DoubleValue (2.0));
424  x3->SetAttribute ("Beta", DoubleValue (1.0));
425 
426  plot.AddDataset ( Histogram (x3, probes, precision,
427  "GammaRandomVariable a=2.0 b=1.0") );
428 
429  plot.AddDataset ( Gnuplot2dFunction ("{/Symbol g}(x, 2.0, 1.0)",
430  "GammaDist(x, 2.0, 1.0)") );
431 
432  Ptr<GammaRandomVariable> x4 = CreateObject<GammaRandomVariable> ();
433  x4->SetAttribute ("Alpha", DoubleValue (4.0));
434  x4->SetAttribute ("Beta", DoubleValue (1.0));
435 
436  plot.AddDataset ( Histogram (x4, probes, precision,
437  "GammaRandomVariable a=4.0 b=1.0") );
438 
439  plot.AddDataset ( Gnuplot2dFunction ("{/Symbol g}(x, 4.0, 1.0)",
440  "GammaDist(x, 4.0, 1.0)") );
441 
442  Ptr<GammaRandomVariable> x5 = CreateObject<GammaRandomVariable> ();
443  x5->SetAttribute ("Alpha", DoubleValue (2.0));
444  x5->SetAttribute ("Beta", DoubleValue (2.0));
445 
446  plot.AddDataset ( Histogram (x5, probes, precision,
447  "GammaRandomVariable a=2.0 b=2.0") );
448 
449  plot.AddDataset ( Gnuplot2dFunction ("{/Symbol g}(x, 2.0, 2.0)",
450  "GammaDist(x, 2.0, 2.0)") );
451 
452  Ptr<GammaRandomVariable> x6 = CreateObject<GammaRandomVariable> ();
453  x6->SetAttribute ("Alpha", DoubleValue (2.5));
454  x6->SetAttribute ("Beta", DoubleValue (3.0));
455 
456  plot.AddDataset ( Histogram (x6, probes, precision,
457  "GammaRandomVariable a=2.5 b=3.0") );
458 
459  plot.AddDataset ( Gnuplot2dFunction ("{/Symbol g}(x, 2.5, 3.0)",
460  "GammaDist(x, 2.5, 3.0)") );
461 
462  Ptr<GammaRandomVariable> x7 = CreateObject<GammaRandomVariable> ();
463  x7->SetAttribute ("Alpha", DoubleValue (2.5));
464  x7->SetAttribute ("Beta", DoubleValue (4.5));
465 
466  plot.AddDataset ( Histogram (x7, probes, precision,
467  "GammaRandomVariable a=2.5 b=4.5") );
468 
469  plot.AddDataset ( Gnuplot2dFunction ("{/Symbol g}(x, 2.5, 4.5)",
470  "GammaDist(x, 2.5, 4.5)") );
471 
472  gnuplots.AddPlot (plot);
473  }
474 
475  {
476  Gnuplot plot;
477  plot.SetTitle ("ErlangRandomVariable");
478  plot.AppendExtra ("set xrange [0:10]");
479  plot.AppendExtra ("ErlangDist(x,k,l) = x**(k-1) * 1/l**k * exp(-x/l) / (k-1)!");
480 
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");
482 
483  Ptr<ErlangRandomVariable> x1 = CreateObject<ErlangRandomVariable> ();
484  x1->SetAttribute ("K", IntegerValue (1));
485  x1->SetAttribute ("Lambda", DoubleValue (1.0));
486 
487  plot.AddDataset ( Histogram (x1, probes, precision,
488  "ErlangRandomVariable k=1 {/Symbol l}=1.0") );
489 
490  plot.AddDataset ( Gnuplot2dFunction ("Erlang(x, 1, 1.0)",
491  "ErlangDist(x, 1, 1.0)") );
492 
493  Ptr<ErlangRandomVariable> x2 = CreateObject<ErlangRandomVariable> ();
494  x2->SetAttribute ("K", IntegerValue (2));
495  x2->SetAttribute ("Lambda", DoubleValue (1.0));
496 
497  plot.AddDataset ( Histogram (x2, probes, precision,
498  "ErlangRandomVariable k=2 {/Symbol l}=1.0") );
499 
500  plot.AddDataset ( Gnuplot2dFunction ("Erlang(x, 2, 1.0)",
501  "ErlangDist(x, 2, 1.0)") );
502 
503  Ptr<ErlangRandomVariable> x3 = CreateObject<ErlangRandomVariable> ();
504  x3->SetAttribute ("K", IntegerValue (3));
505  x3->SetAttribute ("Lambda", DoubleValue (1.0));
506 
507  plot.AddDataset ( Histogram (x3, probes, precision,
508  "ErlangRandomVariable k=3 {/Symbol l}=1.0") );
509 
510  plot.AddDataset ( Gnuplot2dFunction ("Erlang(x, 3, 1.0)",
511  "ErlangDist(x, 3, 1.0)") );
512 
513  Ptr<ErlangRandomVariable> x4 = CreateObject<ErlangRandomVariable> ();
514  x4->SetAttribute ("K", IntegerValue (5));
515  x4->SetAttribute ("Lambda", DoubleValue (1.0));
516 
517  plot.AddDataset ( Histogram (x4, probes, precision,
518  "ErlangRandomVariable k=5 {/Symbol l}=1.0") );
519 
520  plot.AddDataset ( Gnuplot2dFunction ("Erlang(x, 5, 1.0)",
521  "ErlangDist(x, 5, 1.0)") );
522 
523  Ptr<ErlangRandomVariable> x5 = CreateObject<ErlangRandomVariable> ();
524  x5->SetAttribute ("K", IntegerValue (2));
525  x5->SetAttribute ("Lambda", DoubleValue (2.0));
526 
527  plot.AddDataset ( Histogram (x5, probes, precision,
528  "ErlangRandomVariable k=2 {/Symbol l}=2.0") );
529 
530  plot.AddDataset ( Gnuplot2dFunction ("Erlang(x, 2, 2.0)",
531  "ErlangDist(x, 2, 2.0)") );
532 
533  Ptr<ErlangRandomVariable> x6 = CreateObject<ErlangRandomVariable> ();
534  x6->SetAttribute ("K", IntegerValue (2));
535  x6->SetAttribute ("Lambda", DoubleValue (3.0));
536 
537  plot.AddDataset ( Histogram (x6, probes, precision,
538  "ErlangRandomVariable k=2 {/Symbol l}=3.0") );
539 
540  plot.AddDataset ( Gnuplot2dFunction ("Erlang(x, 2, 3.0)",
541  "ErlangDist(x, 2, 3.0)") );
542 
543  Ptr<ErlangRandomVariable> x7 = CreateObject<ErlangRandomVariable> ();
544  x7->SetAttribute ("K", IntegerValue (2));
545  x7->SetAttribute ("Lambda", DoubleValue (5.0));
546 
547  plot.AddDataset ( Histogram (x7, probes, precision,
548  "ErlangRandomVariable k=2 {/Symbol l}=5.0") );
549 
550  plot.AddDataset ( Gnuplot2dFunction ("Erlang(x, 2, 5.0)",
551  "ErlangDist(x, 2, 5.0)") );
552 
553  gnuplots.AddPlot (plot);
554  }
555 
556  gnuplots.GenerateOutput (std::cout);
557 
558  return 0;
559 }
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 Add(double x, double y)
Definition: gnuplot.cc:359
Every class exported by the ns3 library is enclosed in the ns3 namespace.
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