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 // Inherited from MobilityModel
65 Ptr<MobilityModel> Copy() const override
66 {
68 }
69
70 private:
71 /**
72 * @brief Performs the rebound of the node if it reaches a boundary
73 * @param timeLeft The remaining time of the walk
74 */
75 void Rebound(Time timeLeft);
76 /**
77 * @brief Avoid a building
78 * @param delayLeft The remaining time of the walk
79 * @param intersectPosition The position at which the building is intersected
80 */
81 void AvoidBuilding(Time delayLeft, Vector intersectPosition);
82 /**
83 * Walk according to position and velocity, until distance is reached,
84 * time is reached, or intersection with the bounding box, or building
85 * @param delayLeft The remaining time of the walk
86 */
87 void DoWalk(Time delayLeft);
88 /**
89 * Perform initialization of the object before MobilityModel::DoInitialize ()
90 */
92 /**
93 * Check if there is a building between two positions (or if the nextPosition is inside a
94 * building). The code is taken from MmWave3gppBuildingsPropagationLossModel from the NYU/UNIPD
95 * ns-3 mmWave module
96 * @param currentPosition The current position of the node
97 * @param nextPosition The position to check
98 * @return a pair with a boolean (true if the line between the two position does not intersect
99 * building), and a pointer which is 0 if the boolean is true, or it points to the building
100 * which is intersected
101 */
102 std::pair<bool, Ptr<Building>> IsLineClearOfBuildings(Vector currentPosition,
103 Vector nextPosition) const;
104 /**
105 * Compute the intersecting point of the box represented by boundaries and the line between
106 * current and next. Notice that we only consider a 2d plane.
107 * @param current The current position
108 * @param next The next position
109 * @param boundaries The boundaries of the building we will intersect
110 * @return a vector with the position of the intersection
111 */
112 Vector CalculateIntersectionFromOutside(const Vector& current,
113 const Vector& next,
114 const Box boundaries) const;
115
116 void DoDispose() override;
117 void DoInitialize() override;
118 Vector DoGetPosition() const override;
119 void DoSetPosition(const Vector& position) override;
120 Vector DoGetVelocity() const override;
121 int64_t DoAssignStreams(int64_t) override;
122
123 ConstantVelocityHelper m_helper; //!< helper for this object
124 EventId m_event; //!< stored event ID
125 Mode m_mode; //!< whether in time or distance mode
126 double m_modeDistance; //!< Change direction and speed after this distance
127 Time m_modeTime; //!< Change current direction and speed after this delay
128 Ptr<RandomVariableStream> m_speed; //!< rv for picking speed
129 Ptr<RandomVariableStream> m_direction; //!< rv for picking direction
130 Rectangle m_bounds; //!< Bounds of the area to cruise
131 double m_epsilon; //!< Tolerance for the intersection point with buildings
132 uint32_t m_maxIter; //!< Maximum number of tries to find the next position
133 Vector m_prevPosition; //!< Store the previous position in case a step back is needed
134};
135
136} // namespace ns3
137
138#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:44
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:67
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.
Ptr< MobilityModel > Copy() const override
Copy function allows one to copy the underlying MobilityModel from a MobilityModel pointer,...
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:96
a unique identifier for an interface.
Definition type-id.h:49
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
Every class exported by the ns3 library is enclosed in the ns3 namespace.