A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
steady-state-random-waypoint-mobility-model-test.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2009 IITP RAS
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Denis Fakhriev <fakhriev@iitp.ru>
19  */
20 #include <cmath>
21 #include "ns3/simulator.h"
22 #include "ns3/boolean.h"
23 #include "ns3/double.h"
24 #include "ns3/test.h"
25 #include "ns3/config.h"
26 #include "ns3/steady-state-random-waypoint-mobility-model.h"
27 #include "ns3/rng-seed-manager.h"
28 
29 using namespace ns3;
30 
32 {
33 public:
35  : TestCase ("Check steady-state rwp mobility model velocity and position distributions") {}
37 
38 private:
39  std::vector<Ptr<MobilityModel> > mobilityStack;
40  double count;
41 private:
42  virtual void DoRun (void);
43  virtual void DoTeardown (void);
44  void DistribCompare ();
45 };
46 
47 void
49 {
50  mobilityStack.clear();
51 }
52 
53 void
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 
79  // Add this mobility model to the stack.
80  mobilityStack.push_back (model);
81  Simulator::Schedule (Seconds (0.0), &Object::Initialize, model);
82  }
83 
86  Simulator::Stop (Seconds (totalTime));
87  Simulator::Run ();
89 }
90 
91 void
93 {
94  double velocity;
95  double sum_x = 0;
96  double sum_y = 0;
97  double sum_v = 0;
98  std::vector<Ptr<MobilityModel> >::iterator i;
99  Ptr<MobilityModel> model;
100  for (i = mobilityStack.begin (); i != mobilityStack.end (); ++i)
101  {
102  model = (*i);
103  velocity = std::sqrt (std::pow (model->GetVelocity ().x, 2) + std::pow (model->GetVelocity ().y, 2));
104  sum_x += model->GetPosition ().x;
105  sum_y += model->GetPosition ().y;
106  sum_v += velocity;
107  }
108  double mean_x = sum_x / count;
109  double mean_y = sum_y / count;
110  double mean_v = sum_v / count;
111 
112  NS_TEST_EXPECT_MSG_EQ_TOL (mean_x, 500, 25.0, "Got unexpected x-position mean value");
113  NS_TEST_EXPECT_MSG_EQ_TOL (mean_y, 300, 15.0, "Got unexpected y-position mean value");
114  NS_TEST_EXPECT_MSG_EQ_TOL (mean_v, 2.6, 0.13, "Got unexpected velocity mean value");
115 
116  sum_x = 0;
117  sum_y = 0;
118  sum_v = 0;
119  double tmp;
120  for (i = mobilityStack.begin (); i != mobilityStack.end (); ++i)
121  {
122  model = (*i);
123  velocity = 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 
141 {
142  SteadyStateRandomWaypointTestSuite () : TestSuite ("steady-state-rwp-mobility-model", UNIT)
143  {
145  }
double x
x coordinate of vector
Definition: vector.h:49
A suite of tests to run.
Definition: test.h:1105
static void Run(void)
Run the simulation until one of:
Definition: simulator.cc:157
void SetTypeId(TypeId tid)
Vector GetPosition(void) const
encapsulates test code
Definition: test.h:929
static EventId Schedule(Time const &time, MEM mem_ptr, OBJ obj)
Schedule an event to expire at the relative time "time" is reached.
Definition: simulator.h:825
Vector GetVelocity(void) const
Keep track of the current position and velocity of an object.
Ptr< Object > Create(void) const
#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:530
static void Destroy(void)
Every event scheduled by the Simulator::insertAtDestroy method is invoked.
Definition: simulator.cc:121
void Set(std::string name, const AttributeValue &value)
double y
y coordinate of vector
Definition: vector.h:53
virtual void DoRun(void)
Implementation to actually run this TestCase.
static void SetSeed(uint32_t seed)
set the seed it will duplicate the seed value 6 times
Fast test.
Definition: test.h:937
instantiate subclasses of ns3::Object.
static void Stop(void)
If an event invokes this method, it will be the last event scheduled by the Simulator::run method bef...
Definition: simulator.cc:165
void Initialize(void)
This method calls the virtual DoInitialize method on all the objects aggregated to this object...
Definition: object.cc:179
Hold a floating point type.
Definition: double.h:41
Ptr< T > GetObject(void) const
Definition: object.h:362
SteadyStateRandomWaypointTestSuite g_steadyStateRandomWaypointTestSuite
virtual void DoTeardown(void)
Implementation to do any local setup required for this TestCase.