src/mobility/random-direction-2d-mobility-model.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Thu, 08 Nov 2007 12:33:30 +0100
changeset 1817 8b0520433350
parent 1816 d7c9b9da78f4
child 1818 fbdc8361dc77
permissions -rw-r--r--
replace Position and Speed by Vector
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     1
/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     2
/*
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     3
 * Copyright (c) 2007 INRIA
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     4
 * All rights reserved.
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     5
 *
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     6
 * This program is free software; you can redistribute it and/or modify
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     7
 * it under the terms of the GNU General Public License version 2 as
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     8
 * published by the Free Software Foundation;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     9
 *
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    10
 * This program is distributed in the hope that it will be useful,
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    13
 * GNU General Public License for more details.
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    14
 *
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    16
 * along with this program; if not, write to the Free Software
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    18
 *
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    19
 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    20
 */
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    21
#include "ns3/random-variable-default-value.h"
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    22
#include "ns3/rectangle-default-value.h"
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    23
#include "ns3/simulator.h"
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    24
#include <algorithm>
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    25
#include <cmath>
1625
0579a50b2c62 random-direction -> random-direction-2d
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1624
diff changeset
    26
#include "random-direction-2d-mobility-model.h"
1656
99949986bb92 Add a bit of function name logging.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1637
diff changeset
    27
#include "ns3/log.h"
99949986bb92 Add a bit of function name logging.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1637
diff changeset
    28
99949986bb92 Add a bit of function name logging.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1637
diff changeset
    29
NS_LOG_COMPONENT_DEFINE ("RandomDirection2dMobilityModel");
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    30
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    31
namespace ns3 {
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    32
1658
52f6bf2a7caa Improve the precision of the RandomDirection2dMobilityModel::PI constant (value copied from glibc's math.h header file).
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1656
diff changeset
    33
const double RandomDirection2dMobilityModel::PI = 3.14159265358979323846;
1626
feaecfd93b5d RandomDirection -> RandomDirection2d
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1625
diff changeset
    34
const ClassId RandomDirection2dMobilityModel::cid = 
feaecfd93b5d RandomDirection -> RandomDirection2d
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1625
diff changeset
    35
  MakeClassId<RandomDirection2dMobilityModel> ("RandomDirection2dMobilityModel",
1634
2bf997301257 more dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1626
diff changeset
    36
                                               MobilityModel::iid);
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    37
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    38
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    39
static RandomVariableDefaultValue 
1626
feaecfd93b5d RandomDirection -> RandomDirection2d
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1625
diff changeset
    40
  g_speedVariable ("RandomDirection2dSpeed",
feaecfd93b5d RandomDirection -> RandomDirection2d
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1625
diff changeset
    41
		   "A random variable to control the speed of a RandomDirection2d mobility model.",
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    42
		   "Uniform:1:2");
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    43
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    44
static RandomVariableDefaultValue
1626
feaecfd93b5d RandomDirection -> RandomDirection2d
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1625
diff changeset
    45
  g_pauseVariable ("RandomDirection2dPause",
1620
69baa7b1c487 remove mobility model helper, re-enable random direction model with new helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1591
diff changeset
    46
		   "A random variable to control the duration "
69baa7b1c487 remove mobility model helper, re-enable random direction model with new helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1591
diff changeset
    47
                   "of the pause of a RandomDiretion mobility model.",
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    48
		   "Constant:2");
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    49
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    50
static RectangleDefaultValue
1626
feaecfd93b5d RandomDirection -> RandomDirection2d
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1625
diff changeset
    51
  g_bounds ("RandomDirection2dArea",
feaecfd93b5d RandomDirection -> RandomDirection2d
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1625
diff changeset
    52
	       "The bounding area for the RandomDirection2d model.",
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    53
	       -100, 100, -100, 100);
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    54
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    55
1635
935bed1e13e7 RandomDirection2dParameters -> RandomDirection2dMobilityModelParameters
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1634
diff changeset
    56
RandomDirection2dMobilityModelParameters::RandomDirection2dMobilityModelParameters ()
1620
69baa7b1c487 remove mobility model helper, re-enable random direction model with new helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1591
diff changeset
    57
  : m_bounds (g_bounds.GetValue ()),
69baa7b1c487 remove mobility model helper, re-enable random direction model with new helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1591
diff changeset
    58
    m_speedVariable (g_speedVariable.GetCopy ()),
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    59
    m_pauseVariable (g_pauseVariable.GetCopy ())
1620
69baa7b1c487 remove mobility model helper, re-enable random direction model with new helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1591
diff changeset
    60
    
69baa7b1c487 remove mobility model helper, re-enable random direction model with new helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1591
diff changeset
    61
{}
1635
935bed1e13e7 RandomDirection2dParameters -> RandomDirection2dMobilityModelParameters
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1634
diff changeset
    62
RandomDirection2dMobilityModelParameters::RandomDirection2dMobilityModelParameters 
935bed1e13e7 RandomDirection2dParameters -> RandomDirection2dMobilityModelParameters
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1634
diff changeset
    63
(const Rectangle &bounds,
935bed1e13e7 RandomDirection2dParameters -> RandomDirection2dMobilityModelParameters
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1634
diff changeset
    64
 const RandomVariable &speedVariable,
935bed1e13e7 RandomDirection2dParameters -> RandomDirection2dMobilityModelParameters
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1634
diff changeset
    65
 const RandomVariable &pauseVariable)
1620
69baa7b1c487 remove mobility model helper, re-enable random direction model with new helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1591
diff changeset
    66
  : m_bounds (bounds),
69baa7b1c487 remove mobility model helper, re-enable random direction model with new helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1591
diff changeset
    67
    m_speedVariable (speedVariable.Copy ()),
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    68
    m_pauseVariable (pauseVariable.Copy ())
1620
69baa7b1c487 remove mobility model helper, re-enable random direction model with new helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1591
diff changeset
    69
{}
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    70
1635
935bed1e13e7 RandomDirection2dParameters -> RandomDirection2dMobilityModelParameters
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1634
diff changeset
    71
RandomDirection2dMobilityModelParameters::~RandomDirection2dMobilityModelParameters ()
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    72
{
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    73
  delete m_speedVariable;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    74
  delete m_pauseVariable;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    75
  m_speedVariable = 0;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    76
  m_pauseVariable = 0;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    77
}
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    78
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    79
void 
1635
935bed1e13e7 RandomDirection2dParameters -> RandomDirection2dMobilityModelParameters
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1634
diff changeset
    80
RandomDirection2dMobilityModelParameters::SetSpeed (const RandomVariable &speedVariable)
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    81
{
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    82
  delete m_speedVariable;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    83
  m_speedVariable = speedVariable.Copy ();
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    84
}
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    85
void 
1635
935bed1e13e7 RandomDirection2dParameters -> RandomDirection2dMobilityModelParameters
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1634
diff changeset
    86
RandomDirection2dMobilityModelParameters::SetPause (const RandomVariable &pauseVariable)
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    87
{
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    88
  delete m_pauseVariable;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    89
  m_pauseVariable = pauseVariable.Copy ();
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    90
}
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    91
void 
1635
935bed1e13e7 RandomDirection2dParameters -> RandomDirection2dMobilityModelParameters
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1634
diff changeset
    92
RandomDirection2dMobilityModelParameters::SetBounds (const Rectangle &bounds)
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    93
{
1620
69baa7b1c487 remove mobility model helper, re-enable random direction model with new helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1591
diff changeset
    94
  m_bounds = bounds;
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    95
}
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    96
1635
935bed1e13e7 RandomDirection2dParameters -> RandomDirection2dMobilityModelParameters
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1634
diff changeset
    97
Ptr<RandomDirection2dMobilityModelParameters> 
935bed1e13e7 RandomDirection2dParameters -> RandomDirection2dMobilityModelParameters
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1634
diff changeset
    98
RandomDirection2dMobilityModelParameters::GetCurrent (void)
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    99
{
1635
935bed1e13e7 RandomDirection2dParameters -> RandomDirection2dMobilityModelParameters
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1634
diff changeset
   100
  static Ptr<RandomDirection2dMobilityModelParameters> parameters = 0;
1620
69baa7b1c487 remove mobility model helper, re-enable random direction model with new helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1591
diff changeset
   101
  if (parameters == 0 ||
69baa7b1c487 remove mobility model helper, re-enable random direction model with new helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1591
diff changeset
   102
      g_bounds.IsDirty () ||
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   103
      g_speedVariable.IsDirty () ||
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   104
      g_pauseVariable.IsDirty ())
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   105
    {
1635
935bed1e13e7 RandomDirection2dParameters -> RandomDirection2dMobilityModelParameters
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1634
diff changeset
   106
      parameters = Create<RandomDirection2dMobilityModelParameters> ();
1620
69baa7b1c487 remove mobility model helper, re-enable random direction model with new helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1591
diff changeset
   107
      g_bounds.ClearDirtyFlag ();
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   108
      g_speedVariable.ClearDirtyFlag ();
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   109
      g_pauseVariable.ClearDirtyFlag ();
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   110
    }
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   111
  return parameters;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   112
}
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   113
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   114
1626
feaecfd93b5d RandomDirection -> RandomDirection2d
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1625
diff changeset
   115
RandomDirection2dMobilityModel::RandomDirection2dMobilityModel ()
1635
935bed1e13e7 RandomDirection2dParameters -> RandomDirection2dMobilityModelParameters
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1634
diff changeset
   116
  : m_parameters (RandomDirection2dMobilityModelParameters::GetCurrent ())
1591
4a1f822fe9aa split useful code out of random direction mobility model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1584
diff changeset
   117
{
1626
feaecfd93b5d RandomDirection -> RandomDirection2d
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1625
diff changeset
   118
  SetInterfaceId (RandomDirection2dMobilityModel::iid);
feaecfd93b5d RandomDirection -> RandomDirection2d
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1625
diff changeset
   119
  m_event = Simulator::ScheduleNow (&RandomDirection2dMobilityModel::Start, this);
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   120
}
1635
935bed1e13e7 RandomDirection2dParameters -> RandomDirection2dMobilityModelParameters
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1634
diff changeset
   121
RandomDirection2dMobilityModel::RandomDirection2dMobilityModel 
935bed1e13e7 RandomDirection2dParameters -> RandomDirection2dMobilityModelParameters
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1634
diff changeset
   122
(Ptr<RandomDirection2dMobilityModelParameters> parameters)
1591
4a1f822fe9aa split useful code out of random direction mobility model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1584
diff changeset
   123
  : m_parameters (parameters)
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   124
{
1626
feaecfd93b5d RandomDirection -> RandomDirection2d
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1625
diff changeset
   125
  SetInterfaceId (RandomDirection2dMobilityModel::iid);
feaecfd93b5d RandomDirection -> RandomDirection2d
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1625
diff changeset
   126
  m_event = Simulator::ScheduleNow (&RandomDirection2dMobilityModel::Start, this);
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   127
}
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   128
void 
1626
feaecfd93b5d RandomDirection -> RandomDirection2d
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1625
diff changeset
   129
RandomDirection2dMobilityModel::DoDispose (void)
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   130
{
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   131
  m_parameters = 0;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   132
  // chain up.
1579
a4187ed1e45e Position -> MobilityModel
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1575
diff changeset
   133
  MobilityModel::DoDispose ();
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   134
}
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   135
void
1626
feaecfd93b5d RandomDirection -> RandomDirection2d
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1625
diff changeset
   136
RandomDirection2dMobilityModel::Start (void)
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   137
{
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   138
  double direction = UniformVariable::GetSingleValue (0, 2 * PI);
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   139
  SetDirectionAndSpeed (direction);
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   140
}
1661
7583786bd063 Adapt to StaticSpeedHelper change
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1658
diff changeset
   141
7583786bd063 Adapt to StaticSpeedHelper change
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1658
diff changeset
   142
void
7583786bd063 Adapt to StaticSpeedHelper change
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1658
diff changeset
   143
RandomDirection2dMobilityModel::BeginPause (void)
7583786bd063 Adapt to StaticSpeedHelper change
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1658
diff changeset
   144
{
7583786bd063 Adapt to StaticSpeedHelper change
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1658
diff changeset
   145
  Time pause = Seconds (m_parameters->m_pauseVariable->GetValue ());
7583786bd063 Adapt to StaticSpeedHelper change
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1658
diff changeset
   146
  m_helper.Pause ();
7583786bd063 Adapt to StaticSpeedHelper change
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1658
diff changeset
   147
  m_event = Simulator::Schedule (pause, &RandomDirection2dMobilityModel::ResetDirectionAndSpeed, this);
7583786bd063 Adapt to StaticSpeedHelper change
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1658
diff changeset
   148
  NotifyCourseChange ();
7583786bd063 Adapt to StaticSpeedHelper change
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1658
diff changeset
   149
}
7583786bd063 Adapt to StaticSpeedHelper change
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1658
diff changeset
   150
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   151
void
1626
feaecfd93b5d RandomDirection -> RandomDirection2d
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1625
diff changeset
   152
RandomDirection2dMobilityModel::SetDirectionAndSpeed (double direction)
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   153
{
1656
99949986bb92 Add a bit of function name logging.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1637
diff changeset
   154
  NS_LOG_FUNCTION;
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   155
  double speed = m_parameters->m_speedVariable->GetValue ();
1817
8b0520433350 replace Position and Speed by Vector
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1816
diff changeset
   156
  const Vector vector (std::cos (direction) * speed,
8b0520433350 replace Position and Speed by Vector
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1816
diff changeset
   157
                       std::sin (direction) * speed,
8b0520433350 replace Position and Speed by Vector
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1816
diff changeset
   158
                       0.0);
8b0520433350 replace Position and Speed by Vector
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1816
diff changeset
   159
  Vector position = m_helper.GetCurrentPosition (m_parameters->m_bounds);
1661
7583786bd063 Adapt to StaticSpeedHelper change
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1658
diff changeset
   160
  m_helper.Reset (vector);
1817
8b0520433350 replace Position and Speed by Vector
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1816
diff changeset
   161
  Vector next = m_parameters->m_bounds.CalculateIntersection (position, vector);
1620
69baa7b1c487 remove mobility model helper, re-enable random direction model with new helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1591
diff changeset
   162
  Time delay = Seconds (CalculateDistance (position, next) / speed);
1661
7583786bd063 Adapt to StaticSpeedHelper change
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1658
diff changeset
   163
  m_event = Simulator::Schedule (delay,
7583786bd063 Adapt to StaticSpeedHelper change
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1658
diff changeset
   164
				 &RandomDirection2dMobilityModel::BeginPause, this);
1620
69baa7b1c487 remove mobility model helper, re-enable random direction model with new helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1591
diff changeset
   165
  NotifyCourseChange ();
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   166
}
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   167
void
1626
feaecfd93b5d RandomDirection -> RandomDirection2d
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1625
diff changeset
   168
RandomDirection2dMobilityModel::ResetDirectionAndSpeed (void)
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   169
{
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   170
  double direction = UniformVariable::GetSingleValue (0, PI);
1591
4a1f822fe9aa split useful code out of random direction mobility model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1584
diff changeset
   171
  
1817
8b0520433350 replace Position and Speed by Vector
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1816
diff changeset
   172
  Vector position = m_helper.GetCurrentPosition (m_parameters->m_bounds);
1620
69baa7b1c487 remove mobility model helper, re-enable random direction model with new helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1591
diff changeset
   173
  switch (m_parameters->m_bounds.GetClosestSide (position))
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   174
    {
1620
69baa7b1c487 remove mobility model helper, re-enable random direction model with new helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1591
diff changeset
   175
    case Rectangle::RIGHT:
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   176
      direction += PI / 2;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   177
      break;
1620
69baa7b1c487 remove mobility model helper, re-enable random direction model with new helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1591
diff changeset
   178
    case Rectangle::LEFT:
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   179
      direction += - PI / 2;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   180
      break;
1620
69baa7b1c487 remove mobility model helper, re-enable random direction model with new helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1591
diff changeset
   181
    case Rectangle::TOP:
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   182
      direction += PI;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   183
      break;
1620
69baa7b1c487 remove mobility model helper, re-enable random direction model with new helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1591
diff changeset
   184
    case Rectangle::BOTTOM:
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   185
      direction += 0.0;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   186
      break;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   187
    }
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   188
  SetDirectionAndSpeed (direction);
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   189
}
1817
8b0520433350 replace Position and Speed by Vector
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1816
diff changeset
   190
Vector
1816
d7c9b9da78f4 rename MobilityModel::Get/Set to GetPosition/SetPosition
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1661
diff changeset
   191
RandomDirection2dMobilityModel::DoGetPosition (void) const
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   192
{
1620
69baa7b1c487 remove mobility model helper, re-enable random direction model with new helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1591
diff changeset
   193
  return m_helper.GetCurrentPosition (m_parameters->m_bounds);
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   194
}
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   195
void
1817
8b0520433350 replace Position and Speed by Vector
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1816
diff changeset
   196
RandomDirection2dMobilityModel::DoSetPosition (const Vector &position)
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   197
{
1620
69baa7b1c487 remove mobility model helper, re-enable random direction model with new helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1591
diff changeset
   198
  m_helper.InitializePosition (position);
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   199
  Simulator::Remove (m_event);
1626
feaecfd93b5d RandomDirection -> RandomDirection2d
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1625
diff changeset
   200
  m_event = Simulator::ScheduleNow (&RandomDirection2dMobilityModel::Start, this);
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   201
}
1817
8b0520433350 replace Position and Speed by Vector
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1816
diff changeset
   202
Vector
1626
feaecfd93b5d RandomDirection -> RandomDirection2d
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1625
diff changeset
   203
RandomDirection2dMobilityModel::DoGetSpeed (void) const
1624
6e7d48a8c120 add MobilityModel::GetSpeed method and implement it in all mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1620
diff changeset
   204
{
6e7d48a8c120 add MobilityModel::GetSpeed method and implement it in all mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1620
diff changeset
   205
  return m_helper.GetSpeed ();
6e7d48a8c120 add MobilityModel::GetSpeed method and implement it in all mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1620
diff changeset
   206
}
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   207
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   208
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   209
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   210
} // namespace ns3