Random2dPosition -> RandomPosition
This commit is contained in:
@@ -261,7 +261,8 @@ node.add_sources ([
|
||||
'ns2-mobility-file-topology.cc',
|
||||
'mobility-model-helper.cc',
|
||||
'position-2d.cc',
|
||||
'random-2d-position.cc',
|
||||
'position.cc',
|
||||
'random-position.cc',
|
||||
])
|
||||
node.add_inst_headers ([
|
||||
'node.h',
|
||||
@@ -292,7 +293,8 @@ node.add_inst_headers ([
|
||||
'ns2-mobility-file-topology.h',
|
||||
'mobility-model-helper.h',
|
||||
'position-2d.h',
|
||||
'random-2d-position.h',
|
||||
'position.h',
|
||||
'random-position.h',
|
||||
])
|
||||
|
||||
applications = build.Ns3Module ('applications', 'src/applications')
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "random-2d-position.h"
|
||||
#include "random-position.h"
|
||||
#include "ns3/random-variable.h"
|
||||
#include "ns3/random-variable-default-value.h"
|
||||
#include <cmath>
|
||||
@@ -25,21 +25,21 @@ g_discRho ("RandomRectanglePositionRho",
|
||||
"A random variable which represents the radius of a position in a random disc.",
|
||||
"Uniform:0:200");
|
||||
|
||||
const InterfaceId Random2dPosition::iid = MakeInterfaceId ("Random2dPosition", Object::iid);
|
||||
const InterfaceId RandomPosition::iid = MakeInterfaceId ("RandomPosition", Object::iid);
|
||||
|
||||
const ClassId RandomRectanglePosition::cid =
|
||||
MakeClassId<RandomRectanglePosition> ("RandomRectanglePosition",
|
||||
Random2dPosition::iid);
|
||||
RandomPosition::iid);
|
||||
const ClassId RandomDiscPosition::cid =
|
||||
MakeClassId<RandomDiscPosition> ("RandomDiscPosition",
|
||||
Random2dPosition::iid);
|
||||
RandomPosition::iid);
|
||||
|
||||
Random2dPosition::Random2dPosition ()
|
||||
RandomPosition::RandomPosition ()
|
||||
{
|
||||
Object::SetInterfaceId (Random2dPosition::iid);
|
||||
Object::SetInterfaceId (RandomPosition::iid);
|
||||
}
|
||||
|
||||
Random2dPosition::~Random2dPosition ()
|
||||
RandomPosition::~RandomPosition ()
|
||||
{}
|
||||
|
||||
RandomRectanglePosition::RandomRectanglePosition ()
|
||||
@@ -58,12 +58,12 @@ RandomRectanglePosition::~RandomRectanglePosition ()
|
||||
m_x = 0;
|
||||
m_y = 0;
|
||||
}
|
||||
Position2d
|
||||
Position
|
||||
RandomRectanglePosition::Get (void) const
|
||||
{
|
||||
double x = m_x->GetValue ();
|
||||
double y = m_y->GetValue ();
|
||||
return Position2d (x, y);
|
||||
return Position (x, y, 0.0);
|
||||
}
|
||||
|
||||
RandomDiscPosition::RandomDiscPosition ()
|
||||
@@ -82,14 +82,14 @@ RandomDiscPosition::~RandomDiscPosition ()
|
||||
m_theta = 0;
|
||||
m_rho = 0;
|
||||
}
|
||||
Position2d
|
||||
Position
|
||||
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);
|
||||
return Position (x, y, 0.0);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
#ifndef RANDOM_2D_POSITION_H
|
||||
#define RANDOM_2D_POSITION_H
|
||||
#ifndef RANDOM_POSITION_H
|
||||
#define RANDOM_POSITION_H
|
||||
|
||||
#include "ns3/object.h"
|
||||
#include "ns3/component-manager.h"
|
||||
#include "position-2d.h"
|
||||
#include "position.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
class RandomVariable;
|
||||
|
||||
class Random2dPosition : public Object
|
||||
class RandomPosition : public Object
|
||||
{
|
||||
public:
|
||||
static const InterfaceId iid;
|
||||
Random2dPosition ();
|
||||
virtual ~Random2dPosition ();
|
||||
virtual Position2d Get (void) const = 0;
|
||||
RandomPosition ();
|
||||
virtual ~RandomPosition ();
|
||||
virtual Position Get (void) const = 0;
|
||||
};
|
||||
|
||||
class RandomRectanglePosition : public Random2dPosition
|
||||
class RandomRectanglePosition : public RandomPosition
|
||||
{
|
||||
public:
|
||||
static const ClassId cid;
|
||||
@@ -26,13 +26,13 @@ public:
|
||||
RandomRectanglePosition (const RandomVariable &x,
|
||||
const RandomVariable &y);
|
||||
virtual ~RandomRectanglePosition ();
|
||||
virtual Position2d Get (void) const;
|
||||
virtual Position Get (void) const;
|
||||
private:
|
||||
RandomVariable *m_x;
|
||||
RandomVariable *m_y;
|
||||
};
|
||||
|
||||
class RandomDiscPosition : public Random2dPosition
|
||||
class RandomDiscPosition : public RandomPosition
|
||||
{
|
||||
public:
|
||||
static const ClassId cid;
|
||||
@@ -40,7 +40,7 @@ public:
|
||||
RandomDiscPosition (const RandomVariable &theta,
|
||||
const RandomVariable &rho);
|
||||
virtual ~RandomDiscPosition ();
|
||||
virtual Position2d Get (void) const;
|
||||
virtual Position Get (void) const;
|
||||
private:
|
||||
RandomVariable *m_theta;
|
||||
RandomVariable *m_rho;
|
||||
@@ -48,4 +48,4 @@ private:
|
||||
|
||||
} // namespace ns3
|
||||
|
||||
#endif /* RANDOM_2D_POSITION_H */
|
||||
#endif /* RANDOM_POSITION_H */
|
||||
@@ -20,30 +20,30 @@
|
||||
*/
|
||||
#include "ns3/random-variable-default-value.h"
|
||||
#include "random-topology.h"
|
||||
#include "random-2d-position.h"
|
||||
#include "random-position.h"
|
||||
#include "mobility-model.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
static ClassIdDefaultValue
|
||||
g_position ("Random2dTopologyType",
|
||||
"The type of initial random position in a 2d topology.",
|
||||
Random2dPosition::iid,
|
||||
g_position ("RandomTopologyType",
|
||||
"The type of initial random position in a 3d topology.",
|
||||
RandomPosition::iid,
|
||||
"Rectangle");
|
||||
|
||||
static ClassIdDefaultValue
|
||||
g_mobility ("Random2dTopologyMobilityModelType",
|
||||
"The type of mobility model attached to an object in a 2d topology.",
|
||||
g_mobility ("RandomTopologyMobilityModelType",
|
||||
"The type of mobility model attached to an object in a 3d topology.",
|
||||
MobilityModel::iid,
|
||||
"StaticMobilityModel");
|
||||
|
||||
RandomTopology::RandomTopology ()
|
||||
: m_mobilityModel (g_mobility.GetValue ())
|
||||
{
|
||||
m_positionModel = ComponentManager::Create<Random2dPosition> (g_position.GetValue (),
|
||||
Random2dPosition::iid);
|
||||
m_positionModel = ComponentManager::Create<RandomPosition> (g_position.GetValue (),
|
||||
RandomPosition::iid);
|
||||
}
|
||||
RandomTopology::RandomTopology (Ptr<Random2dPosition> positionModel, ClassId mobilityModel)
|
||||
RandomTopology::RandomTopology (Ptr<RandomPosition> positionModel, ClassId mobilityModel)
|
||||
: m_positionModel (positionModel),
|
||||
m_mobilityModel (mobilityModel)
|
||||
{}
|
||||
@@ -59,7 +59,7 @@ RandomTopology::SetMobilityModel (ClassId classId)
|
||||
}
|
||||
|
||||
void
|
||||
RandomTopology::SetPositionModel (Ptr<Random2dPosition> positionModel)
|
||||
RandomTopology::SetPositionModel (Ptr<RandomPosition> positionModel)
|
||||
{
|
||||
m_positionModel = positionModel;
|
||||
}
|
||||
@@ -67,12 +67,9 @@ RandomTopology::SetPositionModel (Ptr<Random2dPosition> positionModel)
|
||||
void
|
||||
RandomTopology::LayoutOne (Ptr<Object> object)
|
||||
{
|
||||
Position2d position2d = m_positionModel->Get ();
|
||||
Ptr<MobilityModel> mobility = ComponentManager::Create<MobilityModel> (m_mobilityModel,
|
||||
MobilityModel::iid);
|
||||
Position position = mobility->Get ();
|
||||
position.x = position2d.x;
|
||||
position.y = position2d.y;
|
||||
Position position = m_positionModel->Get ();
|
||||
mobility->Set (position);
|
||||
object->AddInterface (mobility);
|
||||
}
|
||||
|
||||
@@ -27,26 +27,26 @@
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
class Random2dPosition;
|
||||
class RandomPosition;
|
||||
|
||||
class RandomTopology
|
||||
{
|
||||
public:
|
||||
RandomTopology ();
|
||||
RandomTopology (Ptr<Random2dPosition> positionModel,
|
||||
ClassId mobilityModel);
|
||||
RandomTopology (Ptr<RandomPosition> positionModel,
|
||||
ClassId mobilityModel);
|
||||
|
||||
~RandomTopology ();
|
||||
|
||||
void SetMobilityModel (ClassId classId);
|
||||
void SetPositionModel (Ptr<Random2dPosition> positionModel);
|
||||
void SetPositionModel (Ptr<RandomPosition> positionModel);
|
||||
|
||||
void LayoutOne (Ptr<Object> object);
|
||||
|
||||
template <typename T>
|
||||
void Layout (const T &begin, const T &end);
|
||||
private:
|
||||
Ptr<Random2dPosition> m_positionModel;
|
||||
Ptr<RandomPosition> m_positionModel;
|
||||
ClassId m_mobilityModel;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user