blob: 9ad52ba9e20c7a0486c98ef480c40e99c8e501a3 [file] [log] [blame]
Alexander Afanasyeveaba1572012-02-04 14:20:30 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2007 INRIA
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Author: Lucas Wang <lucas@cs.ucla.edu>
19 */
20
21
22#include "highway-position-allocator.h"
23#include "ns3/random-variable.h"
24#include "ns3/log.h"
25#include "ns3/double.h"
26#include <math.h>
27
28NS_LOG_COMPONENT_DEFINE ("HighwayPositionAllocator");
29
30namespace ns3 {
31
32NS_OBJECT_ENSURE_REGISTERED (HighwayPositionAllocator);
33
34TypeId HighwayPositionAllocator::GetTypeId (void){
35 static TypeId tid = TypeId("ns3::HighwayPositionAllocator").
36 SetParent<PositionAllocator> ().
37 SetGroupName("Mobility").
38 AddConstructor<HighwayPositionAllocator>().
39 AddAttribute("Start", "the start position of the highway",
40 VectorValue (Vector(0.0, 0.0, 0.0)),
41 MakeVectorAccessor(&HighwayPositionAllocator::SetStartPosition,
42 &HighwayPositionAllocator::GetStartPosition),
43 MakeVectorChecker ()).
44 AddAttribute("Direction", "the direction of the highway",
45 DoubleValue (0.0),
46 MakeDoubleAccessor(&HighwayPositionAllocator::SetDirection,
47 &HighwayPositionAllocator::GetDirection),
48 MakeDoubleChecker<double> ()).
49 AddAttribute("Length", "the length of the highway",
50 DoubleValue (0.0),
51 MakeDoubleAccessor(&HighwayPositionAllocator::SetLength,
52 &HighwayPositionAllocator::GetLength),
53 MakeDoubleChecker<double> ());
54
55 return tid;
56}
57
58HighwayPositionAllocator::HighwayPositionAllocator (){
59 m_previous_position = Vector(0.0, 0.0, 0.0);
60}
61
62Vector HighwayPositionAllocator::GetNext (void) const{
63 UniformVariable random_gap_var (1.0, 10.0);
64 double random_gap = random_gap_var.GetValue();
65
66 double delta_x = random_gap * cos(m_direction);
67 double delta_y = random_gap * sin(m_direction);
68
69
70 Vector new_position(m_previous_position.x - delta_x, m_previous_position.y - delta_y, m_previous_position.z);
71 m_previous_position.x = new_position.x;
72 m_previous_position.y = new_position.y;
73 m_previous_position.z = new_position.z;
74
75 return new_position;
76}
77
78void HighwayPositionAllocator::SetStartPosition(Vector start){
79 m_start = start;
80 m_previous_position = m_start; // initialize the m_previous_position to be start of the highway
81}
82
83Vector HighwayPositionAllocator::GetStartPosition(void) const {
84 return m_start;
85}
86
87void HighwayPositionAllocator::SetDirection(double direction){
88 m_direction = direction;
89}
90
91double HighwayPositionAllocator::GetDirection(void) const {
92 return m_direction;
93}
94
95void HighwayPositionAllocator::SetLength(double length){
96 m_length = length;
97}
98
99double HighwayPositionAllocator::GetLength(void) const {
100 return m_length;
101}
102
103}