21 #include "ns3/double.h"
22 #include "ns3/string.h"
23 #include "ns3/pointer.h"
24 #include "ns3/uinteger.h"
27 #include "ns3/csv-reader.h"
42 .SetGroupName (
"Mobility");
58 static TypeId tid =
TypeId (
"ns3::ListPositionAllocator")
60 .SetGroupName (
"Mobility")
81 NS_LOG_FUNCTION (
this << filePath << std::string (
"'") + delimiter +
"'");
97 NS_LOG_INFO (
"read y = " << y << (ok ?
" ok" :
" FAIL"));
102 NS_LOG_INFO (
"read z = " << z << (ok ?
" ok" :
" FAIL"));
111 Vector pos (
x, y, z);
148 static TypeId tid =
TypeId (
"ns3::GridPositionAllocator")
150 .SetGroupName (
"Mobility")
152 .AddAttribute (
"GridWidth",
"The number of objects laid out on a line.",
155 MakeUintegerChecker<uint32_t> ())
156 .AddAttribute (
"MinX",
"The x coordinate where the grid starts.",
159 MakeDoubleChecker<double> ())
160 .AddAttribute (
"MinY",
"The y coordinate where the grid starts.",
163 MakeDoubleChecker<double> ())
165 "The z coordinate of all the positions allocated.",
168 MakeDoubleChecker<double> ())
169 .AddAttribute (
"DeltaX",
"The x space between objects.",
172 MakeDoubleChecker<double> ())
173 .AddAttribute (
"DeltaY",
"The y space between objects.",
176 MakeDoubleChecker<double> ())
177 .AddAttribute (
"LayoutType",
"The type of layout.",
271 double x = 0.0, y = 0.0;
284 return Vector (
x, y,
m_z);
299 static TypeId tid =
TypeId (
"ns3::RandomRectanglePositionAllocator")
301 .SetGroupName (
"Mobility")
304 "A random variable which represents the x coordinate of a position in a random rectangle.",
305 StringValue (
"ns3::UniformRandomVariable[Min=0.0|Max=1.0]"),
307 MakePointerChecker<RandomVariableStream> ())
309 "A random variable which represents the y coordinate of a position in a random rectangle.",
310 StringValue (
"ns3::UniformRandomVariable[Min=0.0|Max=1.0]"),
312 MakePointerChecker<RandomVariableStream> ())
314 "The z coordinate of all the positions allocated.",
317 MakeDoubleChecker<double> ())
351 return Vector (
x, y,
m_z);
368 static TypeId tid =
TypeId (
"ns3::RandomBoxPositionAllocator")
370 .SetGroupName (
"Mobility")
373 "A random variable which represents the x coordinate of a position in a random box.",
374 StringValue (
"ns3::UniformRandomVariable[Min=0.0|Max=1.0]"),
376 MakePointerChecker<RandomVariableStream> ())
378 "A random variable which represents the y coordinate of a position in a random box.",
379 StringValue (
"ns3::UniformRandomVariable[Min=0.0|Max=1.0]"),
381 MakePointerChecker<RandomVariableStream> ())
383 "A random variable which represents the z coordinate of a position in a random box.",
384 StringValue (
"ns3::UniformRandomVariable[Min=0.0|Max=1.0]"),
386 MakePointerChecker<RandomVariableStream> ())
421 return Vector (
x, y, z);
439 static TypeId tid =
TypeId (
"ns3::RandomDiscPositionAllocator")
441 .SetGroupName (
"Mobility")
443 .AddAttribute (
"Theta",
444 "A random variable which represents the angle (gradients) of a position in a random disc.",
445 StringValue (
"ns3::UniformRandomVariable[Min=0.0|Max=6.2830]"),
447 MakePointerChecker<RandomVariableStream> ())
448 .AddAttribute (
"Rho",
449 "A random variable which represents the radius of a position in a random disc.",
450 StringValue (
"ns3::UniformRandomVariable[Min=0.0|Max=200.0]"),
452 MakePointerChecker<RandomVariableStream> ())
454 "The x coordinate of the center of the random position disc.",
457 MakeDoubleChecker<double> ())
459 "The y coordinate of the center of the random position disc.",
462 MakeDoubleChecker<double> ())
464 "The z coordinate of all the positions in the disc.",
467 MakeDoubleChecker<double> ())
513 double x =
m_x + std::cos (theta) * rho;
514 double y =
m_y + std::sin (theta) * rho;
516 return Vector (
x, y,
m_z);
533 static TypeId tid =
TypeId (
"ns3::UniformDiscPositionAllocator")
535 .SetGroupName (
"Mobility")
537 .AddAttribute (
"rho",
538 "The radius of the disc",
541 MakeDoubleChecker<double> ())
543 "The x coordinate of the center of the disc.",
546 MakeDoubleChecker<double> ())
548 "The y coordinate of the center of the disc.",
551 MakeDoubleChecker<double> ())
553 "The z coordinate of all the positions in the disc.",
556 MakeDoubleChecker<double> ())
563 m_rv = CreateObject<UniformRandomVariable> ();
602 while (std::sqrt (
x *
x + y * y) >
m_rho);
607 return Vector (
x, y,
m_z);
Provides functions for parsing and extracting data from Comma Separated Value (CSV) formatted text fi...
bool GetValue(std::size_t columnIndex, T &value) const
Attempt to convert from the string data in the specified column to the specified data type.
std::size_t RowNumber() const
The number of lines that have been read.
std::size_t ColumnCount() const
Returns the number of columns in the csv data.
bool FetchNextRow()
Reads one line from the input until a new line is encountered.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Hold variables of type enum.
Allocate positions on a rectangular 2d grid.
void SetDeltaX(double deltaX)
double m_deltaX
x interval between two consecutive x positions
double GetMinX(void) const
double m_deltaY
y interval between two consecutive y positions
uint32_t GetN(void) const
LayoutType
Determine whether positions are allocated row first or column first.
@ COLUMN_FIRST
In column-first mode, positions are allocated on the first column until N positions have been allocat...
@ ROW_FIRST
In row-first mode, positions are allocated on the first row until N positions have been allocated.
virtual Vector GetNext(void) const
virtual int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
void SetMinY(double yMin)
uint32_t m_current
currently position
void SetDeltaY(double deltaY)
enum LayoutType m_layoutType
currently selected layout type
double m_yMin
minimum boundary on y positions
double m_z
z coordinate of all the positions generated
double GetDeltaX(void) const
void SetLayoutType(enum LayoutType layoutType)
double GetDeltaY(void) const
static TypeId GetTypeId(void)
Register this type with the TypeId system.
double GetMinY(void) const
double m_xMin
minimum boundary on x positions
uint32_t m_n
number of positions to allocate on each row or column
enum LayoutType GetLayoutType(void) const
void SetMinX(double xMin)
Allocate positions from a deterministic list specified by the user.
void Add(Vector v)
Add a position to the list of positions.
std::vector< Vector >::const_iterator m_current
vector iterator
std::vector< Vector > m_positions
vector of positions
static TypeId GetTypeId(void)
Register this type with the TypeId system.
uint32_t GetSize(void) const
Return the number of positions stored.
virtual Vector GetNext(void) const
virtual int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
A base class which provides memory management and object aggregation.
Allocate a set of positions.
virtual ~PositionAllocator()
static TypeId GetTypeId(void)
Register this type with the TypeId system.
Allocate random positions within a 3D box according to a set of three random variables.
void SetZ(Ptr< RandomVariableStream > z)
Set the random variable stream object that generates z-positions.
virtual int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
Ptr< RandomVariableStream > m_x
pointer to x's random variable stream
Ptr< RandomVariableStream > m_y
pointer to y's random variable stream
virtual Vector GetNext(void) const
void SetX(Ptr< RandomVariableStream > x)
Set the random variable stream object that generates x-positions.
static TypeId GetTypeId(void)
Register this type with the TypeId system.
void SetY(Ptr< RandomVariableStream > y)
Set the random variable stream object that generates y-positions.
virtual ~RandomBoxPositionAllocator()
Ptr< RandomVariableStream > m_z
pointer to z's random variable stream
RandomBoxPositionAllocator()
Allocate random positions within a disc according to a given distribution for the polar coordinates o...
RandomDiscPositionAllocator()
double m_y
y coordinate of center of disc
Ptr< RandomVariableStream > m_rho
pointer to rho's random variable stream
void SetRho(Ptr< RandomVariableStream > rho)
Set the random variable that generates position radius, in meters.
virtual ~RandomDiscPositionAllocator()
static TypeId GetTypeId(void)
Register this type with the TypeId system.
double m_x
x coordinate of center of disc
void SetTheta(Ptr< RandomVariableStream > theta)
Set the random variable that generates position angle, in radians.
virtual Vector GetNext(void) const
Ptr< RandomVariableStream > m_theta
pointer to theta's random variable stream
double m_z
z coordinate of the disc
virtual int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
Allocate random positions within a rectangle according to a pair of random variables.
static TypeId GetTypeId(void)
Register this type with the TypeId system.
virtual int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
RandomRectanglePositionAllocator()
virtual ~RandomRectanglePositionAllocator()
virtual Vector GetNext(void) const
Ptr< RandomVariableStream > m_y
pointer to y's random variable stream
Ptr< RandomVariableStream > m_x
pointer to x's random variable stream
void SetY(Ptr< RandomVariableStream > y)
Set the random variable stream object that generates y-positions.
void SetX(Ptr< RandomVariableStream > x)
Set the random variable stream object that generates x-positions.
double m_z
z coordinate of all the positions generated
virtual double GetValue(void)=0
Get the next random value as a double drawn from the distribution.
void SetStream(int64_t stream)
Specifies the stream number for the RngStream.
Hold variables of type string.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Hold an unsigned integer type.
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Ptr< const AttributeAccessor > MakeEnumAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeChecker > MakeEnumChecker(int v, std::string n, Ts... args)
Make an EnumChecker pre-configured with a set of allowed values by name.
list x
Random number samples.