|
A Discrete-Event Network Simulator
|
API
|
Go to the documentation of this file.
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);
a unique identifier for an interface.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
static Iterator Begin(void)
Allocate each position by randomly choosing a building from the list of all buildings,...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
AttributeValue implementation for Boolean.
int64_t AssignStreams(int64_t)
Assign a fixed random variable stream number to the random variables used by this model.
Ptr< UniformRandomVariable > m_rand
Provides uniform random variables.
Generate a random position uniformly distributed in the volume of a chosen room inside a chosen build...
std::vector< Ptr< Building > > m_buildingListWithoutReplacement
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Walks a given NodeContainer sequentially, and for each node allocate a new position randomly in the s...
double zMin
The z coordinate of the down bound of the box.
RandomBuildingPositionAllocator()
OutdoorPositionAllocator()
Ptr< UniformRandomVariable > m_rand
Provides uniform random variables.
double xMin
The x coordinate of the left bound of the box.
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Ptr< RandomVariableStream > m_y
pointer to y's random variable stream
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 Iterator End(void)
double yMin
The y coordinate of the bottom bound of the box.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Ptr< UniformRandomVariable > m_rand
Provides uniform random variables.
static TypeId GetTypeId(void)
Smart pointer class similar to boost::intrusive_ptr.
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
std::vector< Ptr< Building > >::const_iterator Iterator
static uint32_t GetNBuildings(void)
mobility buildings information (to be used by mobility models)
RandomRoomPositionAllocator()
Iterator Begin(void) const
Get an iterator which refers to the first Node in the container.
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
allocate outdoor positions
static TypeId GetTypeId(void)
Ptr< const AttributeChecker > MakeBooleanChecker(void)
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.
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
void SetZ(Ptr< RandomVariableStream > z)
Set the random variable stream object that generates z-positions.
double zMax
The z coordinate of the up bound of the box.
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Hold variables of type string.
std::vector< RoomInfo > m_roomListWithoutReplacement
virtual Vector GetNext(void) const
SameRoomPositionAllocator()
std::vector< Ptr< Node > >::const_iterator Iterator
Node container iterator.
Ptr< RandomVariableStream > m_z
pointer to z's random variable stream
uint32_t m_maxAttempts
maximum number of attempts before giving up
virtual double GetValue(void)=0
Get the next random value as a double drawn from the distribution.
FixedRoomPositionAllocator(uint32_t x, uint32_t y, uint32_t z, Ptr< Building > b)
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model.
double f(double x, void *params)
static Ptr< Building > GetBuilding(uint32_t n)
Allocate a set of positions.
AttributeValue implementation for Box.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Keep track of the current position and velocity of an object.
keep track of a set of node pointers.
Iterator End(void) const
Get an iterator which indicates past-the-last Node in the container.
void SetStream(int64_t stream)
Specifies the stream number for the RngStream.
Hold an unsigned integer type.
NodeContainer::Iterator m_nodeIt
virtual Vector GetNext(void) const
Ptr< RandomVariableStream > m_x
pointer to x's random variable stream
virtual Vector GetNext(void) const
virtual Vector GetNext(void) const
Ptr< UniformRandomVariable > m_rand
Provides uniform random variables.
static TypeId GetTypeId(void)
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
void SetX(Ptr< RandomVariableStream > x)
Set the random variable stream object that generates x-positions.
Allocate each position by randomly choosing a room from the list of all buildings,...
double xMax
The x coordinate of the right bound of the box.
int64_t AssignStreams(int64_t)
Assign a fixed random variable stream number to the random variables used by this model.
static TypeId GetTypeId(void)
static TypeId GetTypeId(void)
void SetY(Ptr< RandomVariableStream > y)
Set the random variable stream object that generates y-positions.
double yMax
The y coordinate of the top bound of the box.