diff --git a/src/mobility/position-allocator.cc b/src/mobility/position-allocator.cc index c4794497c..75cb37be6 100644 --- a/src/mobility/position-allocator.cc +++ b/src/mobility/position-allocator.cc @@ -114,6 +114,68 @@ GridPositionAllocator::GridPositionAllocator () : m_current (0) {} +void +GridPositionAllocator::SetMinX (double xMin) +{ + m_xMin = xMin; +} +void +GridPositionAllocator::SetMinY (double yMin) +{ + m_yMin = yMin; +} +void +GridPositionAllocator::SetDeltaX (double deltaX) +{ + m_deltaX = deltaX; +} +void +GridPositionAllocator::SetDeltaY (double deltaY) +{ + m_deltaY = deltaY; +} +void +GridPositionAllocator::SetN (uint32_t n) +{ + m_n = n; +} +void +GridPositionAllocator::SetLayoutType (enum LayoutType layoutType) +{ + m_layoutType = layoutType; +} + +double +GridPositionAllocator::GetMinX (void) const +{ + return m_xMin; +} +double +GridPositionAllocator::GetMinY (void) const +{ + return m_yMin; +} +double +GridPositionAllocator::GetDeltaX (void) const +{ + return m_deltaX; +} +double +GridPositionAllocator::GetDeltaY (void) const +{ + return m_deltaY; +} +uint32_t +GridPositionAllocator::GetN (void) const +{ + return m_n; +} +enum GridPositionAllocator::LayoutType +GridPositionAllocator::GetLayoutType (void) const +{ + return m_layoutType; +} + Vector GridPositionAllocator::GetNext (void) const { @@ -159,6 +221,18 @@ RandomRectanglePositionAllocator::RandomRectanglePositionAllocator () {} RandomRectanglePositionAllocator::~RandomRectanglePositionAllocator () {} + +void +RandomRectanglePositionAllocator::SetX (RandomVariable x) +{ + m_x = x; +} +void +RandomRectanglePositionAllocator::SetY (RandomVariable y) +{ + m_y = y; +} + Vector RandomRectanglePositionAllocator::GetNext (void) const { @@ -204,6 +278,27 @@ RandomDiscPositionAllocator::RandomDiscPositionAllocator () {} RandomDiscPositionAllocator::~RandomDiscPositionAllocator () {} + +void +RandomDiscPositionAllocator::SetTheta (RandomVariable theta) +{ + m_theta = theta; +} +void +RandomDiscPositionAllocator::SetRho (RandomVariable rho) +{ + m_rho = rho; +} +void +RandomDiscPositionAllocator::SetX (double x) +{ + m_x = x; +} +void +RandomDiscPositionAllocator::SetY (double y) +{ + m_y = y; +} Vector RandomDiscPositionAllocator::GetNext (void) const { diff --git a/src/mobility/position-allocator.h b/src/mobility/position-allocator.h index 19e301a7e..f402de69e 100644 --- a/src/mobility/position-allocator.h +++ b/src/mobility/position-allocator.h @@ -27,7 +27,8 @@ namespace ns3 { /** - * \brief choose a position at random. + * \brief allocate a set of positions. The allocation strategy is implemented + * in subclasses. * * This is a pure abstract base class. */ @@ -38,16 +39,29 @@ public: PositionAllocator (); virtual ~PositionAllocator (); /** - * \returns the next randomly-choosen position. + * \returns the next chosen position. + * + * This method _must_ be implement in subclasses. */ virtual Vector GetNext (void) const = 0; }; +/** + * \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: @@ -55,18 +69,86 @@ private: mutable std::vector::const_iterator m_current; }; +/** + * \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); + + /** + * \param returns the x coordinate of the first allocated position. + */ + double GetMinX (void) const; + /** + * \param returns the y coordinate of the first allocated position. + */ + double GetMinY (void) const; + /** + * \returns the x interval between two x-consecutive positions. + */ + double GetDeltaX (void) const; + /** + * \returns the y interval between two y-consecutive positions. + */ + double GetDeltaY (void) const; + /** + * \returns the number of positions to allocate on each row or each column. + */ + uint32_t GetN (void) const; + /** + * \returns the currently-selected layout type. + */ + enum LayoutType GetLayoutType (void) const; + + virtual Vector GetNext (void) const; private: mutable uint32_t m_current; @@ -88,6 +170,10 @@ 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; @@ -104,6 +190,12 @@ 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;