diff --git a/SConstruct b/SConstruct index 002b84a29..c25806e45 100644 --- a/SConstruct +++ b/SConstruct @@ -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') diff --git a/src/node/position-2d.cc b/src/node/position-2d.cc new file mode 100644 index 000000000..57c9a3b9e --- /dev/null +++ b/src/node/position-2d.cc @@ -0,0 +1,10 @@ +#include "position-2d.h" + +namespace ns3 { + +Position2d::Position2d (double _x, double _y) + : x (_x), + y (_y) +{} + +} // namespace ns3 diff --git a/src/node/position-2d.h b/src/node/position-2d.h new file mode 100644 index 000000000..d1c10030c --- /dev/null +++ b/src/node/position-2d.h @@ -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 */ diff --git a/src/node/random-2d-position.cc b/src/node/random-2d-position.cc new file mode 100644 index 000000000..dd7164ed0 --- /dev/null +++ b/src/node/random-2d-position.cc @@ -0,0 +1,82 @@ +#include "random-2d-position.h" +#include "ns3/random-variable.h" +#include "ns3/random-variable-default-value.h" +#include + +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 diff --git a/src/node/random-2d-position.h b/src/node/random-2d-position.h new file mode 100644 index 000000000..a8ae249df --- /dev/null +++ b/src/node/random-2d-position.h @@ -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 */