A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
random-walk-2d-outdoor-mobility-model.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2006,2007 INRIA
3 * Copyright (c) 2019 University of Padova
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 * Author: Michele Polese <michele.polese@gmail.com>
20 */
21
22#ifndef RANDOM_WALK_2D_OUTDOOR_MOBILITY_MODEL_H
23#define RANDOM_WALK_2D_OUTDOOR_MOBILITY_MODEL_H
24
25#include "building.h"
26
27#include "ns3/constant-velocity-helper.h"
28#include "ns3/event-id.h"
29#include "ns3/mobility-model.h"
30#include "ns3/nstime.h"
31#include "ns3/object.h"
32#include "ns3/random-variable-stream.h"
33#include "ns3/rectangle.h"
34
35namespace ns3
36{
37
38/**
39 * \ingroup buildings
40 * \ingroup mobility
41 *
42 * \brief 2D random walk mobility model which avoids buildings.
43 *
44 * This class reuses most of the code of RandomWalk2dMobilityModel,
45 * but adds the awareness of buildings objects which are avoided
46 * by moving users.
47 * Each instance moves with a speed and direction chosen at random
48 * with the user-provided random variables until
49 * either a fixed distance has been walked or until a fixed amount
50 * of time. If we hit one of the boundaries (specified by a rectangle)
51 * of the model, we rebound on the boundary with a reflexive angle
52 * and speed. If we hit one of the buildings, we rebound with a random
53 * direction which makes sure that the next step does not enter the building.
54 *
55 * The default values for the random variable that describes the speed is
56 * taken from Figure 1 in the paper:
57 * Henderson, L.F., 1971. The statistics of crowd fluids. nature, 229(5284), p.381.
58 */
60{
61 public:
62 /**
63 * Register this type with the TypeId system.
64 * \return the object TypeId
65 */
66 static TypeId GetTypeId();
67
68 /** An enum representing the different working modes of this module. */
69 enum Mode
70 {
73 };
74
75 private:
76 /**
77 * \brief Performs the rebound of the node if it reaches a boundary
78 * \param timeLeft The remaining time of the walk
79 */
80 void Rebound(Time timeLeft);
81 /**
82 * \brief Avoid a building
83 * \param delayLeft The remaining time of the walk
84 * \param intersectPosition The position at which the building is intersected
85 */
86 void AvoidBuilding(Time delayLeft, Vector intersectPosition);
87 /**
88 * Walk according to position and velocity, until distance is reached,
89 * time is reached, or intersection with the bounding box, or building
90 * \param delayLeft The remaining time of the walk
91 */
92 void DoWalk(Time delayLeft);
93 /**
94 * Perform initialization of the object before MobilityModel::DoInitialize ()
95 */
97 /**
98 * Check if there is a building between two positions (or if the nextPosition is inside a
99 * building). The code is taken from MmWave3gppBuildingsPropagationLossModel from the NYU/UNIPD
100 * ns-3 mmWave module
101 * \param currentPosition The current position of the node
102 * \param nextPosition The position to check
103 * \return a pair with a boolean (true if the line between the two position does not intersect
104 * building), and a pointer which is 0 if the boolean is true, or it points to the building
105 * which is intersected
106 */
107 std::pair<bool, Ptr<Building>> IsLineClearOfBuildings(Vector currentPosition,
108 Vector nextPosition) const;
109 /**
110 * Compute the intersecting point of the box represented by boundaries and the line between
111 * current and next. Notice that we only consider a 2d plane.
112 * \param current The current position
113 * \param next The next position
114 * \param boundaries The boundaries of the building we will intersect
115 * \return a vector with the position of the intersection
116 */
117 Vector CalculateIntersectionFromOutside(const Vector& current,
118 const Vector& next,
119 const Box boundaries) const;
120
121 void DoDispose() override;
122 void DoInitialize() override;
123 Vector DoGetPosition() const override;
124 void DoSetPosition(const Vector& position) override;
125 Vector DoGetVelocity() const override;
126 int64_t DoAssignStreams(int64_t) override;
127
128 ConstantVelocityHelper m_helper; //!< helper for this object
129 EventId m_event; //!< stored event ID
130 Mode m_mode; //!< whether in time or distance mode
131 double m_modeDistance; //!< Change direction and speed after this distance
132 Time m_modeTime; //!< Change current direction and speed after this delay
133 Ptr<RandomVariableStream> m_speed; //!< rv for picking speed
134 Ptr<RandomVariableStream> m_direction; //!< rv for picking direction
135 Rectangle m_bounds; //!< Bounds of the area to cruise
136 double m_epsilon; //!< Tolerance for the intersection point with buildings
137 uint32_t m_maxIter; //!< Maximum number of tries to find the next position
138 Vector m_prevPosition; //!< Store the previous position in case a step back is needed
139};
140
141} // namespace ns3
142
143#endif /* RANDOM_WALK_2D_OUTDOOR_MOBILITY_MODEL_H */
a 3d box
Definition: box.h:35
Utility class used to move node with constant velocity.
An identifier for simulation events.
Definition: event-id.h:55
Keep track of the current position and velocity of an object.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
2D random walk mobility model which avoids buildings.
void AvoidBuilding(Time delayLeft, Vector intersectPosition)
Avoid a building.
void DoInitializePrivate()
Perform initialization of the object before MobilityModel::DoInitialize ()
int64_t DoAssignStreams(int64_t) override
The default implementation does nothing but return the passed-in parameter.
double m_modeDistance
Change direction and speed after this distance.
ConstantVelocityHelper m_helper
helper for this object
Mode
An enum representing the different working modes of this module.
Vector m_prevPosition
Store the previous position in case a step back is needed.
void Rebound(Time timeLeft)
Performs the rebound of the node if it reaches a boundary.
uint32_t m_maxIter
Maximum number of tries to find the next position.
Vector CalculateIntersectionFromOutside(const Vector &current, const Vector &next, const Box boundaries) const
Compute the intersecting point of the box represented by boundaries and the line between current and ...
Ptr< RandomVariableStream > m_direction
rv for picking direction
void DoDispose() override
Destructor implementation.
double m_epsilon
Tolerance for the intersection point with buildings.
void DoWalk(Time delayLeft)
Walk according to position and velocity, until distance is reached, time is reached,...
std::pair< bool, Ptr< Building > > IsLineClearOfBuildings(Vector currentPosition, Vector nextPosition) const
Check if there is a building between two positions (or if the nextPosition is inside a building).
static TypeId GetTypeId()
Register this type with the TypeId system.
void DoInitialize() override
Initialize() implementation.
Time m_modeTime
Change current direction and speed after this delay.
Ptr< RandomVariableStream > m_speed
rv for picking speed
a 2d rectangle
Definition: rectangle.h:35
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
a unique identifier for an interface.
Definition: type-id.h:59
Every class exported by the ns3 library is enclosed in the ns3 namespace.