|
|
| 16 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
16 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 |
* |
17 |
* |
| 18 |
* Author: Nicola Baldo <nbaldo@cttc.es> |
18 |
* Author: Nicola Baldo <nbaldo@cttc.es> |
|
|
19 |
* Michele Polese <michele.polese@gmail.com> for the OutdoorPositionAllocator class |
| 19 |
*/ |
20 |
*/ |
| 20 |
#include "building-position-allocator.h" |
21 |
#include "building-position-allocator.h" |
| 21 |
#include <ns3/mobility-building-info.h> |
22 |
#include <ns3/mobility-building-info.h> |
|
|
| 26 |
#include "ns3/uinteger.h" |
27 |
#include "ns3/uinteger.h" |
| 27 |
#include "ns3/enum.h" |
28 |
#include "ns3/enum.h" |
| 28 |
#include "ns3/boolean.h" |
29 |
#include "ns3/boolean.h" |
|
|
30 |
#include "ns3/string.h" |
| 31 |
#include "ns3/pointer.h" |
| 29 |
#include "ns3/log.h" |
32 |
#include "ns3/log.h" |
| 30 |
#include "ns3/box.h" |
33 |
#include "ns3/box.h" |
| 31 |
#include "ns3/building.h" |
34 |
#include "ns3/building.h" |
|
Lines 63-69
RandomBuildingPositionAllocator::GetTypeId (void)
|
Link Here
|
|---|
|
| 63 |
return tid; |
66 |
return tid; |
| 64 |
} |
67 |
} |
| 65 |
|
68 |
|
| 66 |
Vector |
69 |
Vector |
| 67 |
RandomBuildingPositionAllocator::GetNext () const |
70 |
RandomBuildingPositionAllocator::GetNext () const |
| 68 |
{ |
71 |
{ |
| 69 |
NS_ASSERT_MSG (BuildingList::GetNBuildings () > 0, "no building found"); |
72 |
NS_ASSERT_MSG (BuildingList::GetNBuildings () > 0, "no building found"); |
|
Lines 103-108
RandomBuildingPositionAllocator::AssignStreams (int64_t stream)
|
Link Here
|
|---|
|
| 103 |
return 1; |
106 |
return 1; |
| 104 |
} |
107 |
} |
| 105 |
|
108 |
|
|
|
109 |
NS_OBJECT_ENSURE_REGISTERED (OutdoorPositionAllocator); |
| 110 |
|
| 111 |
OutdoorPositionAllocator::OutdoorPositionAllocator () |
| 112 |
{ |
| 113 |
m_maxAttempts = 1000; |
| 114 |
} |
| 115 |
|
| 116 |
TypeId |
| 117 |
OutdoorPositionAllocator::GetTypeId (void) |
| 118 |
{ |
| 119 |
static TypeId tid = TypeId ("ns3::OutdoorPositionAllocator") |
| 120 |
.SetParent<PositionAllocator> () |
| 121 |
.SetGroupName ("Buildings") |
| 122 |
.AddConstructor<OutdoorPositionAllocator> () |
| 123 |
.AddAttribute ("X", |
| 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]"), |
| 126 |
MakePointerAccessor (&OutdoorPositionAllocator::m_x), |
| 127 |
MakePointerChecker<RandomVariableStream> ()) |
| 128 |
.AddAttribute ("Y", |
| 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]"), |
| 131 |
MakePointerAccessor (&OutdoorPositionAllocator::m_y), |
| 132 |
MakePointerChecker<RandomVariableStream> ()) |
| 133 |
.AddAttribute ("Z", |
| 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]"), |
| 136 |
MakePointerAccessor (&OutdoorPositionAllocator::m_z), |
| 137 |
MakePointerChecker<RandomVariableStream> ()) |
| 138 |
.AddAttribute ("MaxAttempts", |
| 139 |
"Maximum number of attempts for the rejection sampling before giving up.", |
| 140 |
UintegerValue (1000), |
| 141 |
MakeUintegerAccessor (&OutdoorPositionAllocator::m_maxAttempts), |
| 142 |
MakeUintegerChecker<uint32_t> ()) |
| 143 |
; |
| 144 |
|
| 145 |
return tid; |
| 146 |
} |
| 147 |
|
| 148 |
void |
| 149 |
OutdoorPositionAllocator::SetX (Ptr<RandomVariableStream> x) |
| 150 |
{ |
| 151 |
m_x = x; |
| 152 |
} |
| 153 |
void |
| 154 |
OutdoorPositionAllocator::SetY (Ptr<RandomVariableStream> y) |
| 155 |
{ |
| 156 |
m_y = y; |
| 157 |
} |
| 158 |
void |
| 159 |
OutdoorPositionAllocator::SetZ (Ptr<RandomVariableStream> z) |
| 160 |
{ |
| 161 |
m_z = z; |
| 162 |
} |
| 163 |
|
| 164 |
Vector |
| 165 |
OutdoorPositionAllocator::GetNext () const |
| 166 |
{ |
| 167 |
NS_ABORT_MSG_IF (BuildingList::GetNBuildings () == 0, "no building found"); |
| 168 |
|
| 169 |
bool outdoor = false; |
| 170 |
uint32_t attempts = 0; |
| 171 |
Vector position = Vector (0,0,0); |
| 172 |
|
| 173 |
while (!outdoor && attempts < m_maxAttempts) |
| 174 |
{ |
| 175 |
// get a random position |
| 176 |
double x = m_x->GetValue (); |
| 177 |
double y = m_y->GetValue (); |
| 178 |
double z = m_z->GetValue (); |
| 179 |
|
| 180 |
position = Vector (x, y, z); |
| 181 |
|
| 182 |
NS_LOG_INFO ("Position " << position); |
| 183 |
|
| 184 |
bool inside = false; |
| 185 |
for (BuildingList::Iterator bit = BuildingList::Begin (); bit != BuildingList::End (); ++bit) |
| 186 |
{ |
| 187 |
if ((*bit)->IsInside (position)) |
| 188 |
{ |
| 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); |
| 193 |
inside = true; |
| 194 |
break; |
| 195 |
} |
| 196 |
} |
| 197 |
|
| 198 |
if (inside) |
| 199 |
{ |
| 200 |
NS_LOG_INFO ("Inside a building, attemp " << attempts << " out of " << m_maxAttempts); |
| 201 |
attempts++; |
| 202 |
} |
| 203 |
else |
| 204 |
{ |
| 205 |
NS_LOG_INFO ("Outdoor position found " << position); |
| 206 |
outdoor = true; |
| 207 |
} |
| 208 |
} |
| 209 |
|
| 210 |
NS_ABORT_MSG_IF (attempts >= m_maxAttempts, "Too many attempts, give up"); |
| 211 |
NS_ABORT_MSG_IF (!outdoor, "Still indoor, give up"); |
| 212 |
return position; |
| 213 |
} |
| 214 |
|
| 215 |
int64_t |
| 216 |
OutdoorPositionAllocator::AssignStreams (int64_t stream) |
| 217 |
{ |
| 218 |
m_x->SetStream (stream); |
| 219 |
m_y->SetStream (stream + 1); |
| 220 |
m_z->SetStream (stream + 2); |
| 221 |
return 3; |
| 222 |
} |
| 223 |
|
| 224 |
|
| 106 |
|
225 |
|
| 107 |
NS_OBJECT_ENSURE_REGISTERED (RandomRoomPositionAllocator); |
226 |
NS_OBJECT_ENSURE_REGISTERED (RandomRoomPositionAllocator); |
| 108 |
|
227 |
|
|
Lines 122-133
RandomRoomPositionAllocator::GetTypeId (void)
|
Link Here
|
|---|
|
| 122 |
return tid; |
241 |
return tid; |
| 123 |
} |
242 |
} |
| 124 |
|
243 |
|
| 125 |
Vector |
244 |
Vector |
| 126 |
RandomRoomPositionAllocator::GetNext () const |
245 |
RandomRoomPositionAllocator::GetNext () const |
| 127 |
{ |
246 |
{ |
| 128 |
NS_LOG_FUNCTION (this); |
247 |
NS_LOG_FUNCTION (this); |
| 129 |
NS_ASSERT_MSG (BuildingList::GetNBuildings () > 0, "no building found"); |
248 |
NS_ASSERT_MSG (BuildingList::GetNBuildings () > 0, "no building found"); |
| 130 |
|
249 |
|
| 131 |
if (m_roomListWithoutReplacement.empty ()) |
250 |
if (m_roomListWithoutReplacement.empty ()) |
| 132 |
{ |
251 |
{ |
| 133 |
for (BuildingList::Iterator bit = BuildingList::Begin (); bit != BuildingList::End (); ++bit) |
252 |
for (BuildingList::Iterator bit = BuildingList::Begin (); bit != BuildingList::End (); ++bit) |
|
Lines 142-148
RandomRoomPositionAllocator::GetNext () const
|
Link Here
|
|---|
|
| 142 |
RoomInfo i; |
261 |
RoomInfo i; |
| 143 |
i.roomx = rx; |
262 |
i.roomx = rx; |
| 144 |
i.roomy = ry; |
263 |
i.roomy = ry; |
| 145 |
i.floor = f; |
264 |
i.floor = f; |
| 146 |
i.b = *bit; |
265 |
i.b = *bit; |
| 147 |
NS_LOG_LOGIC ("adding room (" << rx << ", " << ry << ", " << f << ")"); |
266 |
NS_LOG_LOGIC ("adding room (" << rx << ", " << ry << ", " << f << ")"); |
| 148 |
m_roomListWithoutReplacement.push_back (i); |
267 |
m_roomListWithoutReplacement.push_back (i); |
|
Lines 165-171
RandomRoomPositionAllocator::GetNext () const
|
Link Here
|
|---|
|
| 165 |
double rdz = (box.zMax - box.zMin) / r.b->GetNFloors (); |
284 |
double rdz = (box.zMax - box.zMin) / r.b->GetNFloors (); |
| 166 |
double x1 = box.xMin + rdx * (r.roomx - 1); |
285 |
double x1 = box.xMin + rdx * (r.roomx - 1); |
| 167 |
double x2 = box.xMin + rdx * r.roomx; |
286 |
double x2 = box.xMin + rdx * r.roomx; |
| 168 |
double y1 = box.yMin + rdy * (r.roomy -1); |
287 |
double y1 = box.yMin + rdy * (r.roomy - 1); |
| 169 |
double y2 = box.yMin + rdy * r.roomy; |
288 |
double y2 = box.yMin + rdy * r.roomy; |
| 170 |
double z1 = box.zMin + rdz * (r.floor - 1); |
289 |
double z1 = box.zMin + rdz * (r.floor - 1); |
| 171 |
double z2 = box.zMin + rdz * r.floor; |
290 |
double z2 = box.zMin + rdz * r.floor; |
|
Lines 226-232
SameRoomPositionAllocator::GetTypeId (void)
|
Link Here
|
|---|
|
| 226 |
return tid; |
345 |
return tid; |
| 227 |
} |
346 |
} |
| 228 |
|
347 |
|
| 229 |
Vector |
348 |
Vector |
| 230 |
SameRoomPositionAllocator::GetNext () const |
349 |
SameRoomPositionAllocator::GetNext () const |
| 231 |
{ |
350 |
{ |
| 232 |
NS_LOG_FUNCTION (this); |
351 |
NS_LOG_FUNCTION (this); |
|
Lines 259-265
SameRoomPositionAllocator::GetNext () const
|
Link Here
|
|---|
|
| 259 |
double rdz = (box.zMax - box.zMin) / b->GetNFloors (); |
378 |
double rdz = (box.zMax - box.zMin) / b->GetNFloors (); |
| 260 |
double x1 = box.xMin + rdx * (roomx - 1); |
379 |
double x1 = box.xMin + rdx * (roomx - 1); |
| 261 |
double x2 = box.xMin + rdx * roomx; |
380 |
double x2 = box.xMin + rdx * roomx; |
| 262 |
double y1 = box.yMin + rdy * (roomy -1); |
381 |
double y1 = box.yMin + rdy * (roomy - 1); |
| 263 |
double y2 = box.yMin + rdy * roomy; |
382 |
double y2 = box.yMin + rdy * roomy; |
| 264 |
double z1 = box.zMin + rdz * (floor - 1); |
383 |
double z1 = box.zMin + rdz * (floor - 1); |
| 265 |
double z2 = box.zMin + rdz * floor; |
384 |
double z2 = box.zMin + rdz * floor; |
|
Lines 322-328
FixedRoomPositionAllocator::GetNext () const
|
Link Here
|
|---|
|
| 322 |
double rdz = (box.zMax - box.zMin) / bptr->GetNFloors (); |
441 |
double rdz = (box.zMax - box.zMin) / bptr->GetNFloors (); |
| 323 |
double x1 = box.xMin + rdx * (roomx - 1); |
442 |
double x1 = box.xMin + rdx * (roomx - 1); |
| 324 |
double x2 = box.xMin + rdx * roomx; |
443 |
double x2 = box.xMin + rdx * roomx; |
| 325 |
double y1 = box.yMin + rdy * (roomy -1); |
444 |
double y1 = box.yMin + rdy * (roomy - 1); |
| 326 |
double y2 = box.yMin + rdy * roomy; |
445 |
double y2 = box.yMin + rdy * roomy; |
| 327 |
double z1 = box.zMin + rdz * (floor - 1); |
446 |
double z1 = box.zMin + rdz * (floor - 1); |
| 328 |
double z2 = box.zMin + rdz * floor; |
447 |
double z2 = box.zMin + rdz * floor; |