A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
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
namespace
ns3 {
30
31
class
SteadyStateRandomWaypointTest
:
public
TestCase
32
{
33
public
:
34
SteadyStateRandomWaypointTest
()
35
:
TestCase
(
"Check steady-state rwp mobility model velocity and position distributions"
) {}
36
virtual
~SteadyStateRandomWaypointTest
() {}
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
48
SteadyStateRandomWaypointTest::DoTeardown
(
void
)
49
{
50
mobilityStack
.clear();
51
}
52
53
void
54
SteadyStateRandomWaypointTest::DoRun
(
void
)
55
{
56
SeedManager::SetSeed
(123);
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
84
Simulator::Schedule
(
Seconds
(0.001), &
SteadyStateRandomWaypointTest::DistribCompare
,
this
);
85
Simulator::Schedule
(
Seconds
(totalTime), &
SteadyStateRandomWaypointTest::DistribCompare
,
this
);
86
Simulator::Stop
(
Seconds
(totalTime));
87
Simulator::Run
();
88
Simulator::Destroy
();
89
}
90
91
void
92
SteadyStateRandomWaypointTest::DistribCompare
()
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
140
struct
SteadyStateRandomWaypointTestSuite
:
public
TestSuite
141
{
142
SteadyStateRandomWaypointTestSuite
() :
TestSuite
(
"steady-state-rwp-mobility-model"
,
UNIT
)
143
{
144
AddTestCase
(
new
SteadyStateRandomWaypointTest
,
TestCase::QUICK
);
145
}
146
}
g_steadyStateRandomWaypointTestSuite
;
147
148
}
// namespace ns3
src
mobility
test
steady-state-random-waypoint-mobility-model-test.cc
Generated on Tue May 14 2013 11:08:29 for ns-3 by
1.8.1.2