src/node/random-direction-mobility-model.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Wed, 04 Jul 2007 10:15:18 +0200
changeset 1580 0d2cf8839aee
parent 1579 src/node/random-direction-position.cc@a4187ed1e45e
child 1584 b612c5fe9e6b
permissions -rw-r--r--
position.h -> mobility-model.h
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>
1580
0d2cf8839aee position.h -> mobility-model.h
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1579
diff changeset
    26
#include "random-direction-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 = 
a4187ed1e45e Position -> MobilityModel
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1575
diff changeset
    34
  MakeClassId<RandomDirectionMobilityModel,double,double> ("RandomDirectionMobilityModel",
a4187ed1e45e Position -> MobilityModel
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1575
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",
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    45
		   "A random variable to control the duration of of the pause of a RandomDiretion mobility model.",
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    46
		   "Constant:2");
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    47
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    48
static RectangleDefaultValue
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    49
  g_rectangle ("RandomDirectionArea",
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    50
	       "The bounding area for the RandomDirection model.",
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    51
	       -100, 100, -100, 100);
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    52
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
RandomDirectionParameters::RandomDirectionParameters ()
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    55
  : m_xMin (g_rectangle.GetMinX ()),
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    56
    m_xMax (g_rectangle.GetMaxX ()),
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    57
    m_yMin (g_rectangle.GetMinY ()),
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    58
    m_yMax (g_rectangle.GetMaxY ()),
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    59
    m_speedVariable (g_speedVariable.GetCopy ()),
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    60
    m_pauseVariable (g_pauseVariable.GetCopy ())
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    61
{}
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    62
RandomDirectionParameters::RandomDirectionParameters (double xMin, double xMax, double yMin, double yMax)
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    63
  : m_xMin (xMin),
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    64
    m_xMax (xMax),
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    65
    m_yMin (yMin),
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    66
    m_yMax (yMax),
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    67
    m_speedVariable (g_speedVariable.GetCopy ()),
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    68
    m_pauseVariable (g_pauseVariable.GetCopy ())
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
RandomDirectionParameters::RandomDirectionParameters (double xMin, double xMax, double yMin, double yMax,
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    71
						      const RandomVariable &speedVariable,
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    72
						      const RandomVariable &pauseVariable)
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    73
  : m_xMin (xMin),
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    74
    m_xMax (xMax),
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    75
    m_yMin (yMin),
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    76
    m_yMax (yMax),
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    77
    m_speedVariable (speedVariable.Copy ()),
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    78
    m_pauseVariable (pauseVariable.Copy ())
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
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    81
RandomDirectionParameters::~RandomDirectionParameters ()
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
  delete m_speedVariable;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    84
  delete m_pauseVariable;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    85
  m_speedVariable = 0;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    86
  m_pauseVariable = 0;
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
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    89
void 
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    90
RandomDirectionParameters::SetSpeed (const RandomVariable &speedVariable)
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    91
{
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    92
  delete m_speedVariable;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    93
  m_speedVariable = speedVariable.Copy ();
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
void 
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    96
RandomDirectionParameters::SetPause (const RandomVariable &pauseVariable)
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    97
{
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    98
  delete m_pauseVariable;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    99
  m_pauseVariable = pauseVariable.Copy ();
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   100
}
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   101
void 
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   102
RandomDirectionParameters::SetBounds (double xMin, double xMax, double yMin, double yMax)
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
  m_xMin = xMin;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   105
  m_yMin = yMin;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   106
  m_xMax = xMax;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   107
  m_yMax = yMax;
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
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   110
Ptr<RandomDirectionParameters> 
1579
a4187ed1e45e Position -> MobilityModel
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1575
diff changeset
   111
RandomDirectionMobilityModel::GetDefaultParameters (void)
1575
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
  static Ptr<RandomDirectionParameters> parameters = Create<RandomDirectionParameters> ();
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   114
  if (parameters->m_xMin != g_rectangle.GetMinX () ||
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   115
      parameters->m_yMin != g_rectangle.GetMinY () ||
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   116
      parameters->m_xMax != g_rectangle.GetMaxX () ||
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   117
      parameters->m_yMax != g_rectangle.GetMaxY () ||
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   118
      g_speedVariable.IsDirty () ||
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   119
      g_pauseVariable.IsDirty ())
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   120
    {
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   121
      parameters = Create<RandomDirectionParameters> ();
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   122
      g_speedVariable.ClearDirtyFlag ();
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   123
      g_pauseVariable.ClearDirtyFlag ();
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
  return parameters;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   126
}
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
1579
a4187ed1e45e Position -> MobilityModel
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1575
diff changeset
   129
RandomDirectionMobilityModel::RandomDirectionMobilityModel ()
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   130
  : m_parameters (GetDefaultParameters ()),
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   131
    m_x (0.0),
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   132
    m_y (0.0),
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   133
    m_dx (0.0),
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   134
    m_dy (0.0),
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   135
    m_prevTime (Simulator::Now ()),
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   136
    m_pauseStart (Simulator::Now ())
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   137
{
1579
a4187ed1e45e Position -> MobilityModel
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1575
diff changeset
   138
  SetInterfaceId (RandomDirectionMobilityModel::iid);
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   139
  InitializeDirectionAndSpeed ();
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
bool
1579
a4187ed1e45e Position -> MobilityModel
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1575
diff changeset
   142
RandomDirectionMobilityModel::CheckMobilityModel (void) const
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   143
{
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   144
  return 
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   145
    m_x <= m_parameters->m_xMax && 
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   146
    m_x >= m_parameters->m_xMin &&
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   147
    m_y <= m_parameters->m_yMax && 
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   148
    m_y >= m_parameters->m_yMin;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   149
}
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   150
1579
a4187ed1e45e Position -> MobilityModel
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1575
diff changeset
   151
RandomDirectionMobilityModel::RandomDirectionMobilityModel (double x, double y)
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   152
  : m_parameters (GetDefaultParameters ()),
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   153
    m_x (x),
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   154
    m_y (y),
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   155
    m_dx (0.0),
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   156
    m_dy (0.0),
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   157
    m_prevTime (Simulator::Now ()),
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   158
    m_pauseStart (Simulator::Now ())
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   159
{
1579
a4187ed1e45e Position -> MobilityModel
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1575
diff changeset
   160
  SetInterfaceId (RandomDirectionMobilityModel::iid);
a4187ed1e45e Position -> MobilityModel
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1575
diff changeset
   161
  NS_ASSERT (CheckMobilityModel ());
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   162
  InitializeDirectionAndSpeed ();
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   163
}
1579
a4187ed1e45e Position -> MobilityModel
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1575
diff changeset
   164
RandomDirectionMobilityModel::RandomDirectionMobilityModel (Ptr<RandomDirectionParameters> parameters)
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   165
  : m_parameters (parameters),
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   166
    m_x (0.0),
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   167
    m_y (0.0),
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   168
    m_dx (0.0),
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   169
    m_dy (0.0),
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   170
    m_prevTime (Simulator::Now ()),
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   171
    m_pauseStart (Simulator::Now ())
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   172
{
1579
a4187ed1e45e Position -> MobilityModel
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1575
diff changeset
   173
  SetInterfaceId (RandomDirectionMobilityModel::iid);
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   174
  InitializeDirectionAndSpeed ();
1579
a4187ed1e45e Position -> MobilityModel
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1575
diff changeset
   175
  NS_ASSERT (CheckMobilityModel ());
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   176
}
1579
a4187ed1e45e Position -> MobilityModel
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1575
diff changeset
   177
RandomDirectionMobilityModel::RandomDirectionMobilityModel (Ptr<RandomDirectionParameters> parameters,
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   178
						  double x, double y)
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   179
  : m_parameters (parameters),
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   180
    m_x (x),
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   181
    m_y (y),
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   182
    m_dx (0.0),
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   183
    m_dy (0.0),
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   184
    m_prevTime (Simulator::Now ()),
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   185
    m_pauseStart (Simulator::Now ())
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   186
{
1579
a4187ed1e45e Position -> MobilityModel
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1575
diff changeset
   187
  SetInterfaceId (RandomDirectionMobilityModel::iid);
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   188
  InitializeDirectionAndSpeed ();
1579
a4187ed1e45e Position -> MobilityModel
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1575
diff changeset
   189
  NS_ASSERT (CheckMobilityModel ());
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   190
}
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   191
void 
1579
a4187ed1e45e Position -> MobilityModel
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1575
diff changeset
   192
RandomDirectionMobilityModel::DoDispose (void)
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   193
{
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   194
  m_parameters = 0;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   195
  // chain up.
1579
a4187ed1e45e Position -> MobilityModel
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1575
diff changeset
   196
  MobilityModel::DoDispose ();
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   197
}
1579
a4187ed1e45e Position -> MobilityModel
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1575
diff changeset
   198
enum RandomDirectionMobilityModel::Side
a4187ed1e45e Position -> MobilityModel
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1575
diff changeset
   199
RandomDirectionMobilityModel::CalculateIntersection (double &x, double &y)
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   200
{
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   201
  double xMin = m_parameters->m_xMin;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   202
  double xMax = m_parameters->m_xMax;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   203
  double yMin = m_parameters->m_yMin;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   204
  double yMax = m_parameters->m_yMax;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   205
  double xMaxY = m_y + (xMax - m_x) / m_dx * m_dy;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   206
  double xMinY = m_y + (xMin - m_x) / m_dx * m_dy;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   207
  double yMaxX = m_x + (yMax - m_y) / m_dy * m_dx;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   208
  double yMinX = m_x + (yMin - m_y) / m_dy * m_dx;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   209
  bool xMaxOk = xMaxY <= yMax && xMaxY >= yMin;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   210
  bool xMinOk = xMinY <= yMax && xMinY >= yMin;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   211
  bool yMaxOk = yMaxX <= xMax && yMaxX >= xMin;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   212
  bool yMinOk = yMinX <= xMax && yMinX >= xMin;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   213
  if (xMaxOk && m_dx >= 0)
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   214
    {
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   215
      x = xMax;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   216
      y = xMaxY;
1579
a4187ed1e45e Position -> MobilityModel
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1575
diff changeset
   217
      return RandomDirectionMobilityModel::RIGHT;
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   218
    }
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   219
  else if (xMinOk && m_dx <= 0)
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   220
    {
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   221
      x = xMin;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   222
      y = xMinY;
1579
a4187ed1e45e Position -> MobilityModel
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1575
diff changeset
   223
      return RandomDirectionMobilityModel::LEFT;
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   224
    }
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   225
  else if (yMaxOk && m_dy >= 0)
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   226
    {
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   227
      x = yMaxX;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   228
      y = yMax;
1579
a4187ed1e45e Position -> MobilityModel
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1575
diff changeset
   229
      return RandomDirectionMobilityModel::TOP;
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   230
    }
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   231
  else if (yMinOk && m_dy <= 0)
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   232
    {
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   233
      x = yMinX;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   234
      y = yMin;
1579
a4187ed1e45e Position -> MobilityModel
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1575
diff changeset
   235
      return RandomDirectionMobilityModel::BOTTOM;
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   236
    }
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   237
  else
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   238
    {
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   239
      NS_ASSERT (false);
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   240
      // quiet compiler
1579
a4187ed1e45e Position -> MobilityModel
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1575
diff changeset
   241
      return RandomDirectionMobilityModel::RIGHT;
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   242
    }
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   243
}
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   244
void
1579
a4187ed1e45e Position -> MobilityModel
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1575
diff changeset
   245
RandomDirectionMobilityModel::InitializeDirectionAndSpeed (void)
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   246
{
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   247
  double direction = UniformVariable::GetSingleValue (0, 2 * PI);
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   248
  SetDirectionAndSpeed (direction);
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   249
}
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   250
void
1579
a4187ed1e45e Position -> MobilityModel
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1575
diff changeset
   251
RandomDirectionMobilityModel::SetDirectionAndSpeed (double direction)
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   252
{
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   253
  double speed = m_parameters->m_speedVariable->GetValue ();
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   254
  m_dx = std::cos (direction) * speed;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   255
  m_dy = std::sin (direction) * speed;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   256
  double x, y;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   257
  m_side = CalculateIntersection (x, y);
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   258
  double deltaX = x - m_x;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   259
  double deltaY = y - m_y;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   260
  double distance = sqrt (deltaX * deltaX + deltaY * deltaY);
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   261
  double seconds = distance / speed;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   262
  double pause = m_parameters->m_pauseVariable->GetValue ();
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   263
  m_pauseStart = Simulator::Now () + Seconds (seconds);
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   264
  m_prevTime = Simulator::Now ();
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   265
  m_event = Simulator::Schedule (Seconds (seconds + pause),
1579
a4187ed1e45e Position -> MobilityModel
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1575
diff changeset
   266
				 &RandomDirectionMobilityModel::ResetDirectionAndSpeed, this);
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   267
}
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   268
void
1579
a4187ed1e45e Position -> MobilityModel
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1575
diff changeset
   269
RandomDirectionMobilityModel::ResetDirectionAndSpeed (void)
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   270
{
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   271
  Update ();
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   272
  double direction = UniformVariable::GetSingleValue (0, PI);
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   273
  switch (m_side)
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   274
    {
1579
a4187ed1e45e Position -> MobilityModel
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1575
diff changeset
   275
    case RandomDirectionMobilityModel::RIGHT:
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   276
      direction += PI / 2;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   277
      break;
1579
a4187ed1e45e Position -> MobilityModel
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1575
diff changeset
   278
    case RandomDirectionMobilityModel::LEFT:
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   279
      direction += - PI / 2;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   280
      break;
1579
a4187ed1e45e Position -> MobilityModel
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1575
diff changeset
   281
    case RandomDirectionMobilityModel::TOP:
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   282
      direction += PI;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   283
      break;
1579
a4187ed1e45e Position -> MobilityModel
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1575
diff changeset
   284
    case RandomDirectionMobilityModel::BOTTOM:
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   285
      direction += 0.0;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   286
      break;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   287
    }
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   288
  SetDirectionAndSpeed (direction);
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   289
  NotifyCourseChange ();
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   290
}
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   291
void
1579
a4187ed1e45e Position -> MobilityModel
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1575
diff changeset
   292
RandomDirectionMobilityModel::Update (void) const
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   293
{
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   294
  Time end = std::min (Simulator::Now (), m_pauseStart);
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   295
  if (m_prevTime >= end)
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   296
    {
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   297
      return;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   298
    }
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   299
  Time deltaTime = end - m_prevTime;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   300
  m_prevTime = Simulator::Now ();
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   301
  double deltaS = deltaTime.GetSeconds ();
1579
a4187ed1e45e Position -> MobilityModel
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1575
diff changeset
   302
  NS_ASSERT (CheckMobilityModel ());
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   303
  m_x += m_dx * deltaS;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   304
  m_y += m_dy * deltaS;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   305
  // round to closest boundaries.
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   306
  m_x = std::min (m_x, m_parameters->m_xMax);
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   307
  m_x = std::max (m_x, m_parameters->m_xMin);
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   308
  m_y = std::min (m_y, m_parameters->m_yMax);
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   309
  m_y = std::max (m_y, m_parameters->m_yMin);
1579
a4187ed1e45e Position -> MobilityModel
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1575
diff changeset
   310
  NS_ASSERT (CheckMobilityModel ());
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   311
}
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   312
void 
1579
a4187ed1e45e Position -> MobilityModel
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1575
diff changeset
   313
RandomDirectionMobilityModel::DoGet (double &x, double &y, double &z) const
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   314
{
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   315
  Update ();
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   316
  x = m_x;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   317
  y = m_y;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   318
  z = 0;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   319
}
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   320
void
1579
a4187ed1e45e Position -> MobilityModel
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1575
diff changeset
   321
RandomDirectionMobilityModel::DoSet (double x, double y, double z)
1575
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   322
{
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   323
  bool changed = false;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   324
  if (m_x != x || m_y != y)
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   325
    {
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   326
      changed = true;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   327
    }
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   328
  m_x = x;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   329
  m_y = y;
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   330
  m_prevTime = Simulator::Now ();
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   331
  m_pauseStart = Simulator::Now ();
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   332
  Simulator::Remove (m_event);
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   333
  InitializeDirectionAndSpeed ();
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   334
  NotifyCourseChange ();
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   335
}
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   336
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   337
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   338
cbc37ce4b91d RandomDirection model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   339
} // namespace ns3