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;
196 r = std::sqrt (((x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1))/(a*a + b*b));
219 double dx = (destination.x - m_current.x);
220 double dy = (destination.y - m_current.y);
221 double dz = (destination.z - m_current.z);
222 double k = speed / std::sqrt (dx*dx + dy*dy + dz*dz);
241 double dx = (destination.x - m_current.x);
242 double dy = (destination.y - m_current.y);
243 double dz = (destination.z - m_current.z);
244 double k = speed / std::sqrt (dx*dx + dy*dy + dz*dz);
288 int64_t positionStreamsAllocated = 0;
298 positionStreamsAllocated =
m_position->AssignStreams (stream + 9);
299 return (9 + positionStreamsAllocated);
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
virtual void DoInitialize(void)
Initialize() implementation.
virtual void DoInitialize(void)
Initialize() implementation.
Simulation virtual time values and global simulation resolution.
void SetStream(int64_t stream)
Specifies the stream number for the RngStream.
double m_maxX
maximum x value of traveling region (m)
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
virtual Vector DoGetVelocity(void) const
Vector GetCurrentPosition(void) const
Get current position vector.
Ptr< UniformRandomVariable > m_speed
random variable for speed values
Ptr< UniformRandomVariable > m_pause
random variable for pause values
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Ptr< UniformRandomVariable > m_x1_r
rv used in rejection sampling phase
SteadyStateRandomWaypointMobilityModel()
Ptr< UniformRandomVariable > m_u_r
rv used in step 5 of algorithm
EventId m_event
current event ID
Ptr< UniformRandomVariable > m_x2_r
rv used in rejection sampling phase
ConstantVelocityHelper m_helper
helper for velocity computations
void SteadyStateBeginWalk(const Vector &destination)
Use provided destination to calculate travel delay, and schedule a Start() event at that time...
Keep track of the current position and velocity of an object.
void Update(void) const
Update position, if not paused, from last position and time of last update.
static EventId ScheduleNow(FUNC f, Ts &&... args)
Schedule an event to expire Now.
Ptr< UniformRandomVariable > m_y2_r
rv used in rejection sampling phase
double CalculateDistance(const Vector3D &a, const Vector3D &b)
double m_minX
minimum x value of traveling region (m)
void Start(void)
Start a pause period and schedule the ending of the pause.
double m_minY
minimum y value of traveling region (m)
virtual void DoSetPosition(const Vector &position)
Steady-state random waypoint mobility model.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
double m_maxPause
maximum pause value (s)
void SetVelocity(const Vector &vel)
Set new velocity vector.
double m_minSpeed
minimum speed value (m/s)
void NotifyCourseChange(void) const
Must be invoked by subclasses when the course of the position changes to notify course change listene...
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
double m_maxY
maximum y value of traveling region (m)
double m_z
z value of traveling region
bool alreadyStarted
flag for starting state
Ptr< UniformRandomVariable > m_y1_r
rv used in rejection sampling phase
Ptr< UniformRandomVariable > m_y
rv used for position allocator
Time Seconds(double value)
Construct a Time in the indicated unit.
bool IsRunning(void) const
This method is syntactic sugar for !IsExpired().
Vector GetVelocity(void) const
Get velocity; if paused, will return a zero vector.
void Cancel(void)
This method is syntactic sugar for the ns3::Simulator::Cancel method.
void Unpause(void)
Resume mobility from current position at current velocity.
Ptr< RandomBoxPositionAllocator > m_position
position allocator
virtual int64_t DoAssignStreams(int64_t)
The default implementation does nothing but return the passed-in parameter.
void BeginWalk(void)
Start a motion period and schedule the ending of the motion.
static TypeId GetTypeId(void)
Register this type with the TypeId system.
double m_maxSpeed
maximum speed value (m/s)
void SetPosition(const Vector &position)
Set position vector.
double m_minPause
minimum pause value (s)
This class can be used to hold variables of floating point type such as 'double' or 'float'...
void SetAttribute(std::string name, const AttributeValue &value)
Set a single attribute, raising fatal errors if unsuccessful.
a unique identifier for an interface.
void Pause(void)
Pause mobility at current position.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
virtual Vector DoGetPosition(void) const
Ptr< UniformRandomVariable > m_x
rv used for position allocator
void DoInitializePrivate(void)
Configure random variables based on attributes; calculate the steady state probability that node is i...