A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
main-random-variable-stream.cc
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 
57  Gnuplot2dDataset data;
58  data.SetTitle (title);
59 
60  if (notcontinous)
61  {
62  data.SetStyle (Gnuplot2dDataset::IMPULSES);
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 
232  // XXX Turn this plot back on once its distribution has been finished.
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  // XXX Turn the above plot back on once its distribution has been finished.
253  */
254 
255  // XXX Turn this plot back on once its distribution has been finished.
256  /*
257  {
258  Gnuplot plot;
259  plot.SetTitle ("DeterministicRandomVariable");
260  plot.AppendExtra ("set xrange [*:*]");
261 
262  double values[] = { 0.0, 0.2, 0.2, 0.4, 0.2, 0.6, 0.8, 0.8, 1.0 };
263  DeterministicRandomVariable det1 (values, sizeof(values) / sizeof(values[0]));
264 
265  plot.AddDataset ( Histogramm (det1, probes, precision,
266  "DeterministicRandomVariable", true) );
267 
268  gnuplots.AddPlot (plot);
269  }
270  // XXX Turn the above plot back on once its distribution has been finished.
271  */
272 
273  {
274  Gnuplot plot;
275  plot.SetTitle ("LogNormalRandomVariable");
276  plot.AppendExtra ("set xrange [0:3]");
277 
278  plot.AppendExtra ("LogNormalDist(x,m,s) = 1.0/x * NormalDist(log(x), m, s)");
279 
280  Ptr<LogNormalRandomVariable> x1 = CreateObject<LogNormalRandomVariable> ();
281  x1->SetAttribute ("Mu", DoubleValue (0.0));
282  x1->SetAttribute ("Sigma", DoubleValue (1.0));
283 
284  plot.AddDataset ( Histogramm (x1, probes, precision,
285  "LogNormalRandomVariable m=0.0 s=1.0") );
286 
287  plot.AddDataset ( Gnuplot2dFunction ("LogNormalDist(x, 0.0, 1.0)",
288  "LogNormalDist(x, 0.0, 1.0)") );
289 
290  Ptr<LogNormalRandomVariable> x2 = CreateObject<LogNormalRandomVariable> ();
291  x2->SetAttribute ("Mu", DoubleValue (0.0));
292  x2->SetAttribute ("Sigma", DoubleValue (0.5));
293 
294  plot.AddDataset ( Histogramm (x2, probes, precision,
295  "LogNormalRandomVariable m=0.0 s=0.5") );
296 
297  Ptr<LogNormalRandomVariable> x3 = CreateObject<LogNormalRandomVariable> ();
298  x3->SetAttribute ("Mu", DoubleValue (0.0));
299  x3->SetAttribute ("Sigma", DoubleValue (0.25));
300 
301  plot.AddDataset ( Histogramm (x3, probes, precision,
302  "LogNormalRandomVariable m=0.0 s=0.25") );
303 
304  plot.AddDataset ( Gnuplot2dFunction ("LogNormalDist(x, 0.0, 0.25)",
305  "LogNormalDist(x, 0.0, 0.25)") );
306 
307  Ptr<LogNormalRandomVariable> x4 = CreateObject<LogNormalRandomVariable> ();
308  x4->SetAttribute ("Mu", DoubleValue (0.0));
309  x4->SetAttribute ("Sigma", DoubleValue (0.125));
310 
311  plot.AddDataset ( Histogramm (x4, probes, precision,
312  "LogNormalRandomVariable m=0.0 s=0.125") );
313 
314  Ptr<LogNormalRandomVariable> x5 = CreateObject<LogNormalRandomVariable> ();
315  x5->SetAttribute ("Mu", DoubleValue (0.0));
316  x5->SetAttribute ("Sigma", DoubleValue (2.0));
317 
318  plot.AddDataset ( Histogramm (x5, probes, precision,
319  "LogNormalRandomVariable m=0.0 s=2.0") );
320 
321  plot.AddDataset ( Gnuplot2dFunction ("LogNormalDist(x, 0.0, 2.0)",
322  "LogNormalDist(x, 0.0, 2.0)") );
323 
324  Ptr<LogNormalRandomVariable> x6 = CreateObject<LogNormalRandomVariable> ();
325  x6->SetAttribute ("Mu", DoubleValue (0.0));
326  x6->SetAttribute ("Sigma", DoubleValue (2.5));
327 
328  plot.AddDataset ( Histogramm (x6, probes, precision,
329  "LogNormalRandomVariable m=0.0 s=2.5") );
330 
331  gnuplots.AddPlot (plot);
332  }
333 
334  {
335  Gnuplot plot;
336  plot.SetTitle ("TriangularRandomVariable");
337  plot.AppendExtra ("set xrange [*:*]");
338 
339  Ptr<TriangularRandomVariable> x1 = CreateObject<TriangularRandomVariable> ();
340  x1->SetAttribute ("Min", DoubleValue (0.0));
341  x1->SetAttribute ("Max", DoubleValue (1.0));
342  x1->SetAttribute ("Mean", DoubleValue (0.5));
343 
344  plot.AddDataset ( Histogramm (x1, probes, precision,
345  "TriangularRandomVariable [0.0 .. 1.0) m=0.5") );
346 
347  Ptr<TriangularRandomVariable> x2 = CreateObject<TriangularRandomVariable> ();
348  x2->SetAttribute ("Min", DoubleValue (0.0));
349  x2->SetAttribute ("Max", DoubleValue (1.0));
350  x2->SetAttribute ("Mean", DoubleValue (0.4));
351 
352  plot.AddDataset ( Histogramm (x2, probes, precision,
353  "TriangularRandomVariable [0.0 .. 1.0) m=0.4") );
354 
355  Ptr<TriangularRandomVariable> x3 = CreateObject<TriangularRandomVariable> ();
356  x3->SetAttribute ("Min", DoubleValue (0.0));
357  x3->SetAttribute ("Max", DoubleValue (1.0));
358  x3->SetAttribute ("Mean", DoubleValue (0.65));
359 
360  plot.AddDataset ( Histogramm (x3, probes, precision,
361  "TriangularRandomVariable [0.0 .. 1.0) m=0.65") );
362 
363  gnuplots.AddPlot (plot);
364  }
365 
366  {
367  Gnuplot plot;
368  plot.SetTitle ("GammaRandomVariable");
369  plot.AppendExtra ("set xrange [0:10]");
370  plot.AppendExtra ("set yrange [0:1]");
371  plot.AppendExtra ("GammaDist(x,a,b) = x**(a-1) * 1/b**a * exp(-x/b) / gamma(a)");
372 
373  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");
374 
375  Ptr<GammaRandomVariable> x1 = CreateObject<GammaRandomVariable> ();
376  x1->SetAttribute ("Alpha", DoubleValue (1.0));
377  x1->SetAttribute ("Beta", DoubleValue (1.0));
378 
379  plot.AddDataset ( Histogramm (x1, probes, precision,
380  "GammaRandomVariable a=1.0 b=1.0") );
381 
382  plot.AddDataset ( Gnuplot2dFunction ("{/Symbol g}(x, 1.0, 1.0)",
383  "GammaDist(x, 1.0, 1.0)") );
384 
385  Ptr<GammaRandomVariable> x2 = CreateObject<GammaRandomVariable> ();
386  x2->SetAttribute ("Alpha", DoubleValue (1.5));
387  x2->SetAttribute ("Beta", DoubleValue (1.0));
388 
389  plot.AddDataset ( Histogramm (x2, probes, precision,
390  "GammaRandomVariable a=1.5 b=1.0") );
391 
392  plot.AddDataset ( Gnuplot2dFunction ("{/Symbol g}(x, 1.5, 1.0)",
393  "GammaDist(x, 1.5, 1.0)") );
394 
395  Ptr<GammaRandomVariable> x3 = CreateObject<GammaRandomVariable> ();
396  x3->SetAttribute ("Alpha", DoubleValue (2.0));
397  x3->SetAttribute ("Beta", DoubleValue (1.0));
398 
399  plot.AddDataset ( Histogramm (x3, probes, precision,
400  "GammaRandomVariable a=2.0 b=1.0") );
401 
402  plot.AddDataset ( Gnuplot2dFunction ("{/Symbol g}(x, 2.0, 1.0)",
403  "GammaDist(x, 2.0, 1.0)") );
404 
405  Ptr<GammaRandomVariable> x4 = CreateObject<GammaRandomVariable> ();
406  x4->SetAttribute ("Alpha", DoubleValue (4.0));
407  x4->SetAttribute ("Beta", DoubleValue (1.0));
408 
409  plot.AddDataset ( Histogramm (x4, probes, precision,
410  "GammaRandomVariable a=4.0 b=1.0") );
411 
412  plot.AddDataset ( Gnuplot2dFunction ("{/Symbol g}(x, 4.0, 1.0)",
413  "GammaDist(x, 4.0, 1.0)") );
414 
415  Ptr<GammaRandomVariable> x5 = CreateObject<GammaRandomVariable> ();
416  x5->SetAttribute ("Alpha", DoubleValue (2.0));
417  x5->SetAttribute ("Beta", DoubleValue (2.0));
418 
419  plot.AddDataset ( Histogramm (x5, probes, precision,
420  "GammaRandomVariable a=2.0 b=2.0") );
421 
422  plot.AddDataset ( Gnuplot2dFunction ("{/Symbol g}(x, 2.0, 2.0)",
423  "GammaDist(x, 2.0, 2.0)") );
424 
425  Ptr<GammaRandomVariable> x6 = CreateObject<GammaRandomVariable> ();
426  x6->SetAttribute ("Alpha", DoubleValue (2.5));
427  x6->SetAttribute ("Beta", DoubleValue (3.0));
428 
429  plot.AddDataset ( Histogramm (x6, probes, precision,
430  "GammaRandomVariable a=2.5 b=3.0") );
431 
432  plot.AddDataset ( Gnuplot2dFunction ("{/Symbol g}(x, 2.5, 3.0)",
433  "GammaDist(x, 2.5, 3.0)") );
434 
435  Ptr<GammaRandomVariable> x7 = CreateObject<GammaRandomVariable> ();
436  x7->SetAttribute ("Alpha", DoubleValue (2.5));
437  x7->SetAttribute ("Beta", DoubleValue (4.5));
438 
439  plot.AddDataset ( Histogramm (x7, probes, precision,
440  "GammaRandomVariable a=2.5 b=4.5") );
441 
442  plot.AddDataset ( Gnuplot2dFunction ("{/Symbol g}(x, 2.5, 4.5)",
443  "GammaDist(x, 2.5, 4.5)") );
444 
445  gnuplots.AddPlot (plot);
446  }
447 
448  {
449  Gnuplot plot;
450  plot.SetTitle ("ErlangRandomVariable");
451  plot.AppendExtra ("set xrange [0:10]");
452  plot.AppendExtra ("ErlangDist(x,k,l) = x**(k-1) * 1/l**k * exp(-x/l) / (k-1)!");
453 
454  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");
455 
456  Ptr<ErlangRandomVariable> x1 = CreateObject<ErlangRandomVariable> ();
457  x1->SetAttribute ("K", IntegerValue (1));
458  x1->SetAttribute ("Lambda", DoubleValue (1.0));
459 
460  plot.AddDataset ( Histogramm (x1, probes, precision,
461  "ErlangRandomVariable k=1 {/Symbol l}=1.0") );
462 
463  plot.AddDataset ( Gnuplot2dFunction ("Erlang(x, 1, 1.0)",
464  "ErlangDist(x, 1, 1.0)") );
465 
466  Ptr<ErlangRandomVariable> x2 = CreateObject<ErlangRandomVariable> ();
467  x2->SetAttribute ("K", IntegerValue (2));
468  x2->SetAttribute ("Lambda", DoubleValue (1.0));
469 
470  plot.AddDataset ( Histogramm (x2, probes, precision,
471  "ErlangRandomVariable k=2 {/Symbol l}=1.0") );
472 
473  plot.AddDataset ( Gnuplot2dFunction ("Erlang(x, 2, 1.0)",
474  "ErlangDist(x, 2, 1.0)") );
475 
476  Ptr<ErlangRandomVariable> x3 = CreateObject<ErlangRandomVariable> ();
477  x3->SetAttribute ("K", IntegerValue (3));
478  x3->SetAttribute ("Lambda", DoubleValue (1.0));
479 
480  plot.AddDataset ( Histogramm (x3, probes, precision,
481  "ErlangRandomVariable k=3 {/Symbol l}=1.0") );
482 
483  plot.AddDataset ( Gnuplot2dFunction ("Erlang(x, 3, 1.0)",
484  "ErlangDist(x, 3, 1.0)") );
485 
486  Ptr<ErlangRandomVariable> x4 = CreateObject<ErlangRandomVariable> ();
487  x4->SetAttribute ("K", IntegerValue (5));
488  x4->SetAttribute ("Lambda", DoubleValue (1.0));
489 
490  plot.AddDataset ( Histogramm (x4, probes, precision,
491  "ErlangRandomVariable k=5 {/Symbol l}=1.0") );
492 
493  plot.AddDataset ( Gnuplot2dFunction ("Erlang(x, 5, 1.0)",
494  "ErlangDist(x, 5, 1.0)") );
495 
496  Ptr<ErlangRandomVariable> x5 = CreateObject<ErlangRandomVariable> ();
497  x5->SetAttribute ("K", IntegerValue (2));
498  x5->SetAttribute ("Lambda", DoubleValue (2.0));
499 
500  plot.AddDataset ( Histogramm (x5, probes, precision,
501  "ErlangRandomVariable k=2 {/Symbol l}=2.0") );
502 
503  plot.AddDataset ( Gnuplot2dFunction ("Erlang(x, 2, 2.0)",
504  "ErlangDist(x, 2, 2.0)") );
505 
506  Ptr<ErlangRandomVariable> x6 = CreateObject<ErlangRandomVariable> ();
507  x6->SetAttribute ("K", IntegerValue (2));
508  x6->SetAttribute ("Lambda", DoubleValue (3.0));
509 
510  plot.AddDataset ( Histogramm (x6, probes, precision,
511  "ErlangRandomVariable k=2 {/Symbol l}=3.0") );
512 
513  plot.AddDataset ( Gnuplot2dFunction ("Erlang(x, 2, 3.0)",
514  "ErlangDist(x, 2, 3.0)") );
515 
516  Ptr<ErlangRandomVariable> x7 = CreateObject<ErlangRandomVariable> ();
517  x7->SetAttribute ("K", IntegerValue (2));
518  x7->SetAttribute ("Lambda", DoubleValue (5.0));
519 
520  plot.AddDataset ( Histogramm (x7, probes, precision,
521  "ErlangRandomVariable k=2 {/Symbol l}=5.0") );
522 
523  plot.AddDataset ( Gnuplot2dFunction ("Erlang(x, 2, 5.0)",
524  "ErlangDist(x, 2, 5.0)") );
525 
526  gnuplots.AddPlot (plot);
527  }
528 
529  gnuplots.GenerateOutput (std::cout);
530 
531  return 0;
532 }
void AppendExtra(const std::string &extra)
Definition: gnuplot.cc:613
Class to represent a 2D points plot. Set the line or points style using SetStyle() and set points usi...
Definition: gnuplot.h:107
void SetTitle(const std::string &title)
Change line title.
Definition: gnuplot.cc:112
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:45
void AddDataset(const GnuplotDataset &dataset)
Definition: gnuplot.cc:620
virtual double GetValue(void)=0
Returns a random double from the underlying distribution.
a simple class to generate gnuplot-ready plotting commands from a set of datasets.
Definition: gnuplot.h:343
a simple class to group together multiple gnuplots into one file, e.g. for PDF multi-page output term...
Definition: gnuplot.h:417
void SetTitle(const std::string &title)
Definition: gnuplot.cc:594
void Add(double x, double y)
Definition: gnuplot.cc:291
void SetStyle(enum Style style)
Definition: gnuplot.cc:274
Class to represent a 2D function expression plot.
Definition: gnuplot.h:227
Hold an floating point type.
Definition: double.h:41
void SetAttribute(std::string name, const AttributeValue &value)
Definition: object-base.cc:160