22 #include "highway-position-allocator.h"
23 #include "ns3/random-variable.h"
25 #include "ns3/double.h"
28 NS_LOG_COMPONENT_DEFINE (
"HighwayPositionAllocator");
32 NS_OBJECT_ENSURE_REGISTERED (HighwayPositionAllocator);
34 TypeId 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",
46 MakeDoubleAccessor(&HighwayPositionAllocator::SetDirection,
47 &HighwayPositionAllocator::GetDirection),
48 MakeDoubleChecker<double> ()).
49 AddAttribute(
"Length",
"the length of the highway",
51 MakeDoubleAccessor(&HighwayPositionAllocator::SetLength,
52 &HighwayPositionAllocator::GetLength),
53 MakeDoubleChecker<double> ());
58 HighwayPositionAllocator::HighwayPositionAllocator ()
59 : m_previous_position (Vector (0.0, 0.0, 0.0))
63 Vector HighwayPositionAllocator::GetNext (
void)
const{
64 double random_gap = m_random_gap_var.GetValue (1.0, 10.0);
66 double delta_x = random_gap * cos(m_direction);
67 double delta_y = random_gap * sin(m_direction);
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;
78 void HighwayPositionAllocator::SetStartPosition(Vector start){
80 m_previous_position = m_start;
83 Vector HighwayPositionAllocator::GetStartPosition(
void)
const {
87 void HighwayPositionAllocator::SetDirection(
double direction){
88 m_direction = direction;
91 double HighwayPositionAllocator::GetDirection(
void)
const {
95 void HighwayPositionAllocator::SetLength(
double length){
99 double HighwayPositionAllocator::GetLength(
void)
const {
105 HighwayPositionAllocator::AssignStreams (int64_t stream)
107 m_random_gap_var.SetStream (stream);