00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "position-allocator.h"
00021 #include "ns3/random-variable.h"
00022 #include "ns3/double.h"
00023 #include "ns3/uinteger.h"
00024 #include "ns3/enum.h"
00025 #include "ns3/log.h"
00026 #include <cmath>
00027
00028 NS_LOG_COMPONENT_DEFINE ("PositionAllocator");
00029
00030 namespace ns3 {
00031
00032 NS_OBJECT_ENSURE_REGISTERED (PositionAllocator);
00033
00034 TypeId
00035 PositionAllocator::GetTypeId (void)
00036 {
00037 static TypeId tid = TypeId ("ns3::PositionAllocator")
00038 .SetParent<Object> ();
00039 return tid;
00040 }
00041
00042 PositionAllocator::PositionAllocator ()
00043 {
00044 }
00045
00046 PositionAllocator::~PositionAllocator ()
00047 {}
00048
00049 NS_OBJECT_ENSURE_REGISTERED (ListPositionAllocator);
00050
00051 TypeId
00052 ListPositionAllocator::GetTypeId (void)
00053 {
00054 static TypeId tid = TypeId ("ns3::ListPositionAllocator")
00055 .SetParent<PositionAllocator> ()
00056 .AddConstructor<ListPositionAllocator> ()
00057 ;
00058 return tid;
00059 }
00060 ListPositionAllocator::ListPositionAllocator ()
00061 {}
00062 void
00063 ListPositionAllocator::Add (Vector v)
00064 {
00065 m_positions.push_back (v);
00066 m_current = m_positions.begin ();
00067 }
00068 Vector
00069 ListPositionAllocator::GetNext (void) const
00070 {
00071 Vector v = *m_current;
00072 m_current++;
00073 if (m_current == m_positions.end())
00074 {
00075 m_current = m_positions.begin ();
00076 }
00077 return v;
00078 }
00079
00080 NS_OBJECT_ENSURE_REGISTERED (GridPositionAllocator);
00081
00082 TypeId
00083 GridPositionAllocator::GetTypeId (void)
00084 {
00085 static TypeId tid = TypeId ("ns3::GridPositionAllocator")
00086 .SetParent<PositionAllocator> ()
00087 .SetGroupName ("Mobility")
00088 .AddConstructor<GridPositionAllocator> ()
00089 .AddAttribute ("GridWidth", "The number of objects layed out on a line.",
00090 UintegerValue (10),
00091 MakeUintegerAccessor (&GridPositionAllocator::m_n),
00092 MakeUintegerChecker<uint32_t> ())
00093 .AddAttribute ("MinX", "The x coordinate where the grid starts.",
00094 DoubleValue (1.0),
00095 MakeDoubleAccessor (&GridPositionAllocator::m_xMin),
00096 MakeDoubleChecker<double> ())
00097 .AddAttribute ("MinY", "The y coordinate where the grid starts.",
00098 DoubleValue (0.0),
00099 MakeDoubleAccessor (&GridPositionAllocator::m_yMin),
00100 MakeDoubleChecker<double> ())
00101 .AddAttribute ("DeltaX", "The x space between objects.",
00102 DoubleValue (1.0),
00103 MakeDoubleAccessor (&GridPositionAllocator::m_deltaX),
00104 MakeDoubleChecker<double> ())
00105 .AddAttribute ("DeltaY", "The y space between objects.",
00106 DoubleValue (1.0),
00107 MakeDoubleAccessor (&GridPositionAllocator::m_deltaY),
00108 MakeDoubleChecker<double> ())
00109 .AddAttribute ("LayoutType", "The type of layout.",
00110 EnumValue (ROW_FIRST),
00111 MakeEnumAccessor (&GridPositionAllocator::m_layoutType),
00112 MakeEnumChecker (ROW_FIRST, "RowFirst",
00113 COLUMN_FIRST, "ColumnFirst"))
00114 ;
00115 return tid;
00116 }
00117 GridPositionAllocator::GridPositionAllocator ()
00118 : m_current (0)
00119 {}
00120
00121 void
00122 GridPositionAllocator::SetMinX (double xMin)
00123 {
00124 m_xMin = xMin;
00125 }
00126 void
00127 GridPositionAllocator::SetMinY (double yMin)
00128 {
00129 m_yMin = yMin;
00130 }
00131 void
00132 GridPositionAllocator::SetDeltaX (double deltaX)
00133 {
00134 m_deltaX = deltaX;
00135 }
00136 void
00137 GridPositionAllocator::SetDeltaY (double deltaY)
00138 {
00139 m_deltaY = deltaY;
00140 }
00141 void
00142 GridPositionAllocator::SetN (uint32_t n)
00143 {
00144 m_n = n;
00145 }
00146 void
00147 GridPositionAllocator::SetLayoutType (enum LayoutType layoutType)
00148 {
00149 m_layoutType = layoutType;
00150 }
00151
00152 double
00153 GridPositionAllocator::GetMinX (void) const
00154 {
00155 return m_xMin;
00156 }
00157 double
00158 GridPositionAllocator::GetMinY (void) const
00159 {
00160 return m_yMin;
00161 }
00162 double
00163 GridPositionAllocator::GetDeltaX (void) const
00164 {
00165 return m_deltaX;
00166 }
00167 double
00168 GridPositionAllocator::GetDeltaY (void) const
00169 {
00170 return m_deltaY;
00171 }
00172 uint32_t
00173 GridPositionAllocator::GetN (void) const
00174 {
00175 return m_n;
00176 }
00177 enum GridPositionAllocator::LayoutType
00178 GridPositionAllocator::GetLayoutType (void) const
00179 {
00180 return m_layoutType;
00181 }
00182
00183 Vector
00184 GridPositionAllocator::GetNext (void) const
00185 {
00186 double x = 0.0, y = 0.0;
00187 switch (m_layoutType) {
00188 case ROW_FIRST:
00189 x = m_xMin + m_deltaX * (m_current % m_n);
00190 y = m_yMin + m_deltaY * (m_current / m_n);
00191 break;
00192 case COLUMN_FIRST:
00193 x = m_xMin + m_deltaX * (m_current / m_n);
00194 y = m_yMin + m_deltaY * (m_current % m_n);
00195 break;
00196 }
00197 m_current++;
00198 return Vector (x, y, 0.0);
00199 }
00200
00201
00202 NS_OBJECT_ENSURE_REGISTERED (RandomRectanglePositionAllocator);
00203
00204 TypeId
00205 RandomRectanglePositionAllocator::GetTypeId (void)
00206 {
00207 static TypeId tid = TypeId ("ns3::RandomRectanglePositionAllocator")
00208 .SetParent<PositionAllocator> ()
00209 .SetGroupName ("Mobility")
00210 .AddConstructor<RandomRectanglePositionAllocator> ()
00211 .AddAttribute ("X",
00212 "A random variable which represents the x coordinate of a position in a random rectangle.",
00213 RandomVariableValue (UniformVariable (0.0, 1.0)),
00214 MakeRandomVariableAccessor (&RandomRectanglePositionAllocator::m_x),
00215 MakeRandomVariableChecker ())
00216 .AddAttribute ("Y",
00217 "A random variable which represents the y coordinate of a position in a random rectangle.",
00218 RandomVariableValue (UniformVariable (0.0, 1.0)),
00219 MakeRandomVariableAccessor (&RandomRectanglePositionAllocator::m_y),
00220 MakeRandomVariableChecker ());
00221 return tid;
00222 }
00223
00224 RandomRectanglePositionAllocator::RandomRectanglePositionAllocator ()
00225 {}
00226 RandomRectanglePositionAllocator::~RandomRectanglePositionAllocator ()
00227 {}
00228
00229 void
00230 RandomRectanglePositionAllocator::SetX (RandomVariable x)
00231 {
00232 m_x = x;
00233 }
00234 void
00235 RandomRectanglePositionAllocator::SetY (RandomVariable y)
00236 {
00237 m_y = y;
00238 }
00239
00240 Vector
00241 RandomRectanglePositionAllocator::GetNext (void) const
00242 {
00243 double x = m_x.GetValue ();
00244 double y = m_y.GetValue ();
00245 return Vector (x, y, 0.0);
00246 }
00247
00248 NS_OBJECT_ENSURE_REGISTERED (RandomDiscPositionAllocator);
00249
00250 TypeId
00251 RandomDiscPositionAllocator::GetTypeId (void)
00252 {
00253 static TypeId tid = TypeId ("ns3::RandomDiscPositionAllocator")
00254 .SetParent<PositionAllocator> ()
00255 .SetGroupName ("Mobility")
00256 .AddConstructor<RandomDiscPositionAllocator> ()
00257 .AddAttribute ("Theta",
00258 "A random variable which represents the angle (gradients) of a position in a random disc.",
00259 RandomVariableValue (UniformVariable (0.0, 6.2830)),
00260 MakeRandomVariableAccessor (&RandomDiscPositionAllocator::m_theta),
00261 MakeRandomVariableChecker ())
00262 .AddAttribute ("Rho",
00263 "A random variable which represents the radius of a position in a random disc.",
00264 RandomVariableValue (UniformVariable (0.0, 200.0)),
00265 MakeRandomVariableAccessor (&RandomDiscPositionAllocator::m_rho),
00266 MakeRandomVariableChecker ())
00267 .AddAttribute ("X",
00268 "The x coordinate of the center of the random position disc.",
00269 DoubleValue (0.0),
00270 MakeDoubleAccessor (&RandomDiscPositionAllocator::m_x),
00271 MakeDoubleChecker<double> ())
00272 .AddAttribute ("Y",
00273 "The y coordinate of the center of the random position disc.",
00274 DoubleValue (0.0),
00275 MakeDoubleAccessor (&RandomDiscPositionAllocator::m_y),
00276 MakeDoubleChecker<double> ())
00277 ;
00278 return tid;
00279 }
00280
00281 RandomDiscPositionAllocator::RandomDiscPositionAllocator ()
00282 {}
00283 RandomDiscPositionAllocator::~RandomDiscPositionAllocator ()
00284 {}
00285
00286 void
00287 RandomDiscPositionAllocator::SetTheta (RandomVariable theta)
00288 {
00289 m_theta = theta;
00290 }
00291 void
00292 RandomDiscPositionAllocator::SetRho (RandomVariable rho)
00293 {
00294 m_rho = rho;
00295 }
00296 void
00297 RandomDiscPositionAllocator::SetX (double x)
00298 {
00299 m_x = x;
00300 }
00301 void
00302 RandomDiscPositionAllocator::SetY (double y)
00303 {
00304 m_y = y;
00305 }
00306 Vector
00307 RandomDiscPositionAllocator::GetNext (void) const
00308 {
00309 double theta = m_theta.GetValue ();
00310 double rho = m_rho.GetValue ();
00311 double x = m_x + std::cos (theta) * rho;
00312 double y = m_y + std::sin (theta) * rho;
00313 NS_LOG_DEBUG ("Disc position x=" << x << ", y=" << y);
00314 return Vector (x, y, 0.0);
00315 }
00316
00317
00318 }