A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ns3::HexGridPositionAllocator Class Reference

Position allocator for hexagonal tiling. More...

#include "hex-grid-position-allocator.h"

+ Inheritance diagram for ns3::HexGridPositionAllocator:
+ Collaboration diagram for ns3::HexGridPositionAllocator:

Public Member Functions

 HexGridPositionAllocator ()
 Default constructor.
 
 HexGridPositionAllocator (double radius)
 Construct a new HexGridPositionAllocator object with given radius.
 
 ~HexGridPositionAllocator () override
 Destructor.
 
int64_t AssignStreams (int64_t stream) override
 Assign a fixed random variable stream number to the random variables used by this model.
 
Vector GetNext () const override
 
double GetRadius () const
 Get the radius of the circle inscribed in the hexagonal tiles.
 
void SetRadius (double radius)
 Set the radius of the circle inscribed in the hexagonal tiles.
 
- Public Member Functions inherited from ns3::PositionAllocator
 PositionAllocator ()
 
 ~PositionAllocator () override
 
- Public Member Functions inherited from ns3::Object
 Object ()
 Constructor.
 
 ~Object () override
 Destructor.
 
void AggregateObject (Ptr< Object > other)
 Aggregate two Objects together.
 
void Dispose ()
 Dispose of this Object.
 
AggregateIterator GetAggregateIterator () const
 Get an iterator to the Objects aggregated to this one.
 
TypeId GetInstanceTypeId () const override
 Get the most derived TypeId for this Object.
 
template<typename T >
Ptr< T > GetObject () const
 Get a pointer to the requested aggregated Object.
 
template<>
Ptr< ObjectGetObject () const
 Specialization of () for objects of type ns3::Object.
 
template<typename T >
Ptr< T > GetObject (TypeId tid) const
 Get a pointer to the requested aggregated Object by TypeId.
 
template<>
Ptr< ObjectGetObject (TypeId tid) const
 Specialization of (TypeId tid) for objects of type ns3::Object.
 
void Initialize ()
 Invoke DoInitialize on all Objects aggregated to this one.
 
bool IsInitialized () const
 Check if the object has been initialized.
 
void UnidirectionalAggregateObject (Ptr< Object > other)
 Aggregate an Object to another Object.
 
- Public Member Functions inherited from ns3::SimpleRefCount< Object, ObjectBase, ObjectDeleter >
 SimpleRefCount ()
 Default constructor.
 
 SimpleRefCount (const SimpleRefCount &o)
 Copy constructor.
 
uint32_t GetReferenceCount () const
 Get the reference count of the object.
 
SimpleRefCountoperator= (const SimpleRefCount &o)
 Assignment operator.
 
void Ref () const
 Increment the reference count.
 
void Unref () const
 Decrement the reference count.
 
- Public Member Functions inherited from ns3::ObjectBase
virtual ~ObjectBase ()
 Virtual destructor.
 
void GetAttribute (std::string name, AttributeValue &value, bool permissive=false) const
 Get the value of an attribute, raising fatal errors if unsuccessful.
 
bool GetAttributeFailSafe (std::string name, AttributeValue &value) const
 Get the value of an attribute without raising errors.
 
void SetAttribute (std::string name, const AttributeValue &value)
 Set a single attribute, raising fatal errors if unsuccessful.
 
bool SetAttributeFailSafe (std::string name, const AttributeValue &value)
 Set a single attribute without raising errors.
 
bool TraceConnect (std::string name, std::string context, const CallbackBase &cb)
 Connect a TraceSource to a Callback with a context.
 
bool TraceConnectWithoutContext (std::string name, const CallbackBase &cb)
 Connect a TraceSource to a Callback without a context.
 
bool TraceDisconnect (std::string name, std::string context, const CallbackBase &cb)
 Disconnect from a TraceSource a Callback previously connected with a context.
 
bool TraceDisconnectWithoutContext (std::string name, const CallbackBase &cb)
 Disconnect from a TraceSource a Callback previously connected without a context.
 

Static Public Member Functions

static TypeId GetTypeId ()
 Register this type.
 
- Static Public Member Functions inherited from ns3::PositionAllocator
static TypeId GetTypeId ()
 Register this type with the TypeId system.
 
- Static Public Member Functions inherited from ns3::Object
static TypeId GetTypeId ()
 Register this type.
 
- Static Public Member Functions inherited from ns3::ObjectBase
static TypeId GetTypeId ()
 Get the type ID.
 

Private Member Functions

std::vector< Vector > AddRing (std::vector< Vector > positions)
 This method adds to the given list of positions an outer ring of positions.
 

Private Attributes

std::vector< Vector >::const_iterator m_next
 The iterator pointing to the next position to return.
 
std::vector< Vector > m_positions
 The current list of positions.
 
double m_radius
 The radius of a cell (defined as the half the distance between two adjacent nodes, that is, the radius of the circle inscribed in each hexagonal tile)
 

Static Private Attributes

static const double pi = std::acos(-1)
 Pi.
 

Additional Inherited Members

- Protected Member Functions inherited from ns3::Object
 Object (const Object &o)
 Copy an Object.
 
virtual void DoDispose ()
 Destructor implementation.
 
virtual void DoInitialize ()
 Initialize() implementation.
 
virtual void NotifyNewAggregate ()
 Notify all Objects aggregated to this one of a new Object being aggregated.
 
- Protected Member Functions inherited from ns3::ObjectBase
void ConstructSelf (const AttributeConstructionList &attributes)
 Complete construction of ObjectBase; invoked by derived classes.
 
virtual void NotifyConstructionCompleted ()
 Notifier called once the ObjectBase is fully constructed.
 

Detailed Description

Position allocator for hexagonal tiling.

Starting with a first hexagon in the axes' center, following tiles are added in outward rings. The first position returned for a new ring is always the top one, followed by the others in anti-clockwise rotation.

Visual example with 10 tiles, indexed 0-9:

                _____
               /     \
         _____/   8   \
        /     \   ˙   /
       /   9   \_____/
       \   ˙   /     \
  next  \_____/   1   \_____
    ˙   /     \   ˙   /     \
       /   2   \_____/   7   \
       \   ˙   /     \   ˙   /
        \_____/   0   \_____/
        /     \   ˙   /     \
       /   3   \_____/   5   \
       \   ˙   /     \   ˙   /
        \_____/   4   \_____/
              \   ˙   /
               \_____/

The size of tiles can be configured by setting the radius $\rho_{i}$ of the circle inscribed within hexagons (i.e., the internal circle).

Let's say that we are placing access points, and we want to cover a square/circular area with hexagonal tiles. This leaves us with two questions: (i) which value should we choose for the internal radius? (ii) how many access point nodes (i.e., tiles) do we need to instantiate?

For instance, to guarantee that no point is further than 1km from the center of any tile (i.e., to have no uncovered patches), we can choose the radius $\rho_{c}$ of the circumscribed (external) circle of each hexagonal tile to be exactly 1km. Then, question (i) can be solved by setting the internal radius to $\rho_{i}=\frac{\sqrt{3}}{2}\rho_{c}$ using the properties of equilateral triangles.

To understand how many tiles need to be instantiated (that is, in this example, the number of access point nodes), it is often useful to start from the complete area's diagonal or radius, and to derive the number of complete rings $r$ required for coverage. Let's say we want to be able to cover a distance of at least $d$ km from the center. One way to do this can be to take the floor of $d$ divided by the distance between access points (the tiles' centers), which happens to be $2\rho_{i}$, and adding one/two ring for good measure. More formally, starting from a single central tile, we would need at least $r=\left\lfloor\frac{d}{2\rho_{i}}\right\rfloor+1$ additional rings around it. Then, the total number of tiles $n$ in a tiling of $r$ complete rings around a central tile evaluates to $n=3r^{2}-3r+1$ providing a possible solution for question (ii).

Todo
Move this into the module .rst documentation

Definition at line 72 of file hex-grid-position-allocator.h.

Constructor & Destructor Documentation

◆ HexGridPositionAllocator() [1/2]

ns3::HexGridPositionAllocator::HexGridPositionAllocator ( )

Default constructor.

Definition at line 35 of file hex-grid-position-allocator.cc.

References AddRing(), m_next, m_positions, and NS_LOG_FUNCTION_NOARGS.

+ Here is the call graph for this function:

◆ ~HexGridPositionAllocator()

ns3::HexGridPositionAllocator::~HexGridPositionAllocator ( )
override

Destructor.

Definition at line 72 of file hex-grid-position-allocator.cc.

References NS_LOG_FUNCTION_NOARGS.

◆ HexGridPositionAllocator() [2/2]

ns3::HexGridPositionAllocator::HexGridPositionAllocator ( double radius)

Construct a new HexGridPositionAllocator object with given radius.

Parameters
radiusThe radius length of the circle inscribed in the hexagonal tiles.

Definition at line 53 of file hex-grid-position-allocator.cc.

References AddRing(), m_next, m_positions, and NS_LOG_FUNCTION_NOARGS.

+ Here is the call graph for this function:

Member Function Documentation

◆ AddRing()

std::vector< Vector > ns3::HexGridPositionAllocator::AddRing ( std::vector< Vector > positions)
private

This method adds to the given list of positions an outer ring of positions.

Parameters
positionsThe list of position around which to create the new positions.
Returns
The input list of position with an added outer ring.

Definition at line 107 of file hex-grid-position-allocator.cc.

References ns3::CalculateDistance(), m_radius, NS_LOG_DEBUG, NS_LOG_FUNCTION, and pi.

Referenced by HexGridPositionAllocator(), and HexGridPositionAllocator().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ AssignStreams()

int64_t ns3::HexGridPositionAllocator::AssignStreams ( int64_t stream)
overridevirtual

Assign a fixed random variable stream number to the random variables used by this model.

Return the number of streams (possibly zero) that have been assigned.

This method must be implement in subclasses.

Parameters
streamfirst stream index to use
Returns
the number of stream indices assigned by this model

Implements ns3::PositionAllocator.

Definition at line 101 of file hex-grid-position-allocator.cc.

◆ GetNext()

Vector ns3::HexGridPositionAllocator::GetNext ( ) const
overridevirtual
Returns
the next chosen position.

This method must be implement in subclasses.

Implements ns3::PositionAllocator.

Definition at line 92 of file hex-grid-position-allocator.cc.

References m_next.

◆ GetRadius()

double ns3::HexGridPositionAllocator::GetRadius ( ) const

Get the radius of the circle inscribed in the hexagonal tiles.

Returns
The radius length.

Definition at line 80 of file hex-grid-position-allocator.cc.

References m_radius.

◆ GetTypeId()

TypeId ns3::HexGridPositionAllocator::GetTypeId ( )
static

Register this type.

Returns
The object TypeId.

Definition at line 20 of file hex-grid-position-allocator.cc.

References m_radius, ns3::MakeDoubleAccessor(), ns3::MakeDoubleChecker(), and ns3::TypeId::SetParent().

+ Here is the call graph for this function:

◆ SetRadius()

void ns3::HexGridPositionAllocator::SetRadius ( double radius)

Set the radius of the circle inscribed in the hexagonal tiles.

Parameters
radiusThe radius length.

Definition at line 86 of file hex-grid-position-allocator.cc.

References m_radius.

Member Data Documentation

◆ m_next

std::vector<Vector>::const_iterator ns3::HexGridPositionAllocator::m_next
mutableprivate

The iterator pointing to the next position to return.

Definition at line 120 of file hex-grid-position-allocator.h.

Referenced by HexGridPositionAllocator(), HexGridPositionAllocator(), and GetNext().

◆ m_positions

std::vector<Vector> ns3::HexGridPositionAllocator::m_positions
private

The current list of positions.

Definition at line 118 of file hex-grid-position-allocator.h.

Referenced by HexGridPositionAllocator(), and HexGridPositionAllocator().

◆ m_radius

double ns3::HexGridPositionAllocator::m_radius
private

The radius of a cell (defined as the half the distance between two adjacent nodes, that is, the radius of the circle inscribed in each hexagonal tile)

Definition at line 121 of file hex-grid-position-allocator.h.

Referenced by AddRing(), GetRadius(), GetTypeId(), and SetRadius().

◆ pi

const double ns3::HexGridPositionAllocator::pi = std::acos(-1)
staticprivate

Pi.

Definition at line 125 of file hex-grid-position-allocator.h.

Referenced by AddRing().


The documentation for this class was generated from the following files: