20 #include "building-position-allocator.h"
21 #include "ns3/buildings-mobility-model.h"
22 #include "ns3/buildings-helper.h"
23 #include "ns3/random-variable-stream.h"
24 #include "ns3/double.h"
25 #include "ns3/uinteger.h"
27 #include "ns3/boolean.h"
30 #include "ns3/building.h"
33 #include "ns3/building-list.h"
39 NS_OBJECT_ENSURE_REGISTERED (RandomBuildingPositionAllocator);
42 RandomBuildingPositionAllocator::RandomBuildingPositionAllocator ()
44 m_rand = CreateObject<UniformRandomVariable> ();
48 RandomBuildingPositionAllocator::GetTypeId (
void)
50 static TypeId tid = TypeId (
"ns3::RandomBuildingPositionAllocator")
51 .SetParent<PositionAllocator> ()
52 .SetGroupName (
"Mobility")
53 .AddConstructor<RandomBuildingPositionAllocator> ()
54 .AddAttribute (
"WithReplacement",
55 "If true, the building will be randomly selected with replacement. "
56 "If false, no replacement will occur, until the list of buildings "
57 "to select becomes empty, at which point it will be filled again "
58 "with the list of all buildings.",
60 MakeBooleanAccessor (&RandomBuildingPositionAllocator::m_withReplacement),
61 MakeBooleanChecker ());
70 if (m_withReplacement)
77 if (m_buildingListWithoutReplacement.empty ())
81 m_buildingListWithoutReplacement.push_back (*bit);
84 uint32_t n =
m_rand->
GetInteger (0, m_buildingListWithoutReplacement.size () - 1);
85 b = m_buildingListWithoutReplacement.at (n);
86 m_buildingListWithoutReplacement.erase (m_buildingListWithoutReplacement.begin () + n);
91 b->GetAttribute (
"Boundaries", bv);
109 RandomRoomPositionAllocator::RandomRoomPositionAllocator ()
111 m_rand = CreateObject<UniformRandomVariable> ();
115 RandomRoomPositionAllocator::GetTypeId (
void)
117 static TypeId tid = TypeId (
"ns3::RandomRoomPositionAllocator")
118 .SetParent<PositionAllocator> ()
119 .SetGroupName (
"Mobility")
120 .AddConstructor<RandomRoomPositionAllocator> ();
130 if (m_roomListWithoutReplacement.empty ())
135 for (uint32_t rx = 1; rx <= (*bit)->GetNRoomsX (); ++rx)
137 for (uint32_t ry = 1; ry <= (*bit)->GetNRoomsY (); ++ry)
139 for (uint32_t f = 1; f <= (*bit)->GetNFloors (); ++f)
146 NS_LOG_LOGIC (
"adding room (" << rx <<
", " << ry <<
", " << f <<
")");
147 m_roomListWithoutReplacement.push_back (i);
153 uint32_t n =
m_rand->
GetInteger (0,m_roomListWithoutReplacement.size () - 1);
154 RoomInfo r = m_roomListWithoutReplacement.at (n);
155 m_roomListWithoutReplacement.erase (m_roomListWithoutReplacement.begin () + n);
156 NS_LOG_LOGIC (
"considering building " << r.b->GetId () <<
" room (" << r.roomx <<
", " << r.roomy <<
", " << r.floor <<
")");
160 r.b->GetAttribute (
"Boundaries", bv);
162 double rdx = (box.xMax - box.xMin) / r.b->GetNRoomsX ();
163 double rdy = (box.yMax - box.yMin) / r.b->GetNRoomsY ();
164 double rdz = (box.zMax - box.zMin) / r.b->GetNFloors ();
165 double x1 = box.xMin + rdx * (r.roomx - 1);
166 double x2 = box.xMin + rdx * r.roomx;
167 double y1 = box.yMin + rdy * (r.roomy -1);
168 double y2 = box.yMin + rdy * r.roomy;
169 double z1 = box.zMin + rdz * (r.floor - 1);
170 double z2 = box.zMin + rdz * r.floor;
172 <<
" (" << x1 <<
"," << x2 <<
") "
173 <<
"x (" << y1 <<
"," << y2 <<
") "
174 <<
"x (" << z1 <<
"," << z2 <<
") ");
196 SameRoomPositionAllocator::SameRoomPositionAllocator ()
198 NS_FATAL_ERROR (
" Constructor \"SameRoomPositionAllocator ()\" should not be used");
202 SameRoomPositionAllocator::SameRoomPositionAllocator (NodeContainer c)
205 m_rand = CreateObject<UniformRandomVariable> ();
206 m_nodeIt = m_nodes.Begin ();
208 for (NodeContainer::Iterator it = m_nodes.Begin (); it != m_nodes.End (); ++it)
210 Ptr<MobilityModel> mm = (*it)->
GetObject<MobilityModel> ();
211 NS_ASSERT_MSG (mm,
"no mobility model aggregated to this node");
212 Ptr<BuildingsMobilityModel> bmm = DynamicCast<BuildingsMobilityModel> (mm);
213 NS_ASSERT_MSG (bmm,
"mobility model aggregated to this node is not a BuildingsMobilityModel");
214 BuildingsHelper::MakeConsistent (bmm);
219 SameRoomPositionAllocator::GetTypeId (
void)
221 static TypeId tid = TypeId (
"ns3::SameRoomPositionAllocator")
222 .SetParent<PositionAllocator> ()
223 .SetGroupName (
"Mobility")
224 .AddConstructor<SameRoomPositionAllocator> ();
232 if (m_nodeIt == m_nodes.
End ())
234 m_nodeIt = m_nodes.
Begin ();
239 NS_LOG_LOGIC (
"considering node " << (*m_nodeIt)->GetId ());
241 NS_ASSERT_MSG (mm,
"no mobility model aggregated to this node");
243 NS_ASSERT_MSG (bmm,
"mobility model aggregated to this node is not a BuildingsMobilityModel");
246 uint32_t roomx = bmm->GetRoomNumberX ();
247 uint32_t roomy = bmm->GetRoomNumberY ();
248 uint32_t floor = bmm->GetFloorNumber ();
249 NS_LOG_LOGIC (
"considering building " << bmm->GetBuilding ()->GetId () <<
" room (" << roomx <<
", " << roomy <<
", " << floor <<
")");
254 b->GetAttribute (
"Boundaries", bv);
256 double rdx = (box.xMax - box.xMin) / b->GetNRoomsX ();
257 double rdy = (box.yMax - box.yMin) / b->GetNRoomsY ();
258 double rdz = (box.zMax - box.zMin) / b->GetNFloors ();
259 double x1 = box.xMin + rdx * (roomx - 1);
260 double x2 = box.xMin + rdx * roomx;
261 double y1 = box.yMin + rdy * (roomy -1);
262 double y2 = box.yMin + rdy * roomy;
263 double z1 = box.zMin + rdz * (floor - 1);
264 double z2 = box.zMin + rdz * floor;
266 <<
" (" << x1 <<
"," << x2 <<
") "
267 <<
"x (" << y1 <<
"," << y2 <<
") "
268 <<
"x (" << z1 <<
"," << z2 <<
") ");
Ptr< UniformRandomVariable > m_rand
Provides uniform random variables.
smart pointer class similar to boost::intrusive_ptr
#define NS_LOG_FUNCTION(parameters)
void SetStream(int64_t stream)
Specifies the stream number for this RNG stream.
static uint32_t GetNBuildings(void)
static Ptr< Building > GetBuilding(uint32_t n)
#define NS_LOG_COMPONENT_DEFINE(name)
Iterator End(void) const
Get an iterator which indicates past-the-last Node in the container.
static Iterator End(void)
static Iterator Begin(void)
virtual Vector GetNext(void) const
#define NS_FATAL_ERROR(msg)
fatal error handling
Keep track of the current position and velocity of an object.
int64_t AssignStreams(int64_t stream)
hold objects of type ns3::Box
#define NS_LOG_LOGIC(msg)
Ptr< UniformRandomVariable > m_rand
Provides uniform random variables.
Iterator Begin(void) const
Get an iterator which refers to the first Node in the container.
#define NS_ASSERT_MSG(condition, message)
int64_t AssignStreams(int64_t stream)
Ptr< UniformRandomVariable > m_rand
Provides uniform random variables.
virtual Vector GetNext(void) const
Ptr< T > GetObject(void) const
virtual Vector GetNext(void) const
int64_t AssignStreams(int64_t)