A Discrete-Event Network Simulator
API
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 
38 {
39 public:
41  : TestCase ("Check steady-state rwp mobility model velocity and position distributions") {}
43 
44 private:
45  std::vector<Ptr<MobilityModel> > mobilityStack;
46  double count;
47 private:
48  virtual void DoRun (void);
49  virtual void DoTeardown (void);
51  void DistribCompare ();
52 };
53 
54 void
56 {
57  mobilityStack.clear();
58 }
59 
60 void
62 {
64 
65  // Total simulation time, seconds
66  double totalTime = 1000;
67 
68  ObjectFactory mobilityFactory;
69  mobilityFactory.SetTypeId ("ns3::SteadyStateRandomWaypointMobilityModel");
70  mobilityFactory.Set ("MinSpeed", DoubleValue (0.01));
71  mobilityFactory.Set ("MaxSpeed", DoubleValue (20.0));
72  mobilityFactory.Set ("MinPause", DoubleValue (0.0));
73  mobilityFactory.Set ("MaxPause", DoubleValue (0.0));
74  mobilityFactory.Set ("MinX", DoubleValue (0));
75  mobilityFactory.Set ("MaxX", DoubleValue (1000));
76  mobilityFactory.Set ("MinY", DoubleValue (0));
77  mobilityFactory.Set ("MaxY", DoubleValue (600));
78 
79  // Populate the vector of mobility models.
80  count = 10000;
81  for (uint32_t i = 0; i < count; i++)
82  {
83  // Create a new mobility model.
84  Ptr<MobilityModel> model = mobilityFactory.Create ()->GetObject<MobilityModel> ();
85  model->AssignStreams (100 * (i + 1));
86  // Add this mobility model to the stack.
87  mobilityStack.push_back (model);
89  }
90 
93  Simulator::Stop (Seconds (totalTime));
94  Simulator::Run ();
96 }
97 
98 void
100 {
101  double velocity;
102  double sum_x = 0;
103  double sum_y = 0;
104  double sum_v = 0;
105  std::vector<Ptr<MobilityModel> >::iterator i;
106  Ptr<MobilityModel> model;
107  for (i = mobilityStack.begin (); i != mobilityStack.end (); ++i)
108  {
109  model = (*i);
110  velocity = std::sqrt (std::pow (model->GetVelocity ().x, 2) + std::pow (model->GetVelocity ().y, 2));
111  sum_x += model->GetPosition ().x;
112  sum_y += model->GetPosition ().y;
113  sum_v += velocity;
114  }
115  double mean_x = sum_x / count;
116  double mean_y = sum_y / count;
117  double mean_v = sum_v / count;
118 
119  NS_TEST_EXPECT_MSG_EQ_TOL (mean_x, 500, 25.0, "Got unexpected x-position mean value");
120  NS_TEST_EXPECT_MSG_EQ_TOL (mean_y, 300, 15.0, "Got unexpected y-position mean value");
121  NS_TEST_EXPECT_MSG_EQ_TOL (mean_v, 2.6, 0.13, "Got unexpected velocity mean value");
122 
123  sum_x = 0;
124  sum_y = 0;
125  sum_v = 0;
126  double tmp;
127  for (i = mobilityStack.begin (); i != mobilityStack.end (); ++i)
128  {
129  model = (*i);
130  velocity = std::sqrt (std::pow (model->GetVelocity ().x, 2) + std::pow (model->GetVelocity ().y, 2));
131  tmp = model->GetPosition ().x - mean_x;
132  sum_x += tmp * tmp;
133  tmp = model->GetPosition ().y - mean_y;
134  sum_y += tmp * tmp;
135  tmp = velocity - mean_v;
136  sum_v += tmp * tmp;
137  }
138  double dev_x = std::sqrt (sum_x / (count - 1));
139  double dev_y = std::sqrt (sum_y / (count - 1));
140  double dev_v = std::sqrt (sum_v / (count - 1));
141 
142  NS_TEST_EXPECT_MSG_EQ_TOL (dev_x, 230, 10.0, "Got unexpected x-position standard deviation");
143  NS_TEST_EXPECT_MSG_EQ_TOL (dev_y, 140, 7.0, "Got unexpected y-position standard deviation");
144  NS_TEST_EXPECT_MSG_EQ_TOL (dev_v, 4.4, 0.22, "Got unexpected velocity standard deviation");
145 }
146 
154 {
155  SteadyStateRandomWaypointTestSuite () : TestSuite ("steady-state-rwp-mobility-model", UNIT)
156  {
158  }
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:557
int64_t AssignStreams(int64_t stream)
Assign a fixed random variable stream number to the random variables used by this model...
A suite of tests to run.
Definition: test.h:1343
void Set(const std::string &name, const AttributeValue &value, Args &&... args)
Set an attribute to be set during construction.
static void Run(void)
Run the simulation.
Definition: simulator.cc:172
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
encapsulates test code
Definition: test.h:1153
Keep track of the current position and velocity of an object.
Ptr< Object > Create(void) const
Create an Object instance of the configured TypeId.
#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:563
static void Destroy(void)
Execute the events scheduled with ScheduleDestroy().
Definition: simulator.cc:136
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:470
Every class exported by the ns3 library is enclosed in the ns3 namespace.
virtual void DoRun(void)
Implementation to actually run this TestCase.
static void SetSeed(uint32_t seed)
Set the seed.
Fast test.
Definition: test.h:1159
Vector GetPosition(void) const
Instantiate subclasses of ns3::Object.
std::vector< Ptr< MobilityModel > > mobilityStack
modility model
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
Definition: simulator.cc:180
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1289
SteadyStateRandomWaypointTestSuite g_steadyStateRandomWaypointTestSuite
the test suite
This class can be used to hold variables of floating point type such as &#39;double&#39; or &#39;float&#39;...
Definition: double.h:41
void Initialize(void)
Invoke DoInitialize on all Objects aggregated to this one.
Definition: object.cc:183
virtual void DoTeardown(void)
Implementation to do any local setup required for this TestCase.
Vector GetVelocity(void) const