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 speed 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 speed;
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 speed = model->GetVelocity().GetLength();
102 sum_x += model->GetPosition().x;
103 sum_y += model->GetPosition().y;
104 sum_v += speed;
105 }
106 double mean_x = sum_x / count;
107 double mean_y = sum_y / count;
108 double mean_v = sum_v / count;
109
110 NS_TEST_EXPECT_MSG_EQ_TOL(mean_x, 500, 25.0, "Got unexpected x-position mean value");
111 NS_TEST_EXPECT_MSG_EQ_TOL(mean_y, 300, 15.0, "Got unexpected y-position mean value");
112 NS_TEST_EXPECT_MSG_EQ_TOL(mean_v, 2.6, 0.13, "Got unexpected speed mean value");
113
114 sum_x = 0;
115 sum_y = 0;
116 sum_v = 0;
117 double tmp;
118 for (auto i = mobilityStack.begin(); i != mobilityStack.end(); ++i)
119 {
120 auto model = (*i);
121 speed = model->GetVelocity().GetLength();
122 tmp = model->GetPosition().x - mean_x;
123 sum_x += tmp * tmp;
124 tmp = model->GetPosition().y - mean_y;
125 sum_y += tmp * tmp;
126 tmp = speed - mean_v;
127 sum_v += tmp * tmp;
128 }
129 double dev_x = std::sqrt(sum_x / (count - 1));
130 double dev_y = std::sqrt(sum_y / (count - 1));
131 double dev_v = std::sqrt(sum_v / (count - 1));
132
133 NS_TEST_EXPECT_MSG_EQ_TOL(dev_x, 230, 10.0, "Got unexpected x-position standard deviation");
134 NS_TEST_EXPECT_MSG_EQ_TOL(dev_y, 140, 7.0, "Got unexpected y-position standard deviation");
135 NS_TEST_EXPECT_MSG_EQ_TOL(dev_v, 4.4, 0.22, "Got unexpected speed standard deviation");
136}
137
138/**
139 * @ingroup mobility-test
140 *
141 * @brief Steady State Random Waypoint Test Suite
142 */
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:200
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:70
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:580
static void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition simulator.cc:125
static void Run()
Run the simulation.
Definition simulator.cc:161
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition simulator.cc:169
void AddTestCase(TestCase *testCase, Duration duration=Duration::QUICK)
Add an individual child TestCase to this test suite.
Definition test.cc:296
@ QUICK
Fast test.
Definition test.h:1057
TestCase(const TestCase &)=delete
Caller graph was not generated because of its size.
Type
Type of test.
Definition test.h:1271
@ UNIT
This test suite implements a Unit Test.
Definition test.h:1273
TestSuite(std::string name, Type type=Type::UNIT)
Construct a new test suite.
Definition test.cc:494
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:499
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1273
Every class exported by the ns3 library is enclosed in the ns3 namespace.