position.h -> mobility-model.h

This commit is contained in:
Mathieu Lacage
2007-07-04 10:15:18 +02:00
parent 3e22f47624
commit dd0ff29f66
18 changed files with 351 additions and 25 deletions

View File

@@ -248,14 +248,14 @@ node.add_sources ([
'udp.cc',
'ipv4.cc',
'application.cc',
'position.cc',
'mobility-model.cc',
'mobility-model-notifier.cc',
'static-position.cc',
'static-speed-position.cc',
'static-mobility-model.cc',
'static-speed-mobility-model.cc',
'grid-topology.cc',
'random-rectangle-topology.cc',
'random-walk-position.cc',
'random-direction-position.cc',
'random-walk-mobility-model.cc',
'random-direction-mobility-model.cc',
])
node.add_inst_headers ([
'node.h',
@@ -273,14 +273,14 @@ node.add_inst_headers ([
'udp.h',
'ipv4.h',
'application.h',
'position.h',
'mobility-model.h',
'mobility-model-notifier.h',
'static-position.h',
'static-speed-position.h',
'static-mobility-model.h',
'static-speed-mobility-model.h',
'grid-topology.h',
'random-rectangle-topology.h',
'random-walk-position.h',
'random-direction-position.h',
'random-walk-mobility-model.h',
'random-direction-mobility-model.h',
])
applications = build.Ns3Module ('applications', 'src/applications')

View File

@@ -2,7 +2,7 @@
#include "ns3/ptr.h"
#include "ns3/grid-topology.h"
#include "ns3/static-position.h"
#include "ns3/static-mobility-model.h"
#include "ns3/internet-node.h"
#include "ns3/command-line.h"

View File

@@ -1,9 +1,9 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
#include "ns3/ptr.h"
#include "ns3/position.h"
#include "ns3/mobility-model.h"
#include "ns3/mobility-model-notifier.h"
#include "ns3/random-walk-position.h"
#include "ns3/random-walk-mobility-model.h"
#include "ns3/default-value.h"
#include "ns3/command-line.h"
#include "ns3/simulator.h"

View File

@@ -19,7 +19,7 @@
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
*/
#include "grid-topology.h"
#include "static-position.h"
#include "static-mobility-model.h"
namespace ns3 {

View File

@@ -24,7 +24,7 @@
#include "ns3/object.h"
#include "ns3/component-manager.h"
#include "ns3/callback.h"
#include "position.h"
#include "mobility-model.h"
namespace ns3 {

View File

@@ -18,7 +18,7 @@
*
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
*/
#include "position.h"
#include "mobility-model.h"
#include "mobility-model-notifier.h"
#include <math.h>

View File

@@ -23,7 +23,7 @@
#include "ns3/simulator.h"
#include <algorithm>
#include <cmath>
#include "random-direction-position.h"
#include "random-direction-mobility-model.h"
namespace ns3 {

View File

@@ -26,7 +26,7 @@
#include "ns3/nstime.h"
#include "ns3/event-id.h"
#include "ns3/component-manager.h"
#include "position.h"
#include "mobility-model.h"
namespace ns3 {

View File

@@ -18,7 +18,7 @@
*
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
*/
#include "random-walk-position.h"
#include "random-walk-mobility-model.h"
#include "ns3/default-value.h"
#include "ns3/time-default-value.h"
#include "ns3/simulator.h"

View File

@@ -22,7 +22,7 @@
#define RANDOM_WALK_POSITION_H
#include "ns3/object.h"
#include "ns3/position.h"
#include "ns3/mobility-model.h"
#include "ns3/nstime.h"
#include "ns3/random-variable.h"
#include "ns3/component-manager.h"

View File

@@ -19,7 +19,7 @@
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
*/
#include "random-rectangle-topology.h"
#include "static-position.h"
#include "static-mobility-model.h"
#include "ns3/random-variable-default-value.h"
namespace ns3 {

View File

@@ -0,0 +1,195 @@
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2006,2007 INRIA
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
*/
#include "random-walk-mobility-model.h"
#include "ns3/default-value.h"
#include "ns3/time-default-value.h"
#include "ns3/simulator.h"
#include "ns3/debug.h"
#include <cmath>
NS_DEBUG_COMPONENT_DEFINE ("RandomWalk");
namespace ns3 {
const InterfaceId RandomWalkMobilityModel::iid =
MakeInterfaceId ("RandomWalkMobilityModel", MobilityModel::iid);
const ClassId RandomWalkMobilityModel::cid =
MakeClassId<RandomWalkMobilityModel, double, double> ("RandomWalkMobilityModel", RandomWalkMobilityModel::iid);
static IntegerDefaultValue<double> g_minSpeed ("RandomWalkMinSpeed",
"Minimum speed used during a random walk",
0.1);
static IntegerDefaultValue<double> g_maxSpeed ("RandomWalkMaxSpeed",
"Maximum speed used during a random walk",
0.5);
static EnumDefaultValue<RandomWalkMobilityModelParameters::Mode> g_mode
("RandomWalkMode",
"The mode indicates the condition used to "
"change the current speed and direction",
RandomWalkMobilityModelParameters::MODE_DISTANCE, "Distance",
RandomWalkMobilityModelParameters::MODE_TIME, "Time",
0, 0);
static IntegerDefaultValue<double> g_modeDistance ("RandomWalkModeDistance",
"Distance to walk before changing direction and speed.",
10);
static TimeDefaultValue g_modeTime ("RandomWalkModeTime",
"Time to walk before changing direction and speed.",
Seconds (1));
RandomWalkMobilityModelParameters::RandomWalkMobilityModelParameters ()
: m_minSpeed (g_minSpeed.GetValue ()),
m_maxSpeed (g_maxSpeed.GetValue ()),
m_mode (g_mode.GetValue ()),
m_modeDistance (g_modeDistance.GetValue ()),
m_modeTime (g_modeTime.GetValue ())
{}
bool
RandomWalkMobilityModelParameters::IsDefault (void) const
{
if (m_minSpeed != g_minSpeed.GetValue () ||
m_maxSpeed != g_maxSpeed.GetValue () ||
m_mode != g_mode.GetValue () ||
m_modeDistance != g_modeDistance.GetValue () ||
m_modeTime != g_modeTime.GetValue ())
{
return false;
}
return true;
}
void
RandomWalkMobilityModelParameters::SetSpeedBounds (double minSpeed, double maxSpeed)
{
m_minSpeed = minSpeed;
m_maxSpeed = maxSpeed;
}
UniformVariable RandomWalkMobilityModel::m_randomDirection (0.0, 2*3.141592);
Ptr<RandomWalkMobilityModelParameters>
RandomWalkMobilityModel::GetDefaultParameters (void)
{
static Ptr<RandomWalkMobilityModelParameters> parameters = Create<RandomWalkMobilityModelParameters> ();
if (!parameters->IsDefault ())
{
parameters = Create<RandomWalkMobilityModelParameters> ();
}
return parameters;
}
RandomWalkMobilityModel::RandomWalkMobilityModel ()
: m_x (0.0),
m_y (0.0),
m_dx (0.0),
m_dy (0.0),
m_prevTime (Simulator::Now ()),
m_parameters (RandomWalkMobilityModel::GetDefaultParameters ())
{
SetInterfaceId (RandomWalkMobilityModel::iid);
Reset ();
}
RandomWalkMobilityModel::RandomWalkMobilityModel (double x, double y)
: m_x (x),
m_y (y),
m_dx (0.0),
m_dy (0.0),
m_prevTime (Simulator::Now ()),
m_parameters (RandomWalkMobilityModel::GetDefaultParameters ())
{
SetInterfaceId (RandomWalkMobilityModel::iid);
Reset ();
}
void
RandomWalkMobilityModel::Reset (void)
{
Update ();
double speed = UniformVariable::GetSingleValue (m_parameters->m_minSpeed,
m_parameters->m_maxSpeed);
NS_DEBUG ("min="<< m_parameters->m_minSpeed << ", max=" << m_parameters->m_maxSpeed <<
", speed=" << speed);
double direction = m_randomDirection.GetValue ();
double dx = std::cos (direction) * speed;
double dy = std::sin (direction) * speed;
m_dx = dx;
m_dy = dy;
Time delay;
if (m_parameters->m_mode == RandomWalkMobilityModelParameters::MODE_TIME)
{
delay = m_parameters->m_modeTime;
}
else
{
double distance = m_parameters->m_modeDistance;
delay = Seconds (distance / sqrt (m_dx * m_dx + m_dy * m_dy));
}
NotifyCourseChange ();
NS_DEBUG ("change speed at " << Simulator::Now () << " in " << delay);
Simulator::Schedule (delay, &RandomWalkMobilityModel::Reset, this);
}
void
RandomWalkMobilityModel::Update (void) const
{
Time deltaTime = Simulator::Now () - m_prevTime;
m_prevTime = Simulator::Now ();
double deltaS = deltaTime.GetSeconds ();
m_x += m_dx * deltaS;
m_y += m_dy * deltaS;
}
void
RandomWalkMobilityModel::DoDispose (void)
{
m_parameters = 0;
// chain up
MobilityModel::DoDispose ();
}
void
RandomWalkMobilityModel::DoGet (double &x, double &y, double &z) const
{
Update ();
x = m_x;
y = m_y;
z = 0;
}
void
RandomWalkMobilityModel::DoSet (double x, double y, double z)
{
bool changed = false;
if (m_x != x || m_y != y)
{
changed = true;
}
m_x = x;
m_y = y;
m_prevTime = Simulator::Now ();
if (changed)
{
NotifyCourseChange ();
}
}
} // namespace ns3

View File

@@ -0,0 +1,131 @@
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2006,2007 INRIA
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
*/
#ifndef RANDOM_WALK_POSITION_H
#define RANDOM_WALK_POSITION_H
#include "ns3/object.h"
#include "ns3/mobility-model.h"
#include "ns3/nstime.h"
#include "ns3/random-variable.h"
#include "ns3/component-manager.h"
namespace ns3 {
/**
* \brief parameters to control a random walk model
*/
class RandomWalkMobilityModelParameters : public Object
{
public:
enum Mode {
MODE_DISTANCE,
MODE_TIME
};
/**
* Instantiate a set of RandomWalk parameters initialized
* with the Bind default values.
*/
RandomWalkMobilityModelParameters ();
/**
* \param minSpeed the minimum speed
* \param maxSpeed the maximum speed
*
* The speed of any node is chosen such that minSpeed <= speed <= maxSpeed
*/
void SetSpeedBounds (double minSpeed, double maxSpeed);
/**
* \param distance the distance before a direction change
*
* Unit is meters
*/
void SetModeDistance (double distance);
/**
* \param time the delay before a direction change.
*/
void SetModeTime (Time time);
private:
bool IsDefault (void) const;
friend class RandomWalkMobilityModel;
double m_minSpeed;
double m_maxSpeed;
enum Mode m_mode;
double m_modeDistance;
Time m_modeTime;
};
/**
* \brief an unbounded 2D random walk position model
*
* Each instance moves with a speed and direction choosen at random
* in the intervals [minspeed,maxspeed] and [0,2pi] until
* either a fixed distance has been walked or until a fixed amount
* of time.
*
* The parameters of the model can be specified either with the ns3::Bind
* function and the variables "RandomWalkMinSpeed", "RandomWalkMaxSpeed",
* "RandomWalkMode", "RandomWalkModeDistance", and, "RandomWalkModeTime" or
* with an instance of the RandomWalkMobilityModelParameters class which
* must be fed to the RandomWalkMobilityModel constructors.
*/
class RandomWalkMobilityModel : public MobilityModel
{
public:
static const InterfaceId iid;
static const ClassId cid;
/**
* Create a new position object located at position (0,0,0)
*/
RandomWalkMobilityModel ();
/**
* Create a new position object located at position (x,y,0)
*/
RandomWalkMobilityModel (double x, double y);
/**
* Create a new position object located at position (0,0,0)
*/
RandomWalkMobilityModel (Ptr<RandomWalkMobilityModelParameters> parameters);
/**
* Create a new position object located at position (x,y,0)
*/
RandomWalkMobilityModel (Ptr<RandomWalkMobilityModelParameters> parameters,
double x, double y);
private:
virtual void DoDispose (void);
virtual void DoGet (double &x, double &y, double &z) const;
virtual void DoSet (double x, double y, double z);
void Reset (void);
void Update (void) const;
static Ptr<RandomWalkMobilityModelParameters> GetDefaultParameters (void);
static UniformVariable m_randomDirection;
mutable double m_x;
mutable double m_y;
double m_dx;
double m_dy;
mutable Time m_prevTime;
Ptr<RandomWalkMobilityModelParameters> m_parameters;
};
} // namespace ns3
#endif /* RANDOM_WALK_POSITION_H */

View File

@@ -18,7 +18,7 @@
*
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
*/
#include "static-position.h"
#include "static-mobility-model.h"
namespace ns3 {

View File

@@ -22,7 +22,7 @@
#define STATIC_POSITION_H
#include "ns3/component-manager.h"
#include "position.h"
#include "mobility-model.h"
namespace ns3 {

View File

@@ -18,7 +18,7 @@
*
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
*/
#include "static-speed-position.h"
#include "static-speed-mobility-model.h"
#include "ns3/simulator.h"
namespace ns3 {

View File

@@ -22,7 +22,7 @@
#define STATIC_SPEED_POSITION_H
#include <stdint.h>
#include "position.h"
#include "mobility-model.h"
#include "ns3/nstime.h"
#include "ns3/component-manager.h"