21 #include "ns3/simulator.h"
22 #include "ns3/double.h"
33 static TypeId tid =
TypeId (
"ns3::SteadyStateRandomWaypointMobilityModel")
35 .SetGroupName (
"Mobility")
37 .AddAttribute (
"MinSpeed",
38 "Minimum speed value, [m/s]",
41 MakeDoubleChecker<double> ())
42 .AddAttribute (
"MaxSpeed",
43 "Maximum speed value, [m/s]",
46 MakeDoubleChecker<double> ())
47 .AddAttribute (
"MinPause",
48 "Minimum pause value, [s]",
51 MakeDoubleChecker<double> ())
52 .AddAttribute (
"MaxPause",
53 "Maximum pause value, [s]",
56 MakeDoubleChecker<double> ())
57 .AddAttribute (
"MinX",
58 "Minimum X value of traveling region, [m]",
61 MakeDoubleChecker<double> ())
62 .AddAttribute (
"MaxX",
63 "Maximum X value of traveling region, [m]",
66 MakeDoubleChecker<double> ())
67 .AddAttribute (
"MinY",
68 "Minimum Y value of traveling region, [m]",
71 MakeDoubleChecker<double> ())
72 .AddAttribute (
"MaxY",
73 "Maximum Y value of traveling region, [m]",
76 MakeDoubleChecker<double> ())
78 "Z value of traveling region (fixed), [m]",
81 MakeDoubleChecker<double> ());
87 alreadyStarted (false)
89 m_speed = CreateObject<UniformRandomVariable> ();
90 m_pause = CreateObject<UniformRandomVariable> ();
91 m_x1_r = CreateObject<UniformRandomVariable> ();
92 m_y1_r = CreateObject<UniformRandomVariable> ();
93 m_x2_r = CreateObject<UniformRandomVariable> ();
94 m_y2_r = CreateObject<UniformRandomVariable> ();
95 m_u_r = CreateObject<UniformRandomVariable> ();
96 m_x = CreateObject<UniformRandomVariable> ();
97 m_y = CreateObject<UniformRandomVariable> ();
98 m_position = CreateObject<RandomBoxPositionAllocator> ();
142 double log1 = b*b / a*std::log (std::sqrt ((a*a)/(b*b) + 1) + a/b);
143 double log2 = a*a / b*std::log (std::sqrt ((b*b)/(a*a) + 1) + b/a);
144 double expectedTravelTime = 1.0/6.0*(log1 + log2);
145 expectedTravelTime += 1.0/15.0*((a*a*a)/(b*b) + (b*b*b)/(a*a)) -
146 1.0/15.0*std::sqrt (a*a + b*b)*((a*a)/(b*b) + (b*b)/(a*a) - 3);
149 expectedTravelTime /= v0;
153 expectedTravelTime *= std::log (v1/v0)/(v1 - v0);
155 double probabilityPaused = expectedPauseTime/(expectedPauseTime + expectedTravelTime);
156 NS_ASSERT (probabilityPaused >= 0 && probabilityPaused <= 1);
159 if (u < probabilityPaused)
179 pause =
Seconds (u*expectedPauseTime);
186 double x1, x2, y1, y2;
187 x1 = x2 = y1 = y2 = 0;
197 r = std::sqrt (((x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1))/(a*a + b*b));
220 double dx = (destination.x - m_current.x);
221 double dy = (destination.y - m_current.y);
222 double dz = (destination.z - m_current.z);
223 double k = speed / std::sqrt (dx*dx + dy*dy + dz*dz);
242 double dx = (destination.x - m_current.x);
243 double dy = (destination.y - m_current.y);
244 double dz = (destination.z - m_current.z);
245 double k = speed / std::sqrt (dx*dx + dy*dy + dz*dz);
289 int64_t positionStreamsAllocated = 0;
299 positionStreamsAllocated =
m_position->AssignStreams (stream + 9);
300 return (9 + positionStreamsAllocated);
void Unpause(void)
Resume mobility from current position at current velocity.
Vector GetVelocity(void) const
Get velocity; if paused, will return a zero vector.
void SetPosition(const Vector &position)
Set position vector.
void Pause(void)
Pause mobility at current position.
void SetVelocity(const Vector &vel)
Set new velocity vector.
void Update(void) const
Update position, if not paused, from last position and time of last update.
Vector GetCurrentPosition(void) const
Get current position vector.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
bool IsRunning(void) const
This method is syntactic sugar for !IsExpired().
void Cancel(void)
This method is syntactic sugar for the ns3::Simulator::Cancel method.
Keep track of the current position and velocity of an object.
void NotifyCourseChange(void) 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(void)
Initialize() implementation.
void SetStream(int64_t stream)
Specifies the stream number for the RngStream.
static EventId Schedule(Time const &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
static TypeId GetTypeId(void)
Register this type with the TypeId system.
double m_maxSpeed
maximum speed value (m/s)
double m_minPause
minimum pause value (s)
virtual void DoSetPosition(const Vector &position)
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.
Ptr< UniformRandomVariable > m_y
rv used for position allocator
virtual Vector DoGetVelocity(void) const
void DoInitializePrivate(void)
Configure random variables based on attributes; calculate the steady state probability that node is i...
Ptr< UniformRandomVariable > m_speed
random variable for speed values
void BeginWalk(void)
Start a motion period and schedule the ending of the motion.
double m_z
z value of traveling region
double m_maxX
maximum x value of traveling region (m)
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
virtual void DoInitialize(void)
Initialize() implementation.
double m_minY
minimum y value of traveling region (m)
virtual Vector DoGetPosition(void) const
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
virtual int64_t DoAssignStreams(int64_t)
The default implementation does nothing but return the passed-in parameter.
double m_maxY
maximum y value of traveling region (m)
Ptr< RandomBoxPositionAllocator > m_position
position allocator
void Start(void)
Start a pause period and schedule the ending of the pause.
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,...
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
#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.
double CalculateDistance(const Vector3D &a, const Vector3D &b)