src/mobility/model/position-allocator.cc
changeset 8983 91d4c78133a8
parent 7385 10beb0e53130
child 8984 85eed149a0ea
--- a/src/mobility/model/position-allocator.cc	Tue Aug 14 14:11:29 2012 -0700
+++ b/src/mobility/model/position-allocator.cc	Wed Aug 15 14:28:33 2012 -0700
@@ -18,8 +18,9 @@
  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
  */
 #include "position-allocator.h"
-#include "ns3/random-variable.h"
 #include "ns3/double.h"
+#include "ns3/string.h"
+#include "ns3/pointer.h"
 #include "ns3/uinteger.h"
 #include "ns3/enum.h"
 #include "ns3/log.h"
@@ -213,14 +214,14 @@
     .AddConstructor<RandomRectanglePositionAllocator> ()
     .AddAttribute ("X",
                    "A random variable which represents the x coordinate of a position in a random rectangle.",
-                   RandomVariableValue (UniformVariable (0.0, 1.0)),
-                   MakeRandomVariableAccessor (&RandomRectanglePositionAllocator::m_x),
-                   MakeRandomVariableChecker ())
+                   StringValue ("ns3::UniformRandomVariable[Min=0.0|Max=1.0]"),
+                   MakePointerAccessor (&RandomRectanglePositionAllocator::m_x),
+                   MakePointerChecker<RandomVariableStream> ())
     .AddAttribute ("Y",
                    "A random variable which represents the y coordinate of a position in a random rectangle.",
-                   RandomVariableValue (UniformVariable (0.0, 1.0)),
-                   MakeRandomVariableAccessor (&RandomRectanglePositionAllocator::m_y),
-                   MakeRandomVariableChecker ());
+                   StringValue ("ns3::UniformRandomVariable[Min=0.0|Max=1.0]"),
+                   MakePointerAccessor (&RandomRectanglePositionAllocator::m_y),
+                   MakePointerChecker<RandomVariableStream> ());
   return tid;
 }
 
@@ -232,12 +233,12 @@
 }
 
 void
-RandomRectanglePositionAllocator::SetX (RandomVariable x)
+RandomRectanglePositionAllocator::SetX (Ptr<RandomVariableStream> x)
 {
   m_x = x;
 }
 void
-RandomRectanglePositionAllocator::SetY (RandomVariable y)
+RandomRectanglePositionAllocator::SetY (Ptr<RandomVariableStream> y)
 {
   m_y = y;
 }
@@ -245,8 +246,8 @@
 Vector
 RandomRectanglePositionAllocator::GetNext (void) const
 {
-  double x = m_x.GetValue ();
-  double y = m_y.GetValue ();
+  double x = m_x->GetValue ();
+  double y = m_y->GetValue ();
   return Vector (x, y, 0.0);
 }
 
@@ -262,19 +263,19 @@
     .AddConstructor<RandomBoxPositionAllocator> ()
     .AddAttribute ("X",
                    "A random variable which represents the x coordinate of a position in a random box.",
-                   RandomVariableValue (UniformVariable (0.0, 1.0)),
-                   MakeRandomVariableAccessor (&RandomBoxPositionAllocator::m_x),
-                   MakeRandomVariableChecker ())
+                   StringValue ("ns3::UniformRandomVariable[Min=0.0|Max=1.0]"),
+                   MakePointerAccessor (&RandomBoxPositionAllocator::m_x),
+                   MakePointerChecker<RandomVariableStream> ())
     .AddAttribute ("Y",
                    "A random variable which represents the y coordinate of a position in a random box.",
-                   RandomVariableValue (UniformVariable (0.0, 1.0)),
-                   MakeRandomVariableAccessor (&RandomBoxPositionAllocator::m_y),
-                   MakeRandomVariableChecker ())
+                   StringValue ("ns3::UniformRandomVariable[Min=0.0|Max=1.0]"),
+                   MakePointerAccessor (&RandomBoxPositionAllocator::m_y),
+                   MakePointerChecker<RandomVariableStream> ())
     .AddAttribute ("Z",
                    "A random variable which represents the z coordinate of a position in a random box.",
-                   RandomVariableValue (UniformVariable (0.0, 1.0)),
-                   MakeRandomVariableAccessor (&RandomBoxPositionAllocator::m_z),
-                   MakeRandomVariableChecker ());
+                   StringValue ("ns3::UniformRandomVariable[Min=0.0|Max=1.0]"),
+                   MakePointerAccessor (&RandomBoxPositionAllocator::m_z),
+                   MakePointerChecker<RandomVariableStream> ());
   return tid;
 }
 
@@ -286,17 +287,17 @@
 }
 
 void
-RandomBoxPositionAllocator::SetX (RandomVariable x)
+RandomBoxPositionAllocator::SetX (Ptr<RandomVariableStream> x)
 {
   m_x = x;
 }
 void
-RandomBoxPositionAllocator::SetY (RandomVariable y)
+RandomBoxPositionAllocator::SetY (Ptr<RandomVariableStream> y)
 {
   m_y = y;
 }
 void
-RandomBoxPositionAllocator::SetZ (RandomVariable z)
+RandomBoxPositionAllocator::SetZ (Ptr<RandomVariableStream> z)
 {
   m_z = z;
 }
@@ -304,9 +305,9 @@
 Vector
 RandomBoxPositionAllocator::GetNext (void) const
 {
-  double x = m_x.GetValue ();
-  double y = m_y.GetValue ();
-  double z = m_z.GetValue ();
+  double x = m_x->GetValue ();
+  double y = m_y->GetValue ();
+  double z = m_z->GetValue ();
   return Vector (x, y, z);
 }
 
@@ -323,14 +324,14 @@
     .AddConstructor<RandomDiscPositionAllocator> ()
     .AddAttribute ("Theta",
                    "A random variable which represents the angle (gradients) of a position in a random disc.",
-                   RandomVariableValue (UniformVariable (0.0, 6.2830)),
-                   MakeRandomVariableAccessor (&RandomDiscPositionAllocator::m_theta),
-                   MakeRandomVariableChecker ())
+                   StringValue ("ns3::UniformRandomVariable[Min=0.0|Max=6.2830]"),
+                   MakePointerAccessor (&RandomDiscPositionAllocator::m_theta),
+                   MakePointerChecker<RandomVariableStream> ())
     .AddAttribute ("Rho",
                    "A random variable which represents the radius of a position in a random disc.",
-                   RandomVariableValue (UniformVariable (0.0, 200.0)),
-                   MakeRandomVariableAccessor (&RandomDiscPositionAllocator::m_rho),
-                   MakeRandomVariableChecker ())
+                   StringValue ("ns3::UniformRandomVariable[Min=0.0|Max=200.0]"),
+                   MakePointerAccessor (&RandomDiscPositionAllocator::m_rho),
+                   MakePointerChecker<RandomVariableStream> ())
     .AddAttribute ("X",
                    "The x coordinate of the center of the random position disc.",
                    DoubleValue (0.0),
@@ -353,12 +354,12 @@
 }
 
 void
-RandomDiscPositionAllocator::SetTheta (RandomVariable theta)
+RandomDiscPositionAllocator::SetTheta (Ptr<RandomVariableStream> theta)
 {
   m_theta = theta;
 }
 void
-RandomDiscPositionAllocator::SetRho (RandomVariable rho)
+RandomDiscPositionAllocator::SetRho (Ptr<RandomVariableStream> rho)
 {
   m_rho = rho;
 }
@@ -375,8 +376,8 @@
 Vector
 RandomDiscPositionAllocator::GetNext (void) const
 {
-  double theta = m_theta.GetValue ();
-  double rho = m_rho.GetValue ();
+  double theta = m_theta->GetValue ();
+  double rho = m_rho->GetValue ();
   double x = m_x + std::cos (theta) * rho;
   double y = m_y + std::sin (theta) * rho;
   NS_LOG_DEBUG ("Disc position x=" << x << ", y=" << y);
@@ -415,6 +416,7 @@
 
 UniformDiscPositionAllocator::UniformDiscPositionAllocator ()
 {
+  m_rv = CreateObject<UniformRandomVariable> ();
 }
 UniformDiscPositionAllocator::~UniformDiscPositionAllocator ()
 {
@@ -438,12 +440,11 @@
 Vector
 UniformDiscPositionAllocator::GetNext (void) const
 {
-  UniformVariable r (-m_rho, m_rho);
   double x,y;
   do
     {
-      x = r.GetValue ();
-      y = r.GetValue ();
+      x = m_rv->GetValue (-m_rho, m_rho);
+      y = m_rv->GetValue (-m_rho, m_rho);
     }
   while (sqrt (x*x + y*y) > m_rho);