author | Marco Miozzo <marco.miozzo@cttc.es> |
Mon, 03 Jun 2013 17:01:52 +0200 | |
changeset 10080 | 1b36e2276e15 |
parent 8984 | 85eed149a0ea |
child 10081 | f0879d02aafd |
permissions | -rw-r--r-- |
8651
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
2 |
/* |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
3 |
* Copyright (C) 2012 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC) |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
4 |
* |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
5 |
* This program is free software; you can redistribute it and/or modify |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
6 |
* it under the terms of the GNU General Public License version 2 as |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation; |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
8 |
* |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
9 |
* This program is distributed in the hope that it will be useful, |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
12 |
* GNU General Public License for more details. |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
13 |
* |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
14 |
* You should have received a copy of the GNU General Public License |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
15 |
* along with this program; if not, write to the Free Software |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
16 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
17 |
* |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
18 |
* Author: Nicola Baldo <nbaldo@cttc.es> |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
19 |
*/ |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
20 |
#include "building-position-allocator.h" |
8689
04363f082bec
added SameRoomPositionAllocator
Nicola Baldo <nbaldo@cttc.es>
parents:
8651
diff
changeset
|
21 |
#include "ns3/buildings-mobility-model.h" |
10080
1b36e2276e15
Move from BuildingsMobilityModel to BuildingMobilityInfo source, tests and examples
Marco Miozzo <marco.miozzo@cttc.es>
parents:
8984
diff
changeset
|
22 |
#include "ns3/mobility-model.h" |
8746
e1cbf693c71d
fixed some bugs in SameRoomPositionAllocator
Nicola Baldo <nbaldo@cttc.es>
parents:
8689
diff
changeset
|
23 |
#include "ns3/buildings-helper.h" |
8984
85eed149a0ea
Replace src/mobility usage of RandomVariable with RandomVariableStream (Patch Set 2)
Mitch Watrous
parents:
8768
diff
changeset
|
24 |
#include "ns3/random-variable-stream.h" |
8651
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
25 |
#include "ns3/double.h" |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
26 |
#include "ns3/uinteger.h" |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
27 |
#include "ns3/enum.h" |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
28 |
#include "ns3/boolean.h" |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
29 |
#include "ns3/log.h" |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
30 |
#include "ns3/box.h" |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
31 |
#include "ns3/building.h" |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
32 |
#include <cmath> |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
33 |
|
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
34 |
#include "ns3/building-list.h" |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
35 |
|
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
36 |
NS_LOG_COMPONENT_DEFINE ("BuildingPositionAllocator"); |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
37 |
|
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
38 |
namespace ns3 { |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
39 |
|
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
40 |
NS_OBJECT_ENSURE_REGISTERED (RandomBuildingPositionAllocator); |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
41 |
|
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
42 |
|
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
43 |
RandomBuildingPositionAllocator::RandomBuildingPositionAllocator () |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
44 |
{ |
8984
85eed149a0ea
Replace src/mobility usage of RandomVariable with RandomVariableStream (Patch Set 2)
Mitch Watrous
parents:
8768
diff
changeset
|
45 |
m_rand = CreateObject<UniformRandomVariable> (); |
8651
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
46 |
} |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
47 |
|
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
48 |
TypeId |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
49 |
RandomBuildingPositionAllocator::GetTypeId (void) |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
50 |
{ |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
51 |
static TypeId tid = TypeId ("ns3::RandomBuildingPositionAllocator") |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
52 |
.SetParent<PositionAllocator> () |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
53 |
.SetGroupName ("Mobility") |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
54 |
.AddConstructor<RandomBuildingPositionAllocator> () |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
55 |
.AddAttribute ("WithReplacement", |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
56 |
"If true, the building will be randomly selected with replacement. " |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
57 |
"If false, no replacement will occur, until the list of buildings " |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
58 |
"to select becomes empty, at which point it will be filled again " |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
59 |
"with the list of all buildings.", |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
60 |
BooleanValue (false), |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
61 |
MakeBooleanAccessor (&RandomBuildingPositionAllocator::m_withReplacement), |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
62 |
MakeBooleanChecker ()); |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
63 |
return tid; |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
64 |
} |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
65 |
|
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
66 |
Vector |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
67 |
RandomBuildingPositionAllocator::GetNext () const |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
68 |
{ |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
69 |
NS_ASSERT_MSG (BuildingList::GetNBuildings () > 0, "no building found"); |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
70 |
Ptr<Building> b; |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
71 |
if (m_withReplacement) |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
72 |
{ |
8984
85eed149a0ea
Replace src/mobility usage of RandomVariable with RandomVariableStream (Patch Set 2)
Mitch Watrous
parents:
8768
diff
changeset
|
73 |
uint32_t n = m_rand->GetInteger (0, BuildingList::GetNBuildings () - 1); |
8651
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
74 |
b = BuildingList::GetBuilding (n); |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
75 |
} |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
76 |
else |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
77 |
{ |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
78 |
if (m_buildingListWithoutReplacement.empty ()) |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
79 |
{ |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
80 |
for (BuildingList::Iterator bit = BuildingList::Begin (); bit != BuildingList::End (); ++bit) |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
81 |
{ |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
82 |
m_buildingListWithoutReplacement.push_back (*bit); |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
83 |
} |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
84 |
} |
8984
85eed149a0ea
Replace src/mobility usage of RandomVariable with RandomVariableStream (Patch Set 2)
Mitch Watrous
parents:
8768
diff
changeset
|
85 |
uint32_t n = m_rand->GetInteger (0, m_buildingListWithoutReplacement.size () - 1); |
8651
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
86 |
b = m_buildingListWithoutReplacement.at (n); |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
87 |
m_buildingListWithoutReplacement.erase (m_buildingListWithoutReplacement.begin () + n); |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
88 |
} |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
89 |
|
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
90 |
Ptr<RandomBoxPositionAllocator> pa = CreateObject<RandomBoxPositionAllocator> (); |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
91 |
BoxValue bv; |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
92 |
b->GetAttribute ("Boundaries", bv); |
8984
85eed149a0ea
Replace src/mobility usage of RandomVariable with RandomVariableStream (Patch Set 2)
Mitch Watrous
parents:
8768
diff
changeset
|
93 |
double x = m_rand->GetValue (bv.Get ().xMin, bv.Get ().xMax); |
85eed149a0ea
Replace src/mobility usage of RandomVariable with RandomVariableStream (Patch Set 2)
Mitch Watrous
parents:
8768
diff
changeset
|
94 |
double y = m_rand->GetValue (bv.Get ().yMin, bv.Get ().yMax); |
85eed149a0ea
Replace src/mobility usage of RandomVariable with RandomVariableStream (Patch Set 2)
Mitch Watrous
parents:
8768
diff
changeset
|
95 |
double z = m_rand->GetValue (bv.Get ().zMin, bv.Get ().zMax); |
8651
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
96 |
return Vector (x, y, z); |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
97 |
} |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
98 |
|
8984
85eed149a0ea
Replace src/mobility usage of RandomVariable with RandomVariableStream (Patch Set 2)
Mitch Watrous
parents:
8768
diff
changeset
|
99 |
int64_t |
85eed149a0ea
Replace src/mobility usage of RandomVariable with RandomVariableStream (Patch Set 2)
Mitch Watrous
parents:
8768
diff
changeset
|
100 |
RandomBuildingPositionAllocator::AssignStreams (int64_t stream) |
85eed149a0ea
Replace src/mobility usage of RandomVariable with RandomVariableStream (Patch Set 2)
Mitch Watrous
parents:
8768
diff
changeset
|
101 |
{ |
85eed149a0ea
Replace src/mobility usage of RandomVariable with RandomVariableStream (Patch Set 2)
Mitch Watrous
parents:
8768
diff
changeset
|
102 |
m_rand->SetStream (stream); |
85eed149a0ea
Replace src/mobility usage of RandomVariable with RandomVariableStream (Patch Set 2)
Mitch Watrous
parents:
8768
diff
changeset
|
103 |
return 1; |
85eed149a0ea
Replace src/mobility usage of RandomVariable with RandomVariableStream (Patch Set 2)
Mitch Watrous
parents:
8768
diff
changeset
|
104 |
} |
8651
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
105 |
|
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
106 |
|
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
107 |
NS_OBJECT_ENSURE_REGISTERED (RandomRoomPositionAllocator); |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
108 |
|
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
109 |
|
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
110 |
RandomRoomPositionAllocator::RandomRoomPositionAllocator () |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
111 |
{ |
8984
85eed149a0ea
Replace src/mobility usage of RandomVariable with RandomVariableStream (Patch Set 2)
Mitch Watrous
parents:
8768
diff
changeset
|
112 |
m_rand = CreateObject<UniformRandomVariable> (); |
8651
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
113 |
} |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
114 |
|
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
115 |
TypeId |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
116 |
RandomRoomPositionAllocator::GetTypeId (void) |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
117 |
{ |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
118 |
static TypeId tid = TypeId ("ns3::RandomRoomPositionAllocator") |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
119 |
.SetParent<PositionAllocator> () |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
120 |
.SetGroupName ("Mobility") |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
121 |
.AddConstructor<RandomRoomPositionAllocator> (); |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
122 |
return tid; |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
123 |
} |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
124 |
|
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
125 |
Vector |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
126 |
RandomRoomPositionAllocator::GetNext () const |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
127 |
{ |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
128 |
NS_LOG_FUNCTION (this); |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
129 |
NS_ASSERT_MSG (BuildingList::GetNBuildings () > 0, "no building found"); |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
130 |
|
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
131 |
if (m_roomListWithoutReplacement.empty ()) |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
132 |
{ |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
133 |
for (BuildingList::Iterator bit = BuildingList::Begin (); bit != BuildingList::End (); ++bit) |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
134 |
{ |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
135 |
NS_LOG_LOGIC ("building " << (*bit)->GetId ()); |
8768
e5607ee90a49
buildings module: consistent room & floor indexing
Nicola Baldo <nbaldo@cttc.es>
parents:
8746
diff
changeset
|
136 |
for (uint32_t rx = 1; rx <= (*bit)->GetNRoomsX (); ++rx) |
8651
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
137 |
{ |
8768
e5607ee90a49
buildings module: consistent room & floor indexing
Nicola Baldo <nbaldo@cttc.es>
parents:
8746
diff
changeset
|
138 |
for (uint32_t ry = 1; ry <= (*bit)->GetNRoomsY (); ++ry) |
8651
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
139 |
{ |
8768
e5607ee90a49
buildings module: consistent room & floor indexing
Nicola Baldo <nbaldo@cttc.es>
parents:
8746
diff
changeset
|
140 |
for (uint32_t f = 1; f <= (*bit)->GetNFloors (); ++f) |
8651
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
141 |
{ |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
142 |
RoomInfo i; |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
143 |
i.roomx = rx; |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
144 |
i.roomy = ry; |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
145 |
i.floor = f; |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
146 |
i.b = *bit; |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
147 |
NS_LOG_LOGIC ("adding room (" << rx << ", " << ry << ", " << f << ")"); |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
148 |
m_roomListWithoutReplacement.push_back (i); |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
149 |
} |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
150 |
} |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
151 |
} |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
152 |
} |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
153 |
} |
8984
85eed149a0ea
Replace src/mobility usage of RandomVariable with RandomVariableStream (Patch Set 2)
Mitch Watrous
parents:
8768
diff
changeset
|
154 |
uint32_t n = m_rand->GetInteger (0,m_roomListWithoutReplacement.size () - 1); |
8651
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
155 |
RoomInfo r = m_roomListWithoutReplacement.at (n); |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
156 |
m_roomListWithoutReplacement.erase (m_roomListWithoutReplacement.begin () + n); |
8768
e5607ee90a49
buildings module: consistent room & floor indexing
Nicola Baldo <nbaldo@cttc.es>
parents:
8746
diff
changeset
|
157 |
NS_LOG_LOGIC ("considering building " << r.b->GetId () << " room (" << r.roomx << ", " << r.roomy << ", " << r.floor << ")"); |
8651
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
158 |
|
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
159 |
Ptr<RandomBoxPositionAllocator> pa = CreateObject<RandomBoxPositionAllocator> (); |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
160 |
BoxValue bv; |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
161 |
r.b->GetAttribute ("Boundaries", bv); |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
162 |
Box box = bv.Get (); |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
163 |
double rdx = (box.xMax - box.xMin) / r.b->GetNRoomsX (); |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
164 |
double rdy = (box.yMax - box.yMin) / r.b->GetNRoomsY (); |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
165 |
double rdz = (box.zMax - box.zMin) / r.b->GetNFloors (); |
8768
e5607ee90a49
buildings module: consistent room & floor indexing
Nicola Baldo <nbaldo@cttc.es>
parents:
8746
diff
changeset
|
166 |
double x1 = box.xMin + rdx * (r.roomx - 1); |
e5607ee90a49
buildings module: consistent room & floor indexing
Nicola Baldo <nbaldo@cttc.es>
parents:
8746
diff
changeset
|
167 |
double x2 = box.xMin + rdx * r.roomx; |
e5607ee90a49
buildings module: consistent room & floor indexing
Nicola Baldo <nbaldo@cttc.es>
parents:
8746
diff
changeset
|
168 |
double y1 = box.yMin + rdy * (r.roomy -1); |
e5607ee90a49
buildings module: consistent room & floor indexing
Nicola Baldo <nbaldo@cttc.es>
parents:
8746
diff
changeset
|
169 |
double y2 = box.yMin + rdy * r.roomy; |
e5607ee90a49
buildings module: consistent room & floor indexing
Nicola Baldo <nbaldo@cttc.es>
parents:
8746
diff
changeset
|
170 |
double z1 = box.zMin + rdz * (r.floor - 1); |
e5607ee90a49
buildings module: consistent room & floor indexing
Nicola Baldo <nbaldo@cttc.es>
parents:
8746
diff
changeset
|
171 |
double z2 = box.zMin + rdz * r.floor; |
8651
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
172 |
NS_LOG_LOGIC ("randomly allocating position in " |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
173 |
<< " (" << x1 << "," << x2 << ") " |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
174 |
<< "x (" << y1 << "," << y2 << ") " |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
175 |
<< "x (" << z1 << "," << z2 << ") "); |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
176 |
|
8984
85eed149a0ea
Replace src/mobility usage of RandomVariable with RandomVariableStream (Patch Set 2)
Mitch Watrous
parents:
8768
diff
changeset
|
177 |
double x = m_rand->GetValue (x1, x2); |
85eed149a0ea
Replace src/mobility usage of RandomVariable with RandomVariableStream (Patch Set 2)
Mitch Watrous
parents:
8768
diff
changeset
|
178 |
double y = m_rand->GetValue (y1, y2); |
85eed149a0ea
Replace src/mobility usage of RandomVariable with RandomVariableStream (Patch Set 2)
Mitch Watrous
parents:
8768
diff
changeset
|
179 |
double z = m_rand->GetValue (z1, z2); |
8651
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
180 |
|
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
181 |
return Vector (x, y, z); |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
182 |
} |
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
183 |
|
8984
85eed149a0ea
Replace src/mobility usage of RandomVariable with RandomVariableStream (Patch Set 2)
Mitch Watrous
parents:
8768
diff
changeset
|
184 |
int64_t |
85eed149a0ea
Replace src/mobility usage of RandomVariable with RandomVariableStream (Patch Set 2)
Mitch Watrous
parents:
8768
diff
changeset
|
185 |
RandomRoomPositionAllocator::AssignStreams (int64_t stream) |
85eed149a0ea
Replace src/mobility usage of RandomVariable with RandomVariableStream (Patch Set 2)
Mitch Watrous
parents:
8768
diff
changeset
|
186 |
{ |
85eed149a0ea
Replace src/mobility usage of RandomVariable with RandomVariableStream (Patch Set 2)
Mitch Watrous
parents:
8768
diff
changeset
|
187 |
m_rand->SetStream (stream); |
85eed149a0ea
Replace src/mobility usage of RandomVariable with RandomVariableStream (Patch Set 2)
Mitch Watrous
parents:
8768
diff
changeset
|
188 |
return 1; |
85eed149a0ea
Replace src/mobility usage of RandomVariable with RandomVariableStream (Patch Set 2)
Mitch Watrous
parents:
8768
diff
changeset
|
189 |
} |
85eed149a0ea
Replace src/mobility usage of RandomVariable with RandomVariableStream (Patch Set 2)
Mitch Watrous
parents:
8768
diff
changeset
|
190 |
|
8651
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
191 |
|
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
192 |
|
8689
04363f082bec
added SameRoomPositionAllocator
Nicola Baldo <nbaldo@cttc.es>
parents:
8651
diff
changeset
|
193 |
|
04363f082bec
added SameRoomPositionAllocator
Nicola Baldo <nbaldo@cttc.es>
parents:
8651
diff
changeset
|
194 |
|
04363f082bec
added SameRoomPositionAllocator
Nicola Baldo <nbaldo@cttc.es>
parents:
8651
diff
changeset
|
195 |
NS_OBJECT_ENSURE_REGISTERED (SameRoomPositionAllocator); |
04363f082bec
added SameRoomPositionAllocator
Nicola Baldo <nbaldo@cttc.es>
parents:
8651
diff
changeset
|
196 |
|
04363f082bec
added SameRoomPositionAllocator
Nicola Baldo <nbaldo@cttc.es>
parents:
8651
diff
changeset
|
197 |
SameRoomPositionAllocator::SameRoomPositionAllocator () |
04363f082bec
added SameRoomPositionAllocator
Nicola Baldo <nbaldo@cttc.es>
parents:
8651
diff
changeset
|
198 |
{ |
04363f082bec
added SameRoomPositionAllocator
Nicola Baldo <nbaldo@cttc.es>
parents:
8651
diff
changeset
|
199 |
NS_FATAL_ERROR (" Constructor \"SameRoomPositionAllocator ()\" should not be used"); |
04363f082bec
added SameRoomPositionAllocator
Nicola Baldo <nbaldo@cttc.es>
parents:
8651
diff
changeset
|
200 |
} |
04363f082bec
added SameRoomPositionAllocator
Nicola Baldo <nbaldo@cttc.es>
parents:
8651
diff
changeset
|
201 |
|
04363f082bec
added SameRoomPositionAllocator
Nicola Baldo <nbaldo@cttc.es>
parents:
8651
diff
changeset
|
202 |
|
04363f082bec
added SameRoomPositionAllocator
Nicola Baldo <nbaldo@cttc.es>
parents:
8651
diff
changeset
|
203 |
SameRoomPositionAllocator::SameRoomPositionAllocator (NodeContainer c) |
8746
e1cbf693c71d
fixed some bugs in SameRoomPositionAllocator
Nicola Baldo <nbaldo@cttc.es>
parents:
8689
diff
changeset
|
204 |
: m_nodes (c) |
8689
04363f082bec
added SameRoomPositionAllocator
Nicola Baldo <nbaldo@cttc.es>
parents:
8651
diff
changeset
|
205 |
{ |
8984
85eed149a0ea
Replace src/mobility usage of RandomVariable with RandomVariableStream (Patch Set 2)
Mitch Watrous
parents:
8768
diff
changeset
|
206 |
m_rand = CreateObject<UniformRandomVariable> (); |
8746
e1cbf693c71d
fixed some bugs in SameRoomPositionAllocator
Nicola Baldo <nbaldo@cttc.es>
parents:
8689
diff
changeset
|
207 |
m_nodeIt = m_nodes.Begin (); |
e1cbf693c71d
fixed some bugs in SameRoomPositionAllocator
Nicola Baldo <nbaldo@cttc.es>
parents:
8689
diff
changeset
|
208 |
// this is needed to make sure the building models associated with c have been initialized |
e1cbf693c71d
fixed some bugs in SameRoomPositionAllocator
Nicola Baldo <nbaldo@cttc.es>
parents:
8689
diff
changeset
|
209 |
for (NodeContainer::Iterator it = m_nodes.Begin (); it != m_nodes.End (); ++it) |
e1cbf693c71d
fixed some bugs in SameRoomPositionAllocator
Nicola Baldo <nbaldo@cttc.es>
parents:
8689
diff
changeset
|
210 |
{ |
e1cbf693c71d
fixed some bugs in SameRoomPositionAllocator
Nicola Baldo <nbaldo@cttc.es>
parents:
8689
diff
changeset
|
211 |
Ptr<MobilityModel> mm = (*it)->GetObject<MobilityModel> (); |
e1cbf693c71d
fixed some bugs in SameRoomPositionAllocator
Nicola Baldo <nbaldo@cttc.es>
parents:
8689
diff
changeset
|
212 |
NS_ASSERT_MSG (mm, "no mobility model aggregated to this node"); |
10080
1b36e2276e15
Move from BuildingsMobilityModel to BuildingMobilityInfo source, tests and examples
Marco Miozzo <marco.miozzo@cttc.es>
parents:
8984
diff
changeset
|
213 |
Ptr<MobilityBuildingInfo> bmm = mm->GetObject <MobilityBuildingInfo> (); |
1b36e2276e15
Move from BuildingsMobilityModel to BuildingMobilityInfo source, tests and examples
Marco Miozzo <marco.miozzo@cttc.es>
parents:
8984
diff
changeset
|
214 |
NS_ASSERT_MSG (bmm, "MobilityBuildingInfo has not been aggregated to this node mobility model"); |
1b36e2276e15
Move from BuildingsMobilityModel to BuildingMobilityInfo source, tests and examples
Marco Miozzo <marco.miozzo@cttc.es>
parents:
8984
diff
changeset
|
215 |
BuildingsHelper::MakeConsistent (mm); |
8746
e1cbf693c71d
fixed some bugs in SameRoomPositionAllocator
Nicola Baldo <nbaldo@cttc.es>
parents:
8689
diff
changeset
|
216 |
} |
8689
04363f082bec
added SameRoomPositionAllocator
Nicola Baldo <nbaldo@cttc.es>
parents:
8651
diff
changeset
|
217 |
} |
04363f082bec
added SameRoomPositionAllocator
Nicola Baldo <nbaldo@cttc.es>
parents:
8651
diff
changeset
|
218 |
|
04363f082bec
added SameRoomPositionAllocator
Nicola Baldo <nbaldo@cttc.es>
parents:
8651
diff
changeset
|
219 |
TypeId |
04363f082bec
added SameRoomPositionAllocator
Nicola Baldo <nbaldo@cttc.es>
parents:
8651
diff
changeset
|
220 |
SameRoomPositionAllocator::GetTypeId (void) |
04363f082bec
added SameRoomPositionAllocator
Nicola Baldo <nbaldo@cttc.es>
parents:
8651
diff
changeset
|
221 |
{ |
04363f082bec
added SameRoomPositionAllocator
Nicola Baldo <nbaldo@cttc.es>
parents:
8651
diff
changeset
|
222 |
static TypeId tid = TypeId ("ns3::SameRoomPositionAllocator") |
04363f082bec
added SameRoomPositionAllocator
Nicola Baldo <nbaldo@cttc.es>
parents:
8651
diff
changeset
|
223 |
.SetParent<PositionAllocator> () |
04363f082bec
added SameRoomPositionAllocator
Nicola Baldo <nbaldo@cttc.es>
parents:
8651
diff
changeset
|
224 |
.SetGroupName ("Mobility") |
04363f082bec
added SameRoomPositionAllocator
Nicola Baldo <nbaldo@cttc.es>
parents:
8651
diff
changeset
|
225 |
.AddConstructor<SameRoomPositionAllocator> (); |
04363f082bec
added SameRoomPositionAllocator
Nicola Baldo <nbaldo@cttc.es>
parents:
8651
diff
changeset
|
226 |
return tid; |
04363f082bec
added SameRoomPositionAllocator
Nicola Baldo <nbaldo@cttc.es>
parents:
8651
diff
changeset
|
227 |
} |
04363f082bec
added SameRoomPositionAllocator
Nicola Baldo <nbaldo@cttc.es>
parents:
8651
diff
changeset
|
228 |
|
04363f082bec
added SameRoomPositionAllocator
Nicola Baldo <nbaldo@cttc.es>
parents:
8651
diff
changeset
|
229 |
Vector |
04363f082bec
added SameRoomPositionAllocator
Nicola Baldo <nbaldo@cttc.es>
parents:
8651
diff
changeset
|
230 |
SameRoomPositionAllocator::GetNext () const |
04363f082bec
added SameRoomPositionAllocator
Nicola Baldo <nbaldo@cttc.es>
parents:
8651
diff
changeset
|
231 |
{ |
04363f082bec
added SameRoomPositionAllocator
Nicola Baldo <nbaldo@cttc.es>
parents:
8651
diff
changeset
|
232 |
NS_LOG_FUNCTION (this); |
04363f082bec
added SameRoomPositionAllocator
Nicola Baldo <nbaldo@cttc.es>
parents:
8651
diff
changeset
|
233 |
if (m_nodeIt == m_nodes.End ()) |
04363f082bec
added SameRoomPositionAllocator
Nicola Baldo <nbaldo@cttc.es>
parents:
8651
diff
changeset
|
234 |
{ |
04363f082bec
added SameRoomPositionAllocator
Nicola Baldo <nbaldo@cttc.es>
parents:
8651
diff
changeset
|
235 |
m_nodeIt = m_nodes.Begin (); |
04363f082bec
added SameRoomPositionAllocator
Nicola Baldo <nbaldo@cttc.es>
parents:
8651
diff
changeset
|
236 |
} |
04363f082bec
added SameRoomPositionAllocator
Nicola Baldo <nbaldo@cttc.es>
parents:
8651
diff
changeset
|
237 |
|
04363f082bec
added SameRoomPositionAllocator
Nicola Baldo <nbaldo@cttc.es>
parents:
8651
diff
changeset
|
238 |
NS_ASSERT_MSG (m_nodeIt != m_nodes.End (), "no node in container"); |
04363f082bec
added SameRoomPositionAllocator
Nicola Baldo <nbaldo@cttc.es>
parents:
8651
diff
changeset
|
239 |
|
8746
e1cbf693c71d
fixed some bugs in SameRoomPositionAllocator
Nicola Baldo <nbaldo@cttc.es>
parents:
8689
diff
changeset
|
240 |
NS_LOG_LOGIC ("considering node " << (*m_nodeIt)->GetId ()); |
e1cbf693c71d
fixed some bugs in SameRoomPositionAllocator
Nicola Baldo <nbaldo@cttc.es>
parents:
8689
diff
changeset
|
241 |
Ptr<MobilityModel> mm = (*m_nodeIt)->GetObject<MobilityModel> (); |
e1cbf693c71d
fixed some bugs in SameRoomPositionAllocator
Nicola Baldo <nbaldo@cttc.es>
parents:
8689
diff
changeset
|
242 |
NS_ASSERT_MSG (mm, "no mobility model aggregated to this node"); |
10080
1b36e2276e15
Move from BuildingsMobilityModel to BuildingMobilityInfo source, tests and examples
Marco Miozzo <marco.miozzo@cttc.es>
parents:
8984
diff
changeset
|
243 |
Ptr<MobilityBuildingInfo> bmm = mm->GetObject<MobilityBuildingInfo> (); |
1b36e2276e15
Move from BuildingsMobilityModel to BuildingMobilityInfo source, tests and examples
Marco Miozzo <marco.miozzo@cttc.es>
parents:
8984
diff
changeset
|
244 |
NS_ASSERT_MSG (bmm, "MobilityBuildingInfo has not been aggregated to this node mobility model"); |
8746
e1cbf693c71d
fixed some bugs in SameRoomPositionAllocator
Nicola Baldo <nbaldo@cttc.es>
parents:
8689
diff
changeset
|
245 |
|
e1cbf693c71d
fixed some bugs in SameRoomPositionAllocator
Nicola Baldo <nbaldo@cttc.es>
parents:
8689
diff
changeset
|
246 |
++m_nodeIt; |
8689
04363f082bec
added SameRoomPositionAllocator
Nicola Baldo <nbaldo@cttc.es>
parents:
8651
diff
changeset
|
247 |
uint32_t roomx = bmm->GetRoomNumberX (); |
04363f082bec
added SameRoomPositionAllocator
Nicola Baldo <nbaldo@cttc.es>
parents:
8651
diff
changeset
|
248 |
uint32_t roomy = bmm->GetRoomNumberY (); |
04363f082bec
added SameRoomPositionAllocator
Nicola Baldo <nbaldo@cttc.es>
parents:
8651
diff
changeset
|
249 |
uint32_t floor = bmm->GetFloorNumber (); |
8746
e1cbf693c71d
fixed some bugs in SameRoomPositionAllocator
Nicola Baldo <nbaldo@cttc.es>
parents:
8689
diff
changeset
|
250 |
NS_LOG_LOGIC ("considering building " << bmm->GetBuilding ()->GetId () << " room (" << roomx << ", " << roomy << ", " << floor << ")"); |
8689
04363f082bec
added SameRoomPositionAllocator
Nicola Baldo <nbaldo@cttc.es>
parents:
8651
diff
changeset
|
251 |
|
04363f082bec
added SameRoomPositionAllocator
Nicola Baldo <nbaldo@cttc.es>
parents:
8651
diff
changeset
|
252 |
Ptr<Building> b = bmm->GetBuilding (); |
04363f082bec
added SameRoomPositionAllocator
Nicola Baldo <nbaldo@cttc.es>
parents:
8651
diff
changeset
|
253 |
Ptr<RandomBoxPositionAllocator> pa = CreateObject<RandomBoxPositionAllocator> (); |
04363f082bec
added SameRoomPositionAllocator
Nicola Baldo <nbaldo@cttc.es>
parents:
8651
diff
changeset
|
254 |
BoxValue bv; |
04363f082bec
added SameRoomPositionAllocator
Nicola Baldo <nbaldo@cttc.es>
parents:
8651
diff
changeset
|
255 |
b->GetAttribute ("Boundaries", bv); |
04363f082bec
added SameRoomPositionAllocator
Nicola Baldo <nbaldo@cttc.es>
parents:
8651
diff
changeset
|
256 |
Box box = bv.Get (); |
04363f082bec
added SameRoomPositionAllocator
Nicola Baldo <nbaldo@cttc.es>
parents:
8651
diff
changeset
|
257 |
double rdx = (box.xMax - box.xMin) / b->GetNRoomsX (); |
04363f082bec
added SameRoomPositionAllocator
Nicola Baldo <nbaldo@cttc.es>
parents:
8651
diff
changeset
|
258 |
double rdy = (box.yMax - box.yMin) / b->GetNRoomsY (); |
04363f082bec
added SameRoomPositionAllocator
Nicola Baldo <nbaldo@cttc.es>
parents:
8651
diff
changeset
|
259 |
double rdz = (box.zMax - box.zMin) / b->GetNFloors (); |
8768
e5607ee90a49
buildings module: consistent room & floor indexing
Nicola Baldo <nbaldo@cttc.es>
parents:
8746
diff
changeset
|
260 |
double x1 = box.xMin + rdx * (roomx - 1); |
e5607ee90a49
buildings module: consistent room & floor indexing
Nicola Baldo <nbaldo@cttc.es>
parents:
8746
diff
changeset
|
261 |
double x2 = box.xMin + rdx * roomx; |
e5607ee90a49
buildings module: consistent room & floor indexing
Nicola Baldo <nbaldo@cttc.es>
parents:
8746
diff
changeset
|
262 |
double y1 = box.yMin + rdy * (roomy -1); |
e5607ee90a49
buildings module: consistent room & floor indexing
Nicola Baldo <nbaldo@cttc.es>
parents:
8746
diff
changeset
|
263 |
double y2 = box.yMin + rdy * roomy; |
e5607ee90a49
buildings module: consistent room & floor indexing
Nicola Baldo <nbaldo@cttc.es>
parents:
8746
diff
changeset
|
264 |
double z1 = box.zMin + rdz * (floor - 1); |
e5607ee90a49
buildings module: consistent room & floor indexing
Nicola Baldo <nbaldo@cttc.es>
parents:
8746
diff
changeset
|
265 |
double z2 = box.zMin + rdz * floor; |
8689
04363f082bec
added SameRoomPositionAllocator
Nicola Baldo <nbaldo@cttc.es>
parents:
8651
diff
changeset
|
266 |
NS_LOG_LOGIC ("randomly allocating position in " |
04363f082bec
added SameRoomPositionAllocator
Nicola Baldo <nbaldo@cttc.es>
parents:
8651
diff
changeset
|
267 |
<< " (" << x1 << "," << x2 << ") " |
04363f082bec
added SameRoomPositionAllocator
Nicola Baldo <nbaldo@cttc.es>
parents:
8651
diff
changeset
|
268 |
<< "x (" << y1 << "," << y2 << ") " |
04363f082bec
added SameRoomPositionAllocator
Nicola Baldo <nbaldo@cttc.es>
parents:
8651
diff
changeset
|
269 |
<< "x (" << z1 << "," << z2 << ") "); |
04363f082bec
added SameRoomPositionAllocator
Nicola Baldo <nbaldo@cttc.es>
parents:
8651
diff
changeset
|
270 |
|
8984
85eed149a0ea
Replace src/mobility usage of RandomVariable with RandomVariableStream (Patch Set 2)
Mitch Watrous
parents:
8768
diff
changeset
|
271 |
double x = m_rand->GetValue (x1, x2); |
85eed149a0ea
Replace src/mobility usage of RandomVariable with RandomVariableStream (Patch Set 2)
Mitch Watrous
parents:
8768
diff
changeset
|
272 |
double y = m_rand->GetValue (y1, y2); |
85eed149a0ea
Replace src/mobility usage of RandomVariable with RandomVariableStream (Patch Set 2)
Mitch Watrous
parents:
8768
diff
changeset
|
273 |
double z = m_rand->GetValue (z1, z2); |
8689
04363f082bec
added SameRoomPositionAllocator
Nicola Baldo <nbaldo@cttc.es>
parents:
8651
diff
changeset
|
274 |
|
04363f082bec
added SameRoomPositionAllocator
Nicola Baldo <nbaldo@cttc.es>
parents:
8651
diff
changeset
|
275 |
return Vector (x, y, z); |
04363f082bec
added SameRoomPositionAllocator
Nicola Baldo <nbaldo@cttc.es>
parents:
8651
diff
changeset
|
276 |
} |
04363f082bec
added SameRoomPositionAllocator
Nicola Baldo <nbaldo@cttc.es>
parents:
8651
diff
changeset
|
277 |
|
8984
85eed149a0ea
Replace src/mobility usage of RandomVariable with RandomVariableStream (Patch Set 2)
Mitch Watrous
parents:
8768
diff
changeset
|
278 |
int64_t |
85eed149a0ea
Replace src/mobility usage of RandomVariable with RandomVariableStream (Patch Set 2)
Mitch Watrous
parents:
8768
diff
changeset
|
279 |
SameRoomPositionAllocator::AssignStreams (int64_t stream) |
85eed149a0ea
Replace src/mobility usage of RandomVariable with RandomVariableStream (Patch Set 2)
Mitch Watrous
parents:
8768
diff
changeset
|
280 |
{ |
85eed149a0ea
Replace src/mobility usage of RandomVariable with RandomVariableStream (Patch Set 2)
Mitch Watrous
parents:
8768
diff
changeset
|
281 |
m_rand->SetStream (stream); |
85eed149a0ea
Replace src/mobility usage of RandomVariable with RandomVariableStream (Patch Set 2)
Mitch Watrous
parents:
8768
diff
changeset
|
282 |
return 1; |
85eed149a0ea
Replace src/mobility usage of RandomVariable with RandomVariableStream (Patch Set 2)
Mitch Watrous
parents:
8768
diff
changeset
|
283 |
} |
85eed149a0ea
Replace src/mobility usage of RandomVariable with RandomVariableStream (Patch Set 2)
Mitch Watrous
parents:
8768
diff
changeset
|
284 |
|
8689
04363f082bec
added SameRoomPositionAllocator
Nicola Baldo <nbaldo@cttc.es>
parents:
8651
diff
changeset
|
285 |
|
04363f082bec
added SameRoomPositionAllocator
Nicola Baldo <nbaldo@cttc.es>
parents:
8651
diff
changeset
|
286 |
|
8651
c333744c3ee1
buildings allocator and position allocator
Nicola Baldo <nbaldo@cttc.es>
parents:
diff
changeset
|
287 |
} // namespace ns3 |