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-building-info.h" 
   21#include "ns3/mobility-model.h" 
   22#include "ns3/pointer.h" 
   23#include "ns3/random-variable-stream.h" 
   24#include "ns3/string.h" 
   25#include "ns3/uinteger.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);
 
  171        double x = 
m_x->GetValue();
 
  172        double y = 
m_y->GetValue();
 
  173        double z = 
m_z->GetValue();
 
  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);
 
 
  215    m_x->SetStream(stream);
 
  216    m_y->SetStream(stream + 1);
 
  217    m_z->SetStream(stream + 2);
 
 
  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);
 
  286    NS_LOG_LOGIC(
"randomly allocating position in (" << x1 << 
"," << x2 << 
") " 
  287                                                     << 
"x (" << y1 << 
"," << y2 << 
") " 
  288                                                     << 
"x (" << z1 << 
"," << z2 << 
") ");
 
  290    double x = 
m_rand->GetValue(x1, x2);
 
  291    double y = 
m_rand->GetValue(y1, y2);
 
  292    double z = 
m_rand->GetValue(z1, z2);
 
  294    return Vector(x, y, z);
 
 
  300    m_rand->SetStream(stream);
 
 
  308    NS_FATAL_ERROR(
" Constructor \"SameRoomPositionAllocator ()\" should not be used");
 
 
  320        NS_ASSERT_MSG(mm, 
"no mobility model aggregated to this node");
 
  323                      "MobilityBuildingInfo has not been aggregated to this node mobility model");
 
  324        bmm->MakeConsistent(mm);
 
 
  331    static TypeId tid = 
TypeId(
"ns3::SameRoomPositionAllocator")
 
  333                            .SetGroupName(
"Buildings")
 
 
  349    NS_LOG_LOGIC(
"considering node " << (*m_nodeIt)->GetId());
 
  351    NS_ASSERT_MSG(mm, 
"no mobility model aggregated to this node");
 
  353    NS_ASSERT_MSG(bmm, 
"MobilityBuildingInfo has not been aggregated to this node mobility model");
 
  356    uint32_t roomx = bmm->GetRoomNumberX();
 
  357    uint32_t roomy = bmm->GetRoomNumberY();
 
  358    uint32_t floor = bmm->GetFloorNumber();
 
  359    NS_LOG_LOGIC(
"considering building " << bmm->GetBuilding()->GetId() << 
" room (" << roomx
 
  360                                         << 
", " << roomy << 
", " << floor << 
")");
 
  365    b->GetAttribute(
"Boundaries", bv);
 
  367    double rdx = (box.
xMax - box.
xMin) / b->GetNRoomsX();
 
  368    double rdy = (box.
yMax - box.
yMin) / b->GetNRoomsY();
 
  369    double rdz = (box.
zMax - box.
zMin) / b->GetNFloors();
 
  370    double x1 = box.
xMin + rdx * (roomx - 1);
 
  371    double x2 = box.
xMin + rdx * roomx;
 
  372    double y1 = box.
yMin + rdy * (roomy - 1);
 
  373    double y2 = box.
yMin + rdy * roomy;
 
  374    double z1 = box.
zMin + rdz * (floor - 1);
 
  375    double z2 = box.
zMin + rdz * floor;
 
  376    NS_LOG_LOGIC(
"randomly allocating position in (" << x1 << 
"," << x2 << 
") " 
  377                                                     << 
"x (" << y1 << 
"," << y2 << 
") " 
  378                                                     << 
"x (" << z1 << 
"," << z2 << 
") ");
 
  380    double x = 
m_rand->GetValue(x1, x2);
 
  381    double y = 
m_rand->GetValue(y1, y2);
 
  382    double z = 
m_rand->GetValue(z1, z2);
 
  384    return Vector(x, y, z);
 
 
  390    m_rand->SetStream(stream);
 
 
  411    static TypeId tid = 
TypeId(
"ns3::FixedRoomPositionAllocator")
 
  413                            .SetGroupName(
"Buildings")
 
 
  422                                         << 
", " << 
floor << 
")");
 
  426    Box box = 
bptr->GetBoundaries();
 
  427    double rdx = (box.
xMax - box.
xMin) / 
bptr->GetNRoomsX();
 
  428    double rdy = (box.
yMax - box.
yMin) / 
bptr->GetNRoomsY();
 
  429    double rdz = (box.
zMax - box.
zMin) / 
bptr->GetNFloors();
 
  430    double x1 = box.
xMin + rdx * (
roomx - 1);
 
  432    double y1 = box.
yMin + rdy * (
roomy - 1);
 
  434    double z1 = box.
zMin + rdz * (
floor - 1);
 
  436    NS_LOG_LOGIC(
"randomly allocating position in (" << x1 << 
"," << x2 << 
") " 
  437                                                     << 
"x (" << y1 << 
"," << y2 << 
") " 
  438                                                     << 
"x (" << z1 << 
"," << z2 << 
") ");
 
  440    double x = 
m_rand->GetValue(x1, x2);
 
  441    double y = 
m_rand->GetValue(y1, y2);
 
  442    double z = 
m_rand->GetValue(z1, z2);
 
  443    return Vector(x, y, z);
 
 
  449    m_rand->SetStream(stream);
 
 
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()
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.
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.
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.
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 AttributeChecker > MakeBooleanChecker()
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< AttributeChecker > MakePointerChecker()
Create a PointerChecker for a type.
Ptr< const AttributeChecker > MakeUintegerChecker()
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.
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< Building > b
Building.
uint32_t floor
Room (floor number)
uint32_t roomx
Room (x coord)
uint32_t roomy
Room (y coord)