A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
steady-state-random-waypoint-mobility-model-test.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2009 IITP RAS
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Denis Fakhriev <fakhriev@iitp.ru>
7 */
8#include "ns3/boolean.h"
9#include "ns3/config.h"
10#include "ns3/double.h"
11#include "ns3/rng-seed-manager.h"
12#include "ns3/simulator.h"
13#include "ns3/steady-state-random-waypoint-mobility-model.h"
14#include "ns3/test.h"
15
16#include <cmath>
17
18using namespace ns3;
19
20/**
21 * @ingroup mobility-test
22 *
23 * @brief Steady State Random Waypoint Test
24 */
26{
27 public:
29 : TestCase("Check steady-state rwp mobility model velocity and position distributions")
30 {
31 }
32
34 {
35 }
36
37 private:
38 std::vector<Ptr<MobilityModel>> mobilityStack; ///< modility model
39 double count; ///< count
40 private:
41 void DoRun() override;
42 void DoTeardown() override;
43 /// Distribution compare function
44 void DistribCompare();
45};
46
47void
52
53void
55{
57
58 // Total simulation time, seconds
59 double totalTime = 1000;
60
61 ObjectFactory mobilityFactory;
62 mobilityFactory.SetTypeId("ns3::SteadyStateRandomWaypointMobilityModel");
63 mobilityFactory.Set("MinSpeed", DoubleValue(0.01));
64 mobilityFactory.Set("MaxSpeed", DoubleValue(20.0));
65 mobilityFactory.Set("MinPause", DoubleValue(0.0));
66 mobilityFactory.Set("MaxPause", DoubleValue(0.0));
67 mobilityFactory.Set("MinX", DoubleValue(0));
68 mobilityFactory.Set("MaxX", DoubleValue(1000));
69 mobilityFactory.Set("MinY", DoubleValue(0));
70 mobilityFactory.Set("MaxY", DoubleValue(600));
71
72 // Populate the vector of mobility models.
73 count = 10000;
74 for (uint32_t i = 0; i < count; i++)
75 {
76 // Create a new mobility model.
77 Ptr<MobilityModel> model = mobilityFactory.Create()->GetObject<MobilityModel>();
78 model->AssignStreams(100 * (i + 1));
79 // Add this mobility model to the stack.
80 mobilityStack.push_back(model);
82 }
83
86 Simulator::Stop(Seconds(totalTime));
89}
90
91void
93{
94 double velocity;
95 double sum_x = 0;
96 double sum_y = 0;
97 double sum_v = 0;
98 for (auto i = mobilityStack.begin(); i != mobilityStack.end(); ++i)
99 {
100 auto model = (*i);
101 velocity =
102 std::sqrt(std::pow(model->GetVelocity().x, 2) + std::pow(model->GetVelocity().y, 2));
103 sum_x += model->GetPosition().x;
104 sum_y += model->GetPosition().y;
105 sum_v += velocity;
106 }
107 double mean_x = sum_x / count;
108 double mean_y = sum_y / count;
109 double mean_v = sum_v / count;
110
111 NS_TEST_EXPECT_MSG_EQ_TOL(mean_x, 500, 25.0, "Got unexpected x-position mean value");
112 NS_TEST_EXPECT_MSG_EQ_TOL(mean_y, 300, 15.0, "Got unexpected y-position mean value");
113 NS_TEST_EXPECT_MSG_EQ_TOL(mean_v, 2.6, 0.13, "Got unexpected velocity mean value");
114
115 sum_x = 0;
116 sum_y = 0;
117 sum_v = 0;
118 double tmp;
119 for (auto i = mobilityStack.begin(); i != mobilityStack.end(); ++i)
120 {
121 auto model = (*i);
122 velocity =
123 std::sqrt(std::pow(model->GetVelocity().x, 2) + std::pow(model->GetVelocity().y, 2));
124 tmp = model->GetPosition().x - mean_x;
125 sum_x += tmp * tmp;
126 tmp = model->GetPosition().y - mean_y;
127 sum_y += tmp * tmp;
128 tmp = velocity - mean_v;
129 sum_v += tmp * tmp;
130 }
131 double dev_x = std::sqrt(sum_x / (count - 1));
132 double dev_y = std::sqrt(sum_y / (count - 1));
133 double dev_v = std::sqrt(sum_v / (count - 1));
134
135 NS_TEST_EXPECT_MSG_EQ_TOL(dev_x, 230, 10.0, "Got unexpected x-position standard deviation");
136 NS_TEST_EXPECT_MSG_EQ_TOL(dev_y, 140, 7.0, "Got unexpected y-position standard deviation");
137 NS_TEST_EXPECT_MSG_EQ_TOL(dev_v, 4.4, 0.22, "Got unexpected velocity standard deviation");
138}
139
140/**
141 * @ingroup mobility-test
142 *
143 * @brief Steady State Random Waypoint Test Suite
144 */
146{
148 : TestSuite("steady-state-rwp-mobility-model", Type::UNIT)
149 {
150 AddTestCase(new SteadyStateRandomWaypointTest, TestCase::Duration::QUICK);
151 }
std::vector< Ptr< MobilityModel > > mobilityStack
modility model
void DoRun() override
Implementation to actually run this TestCase.
void DoTeardown() override
Implementation to do any local setup required for this TestCase.
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition double.h:31
Keep track of the current position and velocity of an object.
Instantiate subclasses of ns3::Object.
Ptr< Object > Create() const
Create an Object instance of the configured TypeId.
void Set(const std::string &name, const AttributeValue &value, Args &&... args)
Set an attribute to be set during construction.
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
void Initialize()
Invoke DoInitialize on all Objects aggregated to this one.
Definition object.cc:203
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
Definition object.h:511
Smart pointer class similar to boost::intrusive_ptr.
static void SetSeed(uint32_t seed)
Set the seed.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition simulator.h:560
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:131
static void Run()
Run the simulation.
Definition simulator.cc:167
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition simulator.cc:175
encapsulates test code
Definition test.h:1050
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:292
A suite of tests to run.
Definition test.h:1267
Type
Type of test.
Definition test.h:1274
static constexpr auto UNIT
Definition test.h:1291
SteadyStateRandomWaypointTestSuite g_steadyStateRandomWaypointTestSuite
the test suite
#define NS_TEST_EXPECT_MSG_EQ_TOL(actual, limit, tol, msg)
Test that actual and expected (limit) values are equal to plus or minus some tolerance and report if ...
Definition test.h:500
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1344
Every class exported by the ns3 library is enclosed in the ns3 namespace.