added UniformDiscPositionAllocator (bug 672)

This commit is contained in:
Nicola Baldo
2009-11-13 16:45:28 +01:00
parent 74c973cfaf
commit b4fde3c459
2 changed files with 118 additions and 1 deletions

View File

@@ -315,4 +315,72 @@ RandomDiscPositionAllocator::GetNext (void) const
}
NS_OBJECT_ENSURE_REGISTERED (UniformDiscPositionAllocator);
TypeId
UniformDiscPositionAllocator::GetTypeId (void)
{
static TypeId tid = TypeId ("ns3::UniformDiscPositionAllocator")
.SetParent<PositionAllocator> ()
.SetGroupName ("Mobility")
.AddConstructor<UniformDiscPositionAllocator> ()
.AddAttribute ("rho",
"The radius of the disc",
DoubleValue (0.0),
MakeDoubleAccessor (&UniformDiscPositionAllocator::m_rho),
MakeDoubleChecker<double> ())
.AddAttribute ("X",
"The x coordinate of the center of the disc.",
DoubleValue (0.0),
MakeDoubleAccessor (&UniformDiscPositionAllocator::m_x),
MakeDoubleChecker<double> ())
.AddAttribute ("Y",
"The y coordinate of the center of the disc.",
DoubleValue (0.0),
MakeDoubleAccessor (&UniformDiscPositionAllocator::m_y),
MakeDoubleChecker<double> ())
;
return tid;
}
UniformDiscPositionAllocator::UniformDiscPositionAllocator ()
{}
UniformDiscPositionAllocator::~UniformDiscPositionAllocator ()
{}
void
UniformDiscPositionAllocator::SetRho (double rho)
{
m_rho = rho;
}
void
UniformDiscPositionAllocator::SetX (double x)
{
m_x = x;
}
void
UniformDiscPositionAllocator::SetY (double y)
{
m_y = y;
}
Vector
UniformDiscPositionAllocator::GetNext (void) const
{
UniformVariable r (-m_rho, m_rho);
double x,y;
do
{
x = r.GetValue ();
y = r.GetValue ();
}
while (sqrt(x*x + y*y) > m_rho);
x += m_x;
y += m_y;
NS_LOG_DEBUG ("Disc position x=" << x << ", y=" << y);
return Vector (x, y, 0.0);
}
} // namespace ns3

View File

@@ -182,7 +182,8 @@ private:
/**
* \brief allocate random positions within a disc
* according to a pair of random variables.
* according to a given distribution for the polar coordinates of each
* node with respect to the provided center of the disc
*/
class RandomDiscPositionAllocator : public PositionAllocator
{
@@ -204,6 +205,54 @@ private:
double m_y;
};
/**
* 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$
* 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
* to \f$ \frac{|S|}{|D|} \f$, i.e., to the ratio of the area of the
* subset to the area of the whole disc.
*
* \note using UniformDiscPositionAllocator is not equivalent to using
* a RandomDiscPositionAllocator with a uniformly-distributed radius,
* since doing that would results in a point distribution which is
* more dense towards the center of the disc.
*/
class UniformDiscPositionAllocator : public PositionAllocator
{
public:
static TypeId GetTypeId (void);
UniformDiscPositionAllocator ();
virtual ~UniformDiscPositionAllocator ();
/**
*
* @param rho the value of the radius of the disc
*/
void SetRho (double rho);
/**
*
*
* @param x the X coordinate of the center of the disc
*/
void SetX (double x);
/**
*
* @param y the Y coordinate of the center of the disc
*/
void SetY (double y);
virtual Vector GetNext (void) const;
private:
double m_rho;
double m_x;
double m_y;
};
} // namespace ns3
#endif /* RANDOM_POSITION_H */