a random position helper class
This commit is contained in:
@@ -260,6 +260,8 @@ node.add_sources ([
|
||||
'hierarchical-mobility-model.cc',
|
||||
'ns2-mobility-file-topology.cc',
|
||||
'mobility-model-helper.cc',
|
||||
'position-2d.cc',
|
||||
'random-2d-position.cc',
|
||||
])
|
||||
node.add_inst_headers ([
|
||||
'node.h',
|
||||
@@ -289,6 +291,8 @@ node.add_inst_headers ([
|
||||
'hierarchical-mobility-model.h',
|
||||
'ns2-mobility-file-topology.h',
|
||||
'mobility-model-helper.h',
|
||||
'position-2d.h',
|
||||
'random-2d-position.h',
|
||||
])
|
||||
|
||||
applications = build.Ns3Module ('applications', 'src/applications')
|
||||
|
||||
10
src/node/position-2d.cc
Normal file
10
src/node/position-2d.cc
Normal file
@@ -0,0 +1,10 @@
|
||||
#include "position-2d.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
Position2d::Position2d (double _x, double _y)
|
||||
: x (_x),
|
||||
y (_y)
|
||||
{}
|
||||
|
||||
} // namespace ns3
|
||||
16
src/node/position-2d.h
Normal file
16
src/node/position-2d.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#ifndef POSITION_2D_H
|
||||
#define POSITION_2D_H
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
class Position2d
|
||||
{
|
||||
public:
|
||||
Position2d (double x, double y);
|
||||
double x;
|
||||
double y;
|
||||
};
|
||||
|
||||
} // namespace ns3
|
||||
|
||||
#endif /* POSITION_2D_H */
|
||||
82
src/node/random-2d-position.cc
Normal file
82
src/node/random-2d-position.cc
Normal file
@@ -0,0 +1,82 @@
|
||||
#include "random-2d-position.h"
|
||||
#include "ns3/random-variable.h"
|
||||
#include "ns3/random-variable-default-value.h"
|
||||
#include <cmath>
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
static RandomVariableDefaultValue
|
||||
g_rectangleX ("RandomRectanglePositionX",
|
||||
"A random variable which represents the x position of a position in a random rectangle.",
|
||||
"Uniform:0:200");
|
||||
|
||||
static RandomVariableDefaultValue
|
||||
g_rectangleY ("RandomRectanglePositionY",
|
||||
"A random variable which represents the y position of a position in a random rectangle.",
|
||||
"Uniform:0:200");
|
||||
|
||||
static RandomVariableDefaultValue
|
||||
g_discTheta ("RandomRectanglePositionTheta",
|
||||
"A random variable which represents the angle (gradients) of a position in a random disc.",
|
||||
"Uniform:0:3.1415");
|
||||
|
||||
static RandomVariableDefaultValue
|
||||
g_discRho ("RandomRectanglePositionRho",
|
||||
"A random variable which represents the radius of a position in a random disc.",
|
||||
"Uniform:0:200");
|
||||
|
||||
Random2dPosition::~Random2dPosition ()
|
||||
{}
|
||||
|
||||
RandomRectanglePosition::RandomRectanglePosition ()
|
||||
: m_x (g_rectangleX.GetCopy ()),
|
||||
m_y (g_rectangleY.GetCopy ())
|
||||
{}
|
||||
RandomRectanglePosition::RandomRectanglePosition (const RandomVariable &x,
|
||||
const RandomVariable &y)
|
||||
: m_x (x.Copy ()),
|
||||
m_y (y.Copy ())
|
||||
{}
|
||||
RandomRectanglePosition::~RandomRectanglePosition ()
|
||||
{
|
||||
delete m_x;
|
||||
delete m_y;
|
||||
m_x = 0;
|
||||
m_y = 0;
|
||||
}
|
||||
Position2d
|
||||
RandomRectanglePosition::Get (void) const
|
||||
{
|
||||
double x = m_x->GetValue ();
|
||||
double y = m_y->GetValue ();
|
||||
return Position2d (x, y);
|
||||
}
|
||||
|
||||
RandomDiscPosition::RandomDiscPosition ()
|
||||
: m_theta (g_discTheta.GetCopy ()),
|
||||
m_rho (g_discRho.GetCopy ())
|
||||
{}
|
||||
RandomDiscPosition::RandomDiscPosition (const RandomVariable &theta,
|
||||
const RandomVariable &rho)
|
||||
: m_theta (theta.Copy ()),
|
||||
m_rho (rho.Copy ())
|
||||
{}
|
||||
RandomDiscPosition::~RandomDiscPosition ()
|
||||
{
|
||||
delete m_theta;
|
||||
delete m_rho;
|
||||
m_theta = 0;
|
||||
m_rho = 0;
|
||||
}
|
||||
Position2d
|
||||
RandomDiscPosition::Get (void) const
|
||||
{
|
||||
double theta = m_theta->GetValue ();
|
||||
double rho = m_rho->GetValue ();
|
||||
double x = std::cos (theta) * rho;
|
||||
double y = std::sin (theta) * rho;
|
||||
return Position2d (x, y);
|
||||
}
|
||||
|
||||
|
||||
} // namespace ns3
|
||||
46
src/node/random-2d-position.h
Normal file
46
src/node/random-2d-position.h
Normal file
@@ -0,0 +1,46 @@
|
||||
#ifndef RANDOM_2D_POSITION_H
|
||||
#define RANDOM_2D_POSITION_H
|
||||
|
||||
#include "ns3/object.h"
|
||||
#include "position-2d.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
class RandomVariable;
|
||||
|
||||
class Random2dPosition : public Object
|
||||
{
|
||||
public:
|
||||
virtual ~Random2dPosition ();
|
||||
virtual Position2d Get (void) const = 0;
|
||||
};
|
||||
|
||||
class RandomRectanglePosition : public Random2dPosition
|
||||
{
|
||||
public:
|
||||
RandomRectanglePosition ();
|
||||
RandomRectanglePosition (const RandomVariable &x,
|
||||
const RandomVariable &y);
|
||||
virtual ~RandomRectanglePosition ();
|
||||
virtual Position2d Get (void) const;
|
||||
private:
|
||||
RandomVariable *m_x;
|
||||
RandomVariable *m_y;
|
||||
};
|
||||
|
||||
class RandomDiscPosition : public Random2dPosition
|
||||
{
|
||||
public:
|
||||
RandomDiscPosition ();
|
||||
RandomDiscPosition (const RandomVariable &theta,
|
||||
const RandomVariable &rho);
|
||||
virtual ~RandomDiscPosition ();
|
||||
virtual Position2d Get (void) const;
|
||||
private:
|
||||
RandomVariable *m_theta;
|
||||
RandomVariable *m_rho;
|
||||
};
|
||||
|
||||
} // namespace ns3
|
||||
|
||||
#endif /* RANDOM_2D_POSITION_H */
|
||||
Reference in New Issue
Block a user