21 #include "ns3/double.h"
22 #include "ns3/simulator.h"
36 TypeId(
"ns3::SteadyStateRandomWaypointMobilityModel")
38 .SetGroupName(
"Mobility")
40 .AddAttribute(
"MinSpeed",
41 "Minimum speed value, [m/s]",
44 MakeDoubleChecker<double>())
45 .AddAttribute(
"MaxSpeed",
46 "Maximum speed value, [m/s]",
49 MakeDoubleChecker<double>())
50 .AddAttribute(
"MinPause",
51 "Minimum pause value, [s]",
54 MakeDoubleChecker<double>())
55 .AddAttribute(
"MaxPause",
56 "Maximum pause value, [s]",
59 MakeDoubleChecker<double>())
61 "Minimum X value of traveling region, [m]",
64 MakeDoubleChecker<double>())
66 "Maximum X value of traveling region, [m]",
69 MakeDoubleChecker<double>())
71 "Minimum Y value of traveling region, [m]",
74 MakeDoubleChecker<double>())
76 "Maximum Y value of traveling region, [m]",
79 MakeDoubleChecker<double>())
81 "Z value of traveling region (fixed), [m]",
84 MakeDoubleChecker<double>());
90 : alreadyStarted(false)
92 m_speed = CreateObject<UniformRandomVariable>();
93 m_pause = CreateObject<UniformRandomVariable>();
94 m_x1_r = CreateObject<UniformRandomVariable>();
95 m_y1_r = CreateObject<UniformRandomVariable>();
96 m_x2_r = CreateObject<UniformRandomVariable>();
97 m_y2_r = CreateObject<UniformRandomVariable>();
98 m_u_r = CreateObject<UniformRandomVariable>();
99 m_x = CreateObject<UniformRandomVariable>();
100 m_y = CreateObject<UniformRandomVariable>();
101 m_position = CreateObject<RandomBoxPositionAllocator>();
145 double log1 = b * b / a * std::log(std::sqrt((a * a) / (b * b) + 1) + a / b);
146 double log2 = a * a / b * std::log(std::sqrt((b * b) / (a * a) + 1) + b / a);
147 double expectedTravelTime = 1.0 / 6.0 * (log1 + log2);
148 expectedTravelTime +=
149 1.0 / 15.0 * ((a * a * a) / (b * b) + (b * b * b) / (a * a)) -
150 1.0 / 15.0 * std::sqrt(a * a + b * b) * ((a * a) / (b * b) + (b * b) / (a * a) - 3);
153 expectedTravelTime /= v0;
157 expectedTravelTime *= std::log(v1 / v0) / (v1 - v0);
159 double probabilityPaused = expectedPauseTime / (expectedPauseTime + expectedTravelTime);
160 NS_ASSERT(probabilityPaused >= 0 && probabilityPaused <= 1);
163 if (u < probabilityPaused)
184 pause =
Seconds(u * expectedPauseTime);
196 x1 = x2 = y1 = y2 = 0;
206 r = std::sqrt(((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)) / (a * a + b * b));
211 Vector(
m_minX + u2 * x1 + (1 - u2) * x2,
m_minY + u2 * y1 + (1 - u2) * y2,
m_z));
232 double dx = (destination.x - m_current.x);
233 double dy = (destination.y - m_current.y);
234 double dz = (destination.z - m_current.z);
235 double k = speed / std::sqrt(dx * dx + dy * dy + dz * dz);
254 double dx = (destination.x - m_current.x);
255 double dy = (destination.y - m_current.y);
256 double dz = (destination.z - m_current.z);
257 double k = speed / std::sqrt(dx * dx + dy * dy + dz * dz);
304 int64_t positionStreamsAllocated = 0;
314 positionStreamsAllocated =
m_position->AssignStreams(stream + 9);
315 return (9 + positionStreamsAllocated);
Vector GetCurrentPosition() const
Get current position vector.
Vector GetVelocity() const
Get velocity; if paused, will return a zero vector.
void Update() const
Update position, if not paused, from last position and time of last update.
void Unpause()
Resume mobility from current position at current velocity.
void SetPosition(const Vector &position)
Set position vector.
void SetVelocity(const Vector &vel)
Set new velocity vector.
void Pause()
Pause mobility at current position.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
void Cancel()
This method is syntactic sugar for the ns3::Simulator::Cancel method.
bool IsRunning() const
This method is syntactic sugar for !IsExpired().
Keep track of the current position and velocity of an object.
void NotifyCourseChange() const
Must be invoked by subclasses when the course of the position changes to notify course change listene...
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
virtual void DoInitialize()
Initialize() implementation.
void SetStream(int64_t stream)
Specifies the stream number for the RngStream.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
static EventId ScheduleNow(FUNC f, Ts &&... args)
Schedule an event to expire Now.
Steady-state random waypoint mobility model.
Ptr< UniformRandomVariable > m_u_r
rv used in step 5 of algorithm
void DoSetPosition(const Vector &position) override
int64_t DoAssignStreams(int64_t) override
The default implementation does nothing but return the passed-in parameter.
void DoInitialize() override
Initialize() implementation.
double m_maxSpeed
maximum speed value (m/s)
double m_minPause
minimum pause value (s)
double m_minX
minimum x value of traveling region (m)
Ptr< UniformRandomVariable > m_y2_r
rv used in rejection sampling phase
Ptr< UniformRandomVariable > m_pause
random variable for pause values
Ptr< UniformRandomVariable > m_x2_r
rv used in rejection sampling phase
void SteadyStateBeginWalk(const Vector &destination)
Use provided destination to calculate travel delay, and schedule a Start() event at that time.
Vector DoGetVelocity() const override
Ptr< UniformRandomVariable > m_y
rv used for position allocator
Ptr< UniformRandomVariable > m_speed
random variable for speed values
double m_z
z value of traveling region
double m_maxX
maximum x value of traveling region (m)
Vector DoGetPosition() const override
static TypeId GetTypeId()
Register this type with the TypeId system.
double m_maxPause
maximum pause value (s)
double m_minSpeed
minimum speed value (m/s)
Ptr< UniformRandomVariable > m_x1_r
rv used in rejection sampling phase
void DoInitializePrivate()
Configure random variables based on attributes; calculate the steady state probability that node is i...
void BeginWalk()
Start a motion period and schedule the ending of the motion.
double m_minY
minimum y value of traveling region (m)
void Start()
Start a pause period and schedule the ending of the pause.
Ptr< UniformRandomVariable > m_x
rv used for position allocator
SteadyStateRandomWaypointMobilityModel()
ConstantVelocityHelper m_helper
helper for velocity computations
Ptr< UniformRandomVariable > m_y1_r
rv used in rejection sampling phase
bool alreadyStarted
flag for starting state
EventId m_event
current event ID
double m_maxY
maximum y value of traveling region (m)
Ptr< RandomBoxPositionAllocator > m_position
position allocator
Simulation virtual time values and global simulation resolution.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Time Seconds(double value)
Construct a Time in the indicated unit.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
double CalculateDistance(const Vector3D &a, const Vector3D &b)