21 #include <ns3/mobility-building-info.h>
22 #include "ns3/mobility-model.h"
23 #include "ns3/buildings-helper.h"
24 #include "ns3/random-variable-stream.h"
25 #include "ns3/double.h"
26 #include "ns3/uinteger.h"
28 #include "ns3/boolean.h"
31 #include "ns3/building.h"
34 #include "ns3/building-list.h"
45 m_rand = CreateObject<UniformRandomVariable> ();
51 static TypeId tid =
TypeId (
"ns3::RandomBuildingPositionAllocator")
53 .SetGroupName (
"Buildings")
55 .AddAttribute (
"WithReplacement",
56 "If true, the building will be randomly selected with replacement. "
57 "If false, no replacement will occur, until the list of buildings "
58 "to select becomes empty, at which point it will be filled again "
59 "with the list of all buildings.",
92 b->GetAttribute (
"Boundaries", bv);
96 return Vector (x, y, z);
112 m_rand = CreateObject<UniformRandomVariable> ();
118 static TypeId tid =
TypeId (
"ns3::RandomRoomPositionAllocator")
120 .SetGroupName (
"Buildings")
136 for (uint32_t rx = 1; rx <= (*bit)->GetNRoomsX (); ++rx)
138 for (uint32_t ry = 1; ry <= (*bit)->GetNRoomsY (); ++ry)
140 for (uint32_t f = 1; f <= (*bit)->GetNFloors (); ++f)
147 NS_LOG_LOGIC (
"adding room (" << rx <<
", " << ry <<
", " << f <<
")");
161 r.
b->GetAttribute (
"Boundaries", bv);
163 double rdx = (box.
xMax - box.
xMin) / r.
b->GetNRoomsX ();
164 double rdy = (box.
yMax - box.
yMin) / r.
b->GetNRoomsY ();
165 double rdz = (box.
zMax - box.
zMin) / r.
b->GetNFloors ();
166 double x1 = box.
xMin + rdx * (r.
roomx - 1);
168 double y1 = box.
yMin + rdy * (r.
roomy -1);
170 double z1 = box.
zMin + rdz * (r.
floor - 1);
173 <<
" (" << x1 <<
"," << x2 <<
") "
174 <<
"x (" << y1 <<
"," << y2 <<
") "
175 <<
"x (" << z1 <<
"," << z2 <<
") ");
181 return Vector (x, y, z);
199 NS_FATAL_ERROR (
" Constructor \"SameRoomPositionAllocator ()\" should not be used");
206 m_rand = CreateObject<UniformRandomVariable> ();
212 NS_ASSERT_MSG (mm,
"no mobility model aggregated to this node");
214 NS_ASSERT_MSG (bmm,
"MobilityBuildingInfo has not been aggregated to this node mobility model");
222 static TypeId tid =
TypeId (
"ns3::SameRoomPositionAllocator")
224 .SetGroupName (
"Buildings")
240 NS_LOG_LOGIC (
"considering node " << (*m_nodeIt)->GetId ());
242 NS_ASSERT_MSG (mm,
"no mobility model aggregated to this node");
244 NS_ASSERT_MSG (bmm,
"MobilityBuildingInfo has not been aggregated to this node mobility model");
247 uint32_t roomx = bmm->GetRoomNumberX ();
248 uint32_t roomy = bmm->GetRoomNumberY ();
249 uint32_t floor = bmm->GetFloorNumber ();
250 NS_LOG_LOGIC (
"considering building " << bmm->GetBuilding ()->GetId () <<
" room (" << roomx <<
", " << roomy <<
", " << floor <<
")");
255 b->GetAttribute (
"Boundaries", bv);
257 double rdx = (box.
xMax - box.
xMin) / b->GetNRoomsX ();
258 double rdy = (box.
yMax - box.
yMin) / b->GetNRoomsY ();
259 double rdz = (box.
zMax - box.
zMin) / b->GetNFloors ();
260 double x1 = box.
xMin + rdx * (roomx - 1);
261 double x2 = box.
xMin + rdx * roomx;
262 double y1 = box.
yMin + rdy * (roomy -1);
263 double y2 = box.
yMin + rdy * roomy;
264 double z1 = box.
zMin + rdz * (floor - 1);
265 double z2 = box.
zMin + rdz * floor;
267 <<
" (" << x1 <<
"," << x2 <<
") "
268 <<
"x (" << y1 <<
"," << y2 <<
") "
269 <<
"x (" << z1 <<
"," << z2 <<
") ");
275 return Vector (x, y, z);
294 m_rand = CreateObject<UniformRandomVariable> ();
304 static TypeId tid =
TypeId (
"ns3::FixedRoomPositionAllocator")
306 .SetGroupName (
"Buildings")
319 Box box =
bptr->GetBoundaries ();
320 double rdx = (box.xMax - box.xMin) /
bptr->GetNRoomsX ();
321 double rdy = (box.yMax - box.yMin) /
bptr->GetNRoomsY ();
322 double rdz = (box.zMax - box.zMin) /
bptr->GetNFloors ();
323 double x1 = box.xMin + rdx * (
roomx - 1);
324 double x2 = box.xMin + rdx *
roomx;
325 double y1 = box.yMin + rdy * (
roomy -1);
326 double y2 = box.yMin + rdy *
roomy;
327 double z1 = box.zMin + rdz * (
floor - 1);
328 double z2 = box.zMin + rdz *
floor;
330 <<
" (" << x1 <<
"," << x2 <<
") "
331 <<
"x (" << y1 <<
"," << y2 <<
") "
332 <<
"x (" << z1 <<
"," << z2 <<
") ");
337 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 this RNG stream.
AttributeValue implementation for Boolean.
#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)
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
static Ptr< Building > GetBuilding(uint32_t n)
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...
Iterator End(void) const
Get an iterator which indicates past-the-last Node in the container.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
static Iterator End(void)
double xMax
The x coordinate of the right bound of the box.
static Iterator Begin(void)
virtual Vector GetNext(void) const
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)
Generate a random position uniformly distributed in the volume of a chosen room inside a chosen build...
Allocate each position by randomly chosing a building from the list of all buildings, and then randomly chosing a position inside the building.
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...
virtual Vector GetNext(void) const
std::vector< Ptr< Building > >::const_iterator Iterator
AttributeValue implementation for Box.
double yMin
The y coordinate of the bottom bound of the box.
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Ptr< UniformRandomVariable > m_rand
Provides uniform random variables.
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)
Iterator Begin(void) const
Get an iterator which refers to the first Node in the container.
SameRoomPositionAllocator()
double zMax
The z coordinate of the up bound of the box.
Allocate each position by randomly chosing a room from the list of all buildings, and then randomly c...
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model...
Ptr< UniformRandomVariable > m_rand
Provides uniform random variables.
std::vector< Ptr< Building > > m_buildingListWithoutReplacement
mobility buildings information (to be used by mobility models)
static TypeId GetTypeId(void)
static TypeId GetTypeId(void)
virtual Vector GetNext(void) const
NodeContainer::Iterator m_nodeIt
virtual Vector GetNext(void) const
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
RandomRoomPositionAllocator()
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