Position allocator for hexagonal tiling. More...
#include "hex-grid-position-allocator.h"
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< Object > | GetObject () 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< Object > | GetObject (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. | |
SimpleRefCount & | operator= (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. | |
Related Symbols inherited from ns3::ObjectBase | |
static TypeId | GetObjectIid () |
Ensure the TypeId for ObjectBase gets fully configured to anchor the inheritance tree properly. | |
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 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 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 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 required for coverage. Let's say we want to be able to cover a distance of at least km from the center. One way to do this can be to take the floor of divided by the distance between access points (the tiles' centers), which happens to be , and adding one/two ring for good measure. More formally, starting from a single central tile, we would need at least additional rings around it. Then, the total number of tiles in a tiling of complete rings around a central tile evaluates to providing a possible solution for question (ii).
Definition at line 72 of file hex-grid-position-allocator.h.
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.
|
override |
Destructor.
Definition at line 72 of file hex-grid-position-allocator.cc.
References NS_LOG_FUNCTION_NOARGS.
ns3::HexGridPositionAllocator::HexGridPositionAllocator | ( | double | radius | ) |
Construct a new HexGridPositionAllocator object with given radius.
radius | The 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.
|
private |
This method adds to the given list of positions an outer ring of positions.
positions | The list of position around which to create the new positions. |
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().
|
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.
stream | first stream index to use |
Implements ns3::PositionAllocator.
Definition at line 101 of file hex-grid-position-allocator.cc.
|
overridevirtual |
This method must be implement in subclasses.
Implements ns3::PositionAllocator.
Definition at line 92 of file hex-grid-position-allocator.cc.
References m_next.
double ns3::HexGridPositionAllocator::GetRadius | ( | ) | const |
Get the radius of the circle inscribed in the hexagonal tiles.
Definition at line 80 of file hex-grid-position-allocator.cc.
References m_radius.
|
static |
Register this type.
Definition at line 20 of file hex-grid-position-allocator.cc.
References m_radius, ns3::MakeDoubleAccessor(), ns3::MakeDoubleChecker(), and ns3::TypeId::SetParent().
void ns3::HexGridPositionAllocator::SetRadius | ( | double | radius | ) |
Set the radius of the circle inscribed in the hexagonal tiles.
radius | The radius length. |
Definition at line 86 of file hex-grid-position-allocator.cc.
References m_radius.
|
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().
|
private |
The current list of positions.
Definition at line 118 of file hex-grid-position-allocator.h.
Referenced by HexGridPositionAllocator(), and HexGridPositionAllocator().
|
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().
|
staticprivate |