22#include "ns3/boolean.h"
24#include "ns3/building-list.h"
25#include "ns3/building.h"
26#include "ns3/buildings-helper.h"
27#include "ns3/double.h"
30#include "ns3/mobility-model.h"
31#include "ns3/pointer.h"
32#include "ns3/random-variable-stream.h"
33#include "ns3/string.h"
34#include "ns3/uinteger.h"
35#include <ns3/mobility-building-info.h>
48 m_rand = CreateObject<UniformRandomVariable>();
55 TypeId(
"ns3::RandomBuildingPositionAllocator")
57 .SetGroupName(
"Buildings")
59 .AddAttribute(
"WithReplacement",
60 "If true, the building will be randomly selected with replacement. "
61 "If false, no replacement will occur, until the list of buildings "
62 "to select becomes empty, at which point it will be filled again "
63 "with the list of all buildings.",
97 b->GetAttribute(
"Boundaries", bv);
101 return Vector(x, y, z);
121 TypeId(
"ns3::OutdoorPositionAllocator")
123 .SetGroupName(
"Buildings")
126 "A random variable which represents the x coordinate of a position in a "
128 StringValue(
"ns3::UniformRandomVariable[Min=0.0|Max=1.0]"),
130 MakePointerChecker<RandomVariableStream>())
132 "A random variable which represents the y coordinate of a position in a "
134 StringValue(
"ns3::UniformRandomVariable[Min=0.0|Max=1.0]"),
136 MakePointerChecker<RandomVariableStream>())
138 "A random variable which represents the z coordinate of a position in a "
140 StringValue(
"ns3::UniformRandomVariable[Min=0.0|Max=1.0]"),
142 MakePointerChecker<RandomVariableStream>())
143 .AddAttribute(
"MaxAttempts",
144 "Maximum number of attempts for the rejection sampling before giving up.",
147 MakeUintegerChecker<uint32_t>());
175 bool outdoor =
false;
177 Vector position = Vector(0, 0, 0);
186 position = Vector(x, y, z);
193 if ((*bit)->IsInside(position))
196 << position <<
" is inside the building with boundaries "
197 << (*bit)->GetBoundaries().xMin <<
" " << (*bit)->GetBoundaries().xMax
198 <<
" " << (*bit)->GetBoundaries().yMin <<
" "
199 << (*bit)->GetBoundaries().yMax <<
" " << (*bit)->GetBoundaries().zMin
200 <<
" " << (*bit)->GetBoundaries().zMax);
213 NS_LOG_INFO(
"Outdoor position found " << position);
236 m_rand = CreateObject<UniformRandomVariable>();
242 static TypeId tid =
TypeId(
"ns3::RandomRoomPositionAllocator")
244 .SetGroupName(
"Buildings")
260 for (
uint32_t rx = 1; rx <= (*bit)->GetNRoomsX(); ++rx)
262 for (
uint32_t ry = 1; ry <= (*bit)->GetNRoomsY(); ++ry)
264 for (
uint32_t f = 1;
f <= (*bit)->GetNFloors(); ++
f)
271 NS_LOG_LOGIC(
"adding room (" << rx <<
", " << ry <<
", " <<
f <<
")");
282 <<
", " << r.
floor <<
")");
286 r.
b->GetAttribute(
"Boundaries", bv);
288 double rdx = (box.
xMax - box.
xMin) / r.
b->GetNRoomsX();
289 double rdy = (box.
yMax - box.
yMin) / r.
b->GetNRoomsY();
290 double rdz = (box.
zMax - box.
zMin) / r.
b->GetNFloors();
291 double x1 = box.
xMin + rdx * (r.
roomx - 1);
293 double y1 = box.
yMin + rdy * (r.
roomy - 1);
295 double z1 = box.
zMin + rdz * (r.
floor - 1);
298 <<
" (" << x1 <<
"," << x2 <<
") "
299 <<
"x (" << y1 <<
"," << y2 <<
") "
300 <<
"x (" << z1 <<
"," << z2 <<
") ");
306 return Vector(x, y, z);
320 NS_FATAL_ERROR(
" Constructor \"SameRoomPositionAllocator ()\" should not be used");
326 m_rand = CreateObject<UniformRandomVariable>();
332 NS_ASSERT_MSG(mm,
"no mobility model aggregated to this node");
335 "MobilityBuildingInfo has not been aggregated to this node mobility model");
336 bmm->MakeConsistent(mm);
343 static TypeId tid =
TypeId(
"ns3::SameRoomPositionAllocator")
345 .SetGroupName(
"Buildings")
361 NS_LOG_LOGIC(
"considering node " << (*m_nodeIt)->GetId());
363 NS_ASSERT_MSG(mm,
"no mobility model aggregated to this node");
365 NS_ASSERT_MSG(bmm,
"MobilityBuildingInfo has not been aggregated to this node mobility model");
368 uint32_t roomx = bmm->GetRoomNumberX();
369 uint32_t roomy = bmm->GetRoomNumberY();
370 uint32_t floor = bmm->GetFloorNumber();
371 NS_LOG_LOGIC(
"considering building " << bmm->GetBuilding()->GetId() <<
" room (" << roomx
372 <<
", " << roomy <<
", " << floor <<
")");
377 b->GetAttribute(
"Boundaries", bv);
379 double rdx = (box.
xMax - box.
xMin) / b->GetNRoomsX();
380 double rdy = (box.
yMax - box.
yMin) / b->GetNRoomsY();
381 double rdz = (box.
zMax - box.
zMin) / b->GetNFloors();
382 double x1 = box.
xMin + rdx * (roomx - 1);
383 double x2 = box.
xMin + rdx * roomx;
384 double y1 = box.
yMin + rdy * (roomy - 1);
385 double y2 = box.
yMin + rdy * roomy;
386 double z1 = box.
zMin + rdz * (floor - 1);
387 double z2 = box.
zMin + rdz * floor;
389 <<
" (" << x1 <<
"," << x2 <<
") "
390 <<
"x (" << y1 <<
"," << y2 <<
") "
391 <<
"x (" << z1 <<
"," << z2 <<
") ");
397 return Vector(x, y, z);
414 m_rand = CreateObject<UniformRandomVariable>();
424 static TypeId tid =
TypeId(
"ns3::FixedRoomPositionAllocator")
426 .SetGroupName(
"Buildings")
435 <<
", " <<
floor <<
")");
439 Box box =
bptr->GetBoundaries();
440 double rdx = (box.
xMax - box.
xMin) /
bptr->GetNRoomsX();
441 double rdy = (box.
yMax - box.
yMin) /
bptr->GetNRoomsY();
442 double rdz = (box.
zMax - box.
zMin) /
bptr->GetNFloors();
443 double x1 = box.
xMin + rdx * (
roomx - 1);
445 double y1 = box.
yMin + rdy * (
roomy - 1);
447 double z1 = box.
zMin + rdz * (
floor - 1);
450 <<
" (" << x1 <<
"," << x2 <<
") "
451 <<
"x (" << y1 <<
"," << y2 <<
") "
452 <<
"x (" << z1 <<
"," << z2 <<
") ");
457 return Vector(x, y, z);
double f(double x, void *params)
AttributeValue implementation for Boolean.
double yMax
The y coordinate of the top bound of the box.
double xMin
The x coordinate of the left bound of the box.
double yMin
The y coordinate of the bottom bound of the box.
double xMax
The x coordinate of the right bound of the box.
double zMin
The z coordinate of the down bound of the box.
double zMax
The z coordinate of the up bound of the box.
AttributeValue implementation for Box.
static Ptr< Building > GetBuilding(uint32_t n)
std::vector< Ptr< Building > >::const_iterator Iterator
Const Iterator.
static uint32_t GetNBuildings()
Generate a random position uniformly distributed in the volume of a chosen room inside a chosen build...
uint32_t floor
Index of the room on the z-axis (i.e., floor number)
uint32_t roomx
Index of the room on the x-axis.
uint32_t roomy
Index of the room on the y-axis.
Vector GetNext() const override
Ptr< UniformRandomVariable > m_rand
Provides uniform random variables.
Ptr< Building > bptr
Pointer to the chosen building.
int64_t AssignStreams(int64_t) override
Assign a fixed random variable stream number to the random variables used by this model.
static TypeId GetTypeId()
Get the type ID.
FixedRoomPositionAllocator(uint32_t x, uint32_t y, uint32_t z, Ptr< Building > b)
mobility buildings information (to be used by mobility models)
Keep track of the current position and velocity of an object.
keep track of a set of node pointers.
std::vector< Ptr< Node > >::const_iterator Iterator
Node container iterator.
Iterator End() const
Get an iterator which indicates past-the-last Node in the container.
Iterator Begin() const
Get an iterator which refers to the first Node in the container.
allocate outdoor positions
void SetY(Ptr< RandomVariableStream > y)
Set the random variable stream object that generates y-positions.
uint32_t m_maxAttempts
maximum number of attempts before giving up
static TypeId GetTypeId()
Get the type ID.
void SetX(Ptr< RandomVariableStream > x)
Set the random variable stream object that generates x-positions.
Ptr< RandomVariableStream > m_x
pointer to x's random variable stream
Ptr< RandomVariableStream > m_z
pointer to z's random variable stream
Ptr< RandomVariableStream > m_y
pointer to y's random variable stream
OutdoorPositionAllocator()
void SetZ(Ptr< RandomVariableStream > z)
Set the random variable stream object that generates z-positions.
Vector GetNext() const override
int64_t AssignStreams(int64_t stream) override
Assign a fixed random variable stream number to the random variables used by this model.
Allocate a set of positions.
Smart pointer class similar to boost::intrusive_ptr.
Allocate each position by randomly choosing a building from the list of all buildings,...
std::vector< Ptr< Building > > m_buildingListWithoutReplacement
List of building without replacement.
int64_t AssignStreams(int64_t stream) override
Assign a fixed random variable stream number to the random variables used by this model.
bool m_withReplacement
If true, the building will be randomly selected with replacement.
static TypeId GetTypeId()
Get the type ID.
Ptr< UniformRandomVariable > m_rand
Provides uniform random variables.
Vector GetNext() const override
RandomBuildingPositionAllocator()
Allocate each position by randomly choosing a room from the list of all buildings,...
int64_t AssignStreams(int64_t stream) override
Assign a fixed random variable stream number to the random variables used by this model.
RandomRoomPositionAllocator()
Vector GetNext() const override
std::vector< RoomInfo > m_roomListWithoutReplacement
Container of rooms.
static TypeId GetTypeId()
Get the type ID.
Ptr< UniformRandomVariable > m_rand
Provides uniform random variables.
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.
Walks a given NodeContainer sequentially, and for each node allocate a new position randomly in the s...
SameRoomPositionAllocator()
NodeContainer m_nodes
Nodes container.
Ptr< UniformRandomVariable > m_rand
Provides uniform random variables.
int64_t AssignStreams(int64_t) override
Assign a fixed random variable stream number to the random variables used by this model.
Vector GetNext() const override
NodeContainer::Iterator m_nodeIt
Nodes iterator.
static TypeId GetTypeId()
Get the type ID.
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 > MakeBooleanAccessor(T1 a1)
Ptr< const AttributeChecker > MakeBooleanChecker()
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#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< Building > b
Building.
uint32_t floor
Room (floor number)
uint32_t roomx
Room (x coord)
uint32_t roomy
Room (y coord)