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");
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);
442 double x2 = box.xMin + rdx *
roomx;
443 double y1 = box.yMin + rdy * (
roomy -1);
444 double y2 = box.yMin + rdy *
roomy;
445 double z1 = box.zMin + rdz * (
floor - 1);
446 double z2 = box.zMin + rdz *
floor;
448 <<
" (" << x1 <<
"," << x2 <<
") " 449 <<
"x (" << y1 <<
"," << y2 <<
") " 450 <<
"x (" << z1 <<
"," << z2 <<
") ");
455 return Vector (
x, y, z);
Ptr< UniformRandomVariable > m_rand
Provides uniform random variables.
FixedRoomPositionAllocator(uint32_t x, uint32_t y, uint32_t z, Ptr< Building > b)
Smart pointer class similar to boost::intrusive_ptr.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
double zMin
The z coordinate of the down bound of the box.
void SetStream(int64_t stream)
Specifies the stream number for the RngStream.
AttributeValue implementation for Boolean.
Ptr< RandomVariableStream > m_z
pointer to z's random variable stream
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
std::vector< Ptr< Node > >::const_iterator Iterator
Node container iterator.
static uint32_t GetNBuildings(void)
NS_ASSERT_MSG(false, "Ipv4AddressGenerator::MaskToIndex(): Impossible")
Hold variables of type string.
static Ptr< Building > GetBuilding(uint32_t n)
virtual Vector GetNext(void) const
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
static TypeId GetTypeId(void)
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Walks a given NodeContainer sequentially, and for each node allocate a new position randomly in the s...
virtual Vector GetNext(void) const
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
static Iterator End(void)
Ptr< RandomVariableStream > m_y
pointer to y's random variable stream
Iterator End(void) const
Get an iterator which indicates past-the-last Node in the container.
double xMax
The x coordinate of the right bound of the box.
static Iterator Begin(void)
void SetZ(Ptr< RandomVariableStream > z)
Set the random variable stream object that generates z-positions.
virtual double GetValue(void)=0
Get the next random value as a double drawn from the distribution.
double yMax
The y coordinate of the top bound of the box.
static void MakeConsistent(Ptr< MobilityModel > bmm)
Make the given mobility model consistent, by determining whether its position falls inside any of the...
Keep track of the current position and velocity of an object.
RandomBuildingPositionAllocator()
virtual uint32_t GetInteger(void)=0
Get the next random value as an integer drawn from the distribution.
static TypeId GetTypeId(void)
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Generate a random position uniformly distributed in the volume of a chosen room inside a chosen build...
Allocate each position by randomly choosing a building from the list of all buildings, and then randomly choosing a position inside the building.
Hold an unsigned integer type.
int64_t AssignStreams(int64_t)
Assign a fixed random variable stream number to the random variables used by this model...
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 > >::const_iterator Iterator
AttributeValue implementation for Box.
double yMin
The y coordinate of the bottom bound of the box.
void SetX(Ptr< RandomVariableStream > x)
Set the random variable stream object that generates x-positions.
virtual Vector GetNext(void) const
Ptr< UniformRandomVariable > m_rand
Provides uniform random variables.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
double f(double x, void *params)
Every class exported by the ns3 library is enclosed in the ns3 namespace.
keep track of a set of node pointers.
Ptr< UniformRandomVariable > m_rand
Provides uniform random variables.
Ptr< const AttributeChecker > MakeBooleanChecker(void)
Ptr< RandomVariableStream > m_x
pointer to x's random variable stream
SameRoomPositionAllocator()
double zMax
The z coordinate of the up bound of the box.
void SetY(Ptr< RandomVariableStream > y)
Set the random variable stream object that generates y-positions.
Allocate each position by randomly choosing a room from the list of all buildings, and then randomly choosing a position inside the room.
NS_LOG_LOGIC("Net device "<< nd<< " is not bridged")
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...
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model...
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
Ptr< UniformRandomVariable > m_rand
Provides uniform random variables.
std::vector< Ptr< Building > > m_buildingListWithoutReplacement
OutdoorPositionAllocator()
static TypeId GetTypeId(void)
mobility buildings information (to be used by mobility models)
allocate outdoor positions
virtual Vector GetNext(void) const
static TypeId GetTypeId(void)
static TypeId GetTypeId(void)
virtual Vector GetNext(void) const
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
NodeContainer::Iterator m_nodeIt
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
RandomRoomPositionAllocator()
Iterator Begin(void) const
Get an iterator which refers to the first Node in the container.
int64_t AssignStreams(int64_t)
Assign a fixed random variable stream number to the random variables used by this model...
double xMin
The x coordinate of the left bound of the box.
Allocate a set of positions.
std::vector< RoomInfo > m_roomListWithoutReplacement