A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
position-allocator.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2007 INRIA
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18 */
19#ifndef POSITION_ALLOCATOR_H
20#define POSITION_ALLOCATOR_H
21
22#include "ns3/object.h"
23#include "ns3/random-variable-stream.h"
24#include "ns3/vector.h"
25
26namespace ns3
27{
28
29/**
30 * \ingroup mobility
31 * \brief Allocate a set of positions. The allocation strategy is implemented in subclasses.
32 *
33 * This is a pure abstract base class.
34 */
36{
37 public:
38 /**
39 * Register this type with the TypeId system.
40 * \return the object TypeId
41 */
42 static TypeId GetTypeId();
44 ~PositionAllocator() override;
45 /**
46 * \return the next chosen position.
47 *
48 * This method _must_ be implement in subclasses.
49 */
50 virtual Vector GetNext() const = 0;
51 /**
52 * Assign a fixed random variable stream number to the random variables
53 * used by this model. Return the number of streams (possibly zero) that
54 * have been assigned.
55 *
56 * This method _must_ be implement in subclasses.
57 *
58 * \param stream first stream index to use
59 * \return the number of stream indices assigned by this model
60 */
61 virtual int64_t AssignStreams(int64_t stream) = 0;
62};
63
64/**
65 * \ingroup mobility
66 * \brief Allocate positions from a deterministic list specified by the user.
67 *
68 * The first call to ListPositionAllocator::GetNext will return the
69 * first element of the list, the second call, the second element, and so on.
70 */
72{
73 public:
74 /**
75 * Register this type with the TypeId system.
76 * \return the object TypeId
77 */
78 static TypeId GetTypeId();
80
81 /**
82 * \brief Add a position to the list of positions
83 * \param v the position to append at the end of the list of positions to return from GetNext.
84 */
85 void Add(Vector v);
86
87 /**
88 * \brief Add the positions listed in a file.
89 * The file should be a simple text file, with one position per line,
90 * either X and Y, or X, Y and Z, in meters. The delimiter can
91 * be any character, such as ',' or '\\t'; the default is a comma ','.
92 *
93 * The file is read using CsvReader, which explains how comments
94 * and whitespace are handled.
95 *
96 * \param [in] filePath The path to the input file.
97 * \param [in] defaultZ The default Z value to use when reading files
98 * with only X and Y positions.
99 * \param [in] delimiter The delimiter character; see CsvReader.
100 */
101 void Add(const std::string filePath, double defaultZ = 0, char delimiter = ',');
102
103 /**
104 * Return the number of positions stored. Note that this will not change
105 * based on calling GetNext(), as the number of positions is not altered
106 * by calling GetNext ().
107 *
108 * \return the number of positions stored
109 */
110 uint32_t GetSize() const;
111 Vector GetNext() const override;
112 int64_t AssignStreams(int64_t stream) override;
113
114 private:
115 std::vector<Vector> m_positions; //!< vector of positions
116 mutable std::vector<Vector>::const_iterator m_current; //!< vector iterator
117};
118
119/**
120 * \ingroup mobility
121 * \brief Allocate positions on a rectangular 2d grid.
122 */
124{
125 public:
126 /**
127 * Register this type with the TypeId system.
128 * \return the object TypeId
129 */
130 static TypeId GetTypeId();
131
132 /**
133 * Determine whether positions are allocated row first or column first.
134 */
136 {
137 /**
138 * In row-first mode, positions are allocated on the first row until
139 * N positions have been allocated. Then, the second row located a yMin + yDelta
140 * is used to allocate positions.
141 */
143 /**
144 * In column-first mode, positions are allocated on the first column until
145 * N positions have been allocated. Then, the second column located a xMin + xDelta
146 * is used to allocate positions.
147 */
149 };
150
152
153 /**
154 * \param xMin the x coordinate where layout will start.
155 */
156 void SetMinX(double xMin);
157 /**
158 * \param yMin the y coordinate where layout will start
159 */
160 void SetMinY(double yMin);
161 /**
162 * \param z the Z coordinate of all the positions allocated
163 */
164 void SetZ(double z);
165 /**
166 * \param deltaX the x interval between two x-consecutive positions.
167 */
168 void SetDeltaX(double deltaX);
169 /**
170 * \param deltaY the y interval between two y-consecutive positions.
171 */
172 void SetDeltaY(double deltaY);
173 /**
174 * \param n the number of positions allocated on each row (or each column)
175 * before switching to the next column (or row).
176 */
177 void SetN(uint32_t n);
178 /**
179 * \param layoutType the type of layout to use (row first or column first).
180 */
181 void SetLayoutType(LayoutType layoutType);
182
183 /**
184 * \return the x coordinate of the first allocated position.
185 */
186 double GetMinX() const;
187 /**
188 * \return the y coordinate of the first allocated position.
189 */
190 double GetMinY() const;
191 /**
192 * \return the x interval between two consecutive x-positions.
193 */
194 double GetDeltaX() const;
195 /**
196 * \return the y interval between two consecutive y-positions.
197 */
198 double GetDeltaY() const;
199 /**
200 * \return the number of positions to allocate on each row or each column.
201 */
202 uint32_t GetN() const;
203 /**
204 * \return the currently-selected layout type.
205 */
207
208 Vector GetNext() const override;
209 int64_t AssignStreams(int64_t stream) override;
210
211 private:
212 mutable uint32_t m_current; //!< currently position
213 LayoutType m_layoutType; //!< currently selected layout type
214 double m_xMin; //!< minimum boundary on x positions
215 double m_yMin; //!< minimum boundary on y positions
216 double m_z; //!< z coordinate of all the positions generated
217 uint32_t m_n; //!< number of positions to allocate on each row or column
218 double m_deltaX; //!< x interval between two consecutive x positions
219 double m_deltaY; //!< y interval between two consecutive y positions
220};
221
222/**
223 * \ingroup mobility
224 * \brief Allocate random positions within a rectangle according to a pair of random variables.
225 */
227{
228 public:
229 /**
230 * Register this type with the TypeId system.
231 * \return the object TypeId
232 */
233 static TypeId GetTypeId();
236
237 /**
238 * \brief Set the random variable stream object that generates x-positions
239 * \param x pointer to a RandomVariableStream object
240 */
242 /**
243 * \brief Set the random variable stream object that generates y-positions
244 * \param y pointer to a RandomVariableStream object
245 */
247 /**
248 * \param z the Z coordinate of all the positions allocated
249 */
250 void SetZ(double z);
251
252 Vector GetNext() const override;
253 int64_t AssignStreams(int64_t stream) override;
254
255 private:
256 Ptr<RandomVariableStream> m_x; //!< pointer to x's random variable stream
257 Ptr<RandomVariableStream> m_y; //!< pointer to y's random variable stream
258 double m_z; //!< z coordinate of all the positions generated
259};
260
261/**
262 * \ingroup mobility
263 * \brief Allocate random positions within a 3D box according to a set of three random variables.
264 */
266{
267 public:
268 /**
269 * Register this type with the TypeId system.
270 * \return the object TypeId
271 */
272 static TypeId GetTypeId();
275
276 /**
277 * \brief Set the random variable stream object that generates x-positions
278 * \param x pointer to a RandomVariableStream object
279 */
281 /**
282 * \brief Set the random variable stream object that generates y-positions
283 * \param y pointer to a RandomVariableStream object
284 */
286 /**
287 * \brief Set the random variable stream object that generates z-positions
288 * \param z pointer to a RandomVariableStream object
289 */
291
292 Vector GetNext() const override;
293 int64_t AssignStreams(int64_t stream) override;
294
295 private:
296 Ptr<RandomVariableStream> m_x; //!< pointer to x's random variable stream
297 Ptr<RandomVariableStream> m_y; //!< pointer to y's random variable stream
298 Ptr<RandomVariableStream> m_z; //!< pointer to z's random variable stream
299};
300
301/**
302 * \ingroup mobility
303 * \brief Allocate random positions within a disc according to
304 * a given distribution for the polar coordinates of each node
305 * with respect to the provided center of the disc.
306 *
307 * \note With the default uniform distribution over \f$2 \pi\f$ in \c theta and a
308 * uniform distribution for \c rho this position allocator will *not*
309 * uniformly populate the disc. The radial distribution will be proportional
310 * to \f$\frac{1}{r^2}\f$.
311 *
312 * To get a uniform distribution over a circle use the UniformDiscPositionAllocator.
313 */
315{
316 public:
317 /**
318 * Register this type with the TypeId system.
319 * \return the object TypeId
320 */
321 static TypeId GetTypeId();
324
325 /**
326 * \brief Set the random variable that generates position angle, in radians.
327 * \param theta Random variable that represents the angle in radians of a position in a random
328 * disc.
329 */
331 /**
332 * \brief Set the random variable that generates position radius, in meters
333 * \param rho Random variable that represents the radius of a position, in meters, in a random
334 * disc.
335 */
337 /**
338 * \param x the X coordinate of the center of the disc
339 */
340 void SetX(double x);
341 /**
342 * \param y the Y coordinate of the center of the disc
343 */
344 void SetY(double y);
345 /**
346 * \param z the Z coordinate of all the positions allocated
347 */
348 void SetZ(double z);
349
350 Vector GetNext() const override;
351 int64_t AssignStreams(int64_t stream) override;
352
353 private:
354 Ptr<RandomVariableStream> m_theta; //!< pointer to theta's random variable stream
355 Ptr<RandomVariableStream> m_rho; //!< pointer to rho's random variable stream
356 double m_x; //!< x coordinate of center of disc
357 double m_y; //!< y coordinate of center of disc
358 double m_z; //!< z coordinate of the disc
359};
360
361/**
362 * \ingroup mobility
363 * \brief Allocate the positions uniformly (with constant density) randomly within a disc.
364 *
365 * UniformDiscPositionAllocator allocates the positions randomly within a disc \f$ D \f$ lying on
366 * the plane \f$ z\f$ and having center at coordinates \f$ (x,y,z) \f$ and radius \f$ \rho \f$. The
367 * random positions are chosen such that, for any subset \f$ S \subset D \f$, the expected value of
368 * the fraction of points which fall into \f$ S \subset D \f$ corresponds to \f$ \frac{|S|}{|D|}
369 * \f$, i.e., to the ratio of the area of the subset to the area of the whole disc.
370 *
371 * \note using UniformDiscPositionAllocator is not equivalent to using
372 * a RandomDiscPositionAllocator with a uniformly-distributed radius,
373 * since doing that would result in a point distribution which is
374 * more dense towards the center of the disc.
375 */
377{
378 public:
379 /**
380 * Register this type with the TypeId system.
381 * \return the object TypeId
382 */
383 static TypeId GetTypeId();
386
387 /**
388 * \param rho the value of the radius of the disc
389 */
390 void SetRho(double rho);
391
392 /**
393 * \param x the X coordinate of the center of the disc
394 */
395 void SetX(double x);
396
397 /**
398 * \param y the Y coordinate of the center of the disc
399 */
400 void SetY(double y);
401
402 /**
403 * \param z the Z coordinate of all the positions allocated
404 */
405 void SetZ(double z);
406
407 Vector GetNext() const override;
408 int64_t AssignStreams(int64_t stream) override;
409
410 private:
411 Ptr<UniformRandomVariable> m_rv; //!< pointer to uniform random variable
412 double m_rho; //!< value of the radius of the disc
413 double m_x; //!< x coordinate of center of disc
414 double m_y; //!< y coordinate of center of disc
415 double m_z; //!< z coordinate of the disc
416};
417
418} // namespace ns3
419
420#endif /* RANDOM_POSITION_H */
Allocate positions on a rectangular 2d grid.
double m_deltaX
x interval between two consecutive x positions
double m_deltaY
y interval between two consecutive y positions
LayoutType GetLayoutType() const
LayoutType
Determine whether positions are allocated row first or column first.
@ COLUMN_FIRST
In column-first mode, positions are allocated on the first column until N positions have been allocat...
@ ROW_FIRST
In row-first mode, positions are allocated on the first row until N positions have been allocated.
int64_t AssignStreams(int64_t stream) override
Assign a fixed random variable stream number to the random variables used by this model.
uint32_t m_current
currently position
double m_yMin
minimum boundary on y positions
Vector GetNext() const override
double m_z
z coordinate of all the positions generated
LayoutType m_layoutType
currently selected layout type
double m_xMin
minimum boundary on x positions
uint32_t m_n
number of positions to allocate on each row or column
static TypeId GetTypeId()
Register this type with the TypeId system.
void SetLayoutType(LayoutType layoutType)
Allocate positions from a deterministic list specified by the user.
int64_t AssignStreams(int64_t stream) override
Assign a fixed random variable stream number to the random variables used by this model.
void Add(Vector v)
Add a position to the list of positions.
uint32_t GetSize() const
Return the number of positions stored.
static TypeId GetTypeId()
Register this type with the TypeId system.
std::vector< Vector >::const_iterator m_current
vector iterator
Vector GetNext() const override
std::vector< Vector > m_positions
vector of positions
A base class which provides memory management and object aggregation.
Definition: object.h:89
Allocate a set of positions.
virtual int64_t AssignStreams(int64_t stream)=0
Assign a fixed random variable stream number to the random variables used by this model.
static TypeId GetTypeId()
Register this type with the TypeId system.
virtual Vector GetNext() const =0
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
Allocate random positions within a 3D box according to a set of three random variables.
void SetZ(Ptr< RandomVariableStream > z)
Set the random variable stream object that generates z-positions.
Ptr< RandomVariableStream > m_x
pointer to x's random variable stream
Ptr< RandomVariableStream > m_y
pointer to y's random variable stream
void SetX(Ptr< RandomVariableStream > x)
Set the random variable stream object that generates x-positions.
int64_t AssignStreams(int64_t stream) override
Assign a fixed random variable stream number to the random variables used by this model.
void SetY(Ptr< RandomVariableStream > y)
Set the random variable stream object that generates y-positions.
static TypeId GetTypeId()
Register this type with the TypeId system.
Ptr< RandomVariableStream > m_z
pointer to z's random variable stream
Allocate random positions within a disc according to a given distribution for the polar coordinates o...
double m_y
y coordinate of center of disc
Ptr< RandomVariableStream > m_rho
pointer to rho's random variable stream
static TypeId GetTypeId()
Register this type with the TypeId system.
void SetRho(Ptr< RandomVariableStream > rho)
Set the random variable that generates position radius, in meters.
double m_x
x coordinate of center of disc
void SetTheta(Ptr< RandomVariableStream > theta)
Set the random variable that generates position angle, in radians.
int64_t AssignStreams(int64_t stream) override
Assign a fixed random variable stream number to the random variables used by this model.
Ptr< RandomVariableStream > m_theta
pointer to theta's random variable stream
double m_z
z coordinate of the disc
Allocate random positions within a rectangle according to a pair of random variables.
int64_t AssignStreams(int64_t stream) override
Assign a fixed random variable stream number to the random variables used by this model.
Ptr< RandomVariableStream > m_y
pointer to y's random variable stream
Ptr< RandomVariableStream > m_x
pointer to x's random variable stream
void SetY(Ptr< RandomVariableStream > y)
Set the random variable stream object that generates y-positions.
static TypeId GetTypeId()
Register this type with the TypeId system.
void SetX(Ptr< RandomVariableStream > x)
Set the random variable stream object that generates x-positions.
double m_z
z coordinate of all the positions generated
a unique identifier for an interface.
Definition: type-id.h:59
Allocate the positions uniformly (with constant density) randomly within a disc.
static TypeId GetTypeId()
Register this type with the TypeId system.
int64_t AssignStreams(int64_t stream) override
Assign a fixed random variable stream number to the random variables used by this model.
double m_rho
value of the radius of the disc
double m_x
x coordinate of center of disc
double m_y
y coordinate of center of disc
Ptr< UniformRandomVariable > m_rv
pointer to uniform random variable
double m_z
z coordinate of the disc
Every class exported by the ns3 library is enclosed in the ns3 namespace.