A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
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 
232  {
233  Gnuplot plot;
234  plot.SetTitle ("EmpiricalRandomVariable");
235  plot.AppendExtra ("set xrange [*:*]");
236 
237  Ptr<EmpiricalRandomVariable> emp1 = CreateObject<EmpiricalRandomVariable> ();
238  emp1->CDF (0.0, 0.0 / 15.0);
239  emp1->CDF (0.2, 1.0 / 15.0);
240  emp1->CDF (0.4, 3.0 / 15.0);
241  emp1->CDF (0.6, 6.0 / 15.0);
242  emp1->CDF (0.8, 10.0 / 15.0);
243  emp1->CDF (1.0, 15.0 / 15.0);
244 
245  plot.AddDataset ( Histogramm (emp1, probes, precision,
246  "EmpiricalRandomVariable (Stairs)") );
247 
248  gnuplots.AddPlot (plot);
249  }
250 
251  {
252  Gnuplot plot;
253  plot.SetTitle ("DeterministicRandomVariable");
254  plot.AppendExtra ("set xrange [*:*]");
255 
256  double values[] = { 0.0, 0.2, 0.2, 0.4, 0.2, 0.6, 0.8, 0.8, 1.0 };
257 
258  Ptr<DeterministicRandomVariable> det1 = CreateObject<DeterministicRandomVariable> ();
259  det1->SetValueArray (values, sizeof(values) / sizeof(values[0]));
260 
261  plot.AddDataset ( Histogramm (det1, probes, precision,
262  "DeterministicRandomVariable", true) );
263 
264  gnuplots.AddPlot (plot);
265  }
266 
267  {
268  Gnuplot plot;
269  plot.SetTitle ("LogNormalRandomVariable");
270  plot.AppendExtra ("set xrange [0:3]");
271 
272  plot.AppendExtra ("LogNormalDist(x,m,s) = 1.0/x * NormalDist(log(x), m, s)");
273 
274  Ptr<LogNormalRandomVariable> x1 = CreateObject<LogNormalRandomVariable> ();
275  x1->SetAttribute ("Mu", DoubleValue (0.0));
276  x1->SetAttribute ("Sigma", DoubleValue (1.0));
277 
278  plot.AddDataset ( Histogramm (x1, probes, precision,
279  "LogNormalRandomVariable m=0.0 s=1.0") );
280 
281  plot.AddDataset ( Gnuplot2dFunction ("LogNormalDist(x, 0.0, 1.0)",
282  "LogNormalDist(x, 0.0, 1.0)") );
283 
284  Ptr<LogNormalRandomVariable> x2 = CreateObject<LogNormalRandomVariable> ();
285  x2->SetAttribute ("Mu", DoubleValue (0.0));
286  x2->SetAttribute ("Sigma", DoubleValue (0.5));
287 
288  plot.AddDataset ( Histogramm (x2, probes, precision,
289  "LogNormalRandomVariable m=0.0 s=0.5") );
290 
291  Ptr<LogNormalRandomVariable> x3 = CreateObject<LogNormalRandomVariable> ();
292  x3->SetAttribute ("Mu", DoubleValue (0.0));
293  x3->SetAttribute ("Sigma", DoubleValue (0.25));
294 
295  plot.AddDataset ( Histogramm (x3, probes, precision,
296  "LogNormalRandomVariable m=0.0 s=0.25") );
297 
298  plot.AddDataset ( Gnuplot2dFunction ("LogNormalDist(x, 0.0, 0.25)",
299  "LogNormalDist(x, 0.0, 0.25)") );
300 
301  Ptr<LogNormalRandomVariable> x4 = CreateObject<LogNormalRandomVariable> ();
302  x4->SetAttribute ("Mu", DoubleValue (0.0));
303  x4->SetAttribute ("Sigma", DoubleValue (0.125));
304 
305  plot.AddDataset ( Histogramm (x4, probes, precision,
306  "LogNormalRandomVariable m=0.0 s=0.125") );
307 
308  Ptr<LogNormalRandomVariable> x5 = CreateObject<LogNormalRandomVariable> ();
309  x5->SetAttribute ("Mu", DoubleValue (0.0));
310  x5->SetAttribute ("Sigma", DoubleValue (2.0));
311 
312  plot.AddDataset ( Histogramm (x5, probes, precision,
313  "LogNormalRandomVariable m=0.0 s=2.0") );
314 
315  plot.AddDataset ( Gnuplot2dFunction ("LogNormalDist(x, 0.0, 2.0)",
316  "LogNormalDist(x, 0.0, 2.0)") );
317 
318  Ptr<LogNormalRandomVariable> x6 = CreateObject<LogNormalRandomVariable> ();
319  x6->SetAttribute ("Mu", DoubleValue (0.0));
320  x6->SetAttribute ("Sigma", DoubleValue (2.5));
321 
322  plot.AddDataset ( Histogramm (x6, probes, precision,
323  "LogNormalRandomVariable m=0.0 s=2.5") );
324 
325  gnuplots.AddPlot (plot);
326  }
327 
328  {
329  Gnuplot plot;
330  plot.SetTitle ("TriangularRandomVariable");
331  plot.AppendExtra ("set xrange [*:*]");
332 
333  Ptr<TriangularRandomVariable> x1 = CreateObject<TriangularRandomVariable> ();
334  x1->SetAttribute ("Min", DoubleValue (0.0));
335  x1->SetAttribute ("Max", DoubleValue (1.0));
336  x1->SetAttribute ("Mean", DoubleValue (0.5));
337 
338  plot.AddDataset ( Histogramm (x1, probes, precision,
339  "TriangularRandomVariable [0.0 .. 1.0) m=0.5") );
340 
341  Ptr<TriangularRandomVariable> x2 = CreateObject<TriangularRandomVariable> ();
342  x2->SetAttribute ("Min", DoubleValue (0.0));
343  x2->SetAttribute ("Max", DoubleValue (1.0));
344  x2->SetAttribute ("Mean", DoubleValue (0.4));
345 
346  plot.AddDataset ( Histogramm (x2, probes, precision,
347  "TriangularRandomVariable [0.0 .. 1.0) m=0.4") );
348 
349  Ptr<TriangularRandomVariable> x3 = CreateObject<TriangularRandomVariable> ();
350  x3->SetAttribute ("Min", DoubleValue (0.0));
351  x3->SetAttribute ("Max", DoubleValue (1.0));
352  x3->SetAttribute ("Mean", DoubleValue (0.65));
353 
354  plot.AddDataset ( Histogramm (x3, probes, precision,
355  "TriangularRandomVariable [0.0 .. 1.0) m=0.65") );
356 
357  gnuplots.AddPlot (plot);
358  }
359 
360  {
361  Gnuplot plot;
362  plot.SetTitle ("GammaRandomVariable");
363  plot.AppendExtra ("set xrange [0:10]");
364  plot.AppendExtra ("set yrange [0:1]");
365  plot.AppendExtra ("GammaDist(x,a,b) = x**(a-1) * 1/b**a * exp(-x/b) / gamma(a)");
366 
367  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");
368 
369  Ptr<GammaRandomVariable> x1 = CreateObject<GammaRandomVariable> ();
370  x1->SetAttribute ("Alpha", DoubleValue (1.0));
371  x1->SetAttribute ("Beta", DoubleValue (1.0));
372 
373  plot.AddDataset ( Histogramm (x1, probes, precision,
374  "GammaRandomVariable a=1.0 b=1.0") );
375 
376  plot.AddDataset ( Gnuplot2dFunction ("{/Symbol g}(x, 1.0, 1.0)",
377  "GammaDist(x, 1.0, 1.0)") );
378 
379  Ptr<GammaRandomVariable> x2 = CreateObject<GammaRandomVariable> ();
380  x2->SetAttribute ("Alpha", DoubleValue (1.5));
381  x2->SetAttribute ("Beta", DoubleValue (1.0));
382 
383  plot.AddDataset ( Histogramm (x2, probes, precision,
384  "GammaRandomVariable a=1.5 b=1.0") );
385 
386  plot.AddDataset ( Gnuplot2dFunction ("{/Symbol g}(x, 1.5, 1.0)",
387  "GammaDist(x, 1.5, 1.0)") );
388 
389  Ptr<GammaRandomVariable> x3 = CreateObject<GammaRandomVariable> ();
390  x3->SetAttribute ("Alpha", DoubleValue (2.0));
391  x3->SetAttribute ("Beta", DoubleValue (1.0));
392 
393  plot.AddDataset ( Histogramm (x3, probes, precision,
394  "GammaRandomVariable a=2.0 b=1.0") );
395 
396  plot.AddDataset ( Gnuplot2dFunction ("{/Symbol g}(x, 2.0, 1.0)",
397  "GammaDist(x, 2.0, 1.0)") );
398 
399  Ptr<GammaRandomVariable> x4 = CreateObject<GammaRandomVariable> ();
400  x4->SetAttribute ("Alpha", DoubleValue (4.0));
401  x4->SetAttribute ("Beta", DoubleValue (1.0));
402 
403  plot.AddDataset ( Histogramm (x4, probes, precision,
404  "GammaRandomVariable a=4.0 b=1.0") );
405 
406  plot.AddDataset ( Gnuplot2dFunction ("{/Symbol g}(x, 4.0, 1.0)",
407  "GammaDist(x, 4.0, 1.0)") );
408 
409  Ptr<GammaRandomVariable> x5 = CreateObject<GammaRandomVariable> ();
410  x5->SetAttribute ("Alpha", DoubleValue (2.0));
411  x5->SetAttribute ("Beta", DoubleValue (2.0));
412 
413  plot.AddDataset ( Histogramm (x5, probes, precision,
414  "GammaRandomVariable a=2.0 b=2.0") );
415 
416  plot.AddDataset ( Gnuplot2dFunction ("{/Symbol g}(x, 2.0, 2.0)",
417  "GammaDist(x, 2.0, 2.0)") );
418 
419  Ptr<GammaRandomVariable> x6 = CreateObject<GammaRandomVariable> ();
420  x6->SetAttribute ("Alpha", DoubleValue (2.5));
421  x6->SetAttribute ("Beta", DoubleValue (3.0));
422 
423  plot.AddDataset ( Histogramm (x6, probes, precision,
424  "GammaRandomVariable a=2.5 b=3.0") );
425 
426  plot.AddDataset ( Gnuplot2dFunction ("{/Symbol g}(x, 2.5, 3.0)",
427  "GammaDist(x, 2.5, 3.0)") );
428 
429  Ptr<GammaRandomVariable> x7 = CreateObject<GammaRandomVariable> ();
430  x7->SetAttribute ("Alpha", DoubleValue (2.5));
431  x7->SetAttribute ("Beta", DoubleValue (4.5));
432 
433  plot.AddDataset ( Histogramm (x7, probes, precision,
434  "GammaRandomVariable a=2.5 b=4.5") );
435 
436  plot.AddDataset ( Gnuplot2dFunction ("{/Symbol g}(x, 2.5, 4.5)",
437  "GammaDist(x, 2.5, 4.5)") );
438 
439  gnuplots.AddPlot (plot);
440  }
441 
442  {
443  Gnuplot plot;
444  plot.SetTitle ("ErlangRandomVariable");
445  plot.AppendExtra ("set xrange [0:10]");
446  plot.AppendExtra ("ErlangDist(x,k,l) = x**(k-1) * 1/l**k * exp(-x/l) / (k-1)!");
447 
448  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");
449 
450  Ptr<ErlangRandomVariable> x1 = CreateObject<ErlangRandomVariable> ();
451  x1->SetAttribute ("K", IntegerValue (1));
452  x1->SetAttribute ("Lambda", DoubleValue (1.0));
453 
454  plot.AddDataset ( Histogramm (x1, probes, precision,
455  "ErlangRandomVariable k=1 {/Symbol l}=1.0") );
456 
457  plot.AddDataset ( Gnuplot2dFunction ("Erlang(x, 1, 1.0)",
458  "ErlangDist(x, 1, 1.0)") );
459 
460  Ptr<ErlangRandomVariable> x2 = CreateObject<ErlangRandomVariable> ();
461  x2->SetAttribute ("K", IntegerValue (2));
462  x2->SetAttribute ("Lambda", DoubleValue (1.0));
463 
464  plot.AddDataset ( Histogramm (x2, probes, precision,
465  "ErlangRandomVariable k=2 {/Symbol l}=1.0") );
466 
467  plot.AddDataset ( Gnuplot2dFunction ("Erlang(x, 2, 1.0)",
468  "ErlangDist(x, 2, 1.0)") );
469 
470  Ptr<ErlangRandomVariable> x3 = CreateObject<ErlangRandomVariable> ();
471  x3->SetAttribute ("K", IntegerValue (3));
472  x3->SetAttribute ("Lambda", DoubleValue (1.0));
473 
474  plot.AddDataset ( Histogramm (x3, probes, precision,
475  "ErlangRandomVariable k=3 {/Symbol l}=1.0") );
476 
477  plot.AddDataset ( Gnuplot2dFunction ("Erlang(x, 3, 1.0)",
478  "ErlangDist(x, 3, 1.0)") );
479 
480  Ptr<ErlangRandomVariable> x4 = CreateObject<ErlangRandomVariable> ();
481  x4->SetAttribute ("K", IntegerValue (5));
482  x4->SetAttribute ("Lambda", DoubleValue (1.0));
483 
484  plot.AddDataset ( Histogramm (x4, probes, precision,
485  "ErlangRandomVariable k=5 {/Symbol l}=1.0") );
486 
487  plot.AddDataset ( Gnuplot2dFunction ("Erlang(x, 5, 1.0)",
488  "ErlangDist(x, 5, 1.0)") );
489 
490  Ptr<ErlangRandomVariable> x5 = CreateObject<ErlangRandomVariable> ();
491  x5->SetAttribute ("K", IntegerValue (2));
492  x5->SetAttribute ("Lambda", DoubleValue (2.0));
493 
494  plot.AddDataset ( Histogramm (x5, probes, precision,
495  "ErlangRandomVariable k=2 {/Symbol l}=2.0") );
496 
497  plot.AddDataset ( Gnuplot2dFunction ("Erlang(x, 2, 2.0)",
498  "ErlangDist(x, 2, 2.0)") );
499 
500  Ptr<ErlangRandomVariable> x6 = CreateObject<ErlangRandomVariable> ();
501  x6->SetAttribute ("K", IntegerValue (2));
502  x6->SetAttribute ("Lambda", DoubleValue (3.0));
503 
504  plot.AddDataset ( Histogramm (x6, probes, precision,
505  "ErlangRandomVariable k=2 {/Symbol l}=3.0") );
506 
507  plot.AddDataset ( Gnuplot2dFunction ("Erlang(x, 2, 3.0)",
508  "ErlangDist(x, 2, 3.0)") );
509 
510  Ptr<ErlangRandomVariable> x7 = CreateObject<ErlangRandomVariable> ();
511  x7->SetAttribute ("K", IntegerValue (2));
512  x7->SetAttribute ("Lambda", DoubleValue (5.0));
513 
514  plot.AddDataset ( Histogramm (x7, probes, precision,
515  "ErlangRandomVariable k=2 {/Symbol l}=5.0") );
516 
517  plot.AddDataset ( Gnuplot2dFunction ("Erlang(x, 2, 5.0)",
518  "ErlangDist(x, 2, 5.0)") );
519 
520  gnuplots.AddPlot (plot);
521  }
522 
523  gnuplots.GenerateOutput (std::cout);
524 
525  return 0;
526 }
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:45
void AddDataset(const GnuplotDataset &dataset)
Definition: gnuplot.cc:756
int main(int argc, char *argv[])
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: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 CDF(double v, double c)
Specifies a point in the empirical distribution.
void Add(double x, double y)
Definition: gnuplot.cc:359
void AddPlot(const Gnuplot &plot)
Definition: gnuplot.cc:868
void GenerateOutput(std::ostream &os)
Definition: gnuplot.cc:883
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
void SetTerminal(const std::string &terminal)
Definition: gnuplot.cc:862
static GnuplotDataset Histogramm(Ptr< RandomVariableStream > rndvar, unsigned int probes, double precision, const std::string &title, bool notcontinous=false)
Class to represent a 2D function expression plot.
Definition: gnuplot.h:239
double dround(double number, double precision)
Round a double number to the given precision.
Hold a floating point type.
Definition: double.h:41
void SetAttribute(std::string name, const AttributeValue &value)
Definition: object-base.cc:161