src/wifi/model/random-stream.h
author Stefano Avallone <stefano.avallone@unina.it>
Fri, 05 Sep 2014 16:33:57 -0700
changeset 10883 d919e7194e23
parent 10483 e3a02ed14587
child 11450 9f4ae69f12b7
permissions -rw-r--r--
add support for a Wifi sleep mode
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7385
10beb0e53130 standardize emacs c++ mode comments
Vedran Miletić <rivanvx@gmail.com>
parents: 7141
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
1967
5d75cfed946a add wrapper class around RngStream for testing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     2
/*
5d75cfed946a add wrapper class around RngStream for testing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     3
 * Copyright (c) 2007 INRIA
5d75cfed946a add wrapper class around RngStream for testing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     4
 *
5d75cfed946a add wrapper class around RngStream for testing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
7141
072fb225b714 run check-style.py on src/wifi
Nicola Baldo <nicola@baldo.biz>
parents: 6852
diff changeset
     6
 * it under the terms of the GNU General Public License version 2 as
1967
5d75cfed946a add wrapper class around RngStream for testing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     7
 * published by the Free Software Foundation;
5d75cfed946a add wrapper class around RngStream for testing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     8
 *
5d75cfed946a add wrapper class around RngStream for testing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
5d75cfed946a add wrapper class around RngStream for testing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
5d75cfed946a add wrapper class around RngStream for testing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
5d75cfed946a add wrapper class around RngStream for testing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    12
 * GNU General Public License for more details.
5d75cfed946a add wrapper class around RngStream for testing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    13
 *
5d75cfed946a add wrapper class around RngStream for testing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
5d75cfed946a add wrapper class around RngStream for testing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
5d75cfed946a add wrapper class around RngStream for testing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
5d75cfed946a add wrapper class around RngStream for testing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    17
 *
5d75cfed946a add wrapper class around RngStream for testing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    18
 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
5d75cfed946a add wrapper class around RngStream for testing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    19
 */
5d75cfed946a add wrapper class around RngStream for testing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    20
#ifndef RANDOM_STREAM_H
5d75cfed946a add wrapper class around RngStream for testing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    21
#define RANDOM_STREAM_H
5d75cfed946a add wrapper class around RngStream for testing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    22
5d75cfed946a add wrapper class around RngStream for testing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    23
#include <stdint.h>
5d75cfed946a add wrapper class around RngStream for testing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    24
#include <list>
8981
7e1c95c4d1a7 Replace src/wifi usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 7385
diff changeset
    25
#include "ns3/random-variable-stream.h"
1967
5d75cfed946a add wrapper class around RngStream for testing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    26
5d75cfed946a add wrapper class around RngStream for testing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    27
namespace ns3 {
5d75cfed946a add wrapper class around RngStream for testing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    28
5d75cfed946a add wrapper class around RngStream for testing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    29
/**
7141
072fb225b714 run check-style.py on src/wifi
Nicola Baldo <nicola@baldo.biz>
parents: 6852
diff changeset
    30
 * A simple wrapper around RngStream to make testing
1967
5d75cfed946a add wrapper class around RngStream for testing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    31
 * of the code easier.
5d75cfed946a add wrapper class around RngStream for testing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    32
 */
5d75cfed946a add wrapper class around RngStream for testing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    33
class RandomStream
5d75cfed946a add wrapper class around RngStream for testing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    34
{
5d75cfed946a add wrapper class around RngStream for testing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    35
public:
5d75cfed946a add wrapper class around RngStream for testing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    36
  virtual ~RandomStream ();
10483
e3a02ed14587 [doxygen] wifi module
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 8981
diff changeset
    37
  /**
e3a02ed14587 [doxygen] wifi module
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 8981
diff changeset
    38
   * Get integer between min and max (including min and max).
e3a02ed14587 [doxygen] wifi module
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 8981
diff changeset
    39
   *
e3a02ed14587 [doxygen] wifi module
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 8981
diff changeset
    40
   * \param min lower bound (inclusive)
e3a02ed14587 [doxygen] wifi module
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 8981
diff changeset
    41
   * \param max upper bound (inclusive)
e3a02ed14587 [doxygen] wifi module
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 8981
diff changeset
    42
   * \return a random number between min and max (including min and max)
e3a02ed14587 [doxygen] wifi module
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 8981
diff changeset
    43
   */
1967
5d75cfed946a add wrapper class around RngStream for testing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    44
  virtual uint32_t GetNext (uint32_t min, uint32_t max) = 0;
8981
7e1c95c4d1a7 Replace src/wifi usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 7385
diff changeset
    45
7e1c95c4d1a7 Replace src/wifi usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 7385
diff changeset
    46
 /**
7e1c95c4d1a7 Replace src/wifi usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 7385
diff changeset
    47
  * Assign a fixed random variable stream number to the random variables
7e1c95c4d1a7 Replace src/wifi usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 7385
diff changeset
    48
  * used by this model.  Return the number of streams (possibly zero) that
7e1c95c4d1a7 Replace src/wifi usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 7385
diff changeset
    49
  * have been assigned.
7e1c95c4d1a7 Replace src/wifi usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 7385
diff changeset
    50
  *
7e1c95c4d1a7 Replace src/wifi usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 7385
diff changeset
    51
  * \param stream first stream index to use
7e1c95c4d1a7 Replace src/wifi usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 7385
diff changeset
    52
  * \return the number of stream indices assigned by this model
7e1c95c4d1a7 Replace src/wifi usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 7385
diff changeset
    53
  */
7e1c95c4d1a7 Replace src/wifi usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 7385
diff changeset
    54
  virtual int64_t AssignStreams (int64_t stream) = 0;
1967
5d75cfed946a add wrapper class around RngStream for testing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    55
};
5d75cfed946a add wrapper class around RngStream for testing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    56
5d75cfed946a add wrapper class around RngStream for testing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    57
class RealRandomStream : public RandomStream
5d75cfed946a add wrapper class around RngStream for testing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    58
{
5d75cfed946a add wrapper class around RngStream for testing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    59
public:
5d75cfed946a add wrapper class around RngStream for testing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    60
  RealRandomStream ();
5d75cfed946a add wrapper class around RngStream for testing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    61
  virtual uint32_t GetNext (uint32_t min, uint32_t max);
8981
7e1c95c4d1a7 Replace src/wifi usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 7385
diff changeset
    62
7e1c95c4d1a7 Replace src/wifi usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 7385
diff changeset
    63
 /**
7e1c95c4d1a7 Replace src/wifi usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 7385
diff changeset
    64
  * Assign a fixed random variable stream number to the random variables
7e1c95c4d1a7 Replace src/wifi usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 7385
diff changeset
    65
  * used by this model.  Return the number of streams (possibly zero) that
7e1c95c4d1a7 Replace src/wifi usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 7385
diff changeset
    66
  * have been assigned.
7e1c95c4d1a7 Replace src/wifi usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 7385
diff changeset
    67
  *
7e1c95c4d1a7 Replace src/wifi usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 7385
diff changeset
    68
  * \param stream first stream index to use
7e1c95c4d1a7 Replace src/wifi usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 7385
diff changeset
    69
  * \return the number of stream indices assigned by this model
7e1c95c4d1a7 Replace src/wifi usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 7385
diff changeset
    70
  */
7e1c95c4d1a7 Replace src/wifi usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 7385
diff changeset
    71
  virtual int64_t AssignStreams (int64_t stream);
7e1c95c4d1a7 Replace src/wifi usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 7385
diff changeset
    72
1967
5d75cfed946a add wrapper class around RngStream for testing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    73
private:
8981
7e1c95c4d1a7 Replace src/wifi usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 7385
diff changeset
    74
  /// Provides uniform random variables.
7e1c95c4d1a7 Replace src/wifi usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 7385
diff changeset
    75
  Ptr<UniformRandomVariable> m_stream;
1967
5d75cfed946a add wrapper class around RngStream for testing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    76
};
5d75cfed946a add wrapper class around RngStream for testing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    77
5d75cfed946a add wrapper class around RngStream for testing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    78
class TestRandomStream : public RandomStream
5d75cfed946a add wrapper class around RngStream for testing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    79
{
5d75cfed946a add wrapper class around RngStream for testing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    80
public:
10483
e3a02ed14587 [doxygen] wifi module
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 8981
diff changeset
    81
  /**
e3a02ed14587 [doxygen] wifi module
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 8981
diff changeset
    82
   * Add the given value to the list.
e3a02ed14587 [doxygen] wifi module
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 8981
diff changeset
    83
   *
e3a02ed14587 [doxygen] wifi module
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 8981
diff changeset
    84
   * \param v
e3a02ed14587 [doxygen] wifi module
Daniel Lertpratchya <nikkipui@gmail.com>
parents: 8981
diff changeset
    85
   */
1967
5d75cfed946a add wrapper class around RngStream for testing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    86
  void AddNext (uint32_t v);
5d75cfed946a add wrapper class around RngStream for testing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    87
  virtual uint32_t GetNext (uint32_t min, uint32_t max);
8981
7e1c95c4d1a7 Replace src/wifi usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 7385
diff changeset
    88
7e1c95c4d1a7 Replace src/wifi usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 7385
diff changeset
    89
 /**
7e1c95c4d1a7 Replace src/wifi usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 7385
diff changeset
    90
  * Assign a fixed random variable stream number to the random variables
7e1c95c4d1a7 Replace src/wifi usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 7385
diff changeset
    91
  * used by this model.  Return the number of streams (possibly zero) that
7e1c95c4d1a7 Replace src/wifi usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 7385
diff changeset
    92
  * have been assigned.
7e1c95c4d1a7 Replace src/wifi usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 7385
diff changeset
    93
  *
7e1c95c4d1a7 Replace src/wifi usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 7385
diff changeset
    94
  * \param stream first stream index to use
7e1c95c4d1a7 Replace src/wifi usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 7385
diff changeset
    95
  * \return the number of stream indices assigned by this model
7e1c95c4d1a7 Replace src/wifi usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 7385
diff changeset
    96
  */
7e1c95c4d1a7 Replace src/wifi usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 7385
diff changeset
    97
  virtual int64_t AssignStreams (int64_t stream);
7e1c95c4d1a7 Replace src/wifi usage of RandomVariable with RandomVariableStream
Mitch Watrous
parents: 7385
diff changeset
    98
1967
5d75cfed946a add wrapper class around RngStream for testing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    99
private:
5d75cfed946a add wrapper class around RngStream for testing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   100
  std::list<uint32_t> m_nexts;
5d75cfed946a add wrapper class around RngStream for testing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   101
};
5d75cfed946a add wrapper class around RngStream for testing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   102
5d75cfed946a add wrapper class around RngStream for testing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   103
} // namespace ns3
5d75cfed946a add wrapper class around RngStream for testing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   104
5d75cfed946a add wrapper class around RngStream for testing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   105
#endif /* RANDOM_STREAM_H */