Skip to content

Commit

Permalink
mobility: (fixes #2860) set z coordinate for many position-allocation…
Browse files Browse the repository at this point in the history
… classes
  • Loading branch information
mychele committed Oct 12, 2018
1 parent b76d07d commit 4ebc14d
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGES.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ <h2>New API:</h2>
</ul>
<h2>Changes to existing API:</h2>
<ul>
<li>
Added the possibility of setting the z coordinate for many
position-allocation classes: GridPositionAllocator,
RandomRectanglePositionAllocator, RandomDiscPositionAllocator,
UniformDiscPositionAllocator.
</li>
</ul>
<h2>Changes to build system:</h2>
<ul>
Expand Down
1 change: 1 addition & 0 deletions RELEASE_NOTES
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Bugs fixed

- Bug 2992 - lte: Send method of the LteUeNetDevice doesn't use protocolNumber parameter
- Bug 2997 - lte: EpcTft::PacketFilter::Matches does not use ipv6 address to match an IP packet
- Bug 2860 - mobility: Set Z coordinate for position-allocation classes

Known issues
------------
Expand Down
51 changes: 46 additions & 5 deletions src/mobility/model/position-allocator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ GridPositionAllocator::GetTypeId (void)
DoubleValue (0.0),
MakeDoubleAccessor (&GridPositionAllocator::m_yMin),
MakeDoubleChecker<double> ())
.AddAttribute ("Z",
"The z coordinate of all the positions allocated.",
DoubleValue (0.0),
MakeDoubleAccessor (&GridPositionAllocator::m_z),
MakeDoubleChecker<double> ())
.AddAttribute ("DeltaX", "The x space between objects.",
DoubleValue (1.0),
MakeDoubleAccessor (&GridPositionAllocator::m_deltaX),
Expand Down Expand Up @@ -146,6 +151,11 @@ GridPositionAllocator::SetMinY (double yMin)
m_yMin = yMin;
}
void
GridPositionAllocator::SetZ (double z)
{
m_z = z;
}
void
GridPositionAllocator::SetDeltaX (double deltaX)
{
m_deltaX = deltaX;
Expand Down Expand Up @@ -212,7 +222,7 @@ GridPositionAllocator::GetNext (void) const
break;
}
m_current++;
return Vector (x, y, 0.0);
return Vector (x, y, m_z);
}

int64_t
Expand All @@ -239,7 +249,13 @@ RandomRectanglePositionAllocator::GetTypeId (void)
"A random variable which represents the y coordinate of a position in a random rectangle.",
StringValue ("ns3::UniformRandomVariable[Min=0.0|Max=1.0]"),
MakePointerAccessor (&RandomRectanglePositionAllocator::m_y),
MakePointerChecker<RandomVariableStream> ());
MakePointerChecker<RandomVariableStream> ())
.AddAttribute ("Z",
"The z coordinate of all the positions allocated.",
DoubleValue (0.0),
MakeDoubleAccessor (&RandomRectanglePositionAllocator::m_z),
MakeDoubleChecker<double> ())
;
return tid;
}

Expand All @@ -260,13 +276,18 @@ RandomRectanglePositionAllocator::SetY (Ptr<RandomVariableStream> y)
{
m_y = y;
}
void
RandomRectanglePositionAllocator::SetZ (double z)
{
m_z = z;
}

Vector
RandomRectanglePositionAllocator::GetNext (void) const
{
double x = m_x->GetValue ();
double y = m_y->GetValue ();
return Vector (x, y, 0.0);
return Vector (x, y, m_z);
}

int64_t
Expand Down Expand Up @@ -374,6 +395,11 @@ RandomDiscPositionAllocator::GetTypeId (void)
DoubleValue (0.0),
MakeDoubleAccessor (&RandomDiscPositionAllocator::m_y),
MakeDoubleChecker<double> ())
.AddAttribute ("Z",
"The z coordinate of all the positions in the disc.",
DoubleValue (0.0),
MakeDoubleAccessor (&RandomDiscPositionAllocator::m_z),
MakeDoubleChecker<double> ())
;
return tid;
}
Expand Down Expand Up @@ -405,6 +431,11 @@ RandomDiscPositionAllocator::SetY (double y)
{
m_y = y;
}
void
RandomDiscPositionAllocator::SetZ (double z)
{
m_z = z;
}
Vector
RandomDiscPositionAllocator::GetNext (void) const
{
Expand All @@ -413,7 +444,7 @@ RandomDiscPositionAllocator::GetNext (void) const
double x = m_x + std::cos (theta) * rho;
double y = m_y + std::sin (theta) * rho;
NS_LOG_DEBUG ("Disc position x=" << x << ", y=" << y);
return Vector (x, y, 0.0);
return Vector (x, y, m_z);
}

int64_t
Expand Down Expand Up @@ -450,6 +481,11 @@ UniformDiscPositionAllocator::GetTypeId (void)
DoubleValue (0.0),
MakeDoubleAccessor (&UniformDiscPositionAllocator::m_y),
MakeDoubleChecker<double> ())
.AddAttribute ("Z",
"The z coordinate of all the positions in the disc.",
DoubleValue (0.0),
MakeDoubleAccessor (&UniformDiscPositionAllocator::m_z),
MakeDoubleChecker<double> ())
;
return tid;
}
Expand Down Expand Up @@ -477,6 +513,11 @@ UniformDiscPositionAllocator::SetY (double y)
{
m_y = y;
}
void
UniformDiscPositionAllocator::SetZ (double z)
{
m_z = z;
}
Vector
UniformDiscPositionAllocator::GetNext (void) const
{
Expand All @@ -491,7 +532,7 @@ UniformDiscPositionAllocator::GetNext (void) const
x += m_x;
y += m_y;
NS_LOG_DEBUG ("Disc position x=" << x << ", y=" << y);
return Vector (x, y, 0.0);
return Vector (x, y, m_z);
}

int64_t
Expand Down
23 changes: 22 additions & 1 deletion src/mobility/model/position-allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ class GridPositionAllocator : public PositionAllocator
* \param yMin the y coordinate where layout will start
*/
void SetMinY (double yMin);
/**
* \param z the Z coordinate of all the positions allocated
*/
void SetZ (double z);
/**
* \param deltaX the x interval between two x-consecutive positions.
*/
Expand Down Expand Up @@ -190,6 +194,7 @@ class GridPositionAllocator : public PositionAllocator
enum LayoutType m_layoutType; //!< currently selected layout type
double m_xMin; //!< minimum boundary on x positions
double m_yMin; //!< minimum boundary on y positions
double m_z; //!< z coordinate of all the positions generated
uint32_t m_n; //!< number of positions to allocate on each row or column
double m_deltaX; //!< x interval between two consecutive x positions
double m_deltaY; //!< y interval between two consecutive y positions
Expand Down Expand Up @@ -220,12 +225,17 @@ class RandomRectanglePositionAllocator : public PositionAllocator
* \param y pointer to a RandomVariableStream object
*/
void SetY (Ptr<RandomVariableStream> y);
/**
* \param z the Z coordinate of all the positions allocated
*/
void SetZ (double z);

virtual Vector GetNext (void) const;
virtual int64_t AssignStreams (int64_t stream);
private:
Ptr<RandomVariableStream> m_x; //!< pointer to x's random variable stream
Ptr<RandomVariableStream> m_y; //!< pointer to y's random variable stream
double m_z; //!< z coordinate of all the positions generated
};

/**
Expand Down Expand Up @@ -301,6 +311,10 @@ class RandomDiscPositionAllocator : public PositionAllocator
* \param y the Y coordinate of the center of the disc
*/
void SetY (double y);
/**
* \param z the Z coordinate of all the positions allocated
*/
void SetZ (double z);

virtual Vector GetNext (void) const;
virtual int64_t AssignStreams (int64_t stream);
Expand All @@ -309,6 +323,7 @@ class RandomDiscPositionAllocator : public PositionAllocator
Ptr<RandomVariableStream> m_rho; //!< pointer to rho's random variable stream
double m_x; //!< x coordinate of center of disc
double m_y; //!< y coordinate of center of disc
double m_z; //!< z coordinate of the disc
};


Expand All @@ -317,7 +332,7 @@ class RandomDiscPositionAllocator : public PositionAllocator
* \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$
* plane \f$ z\f$ and having center at coordinates \f$ (x,y,z) \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
Expand Down Expand Up @@ -355,13 +370,19 @@ class UniformDiscPositionAllocator : public PositionAllocator
*/
void SetY (double y);

/**
* \param z the Z coordinate of all the positions allocated
*/
void SetZ (double z);

virtual Vector GetNext (void) const;
virtual int64_t AssignStreams (int64_t stream);
private:
Ptr<UniformRandomVariable> m_rv; //!< pointer to uniform random variable
double m_rho; //!< value of the radius of the disc
double m_x; //!< x coordinate of center of disc
double m_y; //!< y coordinate of center of disc
double m_z; //!< z coordinate of the disc
};

} // namespace ns3
Expand Down

0 comments on commit 4ebc14d

Please sign in to comment.