22 #include <ns3/mobility-building-info.h>
23 #include "ns3/mobility-model.h"
24 #include "ns3/buildings-helper.h"
25 #include "ns3/random-variable-stream.h"
26 #include "ns3/double.h"
27 #include "ns3/uinteger.h"
29 #include "ns3/boolean.h"
32 #include "ns3/building.h"
33 #include "ns3/string.h"
34 #include "ns3/pointer.h"
37 #include "ns3/building-list.h"
48 m_rand = CreateObject<UniformRandomVariable> ();
54 static TypeId tid =
TypeId (
"ns3::RandomBuildingPositionAllocator")
56 .SetGroupName (
"Buildings")
58 .AddAttribute (
"WithReplacement",
59 "If true, the building will be randomly selected with replacement. "
60 "If false, no replacement will occur, until the list of buildings "
61 "to select becomes empty, at which point it will be filled again "
62 "with the list of all buildings.",
95 b->GetAttribute (
"Boundaries", bv);
99 return Vector (
x, y, z);
119 static TypeId tid =
TypeId (
"ns3::OutdoorPositionAllocator")
121 .SetGroupName (
"Buildings")
124 "A random variable which represents the x coordinate of a position in a random box.",
125 StringValue (
"ns3::UniformRandomVariable[Min=0.0|Max=1.0]"),
127 MakePointerChecker<RandomVariableStream> ())
129 "A random variable which represents the y coordinate of a position in a random box.",
130 StringValue (
"ns3::UniformRandomVariable[Min=0.0|Max=1.0]"),
132 MakePointerChecker<RandomVariableStream> ())
134 "A random variable which represents the z coordinate of a position in a random box.",
135 StringValue (
"ns3::UniformRandomVariable[Min=0.0|Max=1.0]"),
137 MakePointerChecker<RandomVariableStream> ())
138 .AddAttribute (
"MaxAttempts",
139 "Maximum number of attempts for the rejection sampling before giving up.",
142 MakeUintegerChecker<uint32_t> ())
169 bool outdoor =
false;
170 uint32_t attempts = 0;
171 Vector position = Vector (0,0,0);
180 position = Vector (
x, y, z);
187 if ((*bit)->IsInside (position))
189 NS_LOG_INFO (
"Position " << position <<
" is inside the building with boundaries "
190 << (*bit)->GetBoundaries ().xMin <<
" " << (*bit)->GetBoundaries ().xMax <<
" "
191 << (*bit)->GetBoundaries ().yMin <<
" " << (*bit)->GetBoundaries ().yMax <<
" "
192 << (*bit)->GetBoundaries ().zMin <<
" " << (*bit)->GetBoundaries ().zMax);
205 NS_LOG_INFO (
"Outdoor position found " << position);
230 m_rand = CreateObject<UniformRandomVariable> ();
236 static TypeId tid =
TypeId (
"ns3::RandomRoomPositionAllocator")
238 .SetGroupName (
"Buildings")
254 for (uint32_t rx = 1; rx <= (*bit)->GetNRoomsX (); ++rx)
256 for (uint32_t ry = 1; ry <= (*bit)->GetNRoomsY (); ++ry)
258 for (uint32_t
f = 1;
f <= (*bit)->GetNFloors (); ++
f)
265 NS_LOG_LOGIC (
"adding room (" << rx <<
", " << ry <<
", " <<
f <<
")");
279 r.
b->GetAttribute (
"Boundaries", bv);
281 double rdx = (box.
xMax - box.
xMin) / r.
b->GetNRoomsX ();
282 double rdy = (box.
yMax - box.
yMin) / r.
b->GetNRoomsY ();
283 double rdz = (box.
zMax - box.
zMin) / r.
b->GetNFloors ();
284 double x1 = box.
xMin + rdx * (r.
roomx - 1);
286 double y1 = box.
yMin + rdy * (r.
roomy -1);
288 double z1 = box.
zMin + rdz * (r.
floor - 1);
291 <<
" (" << x1 <<
"," << x2 <<
") "
292 <<
"x (" << y1 <<
"," << y2 <<
") "
293 <<
"x (" << z1 <<
"," << z2 <<
") ");
299 return Vector (
x, y, z);
317 NS_FATAL_ERROR (
" Constructor \"SameRoomPositionAllocator ()\" should not be used");
324 m_rand = CreateObject<UniformRandomVariable> ();
330 NS_ASSERT_MSG (mm,
"no mobility model aggregated to this node");
332 NS_ASSERT_MSG (bmm,
"MobilityBuildingInfo has not been aggregated to this node mobility model");
333 bmm->MakeConsistent (mm);
340 static TypeId tid =
TypeId (
"ns3::SameRoomPositionAllocator")
342 .SetGroupName (
"Buildings")
358 NS_LOG_LOGIC (
"considering node " << (*m_nodeIt)->GetId ());
360 NS_ASSERT_MSG (mm,
"no mobility model aggregated to this node");
362 NS_ASSERT_MSG (bmm,
"MobilityBuildingInfo has not been aggregated to this node mobility model");
365 uint32_t roomx = bmm->GetRoomNumberX ();
366 uint32_t roomy = bmm->GetRoomNumberY ();
367 uint32_t floor = bmm->GetFloorNumber ();
368 NS_LOG_LOGIC (
"considering building " << bmm->GetBuilding ()->GetId () <<
" room (" << roomx <<
", " << roomy <<
", " << floor <<
")");
373 b->GetAttribute (
"Boundaries", bv);
375 double rdx = (box.
xMax - box.
xMin) / b->GetNRoomsX ();
376 double rdy = (box.
yMax - box.
yMin) / b->GetNRoomsY ();
377 double rdz = (box.
zMax - box.
zMin) / b->GetNFloors ();
378 double x1 = box.
xMin + rdx * (roomx - 1);
379 double x2 = box.
xMin + rdx * roomx;
380 double y1 = box.
yMin + rdy * (roomy -1);
381 double y2 = box.
yMin + rdy * roomy;
382 double z1 = box.
zMin + rdz * (floor - 1);
383 double z2 = box.
zMin + rdz * floor;
385 <<
" (" << x1 <<
"," << x2 <<
") "
386 <<
"x (" << y1 <<
"," << y2 <<
") "
387 <<
"x (" << z1 <<
"," << z2 <<
") ");
393 return Vector (
x, y, z);
412 m_rand = CreateObject<UniformRandomVariable> ();
422 static TypeId tid =
TypeId (
"ns3::FixedRoomPositionAllocator")
424 .SetGroupName (
"Buildings")
437 Box box =
bptr->GetBoundaries ();
438 double rdx = (box.
xMax - box.
xMin) /
bptr->GetNRoomsX ();
439 double rdy = (box.
yMax - box.
yMin) /
bptr->GetNRoomsY ();
440 double rdz = (box.
zMax - box.
zMin) /
bptr->GetNFloors ();
441 double x1 = box.
xMin + rdx * (
roomx - 1);
445 double z1 = box.
zMin + rdz * (
floor - 1);
448 <<
" (" << x1 <<
"," << x2 <<
") "
449 <<
"x (" << y1 <<
"," << y2 <<
") "
450 <<
"x (" << z1 <<
"," << z2 <<
") ");
455 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)
static uint32_t GetNBuildings(void)
std::vector< Ptr< Building > >::const_iterator Iterator
Const Iterator.
static Iterator End(void)
static Iterator Begin(void)
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.
Ptr< UniformRandomVariable > m_rand
Provides uniform random variables.
Ptr< Building > bptr
Pointer to the chosen building.
FixedRoomPositionAllocator(uint32_t x, uint32_t y, uint32_t z, Ptr< Building > b)
int64_t AssignStreams(int64_t)
Assign a fixed random variable stream number to the random variables used by this model.
static TypeId GetTypeId(void)
Get the type ID.
virtual Vector GetNext(void) const
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 Begin(void) const
Get an iterator which refers to the first Node in the container.
Iterator End(void) const
Get an iterator which indicates past-the-last Node in the container.
std::vector< Ptr< Node > >::const_iterator Iterator
Node container iterator.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
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
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
void SetX(Ptr< RandomVariableStream > x)
Set the random variable stream object that generates x-positions.
virtual Vector GetNext(void) const
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.
static TypeId GetTypeId(void)
Get the type ID.
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,...
static TypeId GetTypeId(void)
Get the type ID.
bool m_withReplacement
If true, the building will be randomly selected with replacement.
Ptr< UniformRandomVariable > m_rand
Provides uniform random variables.
virtual Vector GetNext(void) const
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
std::vector< Ptr< Building > > m_buildingListWithoutReplacement
List of building without replacement.
RandomBuildingPositionAllocator()
Allocate each position by randomly choosing a room from the list of all buildings,...
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
RandomRoomPositionAllocator()
std::vector< RoomInfo > m_roomListWithoutReplacement
Container of rooms.
Ptr< UniformRandomVariable > m_rand
Provides uniform random variables.
static TypeId GetTypeId(void)
Get the type ID.
virtual Vector GetNext(void) const
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.
Walks a given NodeContainer sequentially, and for each node allocate a new position randomly in the s...
int64_t AssignStreams(int64_t)
Assign a fixed random variable stream number to the random variables used by this model.
SameRoomPositionAllocator()
NodeContainer m_nodes
Nodes container.
Ptr< UniformRandomVariable > m_rand
Provides uniform random variables.
virtual Vector GetNext(void) const
NodeContainer::Iterator m_nodeIt
Nodes iterator.
static TypeId GetTypeId(void)
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 AttributeChecker > MakeBooleanChecker(void)
Ptr< const AttributeAccessor > MakeBooleanAccessor(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_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.
list x
Random number samples.
Ptr< Building > b
Building.
uint32_t floor
Room (floor number)
uint32_t roomx
Room (x coord)
uint32_t roomy
Room (y coord)