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