A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
position-allocator.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2007 INRIA
4
*
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License version 2 as
7
* published by the Free Software Foundation;
8
*
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
13
*
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
*
18
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19
*/
20
#include "
position-allocator.h
"
21
#include "ns3/double.h"
22
#include "ns3/string.h"
23
#include "ns3/pointer.h"
24
#include "ns3/uinteger.h"
25
#include "ns3/enum.h"
26
#include "ns3/log.h"
27
#include <cmath>
28
29
NS_LOG_COMPONENT_DEFINE
(
"PositionAllocator"
);
30
31
namespace
ns3 {
32
33
NS_OBJECT_ENSURE_REGISTERED
(PositionAllocator);
34
35
TypeId
36
PositionAllocator::GetTypeId
(
void
)
37
{
38
static
TypeId
tid =
TypeId
(
"ns3::PositionAllocator"
)
39
.
SetParent
<
Object
> ();
40
return
tid;
41
}
42
43
PositionAllocator::PositionAllocator
()
44
{
45
}
46
47
PositionAllocator::~PositionAllocator
()
48
{
49
}
50
51
NS_OBJECT_ENSURE_REGISTERED
(
ListPositionAllocator
);
52
53
TypeId
54
ListPositionAllocator::GetTypeId
(
void
)
55
{
56
static
TypeId
tid =
TypeId
(
"ns3::ListPositionAllocator"
)
57
.
SetParent
<
PositionAllocator
> ()
58
.AddConstructor<ListPositionAllocator> ()
59
;
60
return
tid;
61
}
62
ListPositionAllocator::ListPositionAllocator
()
63
{
64
}
65
void
66
ListPositionAllocator::Add
(
Vector
v)
67
{
68
m_positions
.push_back (v);
69
m_current
=
m_positions
.begin ();
70
}
71
Vector
72
ListPositionAllocator::GetNext
(
void
)
const
73
{
74
Vector
v = *
m_current
;
75
m_current
++;
76
if
(
m_current
==
m_positions
.end ())
77
{
78
m_current
=
m_positions
.begin ();
79
}
80
return
v;
81
}
82
int64_t
83
ListPositionAllocator::AssignStreams
(int64_t stream)
84
{
85
return
0;
86
}
87
88
NS_OBJECT_ENSURE_REGISTERED
(
GridPositionAllocator
);
89
90
TypeId
91
GridPositionAllocator::GetTypeId
(
void
)
92
{
93
static
TypeId
tid =
TypeId
(
"ns3::GridPositionAllocator"
)
94
.
SetParent
<
PositionAllocator
> ()
95
.SetGroupName (
"Mobility"
)
96
.AddConstructor<
GridPositionAllocator
> ()
97
.AddAttribute (
"GridWidth"
,
"The number of objects layed out on a line."
,
98
UintegerValue
(10),
99
MakeUintegerAccessor (&
GridPositionAllocator::m_n
),
100
MakeUintegerChecker<uint32_t> ())
101
.AddAttribute (
"MinX"
,
"The x coordinate where the grid starts."
,
102
DoubleValue
(1.0),
103
MakeDoubleAccessor (&
GridPositionAllocator::m_xMin
),
104
MakeDoubleChecker<double> ())
105
.AddAttribute (
"MinY"
,
"The y coordinate where the grid starts."
,
106
DoubleValue
(0.0),
107
MakeDoubleAccessor (&
GridPositionAllocator::m_yMin
),
108
MakeDoubleChecker<double> ())
109
.AddAttribute (
"DeltaX"
,
"The x space between objects."
,
110
DoubleValue
(1.0),
111
MakeDoubleAccessor (&
GridPositionAllocator::m_deltaX
),
112
MakeDoubleChecker<double> ())
113
.AddAttribute (
"DeltaY"
,
"The y space between objects."
,
114
DoubleValue
(1.0),
115
MakeDoubleAccessor (&
GridPositionAllocator::m_deltaY
),
116
MakeDoubleChecker<double> ())
117
.AddAttribute (
"LayoutType"
,
"The type of layout."
,
118
EnumValue
(
ROW_FIRST
),
119
MakeEnumAccessor
(&
GridPositionAllocator::m_layoutType
),
120
MakeEnumChecker
(
ROW_FIRST
,
"RowFirst"
,
121
COLUMN_FIRST
,
"ColumnFirst"
))
122
;
123
return
tid;
124
}
125
GridPositionAllocator::GridPositionAllocator
()
126
: m_current (0)
127
{
128
}
129
130
void
131
GridPositionAllocator::SetMinX
(
double
xMin)
132
{
133
m_xMin
= xMin;
134
}
135
void
136
GridPositionAllocator::SetMinY
(
double
yMin)
137
{
138
m_yMin
= yMin;
139
}
140
void
141
GridPositionAllocator::SetDeltaX
(
double
deltaX)
142
{
143
m_deltaX
= deltaX;
144
}
145
void
146
GridPositionAllocator::SetDeltaY
(
double
deltaY)
147
{
148
m_deltaY
= deltaY;
149
}
150
void
151
GridPositionAllocator::SetN
(uint32_t n)
152
{
153
m_n
= n;
154
}
155
void
156
GridPositionAllocator::SetLayoutType
(
enum
LayoutType
layoutType)
157
{
158
m_layoutType
= layoutType;
159
}
160
161
double
162
GridPositionAllocator::GetMinX
(
void
)
const
163
{
164
return
m_xMin
;
165
}
166
double
167
GridPositionAllocator::GetMinY
(
void
)
const
168
{
169
return
m_yMin
;
170
}
171
double
172
GridPositionAllocator::GetDeltaX
(
void
)
const
173
{
174
return
m_deltaX
;
175
}
176
double
177
GridPositionAllocator::GetDeltaY
(
void
)
const
178
{
179
return
m_deltaY
;
180
}
181
uint32_t
182
GridPositionAllocator::GetN
(
void
)
const
183
{
184
return
m_n
;
185
}
186
enum
GridPositionAllocator::LayoutType
187
GridPositionAllocator::GetLayoutType
(
void
)
const
188
{
189
return
m_layoutType
;
190
}
191
192
Vector
193
GridPositionAllocator::GetNext
(
void
)
const
194
{
195
double
x
= 0.0, y = 0.0;
196
switch
(
m_layoutType
) {
197
case
ROW_FIRST
:
198
x =
m_xMin
+
m_deltaX
* (
m_current
%
m_n
);
199
y =
m_yMin
+
m_deltaY
* (
m_current
/
m_n
);
200
break
;
201
case
COLUMN_FIRST
:
202
x =
m_xMin
+
m_deltaX
* (
m_current
/
m_n
);
203
y =
m_yMin
+ m_deltaY * (
m_current
%
m_n
);
204
break
;
205
}
206
m_current
++;
207
return
Vector
(x, y, 0.0);
208
}
209
210
int64_t
211
GridPositionAllocator::AssignStreams
(int64_t stream)
212
{
213
return
0;
214
}
215
216
NS_OBJECT_ENSURE_REGISTERED
(
RandomRectanglePositionAllocator
);
217
218
TypeId
219
RandomRectanglePositionAllocator::GetTypeId
(
void
)
220
{
221
static
TypeId
tid =
TypeId
(
"ns3::RandomRectanglePositionAllocator"
)
222
.
SetParent
<
PositionAllocator
> ()
223
.SetGroupName (
"Mobility"
)
224
.AddConstructor<
RandomRectanglePositionAllocator
> ()
225
.AddAttribute (
"X"
,
226
"A random variable which represents the x coordinate of a position in a random rectangle."
,
227
StringValue
(
"ns3::UniformRandomVariable[Min=0.0|Max=1.0]"
),
228
MakePointerAccessor (&
RandomRectanglePositionAllocator::m_x
),
229
MakePointerChecker<RandomVariableStream> ())
230
.AddAttribute (
"Y"
,
231
"A random variable which represents the y coordinate of a position in a random rectangle."
,
232
StringValue
(
"ns3::UniformRandomVariable[Min=0.0|Max=1.0]"
),
233
MakePointerAccessor (&
RandomRectanglePositionAllocator::m_y
),
234
MakePointerChecker<RandomVariableStream> ());
235
return
tid;
236
}
237
238
RandomRectanglePositionAllocator::RandomRectanglePositionAllocator
()
239
{
240
}
241
RandomRectanglePositionAllocator::~RandomRectanglePositionAllocator
()
242
{
243
}
244
245
void
246
RandomRectanglePositionAllocator::SetX
(
Ptr<RandomVariableStream>
x
)
247
{
248
m_x
=
x
;
249
}
250
void
251
RandomRectanglePositionAllocator::SetY
(
Ptr<RandomVariableStream>
y)
252
{
253
m_y
= y;
254
}
255
256
Vector
257
RandomRectanglePositionAllocator::GetNext
(
void
)
const
258
{
259
double
x
=
m_x
->
GetValue
();
260
double
y =
m_y
->
GetValue
();
261
return
Vector
(x, y, 0.0);
262
}
263
264
int64_t
265
RandomRectanglePositionAllocator::AssignStreams
(int64_t stream)
266
{
267
m_x
->
SetStream
(stream);
268
m_y
->
SetStream
(stream + 1);
269
return
2;
270
}
271
272
NS_OBJECT_ENSURE_REGISTERED
(
RandomBoxPositionAllocator
);
273
274
TypeId
275
RandomBoxPositionAllocator::GetTypeId
(
void
)
276
{
277
static
TypeId
tid =
TypeId
(
"ns3::RandomBoxPositionAllocator"
)
278
.
SetParent
<
PositionAllocator
> ()
279
.SetGroupName (
"Mobility"
)
280
.AddConstructor<
RandomBoxPositionAllocator
> ()
281
.AddAttribute (
"X"
,
282
"A random variable which represents the x coordinate of a position in a random box."
,
283
StringValue
(
"ns3::UniformRandomVariable[Min=0.0|Max=1.0]"
),
284
MakePointerAccessor (&
RandomBoxPositionAllocator::m_x
),
285
MakePointerChecker<RandomVariableStream> ())
286
.AddAttribute (
"Y"
,
287
"A random variable which represents the y coordinate of a position in a random box."
,
288
StringValue
(
"ns3::UniformRandomVariable[Min=0.0|Max=1.0]"
),
289
MakePointerAccessor (&
RandomBoxPositionAllocator::m_y
),
290
MakePointerChecker<RandomVariableStream> ())
291
.AddAttribute (
"Z"
,
292
"A random variable which represents the z coordinate of a position in a random box."
,
293
StringValue
(
"ns3::UniformRandomVariable[Min=0.0|Max=1.0]"
),
294
MakePointerAccessor (&
RandomBoxPositionAllocator::m_z
),
295
MakePointerChecker<RandomVariableStream> ());
296
return
tid;
297
}
298
299
RandomBoxPositionAllocator::RandomBoxPositionAllocator
()
300
{
301
}
302
RandomBoxPositionAllocator::~RandomBoxPositionAllocator
()
303
{
304
}
305
306
void
307
RandomBoxPositionAllocator::SetX
(
Ptr<RandomVariableStream>
x
)
308
{
309
m_x
=
x
;
310
}
311
void
312
RandomBoxPositionAllocator::SetY
(
Ptr<RandomVariableStream>
y)
313
{
314
m_y
= y;
315
}
316
void
317
RandomBoxPositionAllocator::SetZ
(
Ptr<RandomVariableStream>
z)
318
{
319
m_z
= z;
320
}
321
322
Vector
323
RandomBoxPositionAllocator::GetNext
(
void
)
const
324
{
325
double
x
=
m_x
->
GetValue
();
326
double
y =
m_y
->
GetValue
();
327
double
z =
m_z
->
GetValue
();
328
return
Vector
(x, y, z);
329
}
330
331
int64_t
332
RandomBoxPositionAllocator::AssignStreams
(int64_t stream)
333
{
334
m_x
->
SetStream
(stream);
335
m_y
->
SetStream
(stream + 1);
336
m_z
->
SetStream
(stream + 2);
337
return
3;
338
}
339
340
NS_OBJECT_ENSURE_REGISTERED
(
RandomDiscPositionAllocator
);
341
342
TypeId
343
RandomDiscPositionAllocator::GetTypeId
(
void
)
344
{
345
static
TypeId
tid =
TypeId
(
"ns3::RandomDiscPositionAllocator"
)
346
.
SetParent
<
PositionAllocator
> ()
347
.SetGroupName (
"Mobility"
)
348
.AddConstructor<
RandomDiscPositionAllocator
> ()
349
.AddAttribute (
"Theta"
,
350
"A random variable which represents the angle (gradients) of a position in a random disc."
,
351
StringValue
(
"ns3::UniformRandomVariable[Min=0.0|Max=6.2830]"
),
352
MakePointerAccessor (&
RandomDiscPositionAllocator::m_theta
),
353
MakePointerChecker<RandomVariableStream> ())
354
.AddAttribute (
"Rho"
,
355
"A random variable which represents the radius of a position in a random disc."
,
356
StringValue
(
"ns3::UniformRandomVariable[Min=0.0|Max=200.0]"
),
357
MakePointerAccessor (&
RandomDiscPositionAllocator::m_rho
),
358
MakePointerChecker<RandomVariableStream> ())
359
.AddAttribute (
"X"
,
360
"The x coordinate of the center of the random position disc."
,
361
DoubleValue
(0.0),
362
MakeDoubleAccessor (&
RandomDiscPositionAllocator::m_x
),
363
MakeDoubleChecker<double> ())
364
.AddAttribute (
"Y"
,
365
"The y coordinate of the center of the random position disc."
,
366
DoubleValue
(0.0),
367
MakeDoubleAccessor (&
RandomDiscPositionAllocator::m_y
),
368
MakeDoubleChecker<double> ())
369
;
370
return
tid;
371
}
372
373
RandomDiscPositionAllocator::RandomDiscPositionAllocator
()
374
{
375
}
376
RandomDiscPositionAllocator::~RandomDiscPositionAllocator
()
377
{
378
}
379
380
void
381
RandomDiscPositionAllocator::SetTheta
(
Ptr<RandomVariableStream>
theta)
382
{
383
m_theta
= theta;
384
}
385
void
386
RandomDiscPositionAllocator::SetRho
(
Ptr<RandomVariableStream>
rho)
387
{
388
m_rho
= rho;
389
}
390
void
391
RandomDiscPositionAllocator::SetX
(
double
x
)
392
{
393
m_x
=
x
;
394
}
395
void
396
RandomDiscPositionAllocator::SetY
(
double
y)
397
{
398
m_y
= y;
399
}
400
Vector
401
RandomDiscPositionAllocator::GetNext
(
void
)
const
402
{
403
double
theta =
m_theta
->
GetValue
();
404
double
rho =
m_rho
->
GetValue
();
405
double
x
=
m_x
+ std::cos (theta) * rho;
406
double
y =
m_y
+ std::sin (theta) * rho;
407
NS_LOG_DEBUG
(
"Disc position x="
<< x <<
", y="
<< y);
408
return
Vector
(x, y, 0.0);
409
}
410
411
int64_t
412
RandomDiscPositionAllocator::AssignStreams
(int64_t stream)
413
{
414
m_theta
->
SetStream
(stream);
415
m_rho
->
SetStream
(stream + 1);
416
return
2;
417
}
418
419
420
421
NS_OBJECT_ENSURE_REGISTERED
(
UniformDiscPositionAllocator
);
422
423
TypeId
424
UniformDiscPositionAllocator::GetTypeId
(
void
)
425
{
426
static
TypeId
tid =
TypeId
(
"ns3::UniformDiscPositionAllocator"
)
427
.
SetParent
<
PositionAllocator
> ()
428
.SetGroupName (
"Mobility"
)
429
.AddConstructor<
UniformDiscPositionAllocator
> ()
430
.AddAttribute (
"rho"
,
431
"The radius of the disc"
,
432
DoubleValue
(0.0),
433
MakeDoubleAccessor (&
UniformDiscPositionAllocator::m_rho
),
434
MakeDoubleChecker<double> ())
435
.AddAttribute (
"X"
,
436
"The x coordinate of the center of the disc."
,
437
DoubleValue
(0.0),
438
MakeDoubleAccessor (&
UniformDiscPositionAllocator::m_x
),
439
MakeDoubleChecker<double> ())
440
.AddAttribute (
"Y"
,
441
"The y coordinate of the center of the disc."
,
442
DoubleValue
(0.0),
443
MakeDoubleAccessor (&
UniformDiscPositionAllocator::m_y
),
444
MakeDoubleChecker<double> ())
445
;
446
return
tid;
447
}
448
449
UniformDiscPositionAllocator::UniformDiscPositionAllocator
()
450
{
451
m_rv
= CreateObject<UniformRandomVariable> ();
452
}
453
UniformDiscPositionAllocator::~UniformDiscPositionAllocator
()
454
{
455
}
456
457
void
458
UniformDiscPositionAllocator::SetRho
(
double
rho)
459
{
460
m_rho
= rho;
461
}
462
void
463
UniformDiscPositionAllocator::SetX
(
double
x
)
464
{
465
m_x
=
x
;
466
}
467
void
468
UniformDiscPositionAllocator::SetY
(
double
y)
469
{
470
m_y
= y;
471
}
472
Vector
473
UniformDiscPositionAllocator::GetNext
(
void
)
const
474
{
475
double
x
,y;
476
do
477
{
478
x =
m_rv
->
GetValue
(-
m_rho
,
m_rho
);
479
y =
m_rv
->
GetValue
(-
m_rho
,
m_rho
);
480
}
481
while
(sqrt (x*x + y*y) >
m_rho
);
482
483
x +=
m_x
;
484
y +=
m_y
;
485
NS_LOG_DEBUG
(
"Disc position x="
<< x <<
", y="
<< y);
486
return
Vector
(x, y, 0.0);
487
}
488
489
int64_t
490
UniformDiscPositionAllocator::AssignStreams
(int64_t stream)
491
{
492
m_rv
->
SetStream
(stream);
493
return
1;
494
}
495
496
497
}
// namespace ns3
src
mobility
model
position-allocator.cc
Generated on Tue Oct 9 2012 16:45:42 for ns-3 by
1.8.1.2