21 #include "ns3/simulator.h"
22 #include "ns3/random-variable-stream.h"
23 #include "ns3/pointer.h"
24 #include "ns3/string.h"
25 #include "random-waypoint-mobility-model.h"
26 #include "position-allocator.h"
30 NS_OBJECT_ENSURE_REGISTERED (RandomWaypointMobilityModel);
33 RandomWaypointMobilityModel::GetTypeId (
void)
35 static TypeId tid = TypeId (
"ns3::RandomWaypointMobilityModel")
36 .SetParent<MobilityModel> ()
37 .SetGroupName (
"Mobility")
38 .AddConstructor<RandomWaypointMobilityModel> ()
39 .AddAttribute (
"Speed",
40 "A random variable used to pick the speed of a random waypoint model.",
41 StringValue (
"ns3::UniformRandomVariable[Min=0.3|Max=0.7]"),
42 MakePointerAccessor (&RandomWaypointMobilityModel::m_speed),
43 MakePointerChecker<RandomVariableStream> ())
44 .AddAttribute (
"Pause",
45 "A random variable used to pick the pause of a random waypoint model.",
46 StringValue (
"ns3::ConstantRandomVariable[Constant=2.0]"),
47 MakePointerAccessor (&RandomWaypointMobilityModel::m_pause),
48 MakePointerChecker<RandomVariableStream> ())
49 .AddAttribute (
"PositionAllocator",
50 "The position model used to pick a destination point.",
52 MakePointerAccessor (&RandomWaypointMobilityModel::m_position),
53 MakePointerChecker<PositionAllocator> ());
59 RandomWaypointMobilityModel::BeginWalk (
void)
62 Vector m_current = m_helper.GetCurrentPosition ();
63 NS_ASSERT_MSG (m_position,
"No position allocator added before using this model");
64 Vector destination = m_position->GetNext ();
66 double dx = (destination.x - m_current.x);
67 double dy = (destination.y - m_current.y);
68 double dz = (destination.z - m_current.z);
69 double k = speed / std::sqrt (dx*dx + dy*dy + dz*dz);
71 m_helper.SetVelocity (Vector (k*dx, k*dy, k*dz));
76 &RandomWaypointMobilityModel::DoInitializePrivate,
this);
83 DoInitializePrivate ();
88 RandomWaypointMobilityModel::DoInitializePrivate (
void)
101 return m_helper.GetCurrentPosition ();
106 m_helper.SetPosition (position);
113 return m_helper.GetVelocity ();
118 int64_t positionStreamsAllocated;
121 NS_ASSERT_MSG (m_position,
"No position allocator added before using this model");
122 positionStreamsAllocated = m_position->AssignStreams (stream + 2);
123 return (2 + positionStreamsAllocated);
void SetStream(int64_t stream)
Specifies the stream number for this RNG stream.
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
virtual double GetValue(void)=0
Returns a random double from the underlying distribution.
double CalculateDistance(const Vector3D &a, const Vector3D &b)
virtual Vector DoGetVelocity(void) const
void NotifyCourseChange(void) const
static void Remove(const EventId &id)
static EventId ScheduleNow(MEM mem_ptr, OBJ obj)
virtual void DoSetPosition(const Vector &position)
#define NS_ASSERT_MSG(condition, message)
virtual void DoInitialize(void)
virtual int64_t DoAssignStreams(int64_t)
Time Seconds(double seconds)
create ns3::Time instances in units of seconds.
virtual Vector DoGetPosition(void) const
virtual void DoInitialize(void)