|
|
| 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 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 ("MaxNumAttempts", |
| 139 |
"Maximum number of attempts 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_ASSERT_MSG (BuildingList::GetNBuildings () > 0, "no building found"); |
| 168 |
|
| 169 |
bool outdoor = false; |
| 170 |
uint32_t attempts = 0; |
| 171 |
Vector pos = 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 |
pos = Vector (x, y, z); |
| 181 |
|
| 182 |
NS_LOG_INFO("pos " << pos); |
| 183 |
|
| 184 |
bool inside = false; |
| 185 |
for (BuildingList::Iterator bit = BuildingList::Begin (); bit != BuildingList::End (); ++bit) |
| 186 |
{ |
| 187 |
if((*bit)->IsInside (pos)) |
| 188 |
{ |
| 189 |
NS_LOG_INFO("Pos " << pos << " inside building " << (*bit)->GetBoundaries().xMin << " " << (*bit)->GetBoundaries().xMax << " " |
| 190 |
<< (*bit)->GetBoundaries().yMin << " " << (*bit)->GetBoundaries().yMax << " " |
| 191 |
<< (*bit)->GetBoundaries().zMin << " " << (*bit)->GetBoundaries().zMax); |
| 192 |
inside = true; |
| 193 |
break; |
| 194 |
} |
| 195 |
} |
| 196 |
|
| 197 |
if(inside) |
| 198 |
{ |
| 199 |
NS_LOG_INFO("Inside a building, attemp " << attempts << " out of " << m_maxAttempts); |
| 200 |
attempts++; |
| 201 |
} |
| 202 |
else |
| 203 |
{ |
| 204 |
NS_LOG_INFO("Outdoor position found " << pos); |
| 205 |
outdoor = true; |
| 206 |
} |
| 207 |
} |
| 208 |
|
| 209 |
NS_ASSERT_MSG(attempts < m_maxAttempts, "Too many attempts, give up"); |
| 210 |
NS_ASSERT_MSG(outdoor, "Still indoor, give up"); |
| 211 |
return pos; |
| 212 |
} |
| 213 |
|
| 214 |
int64_t |
| 215 |
OutdoorPositionAllocator::AssignStreams (int64_t stream) |
| 216 |
{ |
| 217 |
m_x->SetStream (stream); |
| 218 |
m_y->SetStream (stream + 1); |
| 219 |
m_z->SetStream (stream + 2); |
| 220 |
return 3; |
| 221 |
} |
| 222 |
|
| 223 |
|
| 106 |
|
224 |
|
| 107 |
NS_OBJECT_ENSURE_REGISTERED (RandomRoomPositionAllocator); |
225 |
NS_OBJECT_ENSURE_REGISTERED (RandomRoomPositionAllocator); |
| 108 |
|
226 |
|