src/mobility/random-direction-2d-mobility-model.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Thu, 19 Jul 2007 12:38:30 +0200
changeset 1637 b2f8c2acf04a
parent 1635 src/node/random-direction-2d-mobility-model.cc@935bed1e13e7
child 1656 99949986bb92
permissions -rw-r--r--
create a mobility module
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"
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    27
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    28
namespace ns3 {
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    29
1626
feaecfd93b5d RandomDirection -> RandomDirection2d
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1625
diff changeset
    30
const double RandomDirection2dMobilityModel::PI = 3.1415;
feaecfd93b5d RandomDirection -> RandomDirection2d
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1625
diff changeset
    31
const ClassId RandomDirection2dMobilityModel::cid = 
feaecfd93b5d RandomDirection -> RandomDirection2d
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1625
diff changeset
    32
  MakeClassId<RandomDirection2dMobilityModel> ("RandomDirection2dMobilityModel",
1634
2bf997301257 more dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1626
diff changeset
    33
                                               MobilityModel::iid);
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    34
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    35
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    36
static RandomVariableDefaultValue 
1626
feaecfd93b5d RandomDirection -> RandomDirection2d
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1625
diff changeset
    37
  g_speedVariable ("RandomDirection2dSpeed",
feaecfd93b5d RandomDirection -> RandomDirection2d
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1625
diff changeset
    38
		   "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
    39
		   "Uniform:1:2");
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    40
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    41
static RandomVariableDefaultValue
1626
feaecfd93b5d RandomDirection -> RandomDirection2d
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1625
diff changeset
    42
  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
    43
		   "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
    44
                   "of the pause of a RandomDiretion mobility model.",
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    45
		   "Constant:2");
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    46
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    47
static RectangleDefaultValue
1626
feaecfd93b5d RandomDirection -> RandomDirection2d
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1625
diff changeset
    48
  g_bounds ("RandomDirection2dArea",
feaecfd93b5d RandomDirection -> RandomDirection2d
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1625
diff changeset
    49
	       "The bounding area for the RandomDirection2d model.",
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    50
	       -100, 100, -100, 100);
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    51
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    52
1635
935bed1e13e7 RandomDirection2dParameters -> RandomDirection2dMobilityModelParameters
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1634
diff changeset
    53
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
    54
  : 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
    55
    m_speedVariable (g_speedVariable.GetCopy ()),
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    56
    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
    57
    
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
{}
1635
935bed1e13e7 RandomDirection2dParameters -> RandomDirection2dMobilityModelParameters
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1634
diff changeset
    59
RandomDirection2dMobilityModelParameters::RandomDirection2dMobilityModelParameters 
935bed1e13e7 RandomDirection2dParameters -> RandomDirection2dMobilityModelParameters
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1634
diff changeset
    60
(const Rectangle &bounds,
935bed1e13e7 RandomDirection2dParameters -> RandomDirection2dMobilityModelParameters
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1634
diff changeset
    61
 const RandomVariable &speedVariable,
935bed1e13e7 RandomDirection2dParameters -> RandomDirection2dMobilityModelParameters
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1634
diff changeset
    62
 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
    63
  : 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
    64
    m_speedVariable (speedVariable.Copy ()),
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    65
    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
    66
{}
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    67
1635
935bed1e13e7 RandomDirection2dParameters -> RandomDirection2dMobilityModelParameters
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1634
diff changeset
    68
RandomDirection2dMobilityModelParameters::~RandomDirection2dMobilityModelParameters ()
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    69
{
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    70
  delete m_speedVariable;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    71
  delete m_pauseVariable;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    72
  m_speedVariable = 0;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    73
  m_pauseVariable = 0;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    74
}
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    75
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    76
void 
1635
935bed1e13e7 RandomDirection2dParameters -> RandomDirection2dMobilityModelParameters
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1634
diff changeset
    77
RandomDirection2dMobilityModelParameters::SetSpeed (const RandomVariable &speedVariable)
1575
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
  delete m_speedVariable;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    80
  m_speedVariable = speedVariable.Copy ();
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
void 
1635
935bed1e13e7 RandomDirection2dParameters -> RandomDirection2dMobilityModelParameters
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1634
diff changeset
    83
RandomDirection2dMobilityModelParameters::SetPause (const RandomVariable &pauseVariable)
1575
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
  delete m_pauseVariable;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    86
  m_pauseVariable = pauseVariable.Copy ();
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
void 
1635
935bed1e13e7 RandomDirection2dParameters -> RandomDirection2dMobilityModelParameters
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1634
diff changeset
    89
RandomDirection2dMobilityModelParameters::SetBounds (const Rectangle &bounds)
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    90
{
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
    91
  m_bounds = bounds;
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    92
}
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    93
1635
935bed1e13e7 RandomDirection2dParameters -> RandomDirection2dMobilityModelParameters
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1634
diff changeset
    94
Ptr<RandomDirection2dMobilityModelParameters> 
935bed1e13e7 RandomDirection2dParameters -> RandomDirection2dMobilityModelParameters
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1634
diff changeset
    95
RandomDirection2dMobilityModelParameters::GetCurrent (void)
1575
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
  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
    98
  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
    99
      g_bounds.IsDirty () ||
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   100
      g_speedVariable.IsDirty () ||
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   101
      g_pauseVariable.IsDirty ())
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   102
    {
1635
935bed1e13e7 RandomDirection2dParameters -> RandomDirection2dMobilityModelParameters
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1634
diff changeset
   103
      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
   104
      g_bounds.ClearDirtyFlag ();
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   105
      g_speedVariable.ClearDirtyFlag ();
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   106
      g_pauseVariable.ClearDirtyFlag ();
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   107
    }
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   108
  return parameters;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   109
}
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
1626
feaecfd93b5d RandomDirection -> RandomDirection2d
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1625
diff changeset
   112
RandomDirection2dMobilityModel::RandomDirection2dMobilityModel ()
1635
935bed1e13e7 RandomDirection2dParameters -> RandomDirection2dMobilityModelParameters
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1634
diff changeset
   113
  : 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
   114
{
1626
feaecfd93b5d RandomDirection -> RandomDirection2d
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1625
diff changeset
   115
  SetInterfaceId (RandomDirection2dMobilityModel::iid);
feaecfd93b5d RandomDirection -> RandomDirection2d
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1625
diff changeset
   116
  m_event = Simulator::ScheduleNow (&RandomDirection2dMobilityModel::Start, this);
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   117
}
1635
935bed1e13e7 RandomDirection2dParameters -> RandomDirection2dMobilityModelParameters
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1634
diff changeset
   118
RandomDirection2dMobilityModel::RandomDirection2dMobilityModel 
935bed1e13e7 RandomDirection2dParameters -> RandomDirection2dMobilityModelParameters
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1634
diff changeset
   119
(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
   120
  : m_parameters (parameters)
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   121
{
1626
feaecfd93b5d RandomDirection -> RandomDirection2d
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1625
diff changeset
   122
  SetInterfaceId (RandomDirection2dMobilityModel::iid);
feaecfd93b5d RandomDirection -> RandomDirection2d
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1625
diff changeset
   123
  m_event = Simulator::ScheduleNow (&RandomDirection2dMobilityModel::Start, this);
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   124
}
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   125
void 
1626
feaecfd93b5d RandomDirection -> RandomDirection2d
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1625
diff changeset
   126
RandomDirection2dMobilityModel::DoDispose (void)
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
  m_parameters = 0;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   129
  // chain up.
1579
a4187ed1e45e Position -> MobilityModel
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1575
diff changeset
   130
  MobilityModel::DoDispose ();
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   131
}
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   132
void
1626
feaecfd93b5d RandomDirection -> RandomDirection2d
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1625
diff changeset
   133
RandomDirection2dMobilityModel::Start (void)
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
  double direction = UniformVariable::GetSingleValue (0, 2 * PI);
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   136
  SetDirectionAndSpeed (direction);
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
void
1626
feaecfd93b5d RandomDirection -> RandomDirection2d
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1625
diff changeset
   139
RandomDirection2dMobilityModel::SetDirectionAndSpeed (double direction)
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   140
{
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   141
  double speed = m_parameters->m_speedVariable->GetValue ();
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
   142
  const Speed vector (std::cos (direction) * speed,
69baa7b1c487 remove mobility model helper, re-enable random direction model with new helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1591
diff changeset
   143
                      std::sin (direction) * speed,
69baa7b1c487 remove mobility model helper, re-enable random direction model with new helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1591
diff changeset
   144
                      0.0);
1591
4a1f822fe9aa split useful code out of random direction mobility model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1584
diff changeset
   145
  Time pause = Seconds (m_parameters->m_pauseVariable->GetValue ());
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
   146
  Position position = m_helper.GetCurrentPosition (m_parameters->m_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
   147
  m_helper.Reset (vector, pause);
69baa7b1c487 remove mobility model helper, re-enable random direction model with new helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1591
diff changeset
   148
  Position next = m_parameters->m_bounds.CalculateIntersection (position, vector);
69baa7b1c487 remove mobility model helper, re-enable random direction model with new helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1591
diff changeset
   149
  Time delay = Seconds (CalculateDistance (position, next) / speed);
1591
4a1f822fe9aa split useful code out of random direction mobility model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1584
diff changeset
   150
  m_event = Simulator::Schedule (delay + pause,
1626
feaecfd93b5d RandomDirection -> RandomDirection2d
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1625
diff changeset
   151
				 &RandomDirection2dMobilityModel::ResetDirectionAndSpeed, 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
   152
  NotifyCourseChange ();
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   153
}
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   154
void
1626
feaecfd93b5d RandomDirection -> RandomDirection2d
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1625
diff changeset
   155
RandomDirection2dMobilityModel::ResetDirectionAndSpeed (void)
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   156
{
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   157
  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
   158
  
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
   159
  Position position = m_helper.GetCurrentPosition (m_parameters->m_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
   160
  switch (m_parameters->m_bounds.GetClosestSide (position))
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   161
    {
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
    case Rectangle::RIGHT:
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   163
      direction += PI / 2;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   164
      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
   165
    case Rectangle::LEFT:
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   166
      direction += - PI / 2;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   167
      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
   168
    case Rectangle::TOP:
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   169
      direction += PI;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   170
      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
   171
    case Rectangle::BOTTOM:
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   172
      direction += 0.0;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   173
      break;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   174
    }
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   175
  SetDirectionAndSpeed (direction);
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   176
}
1584
b612c5fe9e6b new version of DoGet and DoSet
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1580
diff changeset
   177
Position
1626
feaecfd93b5d RandomDirection -> RandomDirection2d
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1625
diff changeset
   178
RandomDirection2dMobilityModel::DoGet (void) const
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   179
{
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
   180
  return m_helper.GetCurrentPosition (m_parameters->m_bounds);
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   181
}
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   182
void
1626
feaecfd93b5d RandomDirection -> RandomDirection2d
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1625
diff changeset
   183
RandomDirection2dMobilityModel::DoSet (const Position &position)
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   184
{
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
   185
  m_helper.InitializePosition (position);
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   186
  Simulator::Remove (m_event);
1626
feaecfd93b5d RandomDirection -> RandomDirection2d
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1625
diff changeset
   187
  m_event = Simulator::ScheduleNow (&RandomDirection2dMobilityModel::Start, this);
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   188
}
1624
6e7d48a8c120 add MobilityModel::GetSpeed method and implement it in all mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1620
diff changeset
   189
Speed 
1626
feaecfd93b5d RandomDirection -> RandomDirection2d
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1625
diff changeset
   190
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
   191
{
6e7d48a8c120 add MobilityModel::GetSpeed method and implement it in all mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1620
diff changeset
   192
  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
   193
}
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
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   196
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   197
} // namespace ns3