src/node/random-direction-2d-mobility-model.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Thu, 19 Jul 2007 10:30:18 +0200
changeset 1625 0579a50b2c62
parent 1624 src/node/random-direction-mobility-model.cc@6e7d48a8c120
child 1626 feaecfd93b5d
permissions -rw-r--r--
random-direction -> random-direction-2d
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
1579
a4187ed1e45e Position -> MobilityModel
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1575
diff changeset
    30
const double RandomDirectionMobilityModel::PI = 3.1415;
a4187ed1e45e Position -> MobilityModel
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1575
diff changeset
    31
const InterfaceId RandomDirectionMobilityModel::iid = 
a4187ed1e45e Position -> MobilityModel
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1575
diff changeset
    32
  MakeInterfaceId ("RandomDirectionMobilityModel", MobilityModel::iid);
a4187ed1e45e Position -> MobilityModel
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1575
diff changeset
    33
const ClassId RandomDirectionMobilityModel::cid = 
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
    34
  MakeClassId<RandomDirectionMobilityModel> ("RandomDirectionMobilityModel",
69baa7b1c487 remove mobility model helper, re-enable random direction model with new helper
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1591
diff changeset
    35
                                             RandomDirectionMobilityModel::iid);
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    36
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
static RandomVariableDefaultValue 
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    39
  g_speedVariable ("RandomDirectionSpeed",
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    40
		   "A random variable to control the speed of a RandomDirection mobility model.",
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    41
		   "Uniform:1:2");
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    42
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    43
static RandomVariableDefaultValue
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    44
  g_pauseVariable ("RandomDirectionPause",
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
    45
		   "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
    46
                   "of the pause of a RandomDiretion mobility model.",
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    47
		   "Constant:2");
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    48
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    49
static RectangleDefaultValue
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
    50
  g_bounds ("RandomDirectionArea",
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    51
	       "The bounding area for the RandomDirection model.",
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    52
	       -100, 100, -100, 100);
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    53
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
RandomDirectionParameters::RandomDirectionParameters ()
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
    56
  : 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
    57
    m_speedVariable (g_speedVariable.GetCopy ()),
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    58
    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
    59
    
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
RandomDirectionParameters::RandomDirectionParameters (const Rectangle &bounds,
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    62
						      const RandomVariable &speedVariable,
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    63
						      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
    64
  : 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
    65
    m_speedVariable (speedVariable.Copy ()),
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    66
    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
    67
{}
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    68
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    69
RandomDirectionParameters::~RandomDirectionParameters ()
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    70
{
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    71
  delete m_speedVariable;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    72
  delete m_pauseVariable;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    73
  m_speedVariable = 0;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    74
  m_pauseVariable = 0;
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
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    77
void 
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    78
RandomDirectionParameters::SetSpeed (const RandomVariable &speedVariable)
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    79
{
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    80
  delete m_speedVariable;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    81
  m_speedVariable = speedVariable.Copy ();
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    82
}
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    83
void 
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    84
RandomDirectionParameters::SetPause (const RandomVariable &pauseVariable)
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    85
{
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    86
  delete m_pauseVariable;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    87
  m_pauseVariable = pauseVariable.Copy ();
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    88
}
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    89
void 
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
    90
RandomDirectionParameters::SetBounds (const Rectangle &bounds)
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    91
{
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
    92
  m_bounds = bounds;
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    93
}
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    94
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    95
Ptr<RandomDirectionParameters> 
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
    96
RandomDirectionParameters::GetCurrent (void)
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    97
{
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
  static Ptr<RandomDirectionParameters> 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
  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
   100
      g_bounds.IsDirty () ||
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   101
      g_speedVariable.IsDirty () ||
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   102
      g_pauseVariable.IsDirty ())
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   103
    {
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   104
      parameters = Create<RandomDirectionParameters> ();
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
   105
      g_bounds.ClearDirtyFlag ();
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   106
      g_speedVariable.ClearDirtyFlag ();
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   107
      g_pauseVariable.ClearDirtyFlag ();
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   108
    }
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   109
  return parameters;
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
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   112
1579
a4187ed1e45e Position -> MobilityModel
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1575
diff changeset
   113
RandomDirectionMobilityModel::RandomDirectionMobilityModel ()
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
   114
  : m_parameters (RandomDirectionParameters::GetCurrent ())
1591
4a1f822fe9aa split useful code out of random direction mobility model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1584
diff changeset
   115
{
4a1f822fe9aa split useful code out of random direction mobility model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1584
diff changeset
   116
  SetInterfaceId (RandomDirectionMobilityModel::iid);
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
   117
  m_event = Simulator::ScheduleNow (&RandomDirectionMobilityModel::Start, this);
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   118
}
1579
a4187ed1e45e Position -> MobilityModel
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1575
diff changeset
   119
RandomDirectionMobilityModel::RandomDirectionMobilityModel (Ptr<RandomDirectionParameters> 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
{
1579
a4187ed1e45e Position -> MobilityModel
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1575
diff changeset
   122
  SetInterfaceId (RandomDirectionMobilityModel::iid);
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
   123
  m_event = Simulator::ScheduleNow (&RandomDirectionMobilityModel::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 
1579
a4187ed1e45e Position -> MobilityModel
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1575
diff changeset
   126
RandomDirectionMobilityModel::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
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
   133
RandomDirectionMobilityModel::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
1579
a4187ed1e45e Position -> MobilityModel
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1575
diff changeset
   139
RandomDirectionMobilityModel::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,
1579
a4187ed1e45e Position -> MobilityModel
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1575
diff changeset
   151
				 &RandomDirectionMobilityModel::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
1579
a4187ed1e45e Position -> MobilityModel
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1575
diff changeset
   155
RandomDirectionMobilityModel::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
b612c5fe9e6b new version of DoGet and DoSet
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1580
diff changeset
   178
RandomDirectionMobilityModel::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
1584
b612c5fe9e6b new version of DoGet and DoSet
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1580
diff changeset
   183
RandomDirectionMobilityModel::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);
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
   187
  m_event = Simulator::ScheduleNow (&RandomDirectionMobilityModel::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 
6e7d48a8c120 add MobilityModel::GetSpeed method and implement it in all mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1620
diff changeset
   190
RandomDirectionMobilityModel::DoGetSpeed (void) const
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