21 #include "ns3/simulator.h"
22 #include "ns3/double.h"
23 #include "ns3/pointer.h"
24 #include "ns3/string.h"
25 #include "gauss-markov-mobility-model.h"
26 #include "position-allocator.h"
30 NS_OBJECT_ENSURE_REGISTERED (GaussMarkovMobilityModel);
33 GaussMarkovMobilityModel::GetTypeId (
void)
35 static TypeId tid = TypeId (
"ns3::GaussMarkovMobilityModel")
36 .SetParent<MobilityModel> ()
37 .SetGroupName (
"Mobility")
38 .AddConstructor<GaussMarkovMobilityModel> ()
39 .AddAttribute (
"Bounds",
40 "Bounds of the area to cruise.",
41 BoxValue (Box (-100.0, 100.0, -100.0, 100.0, 0.0, 100.0)),
42 MakeBoxAccessor (&GaussMarkovMobilityModel::m_bounds),
44 .AddAttribute (
"TimeStep",
45 "Change current direction and speed after moving for this time.",
47 MakeTimeAccessor (&GaussMarkovMobilityModel::m_timeStep),
49 .AddAttribute (
"Alpha",
50 "A constant representing the tunable parameter in the Gauss-Markov model.",
52 MakeDoubleAccessor (&GaussMarkovMobilityModel::m_alpha),
53 MakeDoubleChecker<double> ())
54 .AddAttribute (
"MeanVelocity",
55 "A random variable used to assign the average velocity.",
56 StringValue (
"ns3::UniformRandomVariable[Min=0.0|Max=1.0]"),
57 MakePointerAccessor (&GaussMarkovMobilityModel::m_rndMeanVelocity),
58 MakePointerChecker<RandomVariableStream> ())
59 .AddAttribute (
"MeanDirection",
60 "A random variable used to assign the average direction.",
61 StringValue (
"ns3::UniformRandomVariable[Min=0.0|Max=6.283185307]"),
62 MakePointerAccessor (&GaussMarkovMobilityModel::m_rndMeanDirection),
63 MakePointerChecker<RandomVariableStream> ())
64 .AddAttribute (
"MeanPitch",
65 "A random variable used to assign the average pitch.",
66 StringValue (
"ns3::ConstantRandomVariable[Constant=0.0]"),
67 MakePointerAccessor (&GaussMarkovMobilityModel::m_rndMeanPitch),
68 MakePointerChecker<RandomVariableStream> ())
69 .AddAttribute (
"NormalVelocity",
70 "A gaussian random variable used to calculate the next velocity value.",
71 StringValue (
"ns3::NormalRandomVariable[Mean=0.0|Variance=1.0|Bound=10.0]"),
72 MakePointerAccessor (&GaussMarkovMobilityModel::m_normalVelocity),
73 MakePointerChecker<NormalRandomVariable> ())
74 .AddAttribute (
"NormalDirection",
75 "A gaussian random variable used to calculate the next direction value.",
76 StringValue (
"ns3::NormalRandomVariable[Mean=0.0|Variance=1.0|Bound=10.0]"),
77 MakePointerAccessor (&GaussMarkovMobilityModel::m_normalDirection),
78 MakePointerChecker<NormalRandomVariable> ())
79 .AddAttribute (
"NormalPitch",
80 "A gaussian random variable used to calculate the next pitch value.",
81 StringValue (
"ns3::NormalRandomVariable[Mean=0.0|Variance=1.0|Bound=10.0]"),
82 MakePointerAccessor (&GaussMarkovMobilityModel::m_normalPitch),
83 MakePointerChecker<NormalRandomVariable> ());
88 GaussMarkovMobilityModel::GaussMarkovMobilityModel ()
91 m_meanDirection = 0.0;
98 GaussMarkovMobilityModel::Start (
void)
100 if (m_meanVelocity == 0.0)
103 m_meanVelocity = m_rndMeanVelocity->
GetValue ();
104 m_meanDirection = m_rndMeanDirection->
GetValue ();
105 m_meanPitch = m_rndMeanPitch->
GetValue ();
106 double cosD = std::cos (m_meanDirection);
107 double cosP = std::cos (m_meanPitch);
108 double sinD = std::sin (m_meanDirection);
109 double sinP = std::sin (m_meanPitch);
111 m_Velocity = m_meanVelocity;
112 m_Direction = m_meanDirection;
113 m_Pitch = m_meanPitch;
115 m_helper.SetVelocity (Vector (m_Velocity*cosD*cosP, m_Velocity*sinD*cosP, m_Velocity*sinP));
120 double rv = m_normalVelocity->GetValue ();
121 double rd = m_normalDirection->GetValue ();
122 double rp = m_normalPitch->GetValue ();
127 double one_minus_alpha = 1 - m_alpha;
128 double sqrt_alpha = std::sqrt (1 - m_alpha*m_alpha);
129 m_Velocity = m_alpha * m_Velocity + one_minus_alpha * m_meanVelocity + sqrt_alpha * rv;
130 m_Direction = m_alpha * m_Direction + one_minus_alpha * m_meanDirection + sqrt_alpha * rd;
131 m_Pitch = m_alpha * m_Pitch + one_minus_alpha * m_meanPitch + sqrt_alpha * rp;
134 double cosDir = std::cos (m_Direction);
135 double cosPit = std::cos (m_Pitch);
136 double sinDir = std::sin (m_Direction);
137 double sinPit = std::sin (m_Pitch);
138 double vx = m_Velocity * cosDir * cosPit;
139 double vy = m_Velocity * sinDir * cosPit;
140 double vz = m_Velocity * sinPit;
141 m_helper.SetVelocity (Vector (vx, vy, vz));
149 GaussMarkovMobilityModel::DoWalk (Time delayLeft)
151 m_helper.UpdateWithBounds (m_bounds);
152 Vector position = m_helper.GetCurrentPosition ();
153 Vector speed = m_helper.GetVelocity ();
154 Vector nextPosition = position;
155 nextPosition.
x += speed.x * delayLeft.GetSeconds ();
156 nextPosition.y += speed.y * delayLeft.GetSeconds ();
157 nextPosition.z += speed.z * delayLeft.GetSeconds ();
158 if (delayLeft.GetSeconds () < 0.0) delayLeft =
Seconds (1.0);
162 if (m_bounds.
IsInside (nextPosition))
168 if (nextPosition.x > m_bounds.xMax || nextPosition.x < m_bounds.xMin)
171 m_meanDirection = 3.14159265 - m_meanDirection;
174 if (nextPosition.y > m_bounds.yMax || nextPosition.y < m_bounds.yMin)
177 m_meanDirection = -m_meanDirection;
180 if (nextPosition.z > m_bounds.zMax || nextPosition.z < m_bounds.zMin)
183 m_meanPitch = -m_meanPitch;
186 m_Direction = m_meanDirection;
187 m_Pitch = m_meanPitch;
188 m_helper.SetVelocity (speed);
206 return m_helper.GetCurrentPosition ();
211 m_helper.SetPosition (position);
218 return m_helper.GetVelocity ();
225 m_normalVelocity->SetStream (stream + 1);
226 m_rndMeanDirection->
SetStream (stream + 2);
227 m_normalDirection->SetStream (stream + 3);
229 m_normalPitch->SetStream (stream + 5);
void SetStream(int64_t stream)
Specifies the stream number for this RNG stream.
virtual void DoDispose(void)
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
virtual double GetValue(void)=0
Returns a random double from the underlying distribution.
virtual int64_t DoAssignStreams(int64_t)
virtual void DoSetPosition(const Vector &position)
virtual Vector DoGetVelocity(void) const
void NotifyCourseChange(void) const
virtual void DoDispose(void)
static void Remove(const EventId &id)
virtual Vector DoGetPosition(void) const
static EventId ScheduleNow(MEM mem_ptr, OBJ obj)
Time Seconds(double seconds)
create ns3::Time instances in units of seconds.
bool IsInside(const Vector &position) const