21 #include "ns3/csv-reader.h"
22 #include "ns3/double.h"
25 #include "ns3/pointer.h"
26 #include "ns3/string.h"
27 #include "ns3/uinteger.h"
61 .SetGroupName(
"Mobility")
82 NS_LOG_FUNCTION(
this << filePath << std::string(
"'") + delimiter +
"'");
100 NS_LOG_INFO(
"read y = " << y << (ok ?
" ok" :
" FAIL"));
105 NS_LOG_INFO(
"read z = " << z << (ok ?
" ok" :
" FAIL"));
151 TypeId(
"ns3::GridPositionAllocator")
153 .SetGroupName(
"Mobility")
155 .AddAttribute(
"GridWidth",
156 "The number of objects laid out on a line.",
159 MakeUintegerChecker<uint32_t>())
160 .AddAttribute(
"MinX",
161 "The x coordinate where the grid starts.",
164 MakeDoubleChecker<double>())
165 .AddAttribute(
"MinY",
166 "The y coordinate where the grid starts.",
169 MakeDoubleChecker<double>())
171 "The z coordinate of all the positions allocated.",
174 MakeDoubleChecker<double>())
175 .AddAttribute(
"DeltaX",
176 "The x space between objects.",
179 MakeDoubleChecker<double>())
180 .AddAttribute(
"DeltaY",
181 "The y space between objects.",
184 MakeDoubleChecker<double>())
185 .AddAttribute(
"LayoutType",
186 "The type of layout.",
293 return Vector(
x, y,
m_z);
308 TypeId(
"ns3::RandomRectanglePositionAllocator")
310 .SetGroupName(
"Mobility")
313 "A random variable which represents the x coordinate of a position in a "
315 StringValue(
"ns3::UniformRandomVariable[Min=0.0|Max=1.0]"),
317 MakePointerChecker<RandomVariableStream>())
319 "A random variable which represents the y coordinate of a position in a "
321 StringValue(
"ns3::UniformRandomVariable[Min=0.0|Max=1.0]"),
323 MakePointerChecker<RandomVariableStream>())
325 "The z coordinate of all the positions allocated.",
328 MakeDoubleChecker<double>());
363 return Vector(
x, y,
m_z);
380 TypeId(
"ns3::RandomBoxPositionAllocator")
382 .SetGroupName(
"Mobility")
385 "A random variable which represents the x coordinate of a position in a "
387 StringValue(
"ns3::UniformRandomVariable[Min=0.0|Max=1.0]"),
389 MakePointerChecker<RandomVariableStream>())
391 "A random variable which represents the y coordinate of a position in a "
393 StringValue(
"ns3::UniformRandomVariable[Min=0.0|Max=1.0]"),
395 MakePointerChecker<RandomVariableStream>())
397 "A random variable which represents the z coordinate of a position in a "
399 StringValue(
"ns3::UniformRandomVariable[Min=0.0|Max=1.0]"),
401 MakePointerChecker<RandomVariableStream>());
437 return Vector(
x, y, z);
455 TypeId(
"ns3::RandomDiscPositionAllocator")
457 .SetGroupName(
"Mobility")
459 .AddAttribute(
"Theta",
460 "A random variable which represents the angle (gradients) of a position "
462 StringValue(
"ns3::UniformRandomVariable[Min=0.0|Max=6.2830]"),
464 MakePointerChecker<RandomVariableStream>())
467 "A random variable which represents the radius of a position in a random disc.",
468 StringValue(
"ns3::UniformRandomVariable[Min=0.0|Max=200.0]"),
470 MakePointerChecker<RandomVariableStream>())
472 "The x coordinate of the center of the random position disc.",
475 MakeDoubleChecker<double>())
477 "The y coordinate of the center of the random position disc.",
480 MakeDoubleChecker<double>())
482 "The z coordinate of all the positions in the disc.",
485 MakeDoubleChecker<double>());
532 double x =
m_x + std::cos(theta) * rho;
533 double y =
m_y + std::sin(theta) * rho;
535 return Vector(
x, y,
m_z);
551 static TypeId tid =
TypeId(
"ns3::UniformDiscPositionAllocator")
553 .SetGroupName(
"Mobility")
556 "The radius of the disc",
559 MakeDoubleChecker<double>())
561 "The x coordinate of the center of the disc.",
564 MakeDoubleChecker<double>())
566 "The y coordinate of the center of the disc.",
569 MakeDoubleChecker<double>())
571 "The z coordinate of all the positions in the disc.",
574 MakeDoubleChecker<double>());
580 m_rv = CreateObject<UniformRandomVariable>();
620 }
while (std::sqrt(
x *
x + y * y) >
m_rho);
625 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 m_deltaY
y interval between two consecutive y positions
LayoutType GetLayoutType() 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.
void SetMinY(double yMin)
int64_t AssignStreams(int64_t stream) override
Assign a fixed random variable stream number to the random variables used by this model.
uint32_t m_current
currently position
void SetDeltaY(double deltaY)
double m_yMin
minimum boundary on y positions
Vector GetNext() const override
double m_z
z coordinate of all the positions generated
LayoutType m_layoutType
currently selected layout type
double m_xMin
minimum boundary on x positions
uint32_t m_n
number of positions to allocate on each row or column
static TypeId GetTypeId()
Register this type with the TypeId system.
void SetLayoutType(LayoutType layoutType)
void SetMinX(double xMin)
Allocate positions from a deterministic list specified by the user.
int64_t AssignStreams(int64_t stream) override
Assign a fixed random variable stream number to the random variables used by this model.
void Add(Vector v)
Add a position to the list of positions.
uint32_t GetSize() const
Return the number of positions stored.
static TypeId GetTypeId()
Register this type with the TypeId system.
std::vector< Vector >::const_iterator m_current
vector iterator
Vector GetNext() const override
std::vector< Vector > m_positions
vector of positions
A base class which provides memory management and object aggregation.
Allocate a set of positions.
static TypeId GetTypeId()
Register this type with the TypeId system.
~PositionAllocator() override
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.
Ptr< RandomVariableStream > m_x
pointer to x's random variable stream
Ptr< RandomVariableStream > m_y
pointer to y's random variable stream
void SetX(Ptr< RandomVariableStream > x)
Set the random variable stream object that generates x-positions.
int64_t AssignStreams(int64_t stream) override
Assign a fixed random variable stream number to the random variables used by this model.
void SetY(Ptr< RandomVariableStream > y)
Set the random variable stream object that generates y-positions.
Vector GetNext() const override
~RandomBoxPositionAllocator() override
static TypeId GetTypeId()
Register this type with the TypeId system.
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...
Vector GetNext() const override
~RandomDiscPositionAllocator() override
RandomDiscPositionAllocator()
double m_y
y coordinate of center of disc
Ptr< RandomVariableStream > m_rho
pointer to rho's random variable stream
static TypeId GetTypeId()
Register this type with the TypeId system.
void SetRho(Ptr< RandomVariableStream > rho)
Set the random variable that generates position radius, in meters.
double m_x
x coordinate of center of disc
void SetTheta(Ptr< RandomVariableStream > theta)
Set the random variable that generates position angle, in radians.
int64_t AssignStreams(int64_t stream) override
Assign a fixed random variable stream number to the random variables used by this model.
Ptr< RandomVariableStream > m_theta
pointer to theta's random variable stream
double m_z
z coordinate of the disc
Allocate random positions within a rectangle according to a pair of random variables.
int64_t AssignStreams(int64_t stream) override
Assign a fixed random variable stream number to the random variables used by this model.
Vector GetNext() const override
RandomRectanglePositionAllocator()
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.
static TypeId GetTypeId()
Register this type with the TypeId system.
~RandomRectanglePositionAllocator() override
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()=0
Get the next random value 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...
#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 AttributeAccessor > MakePointerAccessor(T1 a1)
Ptr< const AttributeChecker > MakeEnumChecker(T v, std::string n, Ts... args)
Make an EnumChecker pre-configured with a set of allowed values by name.
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)