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