13#include "ns3/boolean.h"
15#include "ns3/building-list.h"
16#include "ns3/building.h"
17#include "ns3/double.h"
20#include "ns3/mobility-model.h"
21#include "ns3/pointer.h"
22#include "ns3/random-variable-stream.h"
23#include "ns3/string.h"
24#include "ns3/uinteger.h"
25#include <ns3/mobility-building-info.h>
45 TypeId(
"ns3::RandomBuildingPositionAllocator")
47 .SetGroupName(
"Buildings")
49 .AddAttribute(
"WithReplacement",
50 "If true, the building will be randomly selected with replacement. "
51 "If false, no replacement will occur, until the list of buildings "
52 "to select becomes empty, at which point it will be filled again "
53 "with the list of all buildings.",
86 b->GetAttribute(
"Boundaries", bv);
90 return Vector(x, y, z);
110 TypeId(
"ns3::OutdoorPositionAllocator")
112 .SetGroupName(
"Buildings")
115 "A random variable which represents the x coordinate of a position in a "
117 StringValue(
"ns3::UniformRandomVariable[Min=0.0|Max=1.0]"),
121 "A random variable which represents the y coordinate of a position in a "
123 StringValue(
"ns3::UniformRandomVariable[Min=0.0|Max=1.0]"),
127 "A random variable which represents the z coordinate of a position in a "
129 StringValue(
"ns3::UniformRandomVariable[Min=0.0|Max=1.0]"),
132 .AddAttribute(
"MaxAttempts",
133 "Maximum number of attempts for the rejection sampling before giving up.",
164 bool outdoor =
false;
166 Vector position = Vector(0, 0, 0);
175 position = Vector(x, y, z);
182 if ((*bit)->IsInside(position))
185 << position <<
" is inside the building with boundaries "
186 << (*bit)->GetBoundaries().xMin <<
" " << (*bit)->GetBoundaries().xMax
187 <<
" " << (*bit)->GetBoundaries().yMin <<
" "
188 << (*bit)->GetBoundaries().yMax <<
" " << (*bit)->GetBoundaries().zMin
189 <<
" " << (*bit)->GetBoundaries().zMax);
202 NS_LOG_INFO(
"Outdoor position found " << position);
231 static TypeId tid =
TypeId(
"ns3::RandomRoomPositionAllocator")
233 .SetGroupName(
"Buildings")
249 for (
uint32_t rx = 1; rx <= (*bit)->GetNRoomsX(); ++rx)
251 for (
uint32_t ry = 1; ry <= (*bit)->GetNRoomsY(); ++ry)
253 for (
uint32_t f = 1; f <= (*bit)->GetNFloors(); ++f)
260 NS_LOG_LOGIC(
"adding room (" << rx <<
", " << ry <<
", " << f <<
")");
271 <<
", " << r.
floor <<
")");
275 r.
b->GetAttribute(
"Boundaries", bv);
277 double rdx = (box.
xMax - box.
xMin) / r.
b->GetNRoomsX();
278 double rdy = (box.
yMax - box.
yMin) / r.
b->GetNRoomsY();
279 double rdz = (box.
zMax - box.
zMin) / r.
b->GetNFloors();
280 double x1 = box.
xMin + rdx * (r.
roomx - 1);
282 double y1 = box.
yMin + rdy * (r.
roomy - 1);
284 double z1 = box.
zMin + rdz * (r.
floor - 1);
287 <<
" (" << x1 <<
"," << x2 <<
") "
288 <<
"x (" << y1 <<
"," << y2 <<
") "
289 <<
"x (" << z1 <<
"," << z2 <<
") ");
291 double x =
m_rand->GetValue(x1, x2);
292 double y =
m_rand->GetValue(y1, y2);
293 double z =
m_rand->GetValue(z1, z2);
295 return Vector(x, y, z);
301 m_rand->SetStream(stream);
309 NS_FATAL_ERROR(
" Constructor \"SameRoomPositionAllocator ()\" should not be used");
321 NS_ASSERT_MSG(mm,
"no mobility model aggregated to this node");
324 "MobilityBuildingInfo has not been aggregated to this node mobility model");
325 bmm->MakeConsistent(mm);
332 static TypeId tid =
TypeId(
"ns3::SameRoomPositionAllocator")
334 .SetGroupName(
"Buildings")
350 NS_LOG_LOGIC(
"considering node " << (*m_nodeIt)->GetId());
352 NS_ASSERT_MSG(mm,
"no mobility model aggregated to this node");
354 NS_ASSERT_MSG(bmm,
"MobilityBuildingInfo has not been aggregated to this node mobility model");
357 uint32_t roomx = bmm->GetRoomNumberX();
358 uint32_t roomy = bmm->GetRoomNumberY();
359 uint32_t floor = bmm->GetFloorNumber();
360 NS_LOG_LOGIC(
"considering building " << bmm->GetBuilding()->GetId() <<
" room (" << roomx
361 <<
", " << roomy <<
", " << floor <<
")");
366 b->GetAttribute(
"Boundaries", bv);
368 double rdx = (box.
xMax - box.
xMin) / b->GetNRoomsX();
369 double rdy = (box.
yMax - box.
yMin) / b->GetNRoomsY();
370 double rdz = (box.
zMax - box.
zMin) / b->GetNFloors();
371 double x1 = box.
xMin + rdx * (roomx - 1);
372 double x2 = box.
xMin + rdx * roomx;
373 double y1 = box.
yMin + rdy * (roomy - 1);
374 double y2 = box.
yMin + rdy * roomy;
375 double z1 = box.
zMin + rdz * (floor - 1);
376 double z2 = box.
zMin + rdz * floor;
378 <<
" (" << x1 <<
"," << x2 <<
") "
379 <<
"x (" << y1 <<
"," << y2 <<
") "
380 <<
"x (" << z1 <<
"," << z2 <<
") ");
382 double x =
m_rand->GetValue(x1, x2);
383 double y =
m_rand->GetValue(y1, y2);
384 double z =
m_rand->GetValue(z1, z2);
386 return Vector(x, y, z);
392 m_rand->SetStream(stream);
413 static TypeId tid =
TypeId(
"ns3::FixedRoomPositionAllocator")
415 .SetGroupName(
"Buildings")
424 <<
", " <<
floor <<
")");
428 Box box =
bptr->GetBoundaries();
429 double rdx = (box.
xMax - box.
xMin) /
bptr->GetNRoomsX();
430 double rdy = (box.
yMax - box.
yMin) /
bptr->GetNRoomsY();
431 double rdz = (box.
zMax - box.
zMin) /
bptr->GetNFloors();
432 double x1 = box.
xMin + rdx * (
roomx - 1);
434 double y1 = box.
yMin + rdy * (
roomy - 1);
436 double z1 = box.
zMin + rdz * (
floor - 1);
439 <<
" (" << x1 <<
"," << x2 <<
") "
440 <<
"x (" << y1 <<
"," << y2 <<
") "
441 <<
"x (" << z1 <<
"," << z2 <<
") ");
443 double x =
m_rand->GetValue(x1, x2);
444 double y =
m_rand->GetValue(y1, y2);
445 double z =
m_rand->GetValue(z1, z2);
446 return Vector(x, y, z);
452 m_rand->SetStream(stream);
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.
static Ptr< Building > GetBuilding(uint32_t n)
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.
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 > MakePointerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Ptr< AttributeChecker > MakePointerChecker()
Create a PointerChecker for a type.
#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.
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
#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 > MakeBooleanChecker()
Ptr< const AttributeChecker > MakeUintegerChecker()
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Ptr< Building > b
Building.
uint32_t floor
Room (floor number)
uint32_t roomx
Room (x coord)
uint32_t roomy
Room (y coord)