A Discrete-Event Network Simulator
API
random-waypoint-mobility-model.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2007 INRIA
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19  */
20 #include <cmath>
21 #include "ns3/simulator.h"
22 #include "ns3/random-variable-stream.h"
23 #include "ns3/pointer.h"
24 #include "ns3/string.h"
26 #include "position-allocator.h"
27 
28 namespace ns3 {
29 
30 NS_OBJECT_ENSURE_REGISTERED (RandomWaypointMobilityModel);
31 
32 TypeId
34 {
35  static TypeId tid = TypeId ("ns3::RandomWaypointMobilityModel")
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]"),
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]"),
48  MakePointerChecker<RandomVariableStream> ())
49  .AddAttribute ("PositionAllocator",
50  "The position model used to pick a destination point.",
51  PointerValue (),
53  MakePointerChecker<PositionAllocator> ());
54 
55  return tid;
56 }
57 
58 void
60 {
61  m_helper.Update ();
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 ();
65  double speed = m_speed->GetValue ();
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);
70 
71  m_helper.SetVelocity (Vector (k*dx, k*dy, k*dz));
72  m_helper.Unpause ();
73  Time travelDelay = Seconds (CalculateDistance (destination, m_current) / speed);
74  m_event.Cancel ();
75  m_event = Simulator::Schedule (travelDelay,
78 }
79 
80 void
82 {
85 }
86 
87 void
89 {
90  m_helper.Update ();
91  m_helper.Pause ();
92  Time pause = Seconds (m_pause->GetValue ());
95 }
96 
97 Vector
99 {
100  m_helper.Update ();
101  return m_helper.GetCurrentPosition ();
102 }
103 void
105 {
106  m_helper.SetPosition (position);
107  m_event.Cancel ();
109 }
110 Vector
112 {
113  return m_helper.GetVelocity ();
114 }
115 int64_t
117 {
118  int64_t positionStreamsAllocated;
119  m_speed->SetStream (stream);
120  m_pause->SetStream (stream + 1);
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);
124 }
125 
126 
127 } // namespace ns3
ns3::TypeId
a unique identifier for an interface.
Definition: type-id.h:59
ns3::ConstantVelocityHelper::SetVelocity
void SetVelocity(const Vector &vel)
Set new velocity vector.
Definition: constant-velocity-helper.cc:72
NS_OBJECT_ENSURE_REGISTERED
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
position-allocator.h
ns3::RandomWaypointMobilityModel::DoSetPosition
virtual void DoSetPosition(const Vector &position)
Definition: random-waypoint-mobility-model.cc:104
ns3::MobilityModel::NotifyCourseChange
void NotifyCourseChange(void) const
Must be invoked by subclasses when the course of the position changes to notify course change listene...
Definition: mobility-model.cc:108
ns3::PointerValue
Hold objects of type Ptr<T>.
Definition: pointer.h:37
ns3::RandomWaypointMobilityModel::m_helper
ConstantVelocityHelper m_helper
helper for velocity computations
Definition: random-waypoint-mobility-model.h:76
ns3::RandomWaypointMobilityModel
Random waypoint mobility model.
Definition: random-waypoint-mobility-model.h:53
ns3::Simulator::Schedule
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:557
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:923
ns3::RandomWaypointMobilityModel::DoInitializePrivate
void DoInitializePrivate(void)
Begin current pause event, schedule future walk event.
Definition: random-waypoint-mobility-model.cc:88
bianchi11ax.k
int k
Definition: bianchi11ax.py:129
ns3::ConstantVelocityHelper::GetCurrentPosition
Vector GetCurrentPosition(void) const
Get current position vector.
Definition: constant-velocity-helper.cc:59
ns3::RandomWaypointMobilityModel::m_position
Ptr< PositionAllocator > m_position
pointer to position allocator
Definition: random-waypoint-mobility-model.h:77
ns3::EventId::Cancel
void Cancel(void)
This method is syntactic sugar for the ns3::Simulator::Cancel method.
Definition: event-id.cc:53
ns3::CalculateDistance
double CalculateDistance(const Vector3D &a, const Vector3D &b)
Definition: vector.cc:105
ns3::Time
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:104
ns3::ConstantVelocityHelper::Unpause
void Unpause(void)
Resume mobility from current position at current velocity.
Definition: constant-velocity-helper.cc:129
NS_ASSERT_MSG
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition: assert.h:88
ns3::Object::DoInitialize
virtual void DoInitialize(void)
Initialize() implementation.
Definition: object.cc:353
ns3::RandomWaypointMobilityModel::m_event
EventId m_event
event ID of next scheduled event
Definition: random-waypoint-mobility-model.h:80
ns3::MakePointerAccessor
Ptr< const AttributeAccessor > MakePointerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition: pointer.h:227
ns3::StringValue
Hold variables of type string.
Definition: string.h:41
ns3::RandomWaypointMobilityModel::m_pause
Ptr< RandomVariableStream > m_pause
random variable to generate pauses
Definition: random-waypoint-mobility-model.h:79
ns3::RandomWaypointMobilityModel::DoInitialize
virtual void DoInitialize(void)
Initialize() implementation.
Definition: random-waypoint-mobility-model.cc:81
random-waypoint-mobility-model.h
ns3::RandomWaypointMobilityModel::GetTypeId
static TypeId GetTypeId(void)
Register this type with the TypeId system.
Definition: random-waypoint-mobility-model.cc:33
ns3::RandomVariableStream::GetValue
virtual double GetValue(void)=0
Get the next random value as a double drawn from the distribution.
ns3::Seconds
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1289
ns3::ConstantVelocityHelper::Update
void Update(void) const
Update position, if not paused, from last position and time of last update.
Definition: constant-velocity-helper.cc:80
ns3::ConstantVelocityHelper::SetPosition
void SetPosition(const Vector &position)
Set position vector.
Definition: constant-velocity-helper.cc:50
ns3::MobilityModel
Keep track of the current position and velocity of an object.
Definition: mobility-model.h:40
ns3::RandomWaypointMobilityModel::BeginWalk
void BeginWalk(void)
Get next position, begin moving towards it, schedule future pause event.
Definition: random-waypoint-mobility-model.cc:59
ns3::RandomWaypointMobilityModel::m_speed
Ptr< RandomVariableStream > m_speed
random variable to generate speeds
Definition: random-waypoint-mobility-model.h:78
ns3::RandomVariableStream::SetStream
void SetStream(int64_t stream)
Specifies the stream number for the RngStream.
Definition: random-variable-stream.cc:100
ns3::RandomWaypointMobilityModel::DoAssignStreams
virtual int64_t DoAssignStreams(int64_t)
The default implementation does nothing but return the passed-in parameter.
Definition: random-waypoint-mobility-model.cc:116
ns3::RandomWaypointMobilityModel::DoGetPosition
virtual Vector DoGetPosition(void) const
Definition: random-waypoint-mobility-model.cc:98
ns3::ConstantVelocityHelper::Pause
void Pause(void)
Pause mobility at current position.
Definition: constant-velocity-helper.cc:122
ns3::RandomWaypointMobilityModel::DoGetVelocity
virtual Vector DoGetVelocity(void) const
Definition: random-waypoint-mobility-model.cc:111
ns3::Simulator::ScheduleNow
static EventId ScheduleNow(FUNC f, Ts &&... args)
Schedule an event to expire Now.
Definition: simulator.h:588
ns3::ConstantVelocityHelper::GetVelocity
Vector GetVelocity(void) const
Get velocity; if paused, will return a zero vector.
Definition: constant-velocity-helper.cc:66