A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
random-walk-2d-mobility-model.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2006,2007 INRIA
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
7 */
8#ifndef RANDOM_WALK_2D_MOBILITY_MODEL_H
9#define RANDOM_WALK_2D_MOBILITY_MODEL_H
10
12#include "mobility-model.h"
13#include "rectangle.h"
14
15#include "ns3/event-id.h"
16#include "ns3/nstime.h"
17#include "ns3/object.h"
18#include "ns3/random-variable-stream.h"
19
20namespace ns3
21{
22
23/**
24 * @ingroup mobility
25 * @brief 2D random walk mobility model.
26 *
27 * Each instance moves with a speed and direction chosen at random
28 * with the user-provided random variables until
29 * either a fixed distance has been walked or until a fixed amount
30 * of time. If we hit one of the boundaries (specified by a rectangle),
31 * of the model, we rebound on the boundary with a reflexive angle
32 * and speed. This model is often identified as a brownian motion
33 * model.
34 *
35 * The Direction random variable is used for any point strictly
36 * inside the boundaries. The points on the boundary have their
37 * direction chosen randomly, without considering the Direction
38 * Attribute.
39 */
41{
42 public:
43 /**
44 * Register this type with the TypeId system.
45 * @return the object TypeId
46 */
47 static TypeId GetTypeId();
48
50
51 // Inherited from MobilityModel
52 Ptr<MobilityModel> Copy() const override
53 {
55 }
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 * Walk according to position and velocity, until distance is reached,
72 * time is reached, or intersection with the bounding box
73 * @param timeLeft The remaining time of the walk
74 */
75 void DoWalk(Time timeLeft);
76 /**
77 * Draw a new random velocity and distance to travel, and call DoWalk()
78 */
80 void DoDispose() override;
81 void DoInitialize() override;
82 Vector DoGetPosition() const override;
83 void DoSetPosition(const Vector& position) override;
84 Vector DoGetVelocity() const override;
85 int64_t DoAssignStreams(int64_t) override;
86
87 ConstantVelocityHelper m_helper; //!< helper for this object
88 EventId m_event; //!< stored event ID
89 Mode m_mode; //!< whether in time or distance mode
90 double m_modeDistance; //!< Change direction and speed after this distance
91 Time m_modeTime; //!< Change current direction and speed after this delay
92 Ptr<RandomVariableStream> m_speed; //!< rv for picking speed
93 Ptr<RandomVariableStream> m_direction; //!< rv for picking direction
94 Rectangle m_bounds; //!< Bounds of the area to cruise
95};
96
97} // namespace ns3
98
99#endif /* RANDOM_WALK_2D_MOBILITY_MODEL_H */
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
Ptr< MobilityModel > Copy() const override
Copy function allows one to copy the underlying MobilityModel from a MobilityModel pointer,...
Ptr< RandomVariableStream > m_speed
rv for picking speed
static TypeId GetTypeId()
Register this type with the TypeId system.
void DoInitialize() override
Initialize() implementation.
double m_modeDistance
Change direction and speed after this distance.
void DrawRandomVelocityAndDistance()
Draw a new random velocity and distance to travel, and call DoWalk()
void DoWalk(Time timeLeft)
Walk according to position and velocity, until distance is reached, time is reached,...
Mode
An enum representing the different working modes of this module.
void Rebound(Time timeLeft)
Performs the rebound of the node if it reaches a boundary.
ConstantVelocityHelper m_helper
helper for this object
Time m_modeTime
Change current direction and speed after this delay.
Rectangle m_bounds
Bounds of the area to cruise.
void DoSetPosition(const Vector &position) override
void DoDispose() override
Destructor implementation.
Ptr< RandomVariableStream > m_direction
rv for picking direction
int64_t DoAssignStreams(int64_t) override
The default implementation does nothing but return the passed-in parameter.
Mode m_mode
whether in time or distance mode
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.