20 #include "position-allocator.h"
21 #include "ns3/double.h"
22 #include "ns3/string.h"
23 #include "ns3/pointer.h"
24 #include "ns3/uinteger.h"
33 NS_OBJECT_ENSURE_REGISTERED (PositionAllocator);
36 PositionAllocator::GetTypeId (
void)
38 static TypeId tid = TypeId (
"ns3::PositionAllocator")
39 .SetParent<Object> ();
43 PositionAllocator::PositionAllocator ()
47 PositionAllocator::~PositionAllocator ()
51 NS_OBJECT_ENSURE_REGISTERED (ListPositionAllocator);
54 ListPositionAllocator::GetTypeId (
void)
56 static TypeId tid = TypeId (
"ns3::ListPositionAllocator")
57 .SetParent<PositionAllocator> ()
58 .AddConstructor<ListPositionAllocator> ()
62 ListPositionAllocator::ListPositionAllocator ()
68 m_positions.push_back (v);
69 m_current = m_positions.begin ();
76 if (m_current == m_positions.end ())
78 m_current = m_positions.begin ();
91 GridPositionAllocator::GetTypeId (
void)
93 static TypeId tid =
TypeId (
"ns3::GridPositionAllocator")
95 .SetGroupName (
"Mobility")
97 .AddAttribute (
"GridWidth",
"The number of objects layed out on a line.",
99 MakeUintegerAccessor (&GridPositionAllocator::m_n),
100 MakeUintegerChecker<uint32_t> ())
101 .AddAttribute (
"MinX",
"The x coordinate where the grid starts.",
103 MakeDoubleAccessor (&GridPositionAllocator::m_xMin),
104 MakeDoubleChecker<double> ())
105 .AddAttribute (
"MinY",
"The y coordinate where the grid starts.",
107 MakeDoubleAccessor (&GridPositionAllocator::m_yMin),
108 MakeDoubleChecker<double> ())
109 .AddAttribute (
"DeltaX",
"The x space between objects.",
111 MakeDoubleAccessor (&GridPositionAllocator::m_deltaX),
112 MakeDoubleChecker<double> ())
113 .AddAttribute (
"DeltaY",
"The y space between objects.",
115 MakeDoubleAccessor (&GridPositionAllocator::m_deltaY),
116 MakeDoubleChecker<double> ())
117 .AddAttribute (
"LayoutType",
"The type of layout.",
119 MakeEnumAccessor (&GridPositionAllocator::m_layoutType),
125 GridPositionAllocator::GridPositionAllocator ()
158 m_layoutType = layoutType;
195 double x = 0.0, y = 0.0;
196 switch (m_layoutType) {
198 x = m_xMin + m_deltaX * (m_current % m_n);
199 y = m_yMin + m_deltaY * (m_current / m_n);
202 x = m_xMin + m_deltaX * (m_current / m_n);
203 y = m_yMin + m_deltaY * (m_current % m_n);
207 return Vector (x, y, 0.0);
219 RandomRectanglePositionAllocator::GetTypeId (
void)
221 static TypeId tid =
TypeId (
"ns3::RandomRectanglePositionAllocator")
223 .SetGroupName (
"Mobility")
226 "A random variable which represents the x coordinate of a position in a random rectangle.",
227 StringValue (
"ns3::UniformRandomVariable[Min=0.0|Max=1.0]"),
228 MakePointerAccessor (&RandomRectanglePositionAllocator::m_x),
229 MakePointerChecker<RandomVariableStream> ())
231 "A random variable which represents the y coordinate of a position in a random rectangle.",
232 StringValue (
"ns3::UniformRandomVariable[Min=0.0|Max=1.0]"),
233 MakePointerAccessor (&RandomRectanglePositionAllocator::m_y),
234 MakePointerChecker<RandomVariableStream> ());
238 RandomRectanglePositionAllocator::RandomRectanglePositionAllocator ()
241 RandomRectanglePositionAllocator::~RandomRectanglePositionAllocator ()
246 RandomRectanglePositionAllocator::SetX (Ptr<RandomVariableStream> x)
251 RandomRectanglePositionAllocator::SetY (Ptr<RandomVariableStream> y)
261 return Vector (x, y, 0.0);
275 RandomBoxPositionAllocator::GetTypeId (
void)
277 static TypeId tid =
TypeId (
"ns3::RandomBoxPositionAllocator")
279 .SetGroupName (
"Mobility")
282 "A random variable which represents the x coordinate of a position in a random box.",
283 StringValue (
"ns3::UniformRandomVariable[Min=0.0|Max=1.0]"),
284 MakePointerAccessor (&RandomBoxPositionAllocator::m_x),
285 MakePointerChecker<RandomVariableStream> ())
287 "A random variable which represents the y coordinate of a position in a random box.",
288 StringValue (
"ns3::UniformRandomVariable[Min=0.0|Max=1.0]"),
289 MakePointerAccessor (&RandomBoxPositionAllocator::m_y),
290 MakePointerChecker<RandomVariableStream> ())
292 "A random variable which represents the z coordinate of a position in a random box.",
293 StringValue (
"ns3::UniformRandomVariable[Min=0.0|Max=1.0]"),
294 MakePointerAccessor (&RandomBoxPositionAllocator::m_z),
295 MakePointerChecker<RandomVariableStream> ());
299 RandomBoxPositionAllocator::RandomBoxPositionAllocator ()
302 RandomBoxPositionAllocator::~RandomBoxPositionAllocator ()
307 RandomBoxPositionAllocator::SetX (Ptr<RandomVariableStream> x)
312 RandomBoxPositionAllocator::SetY (Ptr<RandomVariableStream> y)
317 RandomBoxPositionAllocator::SetZ (Ptr<RandomVariableStream> z)
343 RandomDiscPositionAllocator::GetTypeId (
void)
345 static TypeId tid =
TypeId (
"ns3::RandomDiscPositionAllocator")
347 .SetGroupName (
"Mobility")
349 .AddAttribute (
"Theta",
350 "A random variable which represents the angle (gradients) of a position in a random disc.",
351 StringValue (
"ns3::UniformRandomVariable[Min=0.0|Max=6.2830]"),
352 MakePointerAccessor (&RandomDiscPositionAllocator::m_theta),
353 MakePointerChecker<RandomVariableStream> ())
354 .AddAttribute (
"Rho",
355 "A random variable which represents the radius of a position in a random disc.",
356 StringValue (
"ns3::UniformRandomVariable[Min=0.0|Max=200.0]"),
357 MakePointerAccessor (&RandomDiscPositionAllocator::m_rho),
358 MakePointerChecker<RandomVariableStream> ())
360 "The x coordinate of the center of the random position disc.",
362 MakeDoubleAccessor (&RandomDiscPositionAllocator::m_x),
363 MakeDoubleChecker<double> ())
365 "The y coordinate of the center of the random position disc.",
367 MakeDoubleAccessor (&RandomDiscPositionAllocator::m_y),
368 MakeDoubleChecker<double> ())
373 RandomDiscPositionAllocator::RandomDiscPositionAllocator ()
376 RandomDiscPositionAllocator::~RandomDiscPositionAllocator ()
381 RandomDiscPositionAllocator::SetTheta (Ptr<RandomVariableStream> theta)
386 RandomDiscPositionAllocator::SetRho (Ptr<RandomVariableStream> rho)
391 RandomDiscPositionAllocator::SetX (
double x)
396 RandomDiscPositionAllocator::SetY (
double y)
403 double theta = m_theta->
GetValue ();
405 double x = m_x + std::cos (theta) * rho;
406 double y = m_y + std::sin (theta) * rho;
408 return Vector (x, y, 0.0);
424 UniformDiscPositionAllocator::GetTypeId (
void)
426 static TypeId tid =
TypeId (
"ns3::UniformDiscPositionAllocator")
428 .SetGroupName (
"Mobility")
430 .AddAttribute (
"rho",
431 "The radius of the disc",
433 MakeDoubleAccessor (&UniformDiscPositionAllocator::m_rho),
434 MakeDoubleChecker<double> ())
436 "The x coordinate of the center of the disc.",
438 MakeDoubleAccessor (&UniformDiscPositionAllocator::m_x),
439 MakeDoubleChecker<double> ())
441 "The y coordinate of the center of the disc.",
443 MakeDoubleAccessor (&UniformDiscPositionAllocator::m_y),
444 MakeDoubleChecker<double> ())
449 UniformDiscPositionAllocator::UniformDiscPositionAllocator ()
451 m_rv = CreateObject<UniformRandomVariable> ();
453 UniformDiscPositionAllocator::~UniformDiscPositionAllocator ()
481 while (std::sqrt (x*x + y*y) > m_rho);
486 return Vector (x, y, 0.0);
void SetStream(int64_t stream)
Specifies the stream number for this RNG stream.
double GetMinY(void) const
void SetDeltaX(double deltaX)
hold variables of type string
void SetMinX(double xMin)
double GetDeltaY(void) const
enum LayoutType GetLayoutType(void) const
virtual Vector GetNext(void) const
#define NS_LOG_COMPONENT_DEFINE(name)
void SetMinY(double yMin)
double GetDeltaX(void) const
virtual int64_t AssignStreams(int64_t stream)
virtual Vector GetNext(void) const
virtual double GetValue(void)=0
Returns a random double from the underlying distribution.
virtual Vector GetNext(void) const
void SetDeltaY(double deltaY)
hold variables of type 'enum'
Hold an unsigned integer type.
Allocate positions on a rectangular 2d grid.
virtual Vector GetNext(void) const
virtual int64_t AssignStreams(int64_t stream)
virtual int64_t AssignStreams(int64_t stream)
Allocate random positions within a rectangle according to a pair of random variables.
virtual int64_t AssignStreams(int64_t stream)
#define NS_LOG_DEBUG(msg)
void SetLayoutType(enum LayoutType layoutType)
virtual Vector GetNext(void) const
uint32_t GetN(void) const
Allocate random positions within a 3D box according to a set of three random variables.
Hold an floating point type.
a unique identifier for an interface.
Allocate random positions within a disc according to a given distribution for the polar coordinates o...
TypeId SetParent(TypeId tid)
virtual int64_t AssignStreams(int64_t stream)
double GetMinX(void) const
Allocate a set of positions. The allocation strategy is implemented in subclasses.