src/core/model/random-variable.cc
author Maja Grubišić <maja.grubisic@live.com>
Sat, 10 Nov 2012 19:16:38 +0100
changeset 9134 7a750f032acd
parent 9063 32755d0516f4
child 9193 9e679a504fc6
permissions -rw-r--r--
Clean up function logging of core module.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     2
//
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     3
// Copyright (c) 2006 Georgia Tech Research Corporation
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     4
//
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     5
// This program is free software; you can redistribute it and/or modify
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     6
// it under the terms of the GNU General Public License version 2 as
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     7
// published by the Free Software Foundation;
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     8
//
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     9
// This program is distributed in the hope that it will be useful,
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    12
// GNU General Public License for more details.
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    13
//
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    14
// You should have received a copy of the GNU General Public License
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    15
// along with this program; if not, write to the Free Software
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    16
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    17
//
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    18
// Author: Rajib Bhattacharjea<raj.b@gatech.edu>
4218
debf1a8a96d3 Proposed RNG API changes
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3679
diff changeset
    19
// Author: Hadi Arbabi<marbabi@cs.odu.edu>
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    20
//
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    21
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    22
#include <iostream>
9063
32755d0516f4 Bug 1237 - code cleanups related to includes
Vedran Miletić <rivanvx@gmail.com>
parents: 8871
diff changeset
    23
#include <cmath>
32755d0516f4 Bug 1237 - code cleanups related to includes
Vedran Miletić <rivanvx@gmail.com>
parents: 8871
diff changeset
    24
#include <cstdlib>
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
    25
#include <sys/time.h>                   // for gettimeofday
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    26
#include <unistd.h>
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    27
#include <iostream>
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    28
#include <sys/types.h>
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    29
#include <sys/stat.h>
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
    30
#include <fcntl.h>
2384
500ada6a4874 add Value support to RandomVariable.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2336
diff changeset
    31
#include <sstream>
5299
67ea1b4dd3fe Remove and replace basic random number unit tests (bug 675)
Craig Dowell <craigdo@ee.washington.edu>
parents: 4736
diff changeset
    32
#include <vector>
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    33
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
    34
#include "assert.h"
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    35
#include "random-variable.h"
8871
60846d2741c0 initial patch to fix rng variability
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7003
diff changeset
    36
#include "rng-seed-manager.h"
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    37
#include "rng-stream.h"
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    38
#include "fatal-error.h"
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
    39
#include "log.h"
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    40
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
    41
namespace ns3 {
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    42
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
    43
// -----------------------------------------------------------------------------
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
    44
// -----------------------------------------------------------------------------
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
    45
// RandomVariableBase methods
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
    46
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
    47
NS_LOG_COMPONENT_DEFINE ("RandomVariable");
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
    48
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
    49
class RandomVariableBase
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
    50
{
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
    51
public:
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
    52
  RandomVariableBase ();
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
    53
  RandomVariableBase (const RandomVariableBase &o);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
    54
  virtual ~RandomVariableBase ();
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
    55
  virtual double  GetValue () = 0;
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
    56
  virtual uint32_t GetInteger ();
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
    57
  virtual RandomVariableBase*   Copy (void) const = 0;
8871
60846d2741c0 initial patch to fix rng variability
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7003
diff changeset
    58
  RngStream *GetStream(void);
60846d2741c0 initial patch to fix rng variability
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7003
diff changeset
    59
private:
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
    60
  RngStream* m_generator;  // underlying generator being wrapped
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
    61
};
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
    62
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
    63
RandomVariableBase::RandomVariableBase ()
8871
60846d2741c0 initial patch to fix rng variability
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7003
diff changeset
    64
  : m_generator (0)
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    65
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
    66
  NS_LOG_FUNCTION (this);
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    67
}
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    68
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
    69
RandomVariableBase::RandomVariableBase (const RandomVariableBase& r)
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
    70
  : m_generator (0)
360
7bffd987426c Fixed major memory bug and docs in RandomVariable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 346
diff changeset
    71
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
    72
  NS_LOG_FUNCTION (this << &r);
8871
60846d2741c0 initial patch to fix rng variability
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7003
diff changeset
    73
  if (r.m_generator != 0)
4224
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4223
diff changeset
    74
    {
8871
60846d2741c0 initial patch to fix rng variability
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7003
diff changeset
    75
      m_generator = new RngStream (RngSeedManager::GetSeed (),
60846d2741c0 initial patch to fix rng variability
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7003
diff changeset
    76
                                   RngSeedManager::GetNextStreamIndex (),
60846d2741c0 initial patch to fix rng variability
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7003
diff changeset
    77
                                   RngSeedManager::GetRun ());
4224
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4223
diff changeset
    78
    }
360
7bffd987426c Fixed major memory bug and docs in RandomVariable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 346
diff changeset
    79
}
7bffd987426c Fixed major memory bug and docs in RandomVariable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 346
diff changeset
    80
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
    81
RandomVariableBase::~RandomVariableBase ()
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    82
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
    83
  NS_LOG_FUNCTION (this);
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    84
  delete m_generator;
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    85
}
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    86
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
    87
uint32_t RandomVariableBase::GetInteger ()
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    88
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
    89
  NS_LOG_FUNCTION (this);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
    90
  return (uint32_t)GetValue ();
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    91
}
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    92
8871
60846d2741c0 initial patch to fix rng variability
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7003
diff changeset
    93
RngStream *
60846d2741c0 initial patch to fix rng variability
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7003
diff changeset
    94
RandomVariableBase::GetStream (void)
60846d2741c0 initial patch to fix rng variability
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7003
diff changeset
    95
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
    96
  NS_LOG_FUNCTION (this);
8871
60846d2741c0 initial patch to fix rng variability
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7003
diff changeset
    97
  if (m_generator == 0)
60846d2741c0 initial patch to fix rng variability
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7003
diff changeset
    98
    {
60846d2741c0 initial patch to fix rng variability
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7003
diff changeset
    99
      m_generator = new RngStream (RngSeedManager::GetSeed (),
60846d2741c0 initial patch to fix rng variability
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7003
diff changeset
   100
                                   RngSeedManager::GetNextStreamIndex (),
60846d2741c0 initial patch to fix rng variability
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7003
diff changeset
   101
                                   RngSeedManager::GetRun ());
60846d2741c0 initial patch to fix rng variability
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7003
diff changeset
   102
    }
60846d2741c0 initial patch to fix rng variability
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7003
diff changeset
   103
  return m_generator;
60846d2741c0 initial patch to fix rng variability
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7003
diff changeset
   104
}
60846d2741c0 initial patch to fix rng variability
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7003
diff changeset
   105
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   106
// -------------------------------------------------------
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   107
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   108
RandomVariable::RandomVariable ()
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   109
  : m_variable (0)
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   110
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   111
  NS_LOG_FUNCTION (this);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   112
}
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   113
RandomVariable::RandomVariable (const RandomVariable&o)
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   114
  : m_variable (o.m_variable->Copy ())
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   115
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   116
  NS_LOG_FUNCTION (this << o);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   117
}
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   118
RandomVariable::RandomVariable (const RandomVariableBase &variable)
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   119
  : m_variable (variable.Copy ())
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   120
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   121
  NS_LOG_FUNCTION (&variable);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   122
}
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   123
RandomVariable &
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   124
RandomVariable::operator = (const RandomVariable &o)
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   125
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   126
  NS_LOG_FUNCTION (this << o);
2384
500ada6a4874 add Value support to RandomVariable.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2336
diff changeset
   127
  if (&o == this)
500ada6a4874 add Value support to RandomVariable.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2336
diff changeset
   128
    {
500ada6a4874 add Value support to RandomVariable.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2336
diff changeset
   129
      return *this;
500ada6a4874 add Value support to RandomVariable.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2336
diff changeset
   130
    }
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   131
  delete m_variable;
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   132
  m_variable = o.m_variable->Copy ();
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   133
  return *this;
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   134
}
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   135
RandomVariable::~RandomVariable ()
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   136
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   137
  NS_LOG_FUNCTION (this);
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   138
  delete m_variable;
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   139
}
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   140
double
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   141
RandomVariable::GetValue (void) const
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   142
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   143
  NS_LOG_FUNCTION (this);
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   144
  return m_variable->GetValue ();
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   145
}
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   146
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   147
uint32_t
2439
4a0b22a3f5fa UintValue -> Uinteger, IntValue -> Integer
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2436
diff changeset
   148
RandomVariable::GetInteger (void) const
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   149
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   150
  NS_LOG_FUNCTION (this);
2439
4a0b22a3f5fa UintValue -> Uinteger, IntValue -> Integer
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2436
diff changeset
   151
  return m_variable->GetInteger ();
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   152
}
4218
debf1a8a96d3 Proposed RNG API changes
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3679
diff changeset
   153
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   154
RandomVariableBase *
2384
500ada6a4874 add Value support to RandomVariable.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2336
diff changeset
   155
RandomVariable::Peek (void) const
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   156
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   157
  NS_LOG_FUNCTION (this);
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   158
  return m_variable;
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   159
}
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   160
4218
debf1a8a96d3 Proposed RNG API changes
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3679
diff changeset
   161
2445
e1b65471f159 convert RandomVariable to new helpers.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2439
diff changeset
   162
ATTRIBUTE_VALUE_IMPLEMENT (RandomVariable);
e1b65471f159 convert RandomVariable to new helpers.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2439
diff changeset
   163
ATTRIBUTE_CHECKER_IMPLEMENT (RandomVariable);
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   164
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   165
// -----------------------------------------------------------------------------
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   166
// -----------------------------------------------------------------------------
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   167
// UniformVariableImpl
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   168
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   169
class UniformVariableImpl : public RandomVariableBase
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   170
{
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   171
public:
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   172
  /**
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   173
   * Creates a uniform random number generator in the
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   174
   * range [0.0 .. 1.0).
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   175
   */
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   176
  UniformVariableImpl ();
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   177
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   178
  /**
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   179
   * Creates a uniform random number generator with the specified range
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   180
   * \param s Low end of the range
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   181
   * \param l High end of the range
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   182
   */
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   183
  UniformVariableImpl (double s, double l);
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   184
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   185
  UniformVariableImpl (const UniformVariableImpl& c);
2384
500ada6a4874 add Value support to RandomVariable.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2336
diff changeset
   186
500ada6a4874 add Value support to RandomVariable.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2336
diff changeset
   187
  double GetMin (void) const;
500ada6a4874 add Value support to RandomVariable.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2336
diff changeset
   188
  double GetMax (void) const;
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   189
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   190
  /**
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   191
   * \return A value between low and high values specified by the constructor
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   192
   */
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   193
  virtual double GetValue ();
4218
debf1a8a96d3 Proposed RNG API changes
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3679
diff changeset
   194
debf1a8a96d3 Proposed RNG API changes
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3679
diff changeset
   195
  /**
debf1a8a96d3 Proposed RNG API changes
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3679
diff changeset
   196
   * \return A value between low and high values specified by parameters
debf1a8a96d3 Proposed RNG API changes
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3679
diff changeset
   197
   */
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   198
  virtual double GetValue (double s, double l);
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   199
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   200
  virtual RandomVariableBase*  Copy (void) const;
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   201
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   202
private:
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   203
  double m_min;
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   204
  double m_max;
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   205
};
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   206
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   207
UniformVariableImpl::UniformVariableImpl ()
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   208
  : m_min (0),
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   209
    m_max (1.0)
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   210
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   211
  NS_LOG_FUNCTION (this);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   212
}
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   213
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   214
UniformVariableImpl::UniformVariableImpl (double s, double l)
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   215
  : m_min (s),
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   216
    m_max (l)
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   217
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   218
  NS_LOG_FUNCTION (this << s << l);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   219
}
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   220
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   221
UniformVariableImpl::UniformVariableImpl (const UniformVariableImpl& c)
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   222
  : RandomVariableBase (c),
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   223
    m_min (c.m_min),
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   224
    m_max (c.m_max)
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   225
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   226
  NS_LOG_FUNCTION (this << &c);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   227
}
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   228
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   229
double
2384
500ada6a4874 add Value support to RandomVariable.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2336
diff changeset
   230
UniformVariableImpl::GetMin (void) const
500ada6a4874 add Value support to RandomVariable.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2336
diff changeset
   231
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   232
  NS_LOG_FUNCTION (this);
2384
500ada6a4874 add Value support to RandomVariable.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2336
diff changeset
   233
  return m_min;
500ada6a4874 add Value support to RandomVariable.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2336
diff changeset
   234
}
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   235
double
2384
500ada6a4874 add Value support to RandomVariable.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2336
diff changeset
   236
UniformVariableImpl::GetMax (void) const
500ada6a4874 add Value support to RandomVariable.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2336
diff changeset
   237
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   238
  NS_LOG_FUNCTION (this);
2384
500ada6a4874 add Value support to RandomVariable.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2336
diff changeset
   239
  return m_max;
500ada6a4874 add Value support to RandomVariable.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2336
diff changeset
   240
}
500ada6a4874 add Value support to RandomVariable.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2336
diff changeset
   241
500ada6a4874 add Value support to RandomVariable.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2336
diff changeset
   242
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   243
double UniformVariableImpl::GetValue ()
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   244
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   245
  NS_LOG_FUNCTION (this);
8871
60846d2741c0 initial patch to fix rng variability
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7003
diff changeset
   246
  RngStream *generator = GetStream ();
60846d2741c0 initial patch to fix rng variability
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7003
diff changeset
   247
  return m_min + generator->RandU01 () * (m_max - m_min);
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   248
}
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   249
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   250
double UniformVariableImpl::GetValue (double s, double l)
4218
debf1a8a96d3 Proposed RNG API changes
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3679
diff changeset
   251
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   252
  NS_LOG_FUNCTION (this << s << l);
8871
60846d2741c0 initial patch to fix rng variability
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7003
diff changeset
   253
  RngStream *generator = GetStream ();
60846d2741c0 initial patch to fix rng variability
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7003
diff changeset
   254
  return s + generator->RandU01 () * (l - s);
4218
debf1a8a96d3 Proposed RNG API changes
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3679
diff changeset
   255
}
debf1a8a96d3 Proposed RNG API changes
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3679
diff changeset
   256
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   257
RandomVariableBase* UniformVariableImpl::Copy () const
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   258
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   259
  NS_LOG_FUNCTION (this);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   260
  return new UniformVariableImpl (*this);
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   261
}
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   262
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   263
UniformVariable::UniformVariable ()
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   264
  : RandomVariable (UniformVariableImpl ())
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   265
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   266
  NS_LOG_FUNCTION (this);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   267
}
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   268
UniformVariable::UniformVariable (double s, double l)
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   269
  : RandomVariable (UniformVariableImpl (s, l))
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   270
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   271
  NS_LOG_FUNCTION (this << s << l);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   272
}
4218
debf1a8a96d3 Proposed RNG API changes
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3679
diff changeset
   273
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   274
double UniformVariable::GetValue (void) const
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   275
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   276
  NS_LOG_FUNCTION (this);
4242
3d4788bd1ddd improve coherency between UniformVariable and RandomVariable, explain why the extra overload is necessary.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4240
diff changeset
   277
  return this->RandomVariable::GetValue ();
4218
debf1a8a96d3 Proposed RNG API changes
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3679
diff changeset
   278
}
debf1a8a96d3 Proposed RNG API changes
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3679
diff changeset
   279
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   280
double UniformVariable::GetValue (double s, double l)
4218
debf1a8a96d3 Proposed RNG API changes
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3679
diff changeset
   281
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   282
  NS_LOG_FUNCTION (this << s << l);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   283
  return ((UniformVariableImpl*)Peek ())->GetValue (s,l);
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   284
}
442
96d3e7dc8bb2 Added static RNGs, like ExponentialVariable::GetSingleValue(mean)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 438
diff changeset
   285
4256
cc06d903ca09 Adding UniformVariable::GetInteger and using it to fix bug in RealRandomStream::GetNext.
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4249
diff changeset
   286
uint32_t UniformVariable::GetInteger (uint32_t s, uint32_t l)
cc06d903ca09 Adding UniformVariable::GetInteger and using it to fix bug in RealRandomStream::GetNext.
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4249
diff changeset
   287
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   288
  NS_LOG_FUNCTION (this << s << l);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   289
  NS_ASSERT (s <= l);
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   290
  return static_cast<uint32_t> ( GetValue (s, l + 1) );
4256
cc06d903ca09 Adding UniformVariable::GetInteger and using it to fix bug in RealRandomStream::GetNext.
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4249
diff changeset
   291
}
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   292
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   293
// -----------------------------------------------------------------------------
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   294
// -----------------------------------------------------------------------------
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   295
// ConstantVariableImpl methods
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   296
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   297
class ConstantVariableImpl : public RandomVariableBase
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   298
{
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   299
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   300
public:
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   301
  /**
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   302
   * Construct a ConstantVariableImpl RNG that returns zero every sample
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   303
   */
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   304
  ConstantVariableImpl ();
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   305
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   306
  /**
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   307
   * Construct a ConstantVariableImpl RNG that returns the specified value
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   308
   * every sample.
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   309
   * \param c Unchanging value for this RNG.
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   310
   */
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   311
  ConstantVariableImpl (double c);
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   312
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   313
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   314
  ConstantVariableImpl (const ConstantVariableImpl& c);
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   315
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   316
  /**
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   317
   * \brief Specify a new constant RNG for this generator.
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   318
   * \param c New constant value for this RNG.
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   319
   */
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   320
  void    NewConstant (double c);
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   321
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   322
  /**
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   323
   * \return The constant value specified
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   324
   */
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   325
  virtual double  GetValue ();
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   326
  virtual uint32_t GetInteger ();
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   327
  virtual RandomVariableBase*   Copy (void) const;
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   328
private:
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   329
  double m_const;
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   330
};
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   331
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   332
ConstantVariableImpl::ConstantVariableImpl ()
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   333
  : m_const (0)
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   334
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   335
  NS_LOG_FUNCTION (this);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   336
}
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   337
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   338
ConstantVariableImpl::ConstantVariableImpl (double c)
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   339
  : m_const (c)
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   340
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   341
  NS_LOG_FUNCTION (this << c);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   342
}
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   343
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   344
ConstantVariableImpl::ConstantVariableImpl (const ConstantVariableImpl& c)
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   345
  : RandomVariableBase (c),
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   346
    m_const (c.m_const)
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   347
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   348
  NS_LOG_FUNCTION (this << &c);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   349
}
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   350
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   351
void ConstantVariableImpl::NewConstant (double c)
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   352
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   353
  NS_LOG_FUNCTION (this << c);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   354
  m_const = c;
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   355
}
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   356
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   357
double ConstantVariableImpl::GetValue ()
442
96d3e7dc8bb2 Added static RNGs, like ExponentialVariable::GetSingleValue(mean)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 438
diff changeset
   358
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   359
  NS_LOG_FUNCTION (this);
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   360
  return m_const;
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   361
}
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   362
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   363
uint32_t ConstantVariableImpl::GetInteger ()
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   364
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   365
  NS_LOG_FUNCTION (this);
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   366
  return (uint32_t)m_const;
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   367
}
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   368
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   369
RandomVariableBase* ConstantVariableImpl::Copy () const
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   370
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   371
  NS_LOG_FUNCTION (this);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   372
  return new ConstantVariableImpl (*this);
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   373
}
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   374
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   375
ConstantVariable::ConstantVariable ()
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   376
  : RandomVariable (ConstantVariableImpl ())
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   377
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   378
  NS_LOG_FUNCTION (this);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   379
}
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   380
ConstantVariable::ConstantVariable (double c)
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   381
  : RandomVariable (ConstantVariableImpl (c))
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   382
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   383
  NS_LOG_FUNCTION (this << c);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   384
}
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   385
void
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   386
ConstantVariable::SetConstant (double c)
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   387
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   388
  NS_LOG_FUNCTION (this << c);
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   389
  *this = ConstantVariable (c);
442
96d3e7dc8bb2 Added static RNGs, like ExponentialVariable::GetSingleValue(mean)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 438
diff changeset
   390
}
96d3e7dc8bb2 Added static RNGs, like ExponentialVariable::GetSingleValue(mean)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 438
diff changeset
   391
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   392
// -----------------------------------------------------------------------------
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   393
// -----------------------------------------------------------------------------
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   394
// SequentialVariableImpl methods
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   395
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   396
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   397
class SequentialVariableImpl : public RandomVariableBase
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   398
{
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   399
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   400
public:
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   401
  /**
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   402
   * \brief Constructor for the SequentialVariableImpl RNG.
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   403
   *
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   404
   * The four parameters define the sequence.  For example
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   405
   * SequentialVariableImpl(0,5,1,2) creates a RNG that has the sequence
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   406
   * 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 0, 0 ...
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   407
   * \param f First value of the sequence.
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   408
   * \param l One more than the last value of the sequence.
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   409
   * \param i Increment between sequence values
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   410
   * \param c Number of times each member of the sequence is repeated
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   411
   */
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   412
  SequentialVariableImpl (double f, double l, double i = 1, uint32_t c = 1);
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   413
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   414
  /**
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   415
   * \brief Constructor for the SequentialVariableImpl RNG.
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   416
   *
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   417
   * Differs from the first only in that the increment parameter is a
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   418
   * random variable
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   419
   * \param f First value of the sequence.
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   420
   * \param l One more than the last value of the sequence.
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   421
   * \param i Reference to a RandomVariableBase for the sequence increment
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   422
   * \param c Number of times each member of the sequence is repeated
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   423
   */
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   424
  SequentialVariableImpl (double f, double l, const RandomVariable& i, uint32_t c = 1);
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   425
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   426
  SequentialVariableImpl (const SequentialVariableImpl& c);
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   427
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   428
  ~SequentialVariableImpl ();
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   429
  /**
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   430
   * \return The next value in the Sequence
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   431
   */
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   432
  virtual double GetValue ();
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   433
  virtual RandomVariableBase*  Copy (void) const;
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   434
private:
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   435
  double m_min;
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   436
  double m_max;
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   437
  RandomVariable  m_increment;
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   438
  uint32_t  m_consecutive;
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   439
  double m_current;
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   440
  uint32_t  m_currentConsecutive;
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   441
};
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   442
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   443
SequentialVariableImpl::SequentialVariableImpl (double f, double l, double i, uint32_t c)
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   444
  : m_min (f),
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   445
    m_max (l),
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   446
    m_increment (ConstantVariable (i)),
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   447
    m_consecutive (c),
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   448
    m_current (f),
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   449
    m_currentConsecutive (0)
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   450
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   451
  NS_LOG_FUNCTION (this << f << l << i << c);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   452
}
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   453
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   454
SequentialVariableImpl::SequentialVariableImpl (double f, double l, const RandomVariable& i, uint32_t c)
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   455
  : m_min (f),
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   456
    m_max (l),
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   457
    m_increment (i),
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   458
    m_consecutive (c),
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   459
    m_current (f),
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   460
    m_currentConsecutive (0)
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   461
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   462
  NS_LOG_FUNCTION (this << f << l << i << c);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   463
}
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   464
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   465
SequentialVariableImpl::SequentialVariableImpl (const SequentialVariableImpl& c)
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   466
  : RandomVariableBase (c),
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   467
    m_min (c.m_min),
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   468
    m_max (c.m_max),
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   469
    m_increment (c.m_increment),
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   470
    m_consecutive (c.m_consecutive),
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   471
    m_current (c.m_current),
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   472
    m_currentConsecutive (c.m_currentConsecutive)
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   473
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   474
  NS_LOG_FUNCTION (this << &c);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   475
}
360
7bffd987426c Fixed major memory bug and docs in RandomVariable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 346
diff changeset
   476
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   477
SequentialVariableImpl::~SequentialVariableImpl ()
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   478
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   479
  NS_LOG_FUNCTION (this);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   480
}
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   481
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   482
double SequentialVariableImpl::GetValue ()
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   483
{ // Return a sequential series of values
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   484
  NS_LOG_FUNCTION (this);
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   485
  double r = m_current;
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   486
  if (++m_currentConsecutive == m_consecutive)
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   487
    { // Time to advance to next
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   488
      m_currentConsecutive = 0;
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   489
      m_current += m_increment.GetValue ();
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   490
      if (m_current >= m_max)
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   491
        {
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   492
          m_current = m_min + (m_current - m_max);
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   493
        }
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   494
    }
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   495
  return r;
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   496
}
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   497
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   498
RandomVariableBase* SequentialVariableImpl::Copy () const
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   499
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   500
  NS_LOG_FUNCTION (this);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   501
  return new SequentialVariableImpl (*this);
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   502
}
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   503
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   504
SequentialVariable::SequentialVariable (double f, double l, double i, uint32_t c)
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   505
  : RandomVariable (SequentialVariableImpl (f, l, i, c))
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   506
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   507
  NS_LOG_FUNCTION (this << f << l << i << c);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   508
}
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   509
SequentialVariable::SequentialVariable (double f, double l, const RandomVariable& i, uint32_t c)
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   510
  : RandomVariable (SequentialVariableImpl (f, l, i, c))
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   511
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   512
  NS_LOG_FUNCTION (this << f << l << i << c);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   513
}
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   514
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   515
// -----------------------------------------------------------------------------
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   516
// -----------------------------------------------------------------------------
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   517
// ExponentialVariableImpl methods
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   518
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   519
class ExponentialVariableImpl : public RandomVariableBase
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   520
{
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   521
public:
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   522
  /**
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   523
   * Constructs an exponential random variable  with a mean
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   524
   * value of 1.0.
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   525
   */
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   526
  ExponentialVariableImpl ();
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   527
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   528
  /**
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   529
   * \brief Constructs an exponential random variable with a specified mean
6094
0ac9a2fffbfb - added Scale and Shape Pareto rng constuctor
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5969
diff changeset
   530
   *
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   531
   * \param m Mean value for the random variable
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   532
   */
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   533
  explicit ExponentialVariableImpl (double m);
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   534
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   535
  /**
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   536
   * \brief Constructs an exponential random variable with specified
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   537
   * mean and upper limit.
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   538
   *
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   539
   * Since exponential distributions can theoretically return unbounded values,
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   540
   * it is sometimes useful to specify a fixed upper limit.  Note however when
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   541
   * the upper limit is specified, the true mean of the distribution is
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   542
   * slightly smaller than the mean value specified: \f$ m - b/(e^{b/m}-1) \f$.
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   543
   * \param m Mean value of the random variable
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   544
   * \param b Upper bound on returned values
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   545
   */
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   546
  ExponentialVariableImpl (double m, double b);
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   547
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   548
  ExponentialVariableImpl (const ExponentialVariableImpl& c);
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   549
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   550
  /**
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   551
   * \return A random value from this exponential distribution
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   552
   */
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   553
  virtual double GetValue ();
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   554
  virtual RandomVariableBase* Copy (void) const;
4218
debf1a8a96d3 Proposed RNG API changes
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3679
diff changeset
   555
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   556
private:
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   557
  double m_mean;  // Mean value of RV
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   558
  double m_bound; // Upper bound on value (if non-zero)
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   559
};
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   560
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   561
ExponentialVariableImpl::ExponentialVariableImpl ()
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   562
  : m_mean (1.0),
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   563
    m_bound (0)
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   564
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   565
  NS_LOG_FUNCTION (this);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   566
}
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   567
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   568
ExponentialVariableImpl::ExponentialVariableImpl (double m)
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   569
  : m_mean (m),
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   570
    m_bound (0)
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   571
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   572
  NS_LOG_FUNCTION (this << m);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   573
}
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   574
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   575
ExponentialVariableImpl::ExponentialVariableImpl (double m, double b)
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   576
  : m_mean (m),
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   577
    m_bound (b)
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   578
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   579
  NS_LOG_FUNCTION (this << m << b);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   580
}
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   581
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   582
ExponentialVariableImpl::ExponentialVariableImpl (const ExponentialVariableImpl& c)
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   583
  : RandomVariableBase (c),
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   584
    m_mean (c.m_mean),
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   585
    m_bound (c.m_bound)
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   586
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   587
  NS_LOG_FUNCTION (this << &c);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   588
}
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   589
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   590
double ExponentialVariableImpl::GetValue ()
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   591
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   592
  NS_LOG_FUNCTION (this);
8871
60846d2741c0 initial patch to fix rng variability
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7003
diff changeset
   593
  RngStream *generator = GetStream ();
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   594
  while (1)
4224
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4223
diff changeset
   595
    {
9063
32755d0516f4 Bug 1237 - code cleanups related to includes
Vedran Miletić <rivanvx@gmail.com>
parents: 8871
diff changeset
   596
      double r = -m_mean*std::log (generator->RandU01 ());
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   597
      if (m_bound == 0 || r <= m_bound)
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   598
        {
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   599
          return r;
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   600
        }
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   601
      // otherwise, try again
4224
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4223
diff changeset
   602
    }
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   603
}
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   604
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   605
RandomVariableBase* ExponentialVariableImpl::Copy () const
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   606
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   607
  NS_LOG_FUNCTION (this);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   608
  return new ExponentialVariableImpl (*this);
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   609
}
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   610
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   611
ExponentialVariable::ExponentialVariable ()
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   612
  : RandomVariable (ExponentialVariableImpl ())
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   613
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   614
  NS_LOG_FUNCTION (this);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   615
}
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   616
ExponentialVariable::ExponentialVariable (double m)
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   617
  : RandomVariable (ExponentialVariableImpl (m))
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   618
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   619
  NS_LOG_FUNCTION (this << m);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   620
}
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   621
ExponentialVariable::ExponentialVariable (double m, double b)
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   622
  : RandomVariable (ExponentialVariableImpl (m, b))
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   623
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   624
  NS_LOG_FUNCTION (this << m << b);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   625
}
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   626
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   627
// -----------------------------------------------------------------------------
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   628
// -----------------------------------------------------------------------------
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   629
// ParetoVariableImpl methods
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   630
class ParetoVariableImpl : public RandomVariableBase
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   631
{
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   632
public:
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   633
  /**
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   634
   * Constructs a pareto random variable with a mean of 1 and a shape
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   635
   * parameter of 1.5
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   636
   */
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   637
  ParetoVariableImpl ();
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   638
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   639
  /**
6094
0ac9a2fffbfb - added Scale and Shape Pareto rng constuctor
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5969
diff changeset
   640
   * \brief Constructs a pareto random variable with specified mean and shape
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   641
   * parameter of 1.5
6094
0ac9a2fffbfb - added Scale and Shape Pareto rng constuctor
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5969
diff changeset
   642
   *
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   643
   * \param m Mean value of the distribution
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   644
   */
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   645
  explicit ParetoVariableImpl (double m);
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   646
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   647
  /**
6094
0ac9a2fffbfb - added Scale and Shape Pareto rng constuctor
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5969
diff changeset
   648
   * \brief Constructs a pareto random variable with the specified mean
0ac9a2fffbfb - added Scale and Shape Pareto rng constuctor
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5969
diff changeset
   649
   * value and shape parameter. Beware, s must be strictly greater than 1.
0ac9a2fffbfb - added Scale and Shape Pareto rng constuctor
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5969
diff changeset
   650
   *
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   651
   * \param m Mean value of the distribution
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   652
   * \param s Shape parameter for the distribution
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   653
   */
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   654
  ParetoVariableImpl (double m, double s);
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   655
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   656
  /**
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   657
   * \brief Constructs a pareto random variable with the specified mean
6094
0ac9a2fffbfb - added Scale and Shape Pareto rng constuctor
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5969
diff changeset
   658
   * value, shape (alpha), and upper bound. Beware, s must be strictly greater than 1.
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   659
   *
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   660
   * Since pareto distributions can theoretically return unbounded values,
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   661
   * it is sometimes useful to specify a fixed upper limit.  Note however
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   662
   * when the upper limit is specified, the true mean of the distribution
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   663
   * is slightly smaller than the mean value specified.
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   664
   * \param m Mean value
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   665
   * \param s Shape parameter
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   666
   * \param b Upper limit on returned values
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   667
   */
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   668
  ParetoVariableImpl (double m, double s, double b);
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   669
6094
0ac9a2fffbfb - added Scale and Shape Pareto rng constuctor
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5969
diff changeset
   670
  /**
0ac9a2fffbfb - added Scale and Shape Pareto rng constuctor
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5969
diff changeset
   671
   * \brief Constructs a pareto random variable with the specified scale and shape
0ac9a2fffbfb - added Scale and Shape Pareto rng constuctor
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5969
diff changeset
   672
   * parameters.
0ac9a2fffbfb - added Scale and Shape Pareto rng constuctor
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5969
diff changeset
   673
   *
0ac9a2fffbfb - added Scale and Shape Pareto rng constuctor
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5969
diff changeset
   674
   * \param params the two parameters, respectively scale and shape, of the distribution
0ac9a2fffbfb - added Scale and Shape Pareto rng constuctor
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5969
diff changeset
   675
   */
0ac9a2fffbfb - added Scale and Shape Pareto rng constuctor
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5969
diff changeset
   676
  ParetoVariableImpl (std::pair<double, double> params);
0ac9a2fffbfb - added Scale and Shape Pareto rng constuctor
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5969
diff changeset
   677
0ac9a2fffbfb - added Scale and Shape Pareto rng constuctor
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5969
diff changeset
   678
  /**
0ac9a2fffbfb - added Scale and Shape Pareto rng constuctor
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5969
diff changeset
   679
   * \brief Constructs a pareto random variable with the specified
0ac9a2fffbfb - added Scale and Shape Pareto rng constuctor
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5969
diff changeset
   680
   * scale, shape (alpha), and upper bound.
0ac9a2fffbfb - added Scale and Shape Pareto rng constuctor
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5969
diff changeset
   681
   *
0ac9a2fffbfb - added Scale and Shape Pareto rng constuctor
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5969
diff changeset
   682
   * Since pareto distributions can theoretically return unbounded values,
0ac9a2fffbfb - added Scale and Shape Pareto rng constuctor
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5969
diff changeset
   683
   * it is sometimes useful to specify a fixed upper limit.  Note however
0ac9a2fffbfb - added Scale and Shape Pareto rng constuctor
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5969
diff changeset
   684
   * when the upper limit is specified, the true mean of the distribution
0ac9a2fffbfb - added Scale and Shape Pareto rng constuctor
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5969
diff changeset
   685
   * is slightly smaller than the mean value specified.
0ac9a2fffbfb - added Scale and Shape Pareto rng constuctor
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5969
diff changeset
   686
   *
0ac9a2fffbfb - added Scale and Shape Pareto rng constuctor
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5969
diff changeset
   687
   * \param params the two parameters, respectively scale and shape, of the distribution
0ac9a2fffbfb - added Scale and Shape Pareto rng constuctor
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5969
diff changeset
   688
   * \param b Upper limit on returned values
0ac9a2fffbfb - added Scale and Shape Pareto rng constuctor
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5969
diff changeset
   689
   */
0ac9a2fffbfb - added Scale and Shape Pareto rng constuctor
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5969
diff changeset
   690
  ParetoVariableImpl (std::pair<double, double> params, double b);
0ac9a2fffbfb - added Scale and Shape Pareto rng constuctor
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5969
diff changeset
   691
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   692
  ParetoVariableImpl (const ParetoVariableImpl& c);
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   693
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   694
  /**
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   695
   * \return A random value from this Pareto distribution
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   696
   */
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   697
  virtual double GetValue ();
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   698
  virtual RandomVariableBase* Copy () const;
4218
debf1a8a96d3 Proposed RNG API changes
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3679
diff changeset
   699
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   700
private:
6094
0ac9a2fffbfb - added Scale and Shape Pareto rng constuctor
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5969
diff changeset
   701
  double m_scale; // Scale value of RV
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   702
  double m_shape; // Shape parameter
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   703
  double m_bound; // Upper bound on value (if non-zero)
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   704
};
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   705
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   706
ParetoVariableImpl::ParetoVariableImpl ()
6094
0ac9a2fffbfb - added Scale and Shape Pareto rng constuctor
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5969
diff changeset
   707
  : m_scale (0.5 / 1.5),
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   708
    m_shape (1.5),
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   709
    m_bound (0)
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   710
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   711
  NS_LOG_FUNCTION (this);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   712
}
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   713
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   714
ParetoVariableImpl::ParetoVariableImpl (double m)
6094
0ac9a2fffbfb - added Scale and Shape Pareto rng constuctor
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5969
diff changeset
   715
  : m_scale (m * 0.5 / 1.5),
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   716
    m_shape (1.5),
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   717
    m_bound (0)
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   718
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   719
  NS_LOG_FUNCTION (this << m);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   720
}
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   721
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   722
ParetoVariableImpl::ParetoVariableImpl (double m, double s)
6094
0ac9a2fffbfb - added Scale and Shape Pareto rng constuctor
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5969
diff changeset
   723
  : m_scale (m * (s - 1.0) / s),
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   724
    m_shape (s),
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   725
    m_bound (0)
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   726
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   727
  NS_LOG_FUNCTION (this << m << s);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   728
}
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   729
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   730
ParetoVariableImpl::ParetoVariableImpl (double m, double s, double b)
6094
0ac9a2fffbfb - added Scale and Shape Pareto rng constuctor
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5969
diff changeset
   731
  : m_scale (m * (s - 1.0) / s),
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   732
    m_shape (s),
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   733
    m_bound (b)
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   734
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   735
  NS_LOG_FUNCTION (this << m << s << b);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   736
}
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   737
6094
0ac9a2fffbfb - added Scale and Shape Pareto rng constuctor
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5969
diff changeset
   738
ParetoVariableImpl::ParetoVariableImpl (std::pair<double, double> params)
0ac9a2fffbfb - added Scale and Shape Pareto rng constuctor
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5969
diff changeset
   739
  : m_scale (params.first),
0ac9a2fffbfb - added Scale and Shape Pareto rng constuctor
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5969
diff changeset
   740
    m_shape (params.second),
0ac9a2fffbfb - added Scale and Shape Pareto rng constuctor
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5969
diff changeset
   741
    m_bound (0)
0ac9a2fffbfb - added Scale and Shape Pareto rng constuctor
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5969
diff changeset
   742
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   743
  NS_LOG_FUNCTION (this << &params);
6094
0ac9a2fffbfb - added Scale and Shape Pareto rng constuctor
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5969
diff changeset
   744
}
0ac9a2fffbfb - added Scale and Shape Pareto rng constuctor
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5969
diff changeset
   745
0ac9a2fffbfb - added Scale and Shape Pareto rng constuctor
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5969
diff changeset
   746
ParetoVariableImpl::ParetoVariableImpl (std::pair<double, double> params, double b)
0ac9a2fffbfb - added Scale and Shape Pareto rng constuctor
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5969
diff changeset
   747
  : m_scale (params.first),
0ac9a2fffbfb - added Scale and Shape Pareto rng constuctor
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5969
diff changeset
   748
    m_shape (params.second),
0ac9a2fffbfb - added Scale and Shape Pareto rng constuctor
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5969
diff changeset
   749
    m_bound (b)
0ac9a2fffbfb - added Scale and Shape Pareto rng constuctor
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5969
diff changeset
   750
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   751
  NS_LOG_FUNCTION (this << &params << b);
6094
0ac9a2fffbfb - added Scale and Shape Pareto rng constuctor
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5969
diff changeset
   752
}
0ac9a2fffbfb - added Scale and Shape Pareto rng constuctor
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5969
diff changeset
   753
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   754
ParetoVariableImpl::ParetoVariableImpl (const ParetoVariableImpl& c)
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   755
  : RandomVariableBase (c),
6094
0ac9a2fffbfb - added Scale and Shape Pareto rng constuctor
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5969
diff changeset
   756
    m_scale (c.m_scale),
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   757
    m_shape (c.m_shape),
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   758
    m_bound (c.m_bound)
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   759
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   760
  NS_LOG_FUNCTION (this << &c);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   761
}
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   762
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   763
double ParetoVariableImpl::GetValue ()
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   764
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   765
  NS_LOG_FUNCTION (this);
8871
60846d2741c0 initial patch to fix rng variability
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7003
diff changeset
   766
  RngStream *generator = GetStream ();
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   767
  while (1)
4224
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4223
diff changeset
   768
    {
9063
32755d0516f4 Bug 1237 - code cleanups related to includes
Vedran Miletić <rivanvx@gmail.com>
parents: 8871
diff changeset
   769
      double r = (m_scale * ( 1.0 / std::pow (generator->RandU01 (), 1.0 / m_shape)));
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   770
      if (m_bound == 0 || r <= m_bound)
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   771
        {
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   772
          return r;
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   773
        }
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   774
      // otherwise, try again
4224
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4223
diff changeset
   775
    }
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   776
}
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   777
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   778
RandomVariableBase* ParetoVariableImpl::Copy () const
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   779
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   780
  NS_LOG_FUNCTION (this);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   781
  return new ParetoVariableImpl (*this);
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   782
}
442
96d3e7dc8bb2 Added static RNGs, like ExponentialVariable::GetSingleValue(mean)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 438
diff changeset
   783
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   784
ParetoVariable::ParetoVariable ()
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   785
  : RandomVariable (ParetoVariableImpl ())
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   786
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   787
  NS_LOG_FUNCTION (this);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   788
}
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   789
ParetoVariable::ParetoVariable (double m)
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   790
  : RandomVariable (ParetoVariableImpl (m))
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   791
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   792
  NS_LOG_FUNCTION (this << m);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   793
}
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   794
ParetoVariable::ParetoVariable (double m, double s)
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   795
  : RandomVariable (ParetoVariableImpl (m, s))
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   796
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   797
  NS_LOG_FUNCTION (this << m << s);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   798
}
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   799
ParetoVariable::ParetoVariable (double m, double s, double b)
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   800
  : RandomVariable (ParetoVariableImpl (m, s, b))
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   801
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   802
  NS_LOG_FUNCTION (this << m << s << b);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   803
}
6094
0ac9a2fffbfb - added Scale and Shape Pareto rng constuctor
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5969
diff changeset
   804
ParetoVariable::ParetoVariable (std::pair<double, double> params)
0ac9a2fffbfb - added Scale and Shape Pareto rng constuctor
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5969
diff changeset
   805
  : RandomVariable (ParetoVariableImpl (params))
0ac9a2fffbfb - added Scale and Shape Pareto rng constuctor
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5969
diff changeset
   806
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   807
  NS_LOG_FUNCTION (this << &params);
6094
0ac9a2fffbfb - added Scale and Shape Pareto rng constuctor
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5969
diff changeset
   808
}
0ac9a2fffbfb - added Scale and Shape Pareto rng constuctor
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5969
diff changeset
   809
ParetoVariable::ParetoVariable (std::pair<double, double> params, double b)
0ac9a2fffbfb - added Scale and Shape Pareto rng constuctor
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5969
diff changeset
   810
  : RandomVariable (ParetoVariableImpl (params, b))
0ac9a2fffbfb - added Scale and Shape Pareto rng constuctor
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5969
diff changeset
   811
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   812
  NS_LOG_FUNCTION (this << &params << b);
6094
0ac9a2fffbfb - added Scale and Shape Pareto rng constuctor
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5969
diff changeset
   813
}
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   814
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   815
// -----------------------------------------------------------------------------
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   816
// -----------------------------------------------------------------------------
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   817
// WeibullVariableImpl methods
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   818
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   819
class WeibullVariableImpl : public RandomVariableBase
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   820
{
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   821
public:
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   822
  /**
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   823
   * Constructs a weibull random variable  with a mean
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   824
   * value of 1.0 and a shape (alpha) parameter of 1
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   825
   */
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   826
  WeibullVariableImpl ();
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   827
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   828
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   829
  /**
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   830
   * Constructs a weibull random variable with the specified mean
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   831
   * value and a shape (alpha) parameter of 1.5.
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   832
   * \param m mean value of the distribution
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   833
   */
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   834
  WeibullVariableImpl (double m);
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   835
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   836
  /**
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   837
   * Constructs a weibull random variable with the specified mean
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   838
   * value and a shape (alpha).
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   839
   * \param m Mean value for the distribution.
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   840
   * \param s Shape (alpha) parameter for the distribution.
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   841
   */
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   842
  WeibullVariableImpl (double m, double s);
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   843
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   844
  /**
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   845
  * \brief Constructs a weibull random variable with the specified mean
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   846
  * \brief value, shape (alpha), and upper bound.
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   847
  * Since WeibullVariableImpl distributions can theoretically return unbounded values,
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   848
  * it is sometimes usefull to specify a fixed upper limit.  Note however
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   849
  * that when the upper limit is specified, the true mean of the distribution
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   850
  * is slightly smaller than the mean value specified.
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   851
  * \param m Mean value for the distribution.
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   852
  * \param s Shape (alpha) parameter for the distribution.
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   853
  * \param b Upper limit on returned values
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   854
  */
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   855
  WeibullVariableImpl (double m, double s, double b);
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   856
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   857
  WeibullVariableImpl (const WeibullVariableImpl& c);
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   858
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   859
  /**
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   860
   * \return A random value from this Weibull distribution
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   861
   */
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   862
  virtual double GetValue ();
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   863
  virtual RandomVariableBase* Copy (void) const;
4218
debf1a8a96d3 Proposed RNG API changes
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3679
diff changeset
   864
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   865
private:
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   866
  double m_mean;  // Mean value of RV
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   867
  double m_alpha; // Shape parameter
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   868
  double m_bound; // Upper bound on value (if non-zero)
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   869
};
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   870
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   871
WeibullVariableImpl::WeibullVariableImpl () : m_mean (1.0),
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   872
                                              m_alpha (1),
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   873
                                              m_bound (0)
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   874
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   875
  NS_LOG_FUNCTION (this);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   876
}
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   877
WeibullVariableImpl::WeibullVariableImpl (double m)
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   878
  : m_mean (m),
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   879
    m_alpha (1),
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   880
    m_bound (0)
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   881
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   882
  NS_LOG_FUNCTION (this << m);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   883
}
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   884
WeibullVariableImpl::WeibullVariableImpl (double m, double s)
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   885
  : m_mean (m),
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   886
    m_alpha (s),
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   887
    m_bound (0)
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   888
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   889
  NS_LOG_FUNCTION (this << m << s);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   890
}
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   891
WeibullVariableImpl::WeibullVariableImpl (double m, double s, double b)
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   892
  : m_mean (m),
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   893
    m_alpha (s),
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   894
    m_bound (b)
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   895
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   896
  NS_LOG_FUNCTION (this << m << s << b);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   897
}
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   898
WeibullVariableImpl::WeibullVariableImpl (const WeibullVariableImpl& c)
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   899
  : RandomVariableBase (c),
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   900
    m_mean (c.m_mean),
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   901
    m_alpha (c.m_alpha),
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   902
    m_bound (c.m_bound)
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   903
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   904
  NS_LOG_FUNCTION (this << &c);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   905
}
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   906
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   907
double WeibullVariableImpl::GetValue ()
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   908
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   909
  NS_LOG_FUNCTION (this);
8871
60846d2741c0 initial patch to fix rng variability
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7003
diff changeset
   910
  RngStream *generator = GetStream ();
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   911
  double exponent = 1.0 / m_alpha;
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   912
  while (1)
4224
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4223
diff changeset
   913
    {
9063
32755d0516f4 Bug 1237 - code cleanups related to includes
Vedran Miletić <rivanvx@gmail.com>
parents: 8871
diff changeset
   914
      double r = m_mean * std::pow ( -std::log (generator->RandU01 ()), exponent);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   915
      if (m_bound == 0 || r <= m_bound)
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   916
        {
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   917
          return r;
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   918
        }
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   919
      // otherwise, try again
4224
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4223
diff changeset
   920
    }
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   921
}
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   922
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   923
RandomVariableBase* WeibullVariableImpl::Copy () const
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   924
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   925
  NS_LOG_FUNCTION (this);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   926
  return new WeibullVariableImpl (*this);
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   927
}
442
96d3e7dc8bb2 Added static RNGs, like ExponentialVariable::GetSingleValue(mean)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 438
diff changeset
   928
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   929
WeibullVariable::WeibullVariable ()
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   930
  : RandomVariable (WeibullVariableImpl ())
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   931
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   932
  NS_LOG_FUNCTION (this);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   933
}
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   934
WeibullVariable::WeibullVariable (double m)
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   935
  : RandomVariable (WeibullVariableImpl (m))
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   936
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   937
  NS_LOG_FUNCTION (this << m);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   938
}
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   939
WeibullVariable::WeibullVariable (double m, double s)
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   940
  : RandomVariable (WeibullVariableImpl (m, s))
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   941
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   942
  NS_LOG_FUNCTION (this << m << s);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   943
}
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   944
WeibullVariable::WeibullVariable (double m, double s, double b)
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   945
  : RandomVariable (WeibullVariableImpl (m, s, b))
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   946
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
   947
  NS_LOG_FUNCTION (this << m << s << b);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   948
}
4218
debf1a8a96d3 Proposed RNG API changes
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3679
diff changeset
   949
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   950
// -----------------------------------------------------------------------------
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   951
// -----------------------------------------------------------------------------
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   952
// NormalVariableImpl methods
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   953
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   954
class NormalVariableImpl : public RandomVariableBase   // Normally Distributed random var
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   955
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   956
{
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   957
public:
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   958
  static const double INFINITE_VALUE;
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   959
  /**
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   960
   * Constructs an normal random variable  with a mean
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   961
   * value of 0 and variance of 1.
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   962
   */
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   963
  NormalVariableImpl ();
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   964
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   965
  /**
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   966
   * \brief Construct a normal random variable with specified mean and variance
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   967
   * \param m Mean value
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   968
   * \param v Variance
4227
b30027eeb387 Michelle's bounds patch
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4224
diff changeset
   969
   * \param b Bound.  The NormalVariableImpl is bounded within +-bound of the mean.
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   970
   */
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   971
  NormalVariableImpl (double m, double v, double b = INFINITE_VALUE);
442
96d3e7dc8bb2 Added static RNGs, like ExponentialVariable::GetSingleValue(mean)
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 438
diff changeset
   972
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   973
  NormalVariableImpl (const NormalVariableImpl& c);
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   974
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   975
  /**
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   976
   * \return A value from this normal distribution
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   977
   */
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   978
  virtual double GetValue ();
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   979
  virtual RandomVariableBase* Copy (void) const;
4218
debf1a8a96d3 Proposed RNG API changes
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3679
diff changeset
   980
4249
c2d4a91bcc8a Bug 485: implement deserialization of normal/gaussian random variables
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4243
diff changeset
   981
  double GetMean (void) const;
c2d4a91bcc8a Bug 485: implement deserialization of normal/gaussian random variables
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4243
diff changeset
   982
  double GetVariance (void) const;
c2d4a91bcc8a Bug 485: implement deserialization of normal/gaussian random variables
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4243
diff changeset
   983
  double GetBound (void) const;
c2d4a91bcc8a Bug 485: implement deserialization of normal/gaussian random variables
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4243
diff changeset
   984
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   985
private:
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   986
  double m_mean;      // Mean value of RV
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   987
  double m_variance;  // Mean value of RV
4227
b30027eeb387 Michelle's bounds patch
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4224
diff changeset
   988
  double m_bound;     // Bound on value's difference from the mean (absolute value)
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   989
  bool   m_nextValid; // True if next valid
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   990
  double m_next;      // The algorithm produces two values at a time
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   991
};
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   992
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   993
const double NormalVariableImpl::INFINITE_VALUE = 1e307;
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
   994
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   995
NormalVariableImpl::NormalVariableImpl ()
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   996
  : m_mean (0.0),
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   997
    m_variance (1.0),
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   998
    m_bound (INFINITE_VALUE),
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
   999
    m_nextValid (false)
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1000
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
  1001
  NS_LOG_FUNCTION (this);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1002
}
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1003
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1004
NormalVariableImpl::NormalVariableImpl (double m, double v, double b)
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1005
  : m_mean (m),
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1006
    m_variance (v),
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1007
    m_bound (b),
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1008
    m_nextValid (false)
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1009
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
  1010
  NS_LOG_FUNCTION (this << m << v << b);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1011
}
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1012
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1013
NormalVariableImpl::NormalVariableImpl (const NormalVariableImpl& c)
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1014
  : RandomVariableBase (c),
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1015
    m_mean (c.m_mean),
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1016
    m_variance (c.m_variance),
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1017
    m_bound (c.m_bound),
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1018
    m_nextValid (false)
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1019
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
  1020
  NS_LOG_FUNCTION (this << &c);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1021
}
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1022
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1023
double NormalVariableImpl::GetValue ()
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1024
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
  1025
  NS_LOG_FUNCTION (this);
8871
60846d2741c0 initial patch to fix rng variability
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7003
diff changeset
  1026
  RngStream *generator = GetStream ();
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1027
  if (m_nextValid)
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1028
    { // use previously generated
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1029
      m_nextValid = false;
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1030
      return m_next;
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1031
    }
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1032
  while (1)
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1033
    { // See Simulation Modeling and Analysis p. 466 (Averill Law)
3292
bd8d2601af21 Bug 181
craigdo@craig-dowells-imac.local
parents: 3267
diff changeset
  1034
      // for algorithm; basically a Box-Muller transform:
bd8d2601af21 Bug 181
craigdo@craig-dowells-imac.local
parents: 3267
diff changeset
  1035
      // http://en.wikipedia.org/wiki/Box-Muller_transform
8871
60846d2741c0 initial patch to fix rng variability
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7003
diff changeset
  1036
      double u1 = generator->RandU01 ();
60846d2741c0 initial patch to fix rng variability
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7003
diff changeset
  1037
      double u2 = generator->RandU01 ();
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1038
      double v1 = 2 * u1 - 1;
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1039
      double v2 = 2 * u2 - 1;
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1040
      double w = v1 * v1 + v2 * v2;
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1041
      if (w <= 1.0)
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1042
        { // Got good pair
9063
32755d0516f4 Bug 1237 - code cleanups related to includes
Vedran Miletić <rivanvx@gmail.com>
parents: 8871
diff changeset
  1043
          double y = std::sqrt ((-2 * std::log (w)) / w);
32755d0516f4 Bug 1237 - code cleanups related to includes
Vedran Miletić <rivanvx@gmail.com>
parents: 8871
diff changeset
  1044
          m_next = m_mean + v2 * y * std::sqrt (m_variance);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1045
          // if next is in bounds, it is valid
9063
32755d0516f4 Bug 1237 - code cleanups related to includes
Vedran Miletić <rivanvx@gmail.com>
parents: 8871
diff changeset
  1046
          m_nextValid = std::fabs (m_next - m_mean) <= m_bound;
32755d0516f4 Bug 1237 - code cleanups related to includes
Vedran Miletić <rivanvx@gmail.com>
parents: 8871
diff changeset
  1047
          double x1 = m_mean + v1 * y * std::sqrt (m_variance);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1048
          // if x1 is in bounds, return it
9063
32755d0516f4 Bug 1237 - code cleanups related to includes
Vedran Miletić <rivanvx@gmail.com>
parents: 8871
diff changeset
  1049
          if (std::fabs (x1 - m_mean) <= m_bound)
4224
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4223
diff changeset
  1050
            {
4227
b30027eeb387 Michelle's bounds patch
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4224
diff changeset
  1051
              return x1;
4224
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4223
diff changeset
  1052
            }
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1053
          // otherwise try and return m_next if it is valid
4227
b30027eeb387 Michelle's bounds patch
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4224
diff changeset
  1054
          else if (m_nextValid)
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1055
            {
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1056
              m_nextValid = false;
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1057
              return m_next;
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1058
            }
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1059
          // otherwise, just run this loop again
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1060
        }
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1061
    }
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1062
}
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1063
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1064
RandomVariableBase* NormalVariableImpl::Copy () const
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1065
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
  1066
  NS_LOG_FUNCTION (this);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1067
  return new NormalVariableImpl (*this);
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1068
}
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1069
4249
c2d4a91bcc8a Bug 485: implement deserialization of normal/gaussian random variables
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4243
diff changeset
  1070
double
c2d4a91bcc8a Bug 485: implement deserialization of normal/gaussian random variables
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4243
diff changeset
  1071
NormalVariableImpl::GetMean (void) const
c2d4a91bcc8a Bug 485: implement deserialization of normal/gaussian random variables
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4243
diff changeset
  1072
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
  1073
  NS_LOG_FUNCTION (this);
4249
c2d4a91bcc8a Bug 485: implement deserialization of normal/gaussian random variables
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4243
diff changeset
  1074
  return m_mean;
c2d4a91bcc8a Bug 485: implement deserialization of normal/gaussian random variables
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4243
diff changeset
  1075
}
c2d4a91bcc8a Bug 485: implement deserialization of normal/gaussian random variables
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4243
diff changeset
  1076
c2d4a91bcc8a Bug 485: implement deserialization of normal/gaussian random variables
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4243
diff changeset
  1077
double
c2d4a91bcc8a Bug 485: implement deserialization of normal/gaussian random variables
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4243
diff changeset
  1078
NormalVariableImpl::GetVariance (void) const
c2d4a91bcc8a Bug 485: implement deserialization of normal/gaussian random variables
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4243
diff changeset
  1079
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
  1080
  NS_LOG_FUNCTION (this);
4249
c2d4a91bcc8a Bug 485: implement deserialization of normal/gaussian random variables
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4243
diff changeset
  1081
  return m_variance;
c2d4a91bcc8a Bug 485: implement deserialization of normal/gaussian random variables
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4243
diff changeset
  1082
}
c2d4a91bcc8a Bug 485: implement deserialization of normal/gaussian random variables
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4243
diff changeset
  1083
c2d4a91bcc8a Bug 485: implement deserialization of normal/gaussian random variables
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4243
diff changeset
  1084
double
c2d4a91bcc8a Bug 485: implement deserialization of normal/gaussian random variables
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4243
diff changeset
  1085
NormalVariableImpl::GetBound (void) const
c2d4a91bcc8a Bug 485: implement deserialization of normal/gaussian random variables
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4243
diff changeset
  1086
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
  1087
  NS_LOG_FUNCTION (this);
4249
c2d4a91bcc8a Bug 485: implement deserialization of normal/gaussian random variables
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4243
diff changeset
  1088
  return m_bound;
c2d4a91bcc8a Bug 485: implement deserialization of normal/gaussian random variables
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4243
diff changeset
  1089
}
c2d4a91bcc8a Bug 485: implement deserialization of normal/gaussian random variables
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4243
diff changeset
  1090
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1091
NormalVariable::NormalVariable ()
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1092
  : RandomVariable (NormalVariableImpl ())
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1093
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
  1094
  NS_LOG_FUNCTION (this);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1095
}
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1096
NormalVariable::NormalVariable (double m, double v)
4223
86a97665dcb0 Fix old code that crept in
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4218
diff changeset
  1097
  : RandomVariable (NormalVariableImpl (m, v))
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1098
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
  1099
  NS_LOG_FUNCTION (this << m << v);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1100
}
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1101
NormalVariable::NormalVariable (double m, double v, double b)
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1102
  : RandomVariable (NormalVariableImpl (m, v, b))
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1103
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
  1104
  NS_LOG_FUNCTION (this << m << v << b);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1105
}
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1106
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1107
// -----------------------------------------------------------------------------
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1108
// -----------------------------------------------------------------------------
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1109
class EmpiricalVariableImpl : public RandomVariableBase
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1110
{
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1111
public:
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1112
  /**
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1113
   * Constructor for the EmpiricalVariableImpl random variables.
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1114
   */
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1115
  explicit EmpiricalVariableImpl ();
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1116
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1117
  virtual ~EmpiricalVariableImpl ();
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1118
  EmpiricalVariableImpl (const EmpiricalVariableImpl& c);
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1119
  /**
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1120
   * \return A value from this empirical distribution
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1121
   */
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1122
  virtual double GetValue ();
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1123
  virtual RandomVariableBase* Copy (void) const;
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1124
  /**
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1125
   * \brief Specifies a point in the empirical distribution
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1126
   * \param v The function value for this point
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1127
   * \param c Probability that the function is less than or equal to v
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1128
   */
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1129
  virtual void CDF (double v, double c);  // Value, prob <= Value
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1130
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1131
private:
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1132
  class ValueCDF
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1133
  {
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1134
public:
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1135
    ValueCDF ();
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1136
    ValueCDF (double v, double c);
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1137
    ValueCDF (const ValueCDF& c);
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1138
    double value;
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1139
    double    cdf;
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1140
  };
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1141
  virtual void Validate ();  // Insure non-decreasing emiprical values
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1142
  virtual double Interpolate (double, double, double, double, double);
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1143
  bool validated; // True if non-decreasing validated
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1144
  std::vector<ValueCDF> emp;       // Empicical CDF
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1145
};
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1146
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1147
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1148
// ValueCDF methods
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1149
EmpiricalVariableImpl::ValueCDF::ValueCDF ()
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1150
  : value (0.0),
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1151
    cdf (0.0)
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1152
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
  1153
  NS_LOG_FUNCTION (this);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1154
}
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1155
EmpiricalVariableImpl::ValueCDF::ValueCDF (double v, double c)
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1156
  : value (v),
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1157
    cdf (c)
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1158
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
  1159
  NS_LOG_FUNCTION (this << v << c);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1160
}
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1161
EmpiricalVariableImpl::ValueCDF::ValueCDF (const ValueCDF& c)
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1162
  : value (c.value),
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1163
    cdf (c.cdf)
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1164
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
  1165
  NS_LOG_FUNCTION (this << &c);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1166
}
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1167
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1168
// -----------------------------------------------------------------------------
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1169
// -----------------------------------------------------------------------------
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1170
// EmpiricalVariableImpl methods
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1171
EmpiricalVariableImpl::EmpiricalVariableImpl ()
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1172
  : validated (false)
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1173
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
  1174
  NS_LOG_FUNCTION (this);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1175
}
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1176
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1177
EmpiricalVariableImpl::EmpiricalVariableImpl (const EmpiricalVariableImpl& c)
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1178
  : RandomVariableBase (c),
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1179
    validated (c.validated),
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1180
    emp (c.emp)
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1181
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
  1182
  NS_LOG_FUNCTION (this << &c);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1183
}
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1184
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1185
EmpiricalVariableImpl::~EmpiricalVariableImpl ()
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1186
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
  1187
  NS_LOG_FUNCTION (this);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1188
}
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1189
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1190
double EmpiricalVariableImpl::GetValue ()
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1191
{ // Return a value from the empirical distribution
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1192
  // This code based (loosely) on code by Bruce Mah (Thanks Bruce!)
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
  1193
  NS_LOG_FUNCTION (this);
8871
60846d2741c0 initial patch to fix rng variability
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7003
diff changeset
  1194
  RngStream *generator = GetStream ();
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1195
  if (emp.size () == 0)
4224
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4223
diff changeset
  1196
    {
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4223
diff changeset
  1197
      return 0.0; // HuH? No empirical data
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4223
diff changeset
  1198
    }
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1199
  if (!validated)
4224
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4223
diff changeset
  1200
    {
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1201
      Validate ();      // Insure in non-decreasing
4224
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4223
diff changeset
  1202
    }
8871
60846d2741c0 initial patch to fix rng variability
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7003
diff changeset
  1203
  double r = generator->RandU01 ();
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1204
  if (r <= emp.front ().cdf)
4224
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4223
diff changeset
  1205
    {
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1206
      return emp.front ().value; // Less than first
4224
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4223
diff changeset
  1207
    }
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1208
  if (r >= emp.back ().cdf)
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1209
    {
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1210
      return emp.back ().value;  // Greater than last
4224
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4223
diff changeset
  1211
    }
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1212
  // Binary search
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1213
  std::vector<ValueCDF>::size_type bottom = 0;
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1214
  std::vector<ValueCDF>::size_type top = emp.size () - 1;
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1215
  while (1)
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1216
    {
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1217
      std::vector<ValueCDF>::size_type c = (top + bottom) / 2;
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1218
      if (r >= emp[c].cdf && r < emp[c + 1].cdf)
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1219
        { // Found it
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1220
          return Interpolate (emp[c].cdf, emp[c + 1].cdf,
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1221
                              emp[c].value, emp[c + 1].value,
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1222
                              r);
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1223
        }
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1224
      // Not here, adjust bounds
4224
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4223
diff changeset
  1225
      if (r < emp[c].cdf)
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4223
diff changeset
  1226
        {
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4223
diff changeset
  1227
          top    = c - 1;
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4223
diff changeset
  1228
        }
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4223
diff changeset
  1229
      else
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4223
diff changeset
  1230
        {
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4223
diff changeset
  1231
          bottom = c + 1;
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4223
diff changeset
  1232
        }
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1233
    }
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1234
}
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1235
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1236
RandomVariableBase* EmpiricalVariableImpl::Copy () const
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1237
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
  1238
  NS_LOG_FUNCTION (this);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1239
  return new EmpiricalVariableImpl (*this);
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1240
}
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1241
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1242
void EmpiricalVariableImpl::CDF (double v, double c)
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1243
{ // Add a new empirical datapoint to the empirical cdf
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1244
  // NOTE.   These MUST be inserted in non-decreasing order
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
  1245
  NS_LOG_FUNCTION (this << v << c);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1246
  emp.push_back (ValueCDF (v, c));
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1247
}
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1248
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1249
void EmpiricalVariableImpl::Validate ()
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1250
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
  1251
  NS_LOG_FUNCTION (this);
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1252
  ValueCDF prior;
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1253
  for (std::vector<ValueCDF>::size_type i = 0; i < emp.size (); ++i)
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1254
    {
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1255
      ValueCDF& current = emp[i];
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1256
      if (current.value < prior.value || current.cdf < prior.cdf)
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1257
        { // Error
9063
32755d0516f4 Bug 1237 - code cleanups related to includes
Vedran Miletić <rivanvx@gmail.com>
parents: 8871
diff changeset
  1258
          std::cerr << "Empirical Dist error,"
32755d0516f4 Bug 1237 - code cleanups related to includes
Vedran Miletić <rivanvx@gmail.com>
parents: 8871
diff changeset
  1259
                    << " current value " << current.value
32755d0516f4 Bug 1237 - code cleanups related to includes
Vedran Miletić <rivanvx@gmail.com>
parents: 8871
diff changeset
  1260
                    << " prior value "   << prior.value
32755d0516f4 Bug 1237 - code cleanups related to includes
Vedran Miletić <rivanvx@gmail.com>
parents: 8871
diff changeset
  1261
                    << " current cdf "   << current.cdf
32755d0516f4 Bug 1237 - code cleanups related to includes
Vedran Miletić <rivanvx@gmail.com>
parents: 8871
diff changeset
  1262
                    << " prior cdf "     << prior.cdf << std::endl;
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1263
          NS_FATAL_ERROR ("Empirical Dist error");
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1264
        }
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1265
      prior = current;
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1266
    }
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1267
  validated = true;
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1268
}
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1269
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1270
double EmpiricalVariableImpl::Interpolate (double c1, double c2,
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1271
                                           double v1, double v2, double r)
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1272
{ // Interpolate random value in range [v1..v2) based on [c1 .. r .. c2)
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
  1273
  NS_LOG_FUNCTION (this << c1 << c2 << v1 << v2 << r);
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1274
  return (v1 + ((v2 - v1) / (c2 - c1)) * (r - c1));
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1275
}
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1276
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1277
EmpiricalVariable::EmpiricalVariable ()
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1278
  : RandomVariable (EmpiricalVariableImpl ())
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1279
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
  1280
  NS_LOG_FUNCTION (this);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1281
}
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1282
EmpiricalVariable::EmpiricalVariable (const RandomVariableBase &variable)
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1283
  : RandomVariable (variable)
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1284
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
  1285
  NS_LOG_FUNCTION (this << &variable);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1286
}
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1287
void
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1288
EmpiricalVariable::CDF (double v, double c)
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1289
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
  1290
  NS_LOG_FUNCTION (this << v << c);
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1291
  EmpiricalVariableImpl *impl = dynamic_cast<EmpiricalVariableImpl *> (Peek ());
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1292
  NS_ASSERT (impl);
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1293
  impl->CDF (v, c);
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1294
}
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1295
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1296
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1297
// -----------------------------------------------------------------------------
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1298
// -----------------------------------------------------------------------------
2965
4b28e9740e3b get rid of Attribute class. Use AttributeValue subclasses directly.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2947
diff changeset
  1299
// IntegerValue EmpiricalVariableImpl methods
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1300
class IntEmpiricalVariableImpl : public EmpiricalVariableImpl
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1301
{
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1302
public:
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1303
  IntEmpiricalVariableImpl ();
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1304
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1305
  virtual RandomVariableBase* Copy (void) const;
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1306
  /**
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1307
   * \return An integer value from this empirical distribution
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1308
   */
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1309
  virtual uint32_t GetInteger ();
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1310
private:
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1311
  virtual double Interpolate (double, double, double, double, double);
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1312
};
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1313
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1314
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1315
IntEmpiricalVariableImpl::IntEmpiricalVariableImpl ()
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1316
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
  1317
  NS_LOG_FUNCTION (this);
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1318
}
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1319
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1320
uint32_t IntEmpiricalVariableImpl::GetInteger ()
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1321
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
  1322
  NS_LOG_FUNCTION (this);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1323
  return (uint32_t)GetValue ();
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1324
}
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1325
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1326
RandomVariableBase* IntEmpiricalVariableImpl::Copy () const
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1327
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
  1328
  NS_LOG_FUNCTION (this);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1329
  return new IntEmpiricalVariableImpl (*this);
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1330
}
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1331
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1332
double IntEmpiricalVariableImpl::Interpolate (double c1, double c2,
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1333
                                              double v1, double v2, double r)
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1334
{ // Interpolate random value in range [v1..v2) based on [c1 .. r .. c2)
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
  1335
  NS_LOG_FUNCTION (this << c1 << c2 << v1 << v2 << r);
9063
32755d0516f4 Bug 1237 - code cleanups related to includes
Vedran Miletić <rivanvx@gmail.com>
parents: 8871
diff changeset
  1336
  return std::ceil (v1 + ((v2 - v1) / (c2 - c1)) * (r - c1));
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1337
}
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1338
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1339
IntEmpiricalVariable::IntEmpiricalVariable ()
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1340
  : EmpiricalVariable (IntEmpiricalVariableImpl ())
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1341
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
  1342
  NS_LOG_FUNCTION (this);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1343
}
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1344
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1345
// -----------------------------------------------------------------------------
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1346
// -----------------------------------------------------------------------------
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1347
// DeterministicVariableImpl
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1348
class DeterministicVariableImpl : public RandomVariableBase
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1349
{
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1350
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1351
public:
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1352
  /**
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1353
   * \brief Constructor
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1354
   *
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1355
   * Creates a generator that returns successive elements of the d array
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1356
   * on successive calls to ::Value().  Note that the d pointer is copied
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1357
   * for use by the generator (shallow-copy), not its contents, so the
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1358
   * contents of the array d points to have to remain unchanged for the use
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1359
   * of DeterministicVariableImpl to be meaningful.
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1360
   * \param d Pointer to array of random values to return in sequence
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1361
   * \param c Number of values in the array
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1362
   */
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1363
  explicit DeterministicVariableImpl (double* d, uint32_t c);
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1364
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1365
  virtual ~DeterministicVariableImpl ();
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1366
  /**
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1367
   * \return The next value in the deterministic sequence
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1368
   */
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1369
  virtual double GetValue ();
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1370
  virtual RandomVariableBase* Copy (void) const;
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1371
private:
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1372
  uint32_t   count;
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1373
  uint32_t   next;
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1374
  double* data;
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1375
};
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1376
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1377
DeterministicVariableImpl::DeterministicVariableImpl (double* d, uint32_t c)
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1378
  : count (c),
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1379
    next (c),
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1380
    data (d)
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1381
{ // Nothing else needed
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
  1382
  NS_LOG_FUNCTION (this << d << c);
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1383
}
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1384
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1385
DeterministicVariableImpl::~DeterministicVariableImpl ()
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1386
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
  1387
  NS_LOG_FUNCTION (this);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1388
}
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1389
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1390
double DeterministicVariableImpl::GetValue ()
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1391
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
  1392
  NS_LOG_FUNCTION (this);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1393
  if (next == count)
4224
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4223
diff changeset
  1394
    {
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4223
diff changeset
  1395
      next = 0;
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4223
diff changeset
  1396
    }
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1397
  return data[next++];
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1398
}
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1399
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1400
RandomVariableBase* DeterministicVariableImpl::Copy () const
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1401
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
  1402
  NS_LOG_FUNCTION (this);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1403
  return new DeterministicVariableImpl (*this);
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1404
}
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
  1405
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1406
DeterministicVariable::DeterministicVariable (double* d, uint32_t c)
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1407
  : RandomVariable (DeterministicVariableImpl (d, c))
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1408
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
  1409
  NS_LOG_FUNCTION (this << d << c);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1410
}
438
515bb5663cf3 Randomvariable Lognormal added
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 423
diff changeset
  1411
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1412
// -----------------------------------------------------------------------------
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1413
// -----------------------------------------------------------------------------
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1414
// LogNormalVariableImpl
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1415
class LogNormalVariableImpl : public RandomVariableBase
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1416
{
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1417
public:
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1418
  /**
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1419
   * \param mu mu parameter of the lognormal distribution
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1420
   * \param sigma sigma parameter of the lognormal distribution
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1421
   */
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1422
  LogNormalVariableImpl (double mu, double sigma);
438
515bb5663cf3 Randomvariable Lognormal added
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 423
diff changeset
  1423
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1424
  /**
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1425
   * \return A random value from this distribution
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1426
   */
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1427
  virtual double GetValue ();
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1428
  virtual RandomVariableBase* Copy (void) const;
4218
debf1a8a96d3 Proposed RNG API changes
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3679
diff changeset
  1429
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1430
private:
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1431
  double m_mu;
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1432
  double m_sigma;
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1433
};
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1434
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1435
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1436
RandomVariableBase* LogNormalVariableImpl::Copy () const
438
515bb5663cf3 Randomvariable Lognormal added
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 423
diff changeset
  1437
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
  1438
  NS_LOG_FUNCTION (this);
4579
c86681050541 New Zipf random variable
Francesco Malandrino <francesco.malandrino@gmail.com>
parents: 4317
diff changeset
  1439
  return new LogNormalVariableImpl (*this);
438
515bb5663cf3 Randomvariable Lognormal added
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 423
diff changeset
  1440
}
515bb5663cf3 Randomvariable Lognormal added
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 423
diff changeset
  1441
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1442
LogNormalVariableImpl::LogNormalVariableImpl (double mu, double sigma)
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1443
  : m_mu (mu),
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1444
    m_sigma (sigma)
438
515bb5663cf3 Randomvariable Lognormal added
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 423
diff changeset
  1445
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
  1446
  NS_LOG_FUNCTION (this << mu << sigma);
438
515bb5663cf3 Randomvariable Lognormal added
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 423
diff changeset
  1447
}
515bb5663cf3 Randomvariable Lognormal added
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 423
diff changeset
  1448
515bb5663cf3 Randomvariable Lognormal added
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 423
diff changeset
  1449
// The code from this function was adapted from the GNU Scientific
515bb5663cf3 Randomvariable Lognormal added
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 423
diff changeset
  1450
// Library 1.8:
515bb5663cf3 Randomvariable Lognormal added
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 423
diff changeset
  1451
/* randist/lognormal.c
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1452
 *
438
515bb5663cf3 Randomvariable Lognormal added
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 423
diff changeset
  1453
 * Copyright (C) 1996, 1997, 1998, 1999, 2000 James Theiler, Brian Gough
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1454
 *
438
515bb5663cf3 Randomvariable Lognormal added
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 423
diff changeset
  1455
 * This program is free software; you can redistribute it and/or modify
515bb5663cf3 Randomvariable Lognormal added
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 423
diff changeset
  1456
 * it under the terms of the GNU General Public License as published by
515bb5663cf3 Randomvariable Lognormal added
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 423
diff changeset
  1457
 * the Free Software Foundation; either version 2 of the License, or (at
515bb5663cf3 Randomvariable Lognormal added
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 423
diff changeset
  1458
 * your option) any later version.
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1459
 *
438
515bb5663cf3 Randomvariable Lognormal added
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 423
diff changeset
  1460
 * This program is distributed in the hope that it will be useful, but
515bb5663cf3 Randomvariable Lognormal added
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 423
diff changeset
  1461
 * WITHOUT ANY WARRANTY; without even the implied warranty of
515bb5663cf3 Randomvariable Lognormal added
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 423
diff changeset
  1462
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
515bb5663cf3 Randomvariable Lognormal added
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 423
diff changeset
  1463
 * General Public License for more details.
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1464
 *
438
515bb5663cf3 Randomvariable Lognormal added
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 423
diff changeset
  1465
 * You should have received a copy of the GNU General Public License
515bb5663cf3 Randomvariable Lognormal added
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 423
diff changeset
  1466
 * along with this program; if not, write to the Free Software
515bb5663cf3 Randomvariable Lognormal added
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 423
diff changeset
  1467
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
515bb5663cf3 Randomvariable Lognormal added
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 423
diff changeset
  1468
 */
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1469
/* The lognormal distribution has the form
438
515bb5663cf3 Randomvariable Lognormal added
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 423
diff changeset
  1470
515bb5663cf3 Randomvariable Lognormal added
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 423
diff changeset
  1471
   p(x) dx = 1/(x * sqrt(2 pi sigma^2)) exp(-(ln(x) - zeta)^2/2 sigma^2) dx
515bb5663cf3 Randomvariable Lognormal added
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 423
diff changeset
  1472
515bb5663cf3 Randomvariable Lognormal added
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 423
diff changeset
  1473
   for x > 0. Lognormal random numbers are the exponentials of
515bb5663cf3 Randomvariable Lognormal added
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 423
diff changeset
  1474
   gaussian random numbers */
515bb5663cf3 Randomvariable Lognormal added
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 423
diff changeset
  1475
double
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1476
LogNormalVariableImpl::GetValue ()
438
515bb5663cf3 Randomvariable Lognormal added
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 423
diff changeset
  1477
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
  1478
  NS_LOG_FUNCTION (this);
8871
60846d2741c0 initial patch to fix rng variability
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7003
diff changeset
  1479
  RngStream *generator = GetStream ();
438
515bb5663cf3 Randomvariable Lognormal added
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 423
diff changeset
  1480
  double u, v, r2, normal, z;
515bb5663cf3 Randomvariable Lognormal added
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 423
diff changeset
  1481
515bb5663cf3 Randomvariable Lognormal added
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 423
diff changeset
  1482
  do
515bb5663cf3 Randomvariable Lognormal added
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 423
diff changeset
  1483
    {
515bb5663cf3 Randomvariable Lognormal added
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 423
diff changeset
  1484
      /* choose x,y in uniform square (-1,-1) to (+1,+1) */
515bb5663cf3 Randomvariable Lognormal added
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 423
diff changeset
  1485
8871
60846d2741c0 initial patch to fix rng variability
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7003
diff changeset
  1486
      u = -1 + 2 * generator->RandU01 ();
60846d2741c0 initial patch to fix rng variability
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7003
diff changeset
  1487
      v = -1 + 2 * generator->RandU01 ();
438
515bb5663cf3 Randomvariable Lognormal added
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 423
diff changeset
  1488
515bb5663cf3 Randomvariable Lognormal added
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 423
diff changeset
  1489
      /* see if it is in the unit circle */
515bb5663cf3 Randomvariable Lognormal added
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 423
diff changeset
  1490
      r2 = u * u + v * v;
515bb5663cf3 Randomvariable Lognormal added
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 423
diff changeset
  1491
    }
515bb5663cf3 Randomvariable Lognormal added
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 423
diff changeset
  1492
  while (r2 > 1.0 || r2 == 0);
515bb5663cf3 Randomvariable Lognormal added
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 423
diff changeset
  1493
9063
32755d0516f4 Bug 1237 - code cleanups related to includes
Vedran Miletić <rivanvx@gmail.com>
parents: 8871
diff changeset
  1494
  normal = u * std::sqrt (-2.0 * std::log (r2) / r2);
438
515bb5663cf3 Randomvariable Lognormal added
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 423
diff changeset
  1495
9063
32755d0516f4 Bug 1237 - code cleanups related to includes
Vedran Miletić <rivanvx@gmail.com>
parents: 8871
diff changeset
  1496
  z = std::exp (m_sigma * normal + m_mu);
438
515bb5663cf3 Randomvariable Lognormal added
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 423
diff changeset
  1497
515bb5663cf3 Randomvariable Lognormal added
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 423
diff changeset
  1498
  return z;
515bb5663cf3 Randomvariable Lognormal added
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 423
diff changeset
  1499
}
515bb5663cf3 Randomvariable Lognormal added
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 423
diff changeset
  1500
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1501
LogNormalVariable::LogNormalVariable (double mu, double sigma)
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1502
  : RandomVariable (LogNormalVariableImpl (mu, sigma))
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1503
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
  1504
  NS_LOG_FUNCTION (this << mu << sigma);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1505
}
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1506
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1507
// -----------------------------------------------------------------------------
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1508
// -----------------------------------------------------------------------------
4317
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1509
// GammaVariableImpl
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1510
class GammaVariableImpl : public RandomVariableBase
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1511
{
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1512
public:
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1513
  /**
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1514
   * \param alpha alpha parameter of the gamma distribution
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1515
   * \param beta beta parameter of the gamma distribution
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1516
   */
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1517
  GammaVariableImpl (double alpha, double beta);
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1518
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1519
  /**
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1520
   * \return A random value from this distribution
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1521
   */
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1522
  virtual double GetValue ();
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1523
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1524
  /**
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1525
   * \return A random value from the gamma distribution with parameters alpha
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1526
   * and beta
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1527
   */
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1528
  double GetValue (double alpha, double beta);
4317
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1529
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1530
  virtual RandomVariableBase* Copy (void) const;
4317
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1531
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1532
private:
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1533
  double m_alpha;
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1534
  double m_beta;
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1535
  NormalVariable m_normal;
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1536
};
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1537
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1538
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1539
RandomVariableBase* GammaVariableImpl::Copy () const
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1540
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
  1541
  NS_LOG_FUNCTION (this);
4317
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1542
  return new GammaVariableImpl (m_alpha, m_beta);
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1543
}
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1544
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1545
GammaVariableImpl::GammaVariableImpl (double alpha, double beta)
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1546
  : m_alpha (alpha),
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1547
    m_beta (beta)
4317
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1548
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
  1549
  NS_LOG_FUNCTION (this << alpha << beta);
4317
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1550
}
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1551
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1552
double
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1553
GammaVariableImpl::GetValue ()
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1554
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
  1555
  NS_LOG_FUNCTION (this);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1556
  return GetValue (m_alpha, m_beta);
4317
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1557
}
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1558
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1559
/*
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1560
  The code for the following generator functions was adapted from ns-2
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1561
  tools/ranvar.cc
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1562
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1563
  Originally the algorithm was devised by Marsaglia in 2000:
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1564
  G. Marsaglia, W. W. Tsang: A simple method for gereating Gamma variables
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1565
  ACM Transactions on mathematical software, Vol. 26, No. 3, Sept. 2000
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1566
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1567
  The Gamma distribution density function has the form
4317
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1568
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1569
                             x^(alpha-1) * exp(-x/beta)
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1570
        p(x; alpha, beta) = ----------------------------
4317
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1571
                             beta^alpha * Gamma(alpha)
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1572
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1573
  for x > 0.
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1574
*/
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1575
double
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1576
GammaVariableImpl::GetValue (double alpha, double beta)
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1577
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
  1578
  NS_LOG_FUNCTION (this << alpha << beta);
8871
60846d2741c0 initial patch to fix rng variability
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7003
diff changeset
  1579
  RngStream *generator = GetStream ();
4317
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1580
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1581
  if (alpha < 1)
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1582
    {
8871
60846d2741c0 initial patch to fix rng variability
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7003
diff changeset
  1583
      double u = generator->RandU01 ();
9063
32755d0516f4 Bug 1237 - code cleanups related to includes
Vedran Miletić <rivanvx@gmail.com>
parents: 8871
diff changeset
  1584
      return GetValue (1.0 + alpha, beta) * std::pow (u, 1.0 / alpha);
4317
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1585
    }
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1586
4317
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1587
  double x, v, u;
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1588
  double d = alpha - 1.0 / 3.0;
9063
32755d0516f4 Bug 1237 - code cleanups related to includes
Vedran Miletić <rivanvx@gmail.com>
parents: 8871
diff changeset
  1589
  double c = (1.0 / 3.0) / std::sqrt (d);
4317
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1590
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1591
  while (1)
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1592
    {
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1593
      do
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1594
        {
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1595
          x = m_normal.GetValue ();
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1596
          v = 1.0 + c * x;
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1597
        }
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1598
      while (v <= 0);
4317
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1599
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1600
      v = v * v * v;
8871
60846d2741c0 initial patch to fix rng variability
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7003
diff changeset
  1601
      u = generator->RandU01 ();
4317
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1602
      if (u < 1 - 0.0331 * x * x * x * x)
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1603
        {
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1604
          break;
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1605
        }
9063
32755d0516f4 Bug 1237 - code cleanups related to includes
Vedran Miletić <rivanvx@gmail.com>
parents: 8871
diff changeset
  1606
      if (std::log (u) < 0.5 * x * x + d * (1 - v + std::log (v)))
4317
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1607
        {
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1608
          break;
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1609
        }
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1610
    }
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1611
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1612
  return beta * d * v;
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1613
}
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1614
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1615
GammaVariable::GammaVariable ()
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1616
  : RandomVariable (GammaVariableImpl (1.0, 1.0))
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1617
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
  1618
  NS_LOG_FUNCTION (this);
4317
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1619
}
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1620
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1621
GammaVariable::GammaVariable (double alpha, double beta)
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1622
  : RandomVariable (GammaVariableImpl (alpha, beta))
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1623
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
  1624
  NS_LOG_FUNCTION (this << alpha << beta);
4317
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1625
}
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1626
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1627
double GammaVariable::GetValue (void) const
4317
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1628
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
  1629
  NS_LOG_FUNCTION (this);
4317
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1630
  return this->RandomVariable::GetValue ();
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1631
}
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1632
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1633
double GammaVariable::GetValue (double alpha, double beta) const
4317
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1634
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
  1635
  NS_LOG_FUNCTION (this << alpha << beta);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1636
  return ((GammaVariableImpl*)Peek ())->GetValue (alpha, beta);
4317
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1637
}
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1638
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1639
// -----------------------------------------------------------------------------
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1640
// -----------------------------------------------------------------------------
4317
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1641
// ErlangVariableImpl
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1642
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1643
class ErlangVariableImpl : public RandomVariableBase
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1644
{
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1645
public:
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1646
  /**
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1647
   * \param k k parameter of the Erlang distribution
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1648
   * \param lambda lambda parameter of the Erlang distribution
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1649
   */
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1650
  ErlangVariableImpl (unsigned int k, double lambda);
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1651
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1652
  /**
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1653
   * \return A random value from this distribution
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1654
   */
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1655
  virtual double GetValue ();
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1656
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1657
  /**
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1658
   * \return A random value from the Erlang distribution with parameters k and
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1659
   * lambda.
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1660
   */
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1661
  double GetValue (unsigned int k, double lambda);
4317
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1662
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1663
  virtual RandomVariableBase* Copy (void) const;
4317
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1664
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1665
private:
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1666
  unsigned int m_k;
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1667
  double m_lambda;
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1668
};
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1669
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1670
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1671
RandomVariableBase* ErlangVariableImpl::Copy () const
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1672
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
  1673
  NS_LOG_FUNCTION (this);
4317
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1674
  return new ErlangVariableImpl (m_k, m_lambda);
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1675
}
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1676
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1677
ErlangVariableImpl::ErlangVariableImpl (unsigned int k, double lambda)
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1678
  : m_k (k),
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1679
    m_lambda (lambda)
4317
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1680
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
  1681
  NS_LOG_FUNCTION (this << k << lambda);
4317
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1682
}
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1683
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1684
double
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1685
ErlangVariableImpl::GetValue ()
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1686
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
  1687
  NS_LOG_FUNCTION (this);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1688
  return GetValue (m_k, m_lambda);
4317
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1689
}
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1690
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1691
/*
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1692
  The code for the following generator functions was adapted from ns-2
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1693
  tools/ranvar.cc
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1694
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1695
  The Erlang distribution density function has the form
4317
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1696
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1697
                           x^(k-1) * exp(-x/lambda)
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1698
        p(x; k, lambda) = ---------------------------
4317
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1699
                             lambda^k * (k-1)!
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1700
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1701
  for x > 0.
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1702
*/
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1703
double
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1704
ErlangVariableImpl::GetValue (unsigned int k, double lambda)
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1705
{
8871
60846d2741c0 initial patch to fix rng variability
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7003
diff changeset
  1706
  // XXX: Fixme: do not create a new 
60846d2741c0 initial patch to fix rng variability
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7003
diff changeset
  1707
  // RNG stream every time the function is called !
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
  1708
  NS_LOG_FUNCTION (this << k << lambda);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1709
  ExponentialVariable exponential (lambda);
4317
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1710
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1711
  double result = 0;
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1712
  for (unsigned int i = 0; i < k; ++i)
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1713
    {
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1714
      result += exponential.GetValue ();
4317
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1715
    }
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1716
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1717
  return result;
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1718
}
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1719
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1720
ErlangVariable::ErlangVariable ()
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1721
  : RandomVariable (ErlangVariableImpl (1, 1.0))
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1722
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
  1723
  NS_LOG_FUNCTION (this);
4317
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1724
}
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1725
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1726
ErlangVariable::ErlangVariable (unsigned int k, double lambda)
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1727
  : RandomVariable (ErlangVariableImpl (k, lambda))
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1728
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
  1729
  NS_LOG_FUNCTION (this << k << lambda);
4317
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1730
}
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1731
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1732
double ErlangVariable::GetValue (void) const
4317
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1733
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
  1734
  NS_LOG_FUNCTION (this);
4317
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1735
  return this->RandomVariable::GetValue ();
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1736
}
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1737
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1738
double ErlangVariable::GetValue (unsigned int k, double lambda) const
4317
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1739
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
  1740
  NS_LOG_FUNCTION (this << k << lambda);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1741
  return ((ErlangVariableImpl*)Peek ())->GetValue (k, lambda);
4317
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1742
}
0a250f44e0ed bug 475: GammaVariable and ErlangVariable
Timo Bingmann <timo.bingmann@student.kit.edu>
parents: 4256
diff changeset
  1743
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1744
// -----------------------------------------------------------------------------
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1745
// -----------------------------------------------------------------------------
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1746
// TriangularVariableImpl methods
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1747
class TriangularVariableImpl : public RandomVariableBase
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1748
{
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1749
public:
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1750
  /**
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1751
   * Creates a triangle distribution random number generator in the
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1752
   * range [0.0 .. 1.0), with mean of 0.5
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1753
   */
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1754
  TriangularVariableImpl ();
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1755
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1756
  /**
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1757
   * Creates a triangle distribution random number generator with the specified
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1758
   * range
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1759
   * \param s Low end of the range
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1760
   * \param l High end of the range
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1761
   * \param mean mean of the distribution
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1762
   */
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1763
  TriangularVariableImpl (double s, double l, double mean);
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1764
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1765
  TriangularVariableImpl (const TriangularVariableImpl& c);
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1766
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1767
  /**
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1768
   * \return A value from this distribution
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1769
   */
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1770
  virtual double GetValue ();
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1771
  virtual RandomVariableBase*  Copy (void) const;
4218
debf1a8a96d3 Proposed RNG API changes
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 3679
diff changeset
  1772
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1773
private:
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1774
  double m_min;
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1775
  double m_max;
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1776
  double m_mode;  // easier to work with the mode internally instead of the mean
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1777
                  // they are related by the simple: mean = (min+max+mode)/3
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1778
};
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1779
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1780
TriangularVariableImpl::TriangularVariableImpl ()
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1781
  : m_min (0),
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1782
    m_max (1),
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1783
    m_mode (0.5)
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1784
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
  1785
  NS_LOG_FUNCTION (this);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1786
}
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1787
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1788
TriangularVariableImpl::TriangularVariableImpl (double s, double l, double mean)
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1789
  : m_min (s),
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1790
    m_max (l),
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1791
    m_mode (3.0 * mean - s - l)
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1792
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
  1793
  NS_LOG_FUNCTION (this << s << l << mean);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1794
}
942
b65368bf40f9 Added Triangularly distributed random variables
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 665
diff changeset
  1795
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1796
TriangularVariableImpl::TriangularVariableImpl (const TriangularVariableImpl& c)
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1797
  : RandomVariableBase (c),
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1798
    m_min (c.m_min),
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1799
    m_max (c.m_max),
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1800
    m_mode (c.m_mode)
942
b65368bf40f9 Added Triangularly distributed random variables
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 665
diff changeset
  1801
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
  1802
  NS_LOG_FUNCTION (this << &c);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1803
}
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1804
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1805
double TriangularVariableImpl::GetValue ()
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1806
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
  1807
  NS_LOG_FUNCTION (this);
8871
60846d2741c0 initial patch to fix rng variability
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7003
diff changeset
  1808
  RngStream *generator = GetStream ();
60846d2741c0 initial patch to fix rng variability
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7003
diff changeset
  1809
  double u = generator->RandU01 ();
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1810
  if (u <= (m_mode - m_min) / (m_max - m_min) )
4224
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4223
diff changeset
  1811
    {
9063
32755d0516f4 Bug 1237 - code cleanups related to includes
Vedran Miletić <rivanvx@gmail.com>
parents: 8871
diff changeset
  1812
      return m_min + std::sqrt (u * (m_max - m_min) * (m_mode - m_min) );
4224
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4223
diff changeset
  1813
    }
942
b65368bf40f9 Added Triangularly distributed random variables
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 665
diff changeset
  1814
  else
4224
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4223
diff changeset
  1815
    {
9063
32755d0516f4 Bug 1237 - code cleanups related to includes
Vedran Miletić <rivanvx@gmail.com>
parents: 8871
diff changeset
  1816
      return m_max - std::sqrt ( (1 - u) * (m_max - m_min) * (m_max - m_mode) );
4224
40e5d5af3c71 Commit Mathieu's coding style cleanup of random-variable
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 4223
diff changeset
  1817
    }
942
b65368bf40f9 Added Triangularly distributed random variables
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 665
diff changeset
  1818
}
b65368bf40f9 Added Triangularly distributed random variables
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 665
diff changeset
  1819
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1820
RandomVariableBase* TriangularVariableImpl::Copy () const
942
b65368bf40f9 Added Triangularly distributed random variables
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 665
diff changeset
  1821
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
  1822
  NS_LOG_FUNCTION (this);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1823
  return new TriangularVariableImpl (*this);
942
b65368bf40f9 Added Triangularly distributed random variables
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 665
diff changeset
  1824
}
b65368bf40f9 Added Triangularly distributed random variables
Raj Bhattacharjea <raj.b@gatech.edu>
parents: 665
diff changeset
  1825
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1826
TriangularVariable::TriangularVariable ()
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1827
  : RandomVariable (TriangularVariableImpl ())
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1828
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
  1829
  NS_LOG_FUNCTION (this);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1830
}
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1831
TriangularVariable::TriangularVariable (double s, double l, double mean)
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1832
  : RandomVariable (TriangularVariableImpl (s,l,mean))
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1833
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
  1834
  NS_LOG_FUNCTION (this << s << l << mean);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1835
}
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1836
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1837
// -----------------------------------------------------------------------------
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1838
// -----------------------------------------------------------------------------
4579
c86681050541 New Zipf random variable
Francesco Malandrino <francesco.malandrino@gmail.com>
parents: 4317
diff changeset
  1839
// ZipfVariableImpl
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1840
class ZipfVariableImpl : public RandomVariableBase
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1841
{
4579
c86681050541 New Zipf random variable
Francesco Malandrino <francesco.malandrino@gmail.com>
parents: 4317
diff changeset
  1842
public:
c86681050541 New Zipf random variable
Francesco Malandrino <francesco.malandrino@gmail.com>
parents: 4317
diff changeset
  1843
  /**
c86681050541 New Zipf random variable
Francesco Malandrino <francesco.malandrino@gmail.com>
parents: 4317
diff changeset
  1844
   * \param n the number of possible items
c86681050541 New Zipf random variable
Francesco Malandrino <francesco.malandrino@gmail.com>
parents: 4317
diff changeset
  1845
   * \param alpha the alpha parameter
c86681050541 New Zipf random variable
Francesco Malandrino <francesco.malandrino@gmail.com>
parents: 4317
diff changeset
  1846
   */
c86681050541 New Zipf random variable
Francesco Malandrino <francesco.malandrino@gmail.com>
parents: 4317
diff changeset
  1847
  ZipfVariableImpl (long n, double alpha);
c86681050541 New Zipf random variable
Francesco Malandrino <francesco.malandrino@gmail.com>
parents: 4317
diff changeset
  1848
c86681050541 New Zipf random variable
Francesco Malandrino <francesco.malandrino@gmail.com>
parents: 4317
diff changeset
  1849
  /**
c86681050541 New Zipf random variable
Francesco Malandrino <francesco.malandrino@gmail.com>
parents: 4317
diff changeset
  1850
   * \A zipf variable with N=1 and alpha=0
c86681050541 New Zipf random variable
Francesco Malandrino <francesco.malandrino@gmail.com>
parents: 4317
diff changeset
  1851
   */
c86681050541 New Zipf random variable
Francesco Malandrino <francesco.malandrino@gmail.com>
parents: 4317
diff changeset
  1852
  ZipfVariableImpl ();
c86681050541 New Zipf random variable
Francesco Malandrino <francesco.malandrino@gmail.com>
parents: 4317
diff changeset
  1853
c86681050541 New Zipf random variable
Francesco Malandrino <francesco.malandrino@gmail.com>
parents: 4317
diff changeset
  1854
  /**
c86681050541 New Zipf random variable
Francesco Malandrino <francesco.malandrino@gmail.com>
parents: 4317
diff changeset
  1855
   * \return A random value from this distribution
c86681050541 New Zipf random variable
Francesco Malandrino <francesco.malandrino@gmail.com>
parents: 4317
diff changeset
  1856
   */
c86681050541 New Zipf random variable
Francesco Malandrino <francesco.malandrino@gmail.com>
parents: 4317
diff changeset
  1857
  virtual double GetValue ();
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1858
  virtual RandomVariableBase* Copy (void) const;
4579
c86681050541 New Zipf random variable
Francesco Malandrino <francesco.malandrino@gmail.com>
parents: 4317
diff changeset
  1859
c86681050541 New Zipf random variable
Francesco Malandrino <francesco.malandrino@gmail.com>
parents: 4317
diff changeset
  1860
private:
c86681050541 New Zipf random variable
Francesco Malandrino <francesco.malandrino@gmail.com>
parents: 4317
diff changeset
  1861
  long m_n;
c86681050541 New Zipf random variable
Francesco Malandrino <francesco.malandrino@gmail.com>
parents: 4317
diff changeset
  1862
  double m_alpha;
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1863
  double m_c; // the normalization constant
4579
c86681050541 New Zipf random variable
Francesco Malandrino <francesco.malandrino@gmail.com>
parents: 4317
diff changeset
  1864
};
c86681050541 New Zipf random variable
Francesco Malandrino <francesco.malandrino@gmail.com>
parents: 4317
diff changeset
  1865
c86681050541 New Zipf random variable
Francesco Malandrino <francesco.malandrino@gmail.com>
parents: 4317
diff changeset
  1866
c86681050541 New Zipf random variable
Francesco Malandrino <francesco.malandrino@gmail.com>
parents: 4317
diff changeset
  1867
RandomVariableBase* ZipfVariableImpl::Copy () const
c86681050541 New Zipf random variable
Francesco Malandrino <francesco.malandrino@gmail.com>
parents: 4317
diff changeset
  1868
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
  1869
  NS_LOG_FUNCTION (this);
4579
c86681050541 New Zipf random variable
Francesco Malandrino <francesco.malandrino@gmail.com>
parents: 4317
diff changeset
  1870
  return new ZipfVariableImpl (m_n, m_alpha);
c86681050541 New Zipf random variable
Francesco Malandrino <francesco.malandrino@gmail.com>
parents: 4317
diff changeset
  1871
}
c86681050541 New Zipf random variable
Francesco Malandrino <francesco.malandrino@gmail.com>
parents: 4317
diff changeset
  1872
c86681050541 New Zipf random variable
Francesco Malandrino <francesco.malandrino@gmail.com>
parents: 4317
diff changeset
  1873
ZipfVariableImpl::ZipfVariableImpl ()
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1874
  : m_n (1),
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1875
    m_alpha (0),
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1876
    m_c (1)
4579
c86681050541 New Zipf random variable
Francesco Malandrino <francesco.malandrino@gmail.com>
parents: 4317
diff changeset
  1877
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
  1878
  NS_LOG_FUNCTION (this);
4579
c86681050541 New Zipf random variable
Francesco Malandrino <francesco.malandrino@gmail.com>
parents: 4317
diff changeset
  1879
}
c86681050541 New Zipf random variable
Francesco Malandrino <francesco.malandrino@gmail.com>
parents: 4317
diff changeset
  1880
c86681050541 New Zipf random variable
Francesco Malandrino <francesco.malandrino@gmail.com>
parents: 4317
diff changeset
  1881
c86681050541 New Zipf random variable
Francesco Malandrino <francesco.malandrino@gmail.com>
parents: 4317
diff changeset
  1882
ZipfVariableImpl::ZipfVariableImpl (long n, double alpha)
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1883
  : m_n (n),
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1884
    m_alpha (alpha),
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1885
    m_c (0)
4579
c86681050541 New Zipf random variable
Francesco Malandrino <francesco.malandrino@gmail.com>
parents: 4317
diff changeset
  1886
{
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1887
  // calculate the normalization constant c
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
  1888
  NS_LOG_FUNCTION (this << n << alpha);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1889
  for (int i = 1; i <= n; i++)
4579
c86681050541 New Zipf random variable
Francesco Malandrino <francesco.malandrino@gmail.com>
parents: 4317
diff changeset
  1890
    {
9063
32755d0516f4 Bug 1237 - code cleanups related to includes
Vedran Miletić <rivanvx@gmail.com>
parents: 8871
diff changeset
  1891
      m_c += (1.0 / std::pow ((double)i, alpha));
4579
c86681050541 New Zipf random variable
Francesco Malandrino <francesco.malandrino@gmail.com>
parents: 4317
diff changeset
  1892
    }
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1893
  m_c = 1.0 / m_c;
4579
c86681050541 New Zipf random variable
Francesco Malandrino <francesco.malandrino@gmail.com>
parents: 4317
diff changeset
  1894
}
c86681050541 New Zipf random variable
Francesco Malandrino <francesco.malandrino@gmail.com>
parents: 4317
diff changeset
  1895
c86681050541 New Zipf random variable
Francesco Malandrino <francesco.malandrino@gmail.com>
parents: 4317
diff changeset
  1896
double
c86681050541 New Zipf random variable
Francesco Malandrino <francesco.malandrino@gmail.com>
parents: 4317
diff changeset
  1897
ZipfVariableImpl::GetValue ()
c86681050541 New Zipf random variable
Francesco Malandrino <francesco.malandrino@gmail.com>
parents: 4317
diff changeset
  1898
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
  1899
  NS_LOG_FUNCTION (this);
8871
60846d2741c0 initial patch to fix rng variability
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7003
diff changeset
  1900
  RngStream *generator = GetStream ();
4579
c86681050541 New Zipf random variable
Francesco Malandrino <francesco.malandrino@gmail.com>
parents: 4317
diff changeset
  1901
8871
60846d2741c0 initial patch to fix rng variability
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7003
diff changeset
  1902
  double u = generator->RandU01 ();
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1903
  double sum_prob = 0,zipf_value = 0;
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1904
  for (int i = 1; i <= m_n; i++)
4579
c86681050541 New Zipf random variable
Francesco Malandrino <francesco.malandrino@gmail.com>
parents: 4317
diff changeset
  1905
    {
9063
32755d0516f4 Bug 1237 - code cleanups related to includes
Vedran Miletić <rivanvx@gmail.com>
parents: 8871
diff changeset
  1906
      sum_prob += m_c / std::pow ((double)i, m_alpha);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1907
      if (sum_prob > u)
4579
c86681050541 New Zipf random variable
Francesco Malandrino <francesco.malandrino@gmail.com>
parents: 4317
diff changeset
  1908
        {
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1909
          zipf_value = i;
4579
c86681050541 New Zipf random variable
Francesco Malandrino <francesco.malandrino@gmail.com>
parents: 4317
diff changeset
  1910
          break;
c86681050541 New Zipf random variable
Francesco Malandrino <francesco.malandrino@gmail.com>
parents: 4317
diff changeset
  1911
        }
c86681050541 New Zipf random variable
Francesco Malandrino <francesco.malandrino@gmail.com>
parents: 4317
diff changeset
  1912
    }
c86681050541 New Zipf random variable
Francesco Malandrino <francesco.malandrino@gmail.com>
parents: 4317
diff changeset
  1913
  return zipf_value;
c86681050541 New Zipf random variable
Francesco Malandrino <francesco.malandrino@gmail.com>
parents: 4317
diff changeset
  1914
}
c86681050541 New Zipf random variable
Francesco Malandrino <francesco.malandrino@gmail.com>
parents: 4317
diff changeset
  1915
c86681050541 New Zipf random variable
Francesco Malandrino <francesco.malandrino@gmail.com>
parents: 4317
diff changeset
  1916
ZipfVariable::ZipfVariable ()
c86681050541 New Zipf random variable
Francesco Malandrino <francesco.malandrino@gmail.com>
parents: 4317
diff changeset
  1917
  : RandomVariable (ZipfVariableImpl ())
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1918
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
  1919
  NS_LOG_FUNCTION (this);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1920
}
4579
c86681050541 New Zipf random variable
Francesco Malandrino <francesco.malandrino@gmail.com>
parents: 4317
diff changeset
  1921
c86681050541 New Zipf random variable
Francesco Malandrino <francesco.malandrino@gmail.com>
parents: 4317
diff changeset
  1922
ZipfVariable::ZipfVariable (long n, double alpha)
c86681050541 New Zipf random variable
Francesco Malandrino <francesco.malandrino@gmail.com>
parents: 4317
diff changeset
  1923
  : RandomVariable (ZipfVariableImpl (n, alpha))
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1924
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
  1925
  NS_LOG_FUNCTION (this << n << alpha);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1926
}
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1927
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1928
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1929
// -----------------------------------------------------------------------------
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1930
// -----------------------------------------------------------------------------
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1931
// ZetaVariableImpl
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1932
class ZetaVariableImpl : public RandomVariableBase
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1933
{
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1934
public:
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1935
  /**
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1936
   * \param alpha the alpha parameter
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1937
   */
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1938
  ZetaVariableImpl (double alpha);
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1939
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1940
  /**
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1941
   * \A zipf variable with alpha=1.1
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1942
   */
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1943
  ZetaVariableImpl ();
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1944
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1945
  /**
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1946
   * \return A random value from this distribution
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1947
   */
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1948
  virtual double GetValue ();
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1949
  virtual RandomVariableBase* Copy (void) const;
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1950
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1951
private:
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1952
  double m_alpha;
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1953
  double m_b; // just for calculus simplifications
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1954
};
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1955
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1956
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1957
RandomVariableBase* ZetaVariableImpl::Copy () const
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1958
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
  1959
  NS_LOG_FUNCTION (this);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1960
  return new ZetaVariableImpl (m_alpha);
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1961
}
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1962
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1963
ZetaVariableImpl::ZetaVariableImpl ()
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1964
  : m_alpha (3.14),
9063
32755d0516f4 Bug 1237 - code cleanups related to includes
Vedran Miletić <rivanvx@gmail.com>
parents: 8871
diff changeset
  1965
    m_b (std::pow (2.0, 2.14))
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1966
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
  1967
  NS_LOG_FUNCTION (this);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1968
}
4579
c86681050541 New Zipf random variable
Francesco Malandrino <francesco.malandrino@gmail.com>
parents: 4317
diff changeset
  1969
2336
28ce210b91bb bug 133: automate RandomVariable memory management.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1811
diff changeset
  1970
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1971
ZetaVariableImpl::ZetaVariableImpl (double alpha)
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1972
  : m_alpha (alpha),
9063
32755d0516f4 Bug 1237 - code cleanups related to includes
Vedran Miletić <rivanvx@gmail.com>
parents: 8871
diff changeset
  1973
    m_b (std::pow (2.0, alpha - 1.0))
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1974
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
  1975
  NS_LOG_FUNCTION (this << alpha);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1976
}
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1977
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1978
/*
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1979
 The code for the following generator functions is borrowed from:
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1980
 L. Devroye: Non-Uniform Random Variate Generation, Springer-Verlag, New York, 1986.
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1981
 page 551
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1982
 */
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1983
double
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1984
ZetaVariableImpl::GetValue ()
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1985
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
  1986
  NS_LOG_FUNCTION (this);
8871
60846d2741c0 initial patch to fix rng variability
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7003
diff changeset
  1987
  RngStream *generator = GetStream ();
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1988
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1989
  double u, v;
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1990
  double X, T;
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1991
  double test;
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1992
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1993
  do
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1994
    {
8871
60846d2741c0 initial patch to fix rng variability
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7003
diff changeset
  1995
      u = generator->RandU01 ();
60846d2741c0 initial patch to fix rng variability
Mathieu Lacage <mathieu.lacage@cutebugs.net>
parents: 7003
diff changeset
  1996
      v = generator->RandU01 ();
9063
32755d0516f4 Bug 1237 - code cleanups related to includes
Vedran Miletić <rivanvx@gmail.com>
parents: 8871
diff changeset
  1997
      X = floor (std::pow (u, -1.0 / (m_alpha - 1.0)));
32755d0516f4 Bug 1237 - code cleanups related to includes
Vedran Miletić <rivanvx@gmail.com>
parents: 8871
diff changeset
  1998
      T = std::pow (1.0 + 1.0 / X, m_alpha - 1.0);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  1999
      test = v * X * (T - 1.0) / (m_b - 1.0);
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  2000
    }
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  2001
  while ( test > (T / m_b) );
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  2002
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  2003
  return X;
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  2004
}
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  2005
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  2006
ZetaVariable::ZetaVariable ()
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  2007
  : RandomVariable (ZetaVariableImpl ())
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  2008
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
  2009
  NS_LOG_FUNCTION (this);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  2010
}
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  2011
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  2012
ZetaVariable::ZetaVariable (double alpha)
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  2013
  : RandomVariable (ZetaVariableImpl (alpha))
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  2014
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
  2015
  NS_LOG_FUNCTION (this << alpha);
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  2016
}
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  2017
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  2018
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  2019
std::ostream & operator << (std::ostream &os, const RandomVariable &var)
2384
500ada6a4874 add Value support to RandomVariable.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2336
diff changeset
  2020
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
  2021
  NS_LOG_FUNCTION (&os << &var);
2409
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2384
diff changeset
  2022
  RandomVariableBase *base = var.Peek ();
2384
500ada6a4874 add Value support to RandomVariable.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2336
diff changeset
  2023
  ConstantVariableImpl *constant = dynamic_cast<ConstantVariableImpl *> (base);
500ada6a4874 add Value support to RandomVariable.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2336
diff changeset
  2024
  if (constant != 0)
500ada6a4874 add Value support to RandomVariable.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2336
diff changeset
  2025
    {
2409
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2384
diff changeset
  2026
      os << "Constant:" << constant->GetValue ();
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2384
diff changeset
  2027
      return os;
2384
500ada6a4874 add Value support to RandomVariable.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2336
diff changeset
  2028
    }
500ada6a4874 add Value support to RandomVariable.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2336
diff changeset
  2029
  UniformVariableImpl *uniform = dynamic_cast<UniformVariableImpl *> (base);
500ada6a4874 add Value support to RandomVariable.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2336
diff changeset
  2030
  if (uniform != 0)
500ada6a4874 add Value support to RandomVariable.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2336
diff changeset
  2031
    {
2409
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2384
diff changeset
  2032
      os << "Uniform:" << uniform->GetMin () << ":" << uniform->GetMax ();
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2384
diff changeset
  2033
      return os;
2384
500ada6a4874 add Value support to RandomVariable.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2336
diff changeset
  2034
    }
4249
c2d4a91bcc8a Bug 485: implement deserialization of normal/gaussian random variables
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4243
diff changeset
  2035
  NormalVariableImpl *normal = dynamic_cast<NormalVariableImpl *> (base);
c2d4a91bcc8a Bug 485: implement deserialization of normal/gaussian random variables
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4243
diff changeset
  2036
  if (normal != 0)
c2d4a91bcc8a Bug 485: implement deserialization of normal/gaussian random variables
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4243
diff changeset
  2037
    {
c2d4a91bcc8a Bug 485: implement deserialization of normal/gaussian random variables
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4243
diff changeset
  2038
      os << "Normal:" << normal->GetMean () << ":" << normal->GetVariance ();
c2d4a91bcc8a Bug 485: implement deserialization of normal/gaussian random variables
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4243
diff changeset
  2039
      double bound = normal->GetBound ();
c2d4a91bcc8a Bug 485: implement deserialization of normal/gaussian random variables
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4243
diff changeset
  2040
      if (bound != NormalVariableImpl::INFINITE_VALUE)
c2d4a91bcc8a Bug 485: implement deserialization of normal/gaussian random variables
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4243
diff changeset
  2041
        {
c2d4a91bcc8a Bug 485: implement deserialization of normal/gaussian random variables
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4243
diff changeset
  2042
          os << ":" << bound;
c2d4a91bcc8a Bug 485: implement deserialization of normal/gaussian random variables
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4243
diff changeset
  2043
        }
c2d4a91bcc8a Bug 485: implement deserialization of normal/gaussian random variables
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4243
diff changeset
  2044
      return os;
c2d4a91bcc8a Bug 485: implement deserialization of normal/gaussian random variables
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4243
diff changeset
  2045
    }
2384
500ada6a4874 add Value support to RandomVariable.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2336
diff changeset
  2046
  // XXX: support other distributions
2409
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2384
diff changeset
  2047
  os.setstate (std::ios_base::badbit);
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2384
diff changeset
  2048
  return os;
2384
500ada6a4874 add Value support to RandomVariable.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2336
diff changeset
  2049
}
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  2050
std::istream & operator >> (std::istream &is, RandomVariable &var)
2384
500ada6a4874 add Value support to RandomVariable.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2336
diff changeset
  2051
{
9134
7a750f032acd Clean up function logging of core module.
Maja Grubišić <maja.grubisic@live.com>
parents: 9063
diff changeset
  2052
  NS_LOG_FUNCTION (&is << &var);
2409
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2384
diff changeset
  2053
  std::string value;
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2384
diff changeset
  2054
  is >> value;
2384
500ada6a4874 add Value support to RandomVariable.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2336
diff changeset
  2055
  std::string::size_type tmp;
500ada6a4874 add Value support to RandomVariable.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2336
diff changeset
  2056
  tmp = value.find (":");
500ada6a4874 add Value support to RandomVariable.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2336
diff changeset
  2057
  if (tmp == std::string::npos)
500ada6a4874 add Value support to RandomVariable.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2336
diff changeset
  2058
    {
2409
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2384
diff changeset
  2059
      is.setstate (std::ios_base::badbit);
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2384
diff changeset
  2060
      return is;
2384
500ada6a4874 add Value support to RandomVariable.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2336
diff changeset
  2061
    }
500ada6a4874 add Value support to RandomVariable.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2336
diff changeset
  2062
  std::string type = value.substr (0, tmp);
2628
88cdcd394491 Fix deserialization for Constant and Uniform random variables.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2445
diff changeset
  2063
  value = value.substr (tmp + 1, value.npos);
88cdcd394491 Fix deserialization for Constant and Uniform random variables.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2445
diff changeset
  2064
  if (type == "Constant")
2384
500ada6a4874 add Value support to RandomVariable.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2336
diff changeset
  2065
    {
9063
32755d0516f4 Bug 1237 - code cleanups related to includes
Vedran Miletić <rivanvx@gmail.com>
parents: 8871
diff changeset
  2066
      std::istringstream iss (value);
2628
88cdcd394491 Fix deserialization for Constant and Uniform random variables.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2445
diff changeset
  2067
      double constant;
88cdcd394491 Fix deserialization for Constant and Uniform random variables.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2445
diff changeset
  2068
      iss >> constant;
88cdcd394491 Fix deserialization for Constant and Uniform random variables.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2445
diff changeset
  2069
      var = ConstantVariable (constant);
2384
500ada6a4874 add Value support to RandomVariable.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2336
diff changeset
  2070
    }
2628
88cdcd394491 Fix deserialization for Constant and Uniform random variables.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2445
diff changeset
  2071
  else if (type == "Uniform")
2384
500ada6a4874 add Value support to RandomVariable.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2336
diff changeset
  2072
    {
2628
88cdcd394491 Fix deserialization for Constant and Uniform random variables.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2445
diff changeset
  2073
      if (value.size () == 0)
88cdcd394491 Fix deserialization for Constant and Uniform random variables.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2445
diff changeset
  2074
        {
88cdcd394491 Fix deserialization for Constant and Uniform random variables.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2445
diff changeset
  2075
          var = UniformVariable ();
88cdcd394491 Fix deserialization for Constant and Uniform random variables.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2445
diff changeset
  2076
        }
88cdcd394491 Fix deserialization for Constant and Uniform random variables.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2445
diff changeset
  2077
      else
88cdcd394491 Fix deserialization for Constant and Uniform random variables.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2445
diff changeset
  2078
        {
88cdcd394491 Fix deserialization for Constant and Uniform random variables.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2445
diff changeset
  2079
          tmp = value.find (":");
88cdcd394491 Fix deserialization for Constant and Uniform random variables.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2445
diff changeset
  2080
          if (tmp == value.npos)
88cdcd394491 Fix deserialization for Constant and Uniform random variables.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2445
diff changeset
  2081
            {
88cdcd394491 Fix deserialization for Constant and Uniform random variables.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2445
diff changeset
  2082
              NS_FATAL_ERROR ("bad Uniform value: " << value);
88cdcd394491 Fix deserialization for Constant and Uniform random variables.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2445
diff changeset
  2083
            }
9063
32755d0516f4 Bug 1237 - code cleanups related to includes
Vedran Miletić <rivanvx@gmail.com>
parents: 8871
diff changeset
  2084
          std::istringstream issA (value.substr (0, tmp));
32755d0516f4 Bug 1237 - code cleanups related to includes
Vedran Miletić <rivanvx@gmail.com>
parents: 8871
diff changeset
  2085
          std::istringstream issB (value.substr (tmp + 1, value.npos));
2628
88cdcd394491 Fix deserialization for Constant and Uniform random variables.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2445
diff changeset
  2086
          double a, b;
88cdcd394491 Fix deserialization for Constant and Uniform random variables.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2445
diff changeset
  2087
          issA >> a;
88cdcd394491 Fix deserialization for Constant and Uniform random variables.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2445
diff changeset
  2088
          issB >> b;
88cdcd394491 Fix deserialization for Constant and Uniform random variables.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2445
diff changeset
  2089
          var = UniformVariable (a, b);
88cdcd394491 Fix deserialization for Constant and Uniform random variables.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2445
diff changeset
  2090
        }
2384
500ada6a4874 add Value support to RandomVariable.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2336
diff changeset
  2091
    }
4249
c2d4a91bcc8a Bug 485: implement deserialization of normal/gaussian random variables
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4243
diff changeset
  2092
  else if (type == "Normal")
c2d4a91bcc8a Bug 485: implement deserialization of normal/gaussian random variables
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4243
diff changeset
  2093
    {
c2d4a91bcc8a Bug 485: implement deserialization of normal/gaussian random variables
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4243
diff changeset
  2094
      if (value.size () == 0)
c2d4a91bcc8a Bug 485: implement deserialization of normal/gaussian random variables
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4243
diff changeset
  2095
        {
c2d4a91bcc8a Bug 485: implement deserialization of normal/gaussian random variables
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4243
diff changeset
  2096
          var = NormalVariable ();
c2d4a91bcc8a Bug 485: implement deserialization of normal/gaussian random variables
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4243
diff changeset
  2097
        }
c2d4a91bcc8a Bug 485: implement deserialization of normal/gaussian random variables
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4243
diff changeset
  2098
      else
c2d4a91bcc8a Bug 485: implement deserialization of normal/gaussian random variables
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4243
diff changeset
  2099
        {
c2d4a91bcc8a Bug 485: implement deserialization of normal/gaussian random variables
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4243
diff changeset
  2100
          tmp = value.find (":");
c2d4a91bcc8a Bug 485: implement deserialization of normal/gaussian random variables
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4243
diff changeset
  2101
          if (tmp == value.npos)
c2d4a91bcc8a Bug 485: implement deserialization of normal/gaussian random variables
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4243
diff changeset
  2102
            {
c2d4a91bcc8a Bug 485: implement deserialization of normal/gaussian random variables
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4243
diff changeset
  2103
              NS_FATAL_ERROR ("bad Normal value: " << value);
c2d4a91bcc8a Bug 485: implement deserialization of normal/gaussian random variables
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4243
diff changeset
  2104
            }
c2d4a91bcc8a Bug 485: implement deserialization of normal/gaussian random variables
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4243
diff changeset
  2105
          std::string::size_type tmp2;
c2d4a91bcc8a Bug 485: implement deserialization of normal/gaussian random variables
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4243
diff changeset
  2106
          std::string sub = value.substr (tmp + 1, value.npos);
c2d4a91bcc8a Bug 485: implement deserialization of normal/gaussian random variables
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4243
diff changeset
  2107
          tmp2 = sub.find (":");
c2d4a91bcc8a Bug 485: implement deserialization of normal/gaussian random variables
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4243
diff changeset
  2108
          if (tmp2 == value.npos)
c2d4a91bcc8a Bug 485: implement deserialization of normal/gaussian random variables
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4243
diff changeset
  2109
            {
9063
32755d0516f4 Bug 1237 - code cleanups related to includes
Vedran Miletić <rivanvx@gmail.com>
parents: 8871
diff changeset
  2110
              std::istringstream issA (value.substr (0, tmp));
32755d0516f4 Bug 1237 - code cleanups related to includes
Vedran Miletić <rivanvx@gmail.com>
parents: 8871
diff changeset
  2111
              std::istringstream issB (sub);
4249
c2d4a91bcc8a Bug 485: implement deserialization of normal/gaussian random variables
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4243
diff changeset
  2112
              double a, b;
c2d4a91bcc8a Bug 485: implement deserialization of normal/gaussian random variables
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4243
diff changeset
  2113
              issA >> a;
c2d4a91bcc8a Bug 485: implement deserialization of normal/gaussian random variables
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4243
diff changeset
  2114
              issB >> b;
c2d4a91bcc8a Bug 485: implement deserialization of normal/gaussian random variables
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4243
diff changeset
  2115
              var = NormalVariable (a, b);
c2d4a91bcc8a Bug 485: implement deserialization of normal/gaussian random variables
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4243
diff changeset
  2116
            }
c2d4a91bcc8a Bug 485: implement deserialization of normal/gaussian random variables
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4243
diff changeset
  2117
          else
c2d4a91bcc8a Bug 485: implement deserialization of normal/gaussian random variables
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4243
diff changeset
  2118
            {
9063
32755d0516f4 Bug 1237 - code cleanups related to includes
Vedran Miletić <rivanvx@gmail.com>
parents: 8871
diff changeset
  2119
              std::istringstream issA (value.substr (0, tmp));
32755d0516f4 Bug 1237 - code cleanups related to includes
Vedran Miletić <rivanvx@gmail.com>
parents: 8871
diff changeset
  2120
              std::istringstream issB (sub.substr (0, tmp2));
32755d0516f4 Bug 1237 - code cleanups related to includes
Vedran Miletić <rivanvx@gmail.com>
parents: 8871
diff changeset
  2121
              std::istringstream issC (sub.substr (tmp2 + 1, value.npos));
4249
c2d4a91bcc8a Bug 485: implement deserialization of normal/gaussian random variables
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4243
diff changeset
  2122
              double a, b, c;
c2d4a91bcc8a Bug 485: implement deserialization of normal/gaussian random variables
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4243
diff changeset
  2123
              issA >> a;
c2d4a91bcc8a Bug 485: implement deserialization of normal/gaussian random variables
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4243
diff changeset
  2124
              issB >> b;
c2d4a91bcc8a Bug 485: implement deserialization of normal/gaussian random variables
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4243
diff changeset
  2125
              issC >> c;
c2d4a91bcc8a Bug 485: implement deserialization of normal/gaussian random variables
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4243
diff changeset
  2126
              var = NormalVariable (a, b, c);
c2d4a91bcc8a Bug 485: implement deserialization of normal/gaussian random variables
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4243
diff changeset
  2127
            }
c2d4a91bcc8a Bug 485: implement deserialization of normal/gaussian random variables
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4243
diff changeset
  2128
        }
c2d4a91bcc8a Bug 485: implement deserialization of normal/gaussian random variables
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4243
diff changeset
  2129
    }
2409
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2384
diff changeset
  2130
  else
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2384
diff changeset
  2131
    {
2628
88cdcd394491 Fix deserialization for Constant and Uniform random variables.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2445
diff changeset
  2132
      NS_FATAL_ERROR ("RandomVariable deserialization not implemented for " << type);
2409
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2384
diff changeset
  2133
      // XXX: support other distributions.
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2384
diff changeset
  2134
    }
8744ec60e8e6 convert RandomVariable, Rectangle, Vector, and Time to the new Class Helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2384
diff changeset
  2135
  return is;
2384
500ada6a4874 add Value support to RandomVariable.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2336
diff changeset
  2136
}
500ada6a4874 add Value support to RandomVariable.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 2336
diff changeset
  2137
5969
68bd5111f38c random-variable - doc updated and new Zeta distribution
Tommaso Pecorella <tommaso.pecorella@unifi.it>
parents: 5299
diff changeset
  2138
} // namespace ns3