/usr/include/ns3/position-allocator.h is in libns3-dev 3.13+dfsg-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2007 INRIA
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
*/
#ifndef POSITION_ALLOCATOR_H
#define POSITION_ALLOCATOR_H
#include "ns3/object.h"
#include "ns3/random-variable.h"
#include "ns3/vector.h"
namespace ns3 {
/**
* \ingroup mobility
* \brief Allocate a set of positions. The allocation strategy is implemented in subclasses.
*
* This is a pure abstract base class.
*/
class PositionAllocator : public Object
{
public:
static TypeId GetTypeId (void);
PositionAllocator ();
virtual ~PositionAllocator ();
/**
* \return the next chosen position.
*
* This method _must_ be implement in subclasses.
*/
virtual Vector GetNext (void) const = 0;
};
/**
* \ingroup mobility
* \brief Allocate positions from a deterministic list specified by the user.
*
* The first call to ListPositionAllocator::GetNext will return the
* first element of the list, the second call, the second element, and so on.
*/
class ListPositionAllocator : public PositionAllocator
{
public:
static TypeId GetTypeId (void);
ListPositionAllocator ();
/**
* \param v the position to append at the end of the list of positions to return from GetNext.
*/
void Add (Vector v);
virtual Vector GetNext (void) const;
private:
std::vector<Vector> m_positions;
mutable std::vector<Vector>::const_iterator m_current;
};
/**
* \ingroup mobility
* \brief Allocate positions on a rectangular 2d grid.
*/
class GridPositionAllocator : public PositionAllocator
{
public:
static TypeId GetTypeId (void);
/**
* Determine whether positions are allocated row first or column first.
*/
enum LayoutType {
/**
* In row-first mode, positions are allocated on the first row until
* N positions have been allocated. Then, the second row located a yMin + yDelta
* is used to allocate positions.
*/
ROW_FIRST,
/**
* In column-first mode, positions are allocated on the first column until
* N positions have been allocated. Then, the second column located a xMin + xDelta
* is used to allocate positions.
*/
COLUMN_FIRST
};
GridPositionAllocator ();
/**
* \param xMin the x coordinate where layout will start.
*/
void SetMinX (double xMin);
/**
* \param yMin the y coordinate where layout will start
*/
void SetMinY (double yMin);
/**
* \param deltaX the x interval between two x-consecutive positions.
*/
void SetDeltaX (double deltaX);
/**
* \param deltaY the y interval between two y-consecutive positions.
*/
void SetDeltaY (double deltaY);
/**
* \param n the number of positions allocated on each row (or each column)
* before switching to the next column (or row).
*/
void SetN (uint32_t n);
/**
* \param layoutType the type of layout to use (row first or column first).
*/
void SetLayoutType (enum LayoutType layoutType);
/**
* \return the x coordinate of the first allocated position.
*/
double GetMinX (void) const;
/**
* \return the y coordinate of the first allocated position.
*/
double GetMinY (void) const;
/**
* \return the x interval between two x-consecutive positions.
*/
double GetDeltaX (void) const;
/**
* \return the y interval between two y-consecutive positions.
*/
double GetDeltaY (void) const;
/**
* \return the number of positions to allocate on each row or each column.
*/
uint32_t GetN (void) const;
/**
* \return the currently-selected layout type.
*/
enum LayoutType GetLayoutType (void) const;
virtual Vector GetNext (void) const;
private:
mutable uint32_t m_current;
enum LayoutType m_layoutType;
double m_xMin;
double m_yMin;
uint32_t m_n;
double m_deltaX;
double m_deltaY;
};
/**
* \ingroup mobility
* \brief Allocate random positions within a rectangle according to a pair of random variables.
*/
class RandomRectanglePositionAllocator : public PositionAllocator
{
public:
static TypeId GetTypeId (void);
RandomRectanglePositionAllocator ();
virtual ~RandomRectanglePositionAllocator ();
void SetX (RandomVariable x);
void SetY (RandomVariable y);
virtual Vector GetNext (void) const;
private:
RandomVariable m_x;
RandomVariable m_y;
};
/**
* \ingroup mobility
* \brief Allocate random positions within a 3D box according to a set of three random variables.
*/
class RandomBoxPositionAllocator : public PositionAllocator
{
public:
static TypeId GetTypeId (void);
RandomBoxPositionAllocator ();
virtual ~RandomBoxPositionAllocator ();
void SetX (RandomVariable x);
void SetY (RandomVariable y);
void SetZ (RandomVariable z);
virtual Vector GetNext (void) const;
private:
RandomVariable m_x;
RandomVariable m_y;
RandomVariable m_z;
};
/**
* \ingroup mobility
* \brief Allocate random positions within a disc according to a given distribution for the polar coordinates of each node
with respect to the provided center of the disc
*/
class RandomDiscPositionAllocator : public PositionAllocator
{
public:
static TypeId GetTypeId (void);
RandomDiscPositionAllocator ();
virtual ~RandomDiscPositionAllocator ();
void SetTheta (RandomVariable theta);
void SetRho (RandomVariable rho);
void SetX (double x);
void SetY (double y);
virtual Vector GetNext (void) const;
private:
RandomVariable m_theta;
RandomVariable m_rho;
double m_x;
double m_y;
};
/**
* \ingroup mobility
* \brief Allocate the positions uniformely (with constant density) randomly within a disc.
*
* UniformDiscPositionAllocator allocates the positions randomly within a disc \f$ D \f$ lying on the
* plane \f$ z=0 \f$ and having center at coordinates \f$ (x,y,0) \f$
* and radius \f$ \rho \f$. The random positions are chosen such that,
* for any subset \f$ S \subset D \f$, the expected value of the
* fraction of points which fall into \f$ S \subset D \f$ corresponds
* to \f$ \frac{|S|}{|D|} \f$, i.e., to the ratio of the area of the
* subset to the area of the whole disc.
*
* \note using UniformDiscPositionAllocator is not equivalent to using
* a RandomDiscPositionAllocator with a uniformly-distributed radius,
* since doing that would results in a point distribution which is
* more dense towards the center of the disc.
*/
class UniformDiscPositionAllocator : public PositionAllocator
{
public:
static TypeId GetTypeId (void);
UniformDiscPositionAllocator ();
virtual ~UniformDiscPositionAllocator ();
/**
* \param rho the value of the radius of the disc
*/
void SetRho (double rho);
/**
* \param x the X coordinate of the center of the disc
*/
void SetX (double x);
/**
* \param y the Y coordinate of the center of the disc
*/
void SetY (double y);
virtual Vector GetNext (void) const;
private:
double m_rho;
double m_x;
double m_y;
};
} // namespace ns3
#endif /* RANDOM_POSITION_H */
|