A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
hex-grid-position-allocator.h
Go to the documentation of this file.
1
/*
2
* SPDX-License-Identifier: GPL-2.0-only
3
*
4
* Author: Davide Magrin <magrinda@dei.unipd.it>
5
*/
6
7
#ifndef HEX_GRID_POSITION_ALLOCATOR_H
8
#define HEX_GRID_POSITION_ALLOCATOR_H
9
10
#include "ns3/position-allocator.h"
11
12
namespace
ns3
13
{
14
15
/**
16
* @ingroup lorawan
17
*
18
* Position allocator for hexagonal tiling.
19
*
20
* Starting with a first hexagon in the axes' center, following tiles are added in outward
21
* rings. The first position returned for a new ring is always the top one, followed by the others
22
* in anti-clockwise rotation.
23
*
24
* Visual example with 10 tiles, indexed 0-9:
25
*
26
* _____
27
* / \
28
* _____/ 8 \
29
* / \ ˙ /
30
* / 9 \_____/
31
* \ ˙ / \
32
* next \_____/ 1 \_____
33
* ˙ / \ ˙ / \
34
* / 2 \_____/ 7 \
35
* \ ˙ / \ ˙ /
36
* \_____/ 0 \_____/
37
* / \ ˙ / \
38
* / 3 \_____/ 5 \
39
* \ ˙ / \ ˙ /
40
* \_____/ 4 \_____/
41
* \ ˙ /
42
* \_____/
43
*
44
* The size of tiles can be configured by setting the radius \f$\rho_{i}\f$ of the circle
45
* \b inscribed within hexagons (i.e., the internal circle).
46
*
47
* Let's say that we are placing access points, and we want to cover a square/circular area with
48
* hexagonal tiles. This leaves us with two questions: (i) which value should we choose for the
49
* internal radius? (ii) how many access point nodes (i.e., tiles) do we need to instantiate?
50
*
51
* For instance, to guarantee that no point is further than 1km from the center of any tile (i.e.,
52
* to have no uncovered patches), we can choose the radius \f$\rho_{c}\f$ of the
53
* \b circumscribed (external) circle of each hexagonal tile to be exactly 1km. Then, question
54
* (i) can be solved by setting the internal radius to \f$\rho_{i}=\frac{\sqrt{3}}{2}\rho_{c}\f$
55
* using the properties of equilateral triangles.
56
*
57
* To understand how many tiles need to be instantiated (that is, in this example, the number of
58
* access point nodes), it is often useful to start from the complete area's diagonal or radius, and
59
* to derive the number of complete rings \f$r\f$ required for coverage. Let's say we want to be
60
* able to cover a distance of at least \f$d\f$ km from the center. One way to do this can be to
61
* take the floor of \f$d\f$ divided by the distance between access points (the tiles' centers),
62
* which happens to be \f$2\rho_{i}\f$, and adding one/two ring for good measure. More formally,
63
* starting from a single central tile, we would need at least
64
* \f$r=\left\lfloor\frac{d}{2\rho_{i}}\right\rfloor+1\f$ \b additional rings around it. Then,
65
* the total number of tiles \f$n\f$ in a tiling of \f$r\f$ complete rings around a central tile
66
* evaluates to \f$n=3r^{2}-3r+1\f$ providing a possible solution for question (ii).
67
*
68
* @todo Move this into the module .rst documentation
69
*/
70
class
HexGridPositionAllocator
:
public
PositionAllocator
71
{
72
public
:
73
HexGridPositionAllocator
();
//!< Default constructor
74
~HexGridPositionAllocator
()
override
;
//!< Destructor
75
76
/**
77
* Construct a new HexGridPositionAllocator object with given radius.
78
*
79
* @param radius The radius length of the circle inscribed in the hexagonal tiles.
80
*/
81
HexGridPositionAllocator
(
double
radius);
82
83
Vector
GetNext
()
const override
;
84
85
int64_t
AssignStreams
(int64_t stream)
override
;
86
87
/**
88
* Register this type.
89
* @return The object TypeId.
90
*/
91
static
TypeId
GetTypeId
();
92
93
/**
94
* Get the radius of the circle inscribed in the hexagonal tiles.
95
*
96
* @return The radius length.
97
*/
98
double
GetRadius
()
const
;
99
100
/**
101
* Set the radius of the circle inscribed in the hexagonal tiles.
102
*
103
* @param radius The radius length.
104
*/
105
void
SetRadius
(
double
radius);
106
107
private
:
108
/**
109
* This method adds to the given list of positions an outer ring of positions.
110
*
111
* @param positions The list of position around which to create the new positions.
112
* @return The input list of position with an added outer ring.
113
*/
114
std::vector<Vector>
AddRing
(std::vector<Vector> positions);
115
116
std::vector<Vector>
m_positions
;
//!< The current list of positions
117
mutable
std::vector<Vector>::const_iterator
118
m_next
;
//!< The iterator pointing to the next position to return
119
double
m_radius
;
//!< The radius of a cell (defined as the half the distance between two
120
//!< adjacent nodes, that is, the radius of the circle inscribed in each
121
//!< hexagonal tile)
122
123
const
static
double
pi
;
//!< Pi
124
};
125
126
}
// namespace ns3
127
128
#endif
/* PERIODIC_SENDER_HELPER_H */
ns3::HexGridPositionAllocator::AssignStreams
int64_t AssignStreams(int64_t stream) override
Assign a fixed random variable stream number to the random variables used by this model.
Definition
hex-grid-position-allocator.cc:100
ns3::HexGridPositionAllocator::SetRadius
void SetRadius(double radius)
Set the radius of the circle inscribed in the hexagonal tiles.
Definition
hex-grid-position-allocator.cc:85
ns3::HexGridPositionAllocator::GetTypeId
static TypeId GetTypeId()
Register this type.
Definition
hex-grid-position-allocator.cc:19
ns3::HexGridPositionAllocator::AddRing
std::vector< Vector > AddRing(std::vector< Vector > positions)
This method adds to the given list of positions an outer ring of positions.
Definition
hex-grid-position-allocator.cc:106
ns3::HexGridPositionAllocator::GetRadius
double GetRadius() const
Get the radius of the circle inscribed in the hexagonal tiles.
Definition
hex-grid-position-allocator.cc:79
ns3::HexGridPositionAllocator::HexGridPositionAllocator
HexGridPositionAllocator()
Default constructor.
Definition
hex-grid-position-allocator.cc:34
ns3::HexGridPositionAllocator::pi
static const double pi
Pi.
Definition
hex-grid-position-allocator.h:123
ns3::HexGridPositionAllocator::m_radius
double m_radius
The radius of a cell (defined as the half the distance between two adjacent nodes,...
Definition
hex-grid-position-allocator.h:119
ns3::HexGridPositionAllocator::GetNext
Vector GetNext() const override
Definition
hex-grid-position-allocator.cc:91
ns3::HexGridPositionAllocator::~HexGridPositionAllocator
~HexGridPositionAllocator() override
Destructor.
Definition
hex-grid-position-allocator.cc:71
ns3::HexGridPositionAllocator::m_positions
std::vector< Vector > m_positions
The current list of positions.
Definition
hex-grid-position-allocator.h:116
ns3::HexGridPositionAllocator::m_next
std::vector< Vector >::const_iterator m_next
The iterator pointing to the next position to return.
Definition
hex-grid-position-allocator.h:118
ns3::PositionAllocator::PositionAllocator
PositionAllocator()
Definition
position-allocator.cc:35
ns3::TypeId
a unique identifier for an interface.
Definition
type-id.h:50
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
src
lorawan
model
hex-grid-position-allocator.h
Generated on
for ns-3 by
1.15.0