use Random2dPosition from RandomRectangleTopology
This commit is contained in:
@@ -18,58 +18,63 @@
|
||||
*
|
||||
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
|
||||
*/
|
||||
#include "random-rectangle-topology.h"
|
||||
#include "static-mobility-model.h"
|
||||
#include "ns3/random-variable-default-value.h"
|
||||
#include "random-rectangle-topology.h"
|
||||
#include "random-2d-position.h"
|
||||
#include "mobility-model.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
static RandomVariableDefaultValue
|
||||
g_xVariable ("RandomRectangleTopologyX",
|
||||
"Random variable to choose the x coordinate of the elements of a RandomRectangleTopology.",
|
||||
"Uniform:-100:100");
|
||||
static RandomVariableDefaultValue
|
||||
g_yVariable ("RandomRectangleTopologyY",
|
||||
"Random variable to choose the y coordinate of the elements of a RandomRectangleTopology.",
|
||||
"Uniform:-100:100");
|
||||
static ClassIdDefaultValue
|
||||
g_position ("Random2dTopologyType",
|
||||
"The type of initial random position in a 2d topology.",
|
||||
Random2dPosition::iid,
|
||||
"Rectangle");
|
||||
|
||||
static ClassIdDefaultValue
|
||||
g_mobility ("Random2dTopologyMobilityModelType",
|
||||
"The type of mobility model attached to an object in a 2d topology.",
|
||||
MobilityModel::iid,
|
||||
"StaticMobilityModel");
|
||||
|
||||
RandomRectangleTopology::RandomRectangleTopology ()
|
||||
: m_xVariable (g_xVariable.GetCopy ()),
|
||||
m_yVariable (g_yVariable.GetCopy ()),
|
||||
m_positionModel (StaticMobilityModel::cid)
|
||||
{}
|
||||
|
||||
RandomRectangleTopology::RandomRectangleTopology (double xMin, double xMax, double yMin, double yMax)
|
||||
: m_xVariable (new UniformVariable (xMin, xMax)),
|
||||
m_yVariable (new UniformVariable (yMin, yMax)),
|
||||
m_positionModel (StaticMobilityModel::cid)
|
||||
{}
|
||||
RandomRectangleTopology::RandomRectangleTopology (const RandomVariable &xVariable,
|
||||
const RandomVariable &yVariable)
|
||||
: m_xVariable (xVariable.Copy ()),
|
||||
m_yVariable (yVariable.Copy ()),
|
||||
m_positionModel (StaticMobilityModel::cid)
|
||||
: m_mobilityModel (g_mobility.GetValue ())
|
||||
{
|
||||
m_positionModel = ComponentManager::Create<Random2dPosition> (g_position.GetValue (),
|
||||
Random2dPosition::iid);
|
||||
}
|
||||
RandomRectangleTopology::RandomRectangleTopology (Ptr<Random2dPosition> positionModel, ClassId mobilityModel)
|
||||
: m_positionModel (positionModel),
|
||||
m_mobilityModel (mobilityModel)
|
||||
{}
|
||||
RandomRectangleTopology::~RandomRectangleTopology ()
|
||||
{
|
||||
delete m_xVariable;
|
||||
delete m_yVariable;
|
||||
m_xVariable = 0;
|
||||
m_yVariable = 0;
|
||||
m_positionModel = 0;
|
||||
}
|
||||
|
||||
void
|
||||
RandomRectangleTopology::SetMobilityModelModel (ClassId classId)
|
||||
RandomRectangleTopology::SetMobilityModel (ClassId classId)
|
||||
{
|
||||
m_positionModel = classId;
|
||||
m_mobilityModel = classId;
|
||||
}
|
||||
|
||||
void
|
||||
RandomRectangleTopology::SetPositionModel (Ptr<Random2dPosition> positionModel)
|
||||
{
|
||||
m_positionModel = positionModel;
|
||||
}
|
||||
|
||||
void
|
||||
RandomRectangleTopology::LayoutOne (Ptr<Object> object)
|
||||
{
|
||||
double x = m_xVariable->GetValue ();
|
||||
double y = m_yVariable->GetValue ();
|
||||
object->AddInterface (ComponentManager::Create (m_positionModel, x, y));
|
||||
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;
|
||||
mobility->Set (position);
|
||||
object->AddInterface (mobility);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -21,33 +21,33 @@
|
||||
#ifndef RANDOM_RECTANGLE_TOPOLOGY_H
|
||||
#define RANDOM_RECTANGLE_TOPOLOGY_H
|
||||
|
||||
#include "ns3/random-variable.h"
|
||||
#include "ns3/ptr.h"
|
||||
#include "ns3/object.h"
|
||||
#include "ns3/component-manager.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
class Random2dPosition;
|
||||
|
||||
class RandomRectangleTopology
|
||||
{
|
||||
public:
|
||||
|
||||
RandomRectangleTopology ();
|
||||
RandomRectangleTopology (double xMin, double xMax, double yMin, double yMax);
|
||||
RandomRectangleTopology (const RandomVariable &xVariable, const RandomVariable &yVariable);
|
||||
RandomRectangleTopology (Ptr<Random2dPosition> positionModel,
|
||||
ClassId mobilityModel);
|
||||
|
||||
~RandomRectangleTopology ();
|
||||
|
||||
void SetMobilityModelModel (ClassId classId);
|
||||
void SetMobilityModel (ClassId classId);
|
||||
void SetPositionModel (Ptr<Random2dPosition> positionModel);
|
||||
|
||||
void LayoutOne (Ptr<Object> object);
|
||||
|
||||
template <typename T>
|
||||
void Layout (const T &begin, const T &end);
|
||||
private:
|
||||
RandomVariable *m_xVariable;
|
||||
RandomVariable *m_yVariable;
|
||||
ClassId m_positionModel;
|
||||
Ptr<Random2dPosition> m_positionModel;
|
||||
ClassId m_mobilityModel;
|
||||
};
|
||||
|
||||
} // namespace ns3
|
||||
|
||||
Reference in New Issue
Block a user