A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
building-position-allocator.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2012 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Nicola Baldo <nbaldo@cttc.es>
18 * Michele Polese <michele.polese@gmail.com> for the OutdoorPositionAllocator class
19 */
20#ifndef BUILDING_POSITION_ALLOCATOR_H
21#define BUILDING_POSITION_ALLOCATOR_H
22
23#include "ns3/random-variable-stream.h"
24#include <ns3/node-container.h>
25#include <ns3/position-allocator.h>
26#include <ns3/ptr.h>
27
28namespace ns3
29{
30
31class Building;
32class UniformRandomVariable;
33
34/**
35 * \ingroup buildings
36 *
37 * Allocate each position by randomly choosing a building from the list
38 * of all buildings, and then randomly choosing a position inside the building.
39 */
41{
42 public:
44
45 /**
46 * \brief Get the type ID.
47 * \return The object TypeId.
48 */
49 static TypeId GetTypeId();
50
51 // inherited from PositionAllocator
52 Vector GetNext() const override;
53
54 /**
55 * Assign a fixed random variable stream number to the random variables
56 * used by this model. Return the number of streams (possibly zero) that
57 * have been assigned.
58 *
59 * \param stream first stream index to use
60 * \return the number of stream indices assigned by this model
61 */
62 int64_t AssignStreams(int64_t stream) override;
63
64 private:
65 bool m_withReplacement; //!< If true, the building will be randomly selected with replacement
66 mutable std::vector<Ptr<Building>>
67 m_buildingListWithoutReplacement; //!< List of building without replacement
68
69 /// Provides uniform random variables.
71};
72
73/**
74 * \ingroup buildings
75 * \brief allocate outdoor positions
76 *
77 * Allocate positions outside of existing buildings using rejection sampling.
78 * This class extracts a random position in a box defined by the three
79 * RandomVariableStreams for the X, Y and Z dimensions (similarly to
80 * RandomBoxPositionAllocator), until a position is found that is outdoors
81 * with respect to all of the buildings in the scenario, or a maximum number
82 * of attempts is reached. The RandomVariableStream and the maximum number
83 * of attempts can be set using attributes. If the maximum number of
84 * attempts is reached, then the simulation aborts due to failure of properly
85 * positioning the node.
86 */
88{
89 public:
91
92 /**
93 * \brief Get the type ID.
94 * \return The object TypeId.
95 */
96 static TypeId GetTypeId();
97
98 // inherited from PositionAllocator
99 Vector GetNext() const override;
100
101 /**
102 * \brief Set the random variable stream object that generates x-positions
103 * \param x pointer to a RandomVariableStream object
104 */
106 /**
107 * \brief Set the random variable stream object that generates y-positions
108 * \param y pointer to a RandomVariableStream object
109 */
111 /**
112 * \brief Set the random variable stream object that generates z-positions
113 * \param z pointer to a RandomVariableStream object
114 */
116
117 /**
118 * Assign a fixed random variable stream number to the random variables
119 * used by this model. Return the number of streams (possibly zero) that
120 * have been assigned.
121 *
122 * \param stream first stream index to use
123 * \return the number of stream indices assigned by this model
124 */
125 int64_t AssignStreams(int64_t stream) override;
126
127 private:
128 Ptr<RandomVariableStream> m_x; //!< pointer to x's random variable stream
129 Ptr<RandomVariableStream> m_y; //!< pointer to y's random variable stream
130 Ptr<RandomVariableStream> m_z; //!< pointer to z's random variable stream
131
132 uint32_t m_maxAttempts; //!< maximum number of attempts before giving up
133};
134
135/**
136 * Allocate each position by randomly choosing a room from the list
137 * of all buildings, and then randomly choosing a position inside the room.
138 * The selection of the room is always done without replacement.
139 *
140 */
142{
143 public:
145
146 /**
147 * \brief Get the type ID.
148 * \return The object TypeId.
149 */
150 static TypeId GetTypeId();
151
152 // inherited from PositionAllocator
153 Vector GetNext() const override;
154
155 /**
156 * Assign a fixed random variable stream number to the random variables
157 * used by this model. Return the number of streams (possibly zero) that
158 * have been assigned.
159 *
160 * \param stream first stream index to use
161 * \return the number of stream indices assigned by this model
162 */
163 int64_t AssignStreams(int64_t stream) override;
164
165 private:
166 /**
167 * Room information
168 */
169 struct RoomInfo
170 {
171 Ptr<Building> b; //!< Building
172 uint32_t roomx; //!< Room (x coord)
173 uint32_t roomy; //!< Room (y coord)
174 uint32_t floor; //!< Room (floor number)
175 };
176
177 mutable std::vector<RoomInfo> m_roomListWithoutReplacement; //!< Container of rooms
178
179 /// Provides uniform random variables.
181};
182
183/**
184 * Walks a given NodeContainer sequentially, and for each node allocate a new
185 * position randomly in the same room of that node
186 *
187 */
189{
190 public:
192
193 /**
194 * Constructor
195 * \param c Node container
196 */
198
199 /**
200 * \brief Get the type ID.
201 * \return The object TypeId.
202 */
203 static TypeId GetTypeId();
204
205 // inherited from PositionAllocator
206 Vector GetNext() const override;
207
208 /**
209 * Assign a fixed random variable stream number to the random variables
210 * used by this model. Return the number of streams (possibly zero) that
211 * have been assigned.
212 *
213 * \param stream first stream index to use
214 * \return the number of stream indices assigned by this model
215 */
216 int64_t AssignStreams(int64_t) override;
217
218 private:
219 NodeContainer m_nodes; //!< Nodes container
220 mutable NodeContainer::Iterator m_nodeIt; //!< Nodes iterator
221
222 /// Provides uniform random variables.
224};
225
226/**
227 * Generate a random position uniformly distributed in the volume of a
228 * chosen room inside a chosen building.
229 */
231{
232 public:
233 /**
234 *
235 *
236 * \param x index of the room on the x-axis
237 * \param y index of the room on the y-axis
238 * \param z index of the room on the z-axis (i.e., floor number)
239 * \param b pointer to the chosen building
240 *
241 */
243 /**
244 * \brief Get the type ID.
245 * \return The object TypeId.
246 */
247 static TypeId GetTypeId();
248 // inherited from PositionAllocator
249 Vector GetNext() const override;
250
251 /**
252 * Assign a fixed random variable stream number to the random variables
253 * used by this model. Return the number of streams (possibly zero) that
254 * have been assigned.
255 *
256 * \param stream first stream index to use
257 * \return the number of stream indices assigned by this model
258 */
259 int64_t AssignStreams(int64_t) override;
260
261 private:
262 uint32_t roomx; //!< Index of the room on the x-axis
263 uint32_t roomy; //!< Index of the room on the y-axis
264 uint32_t floor; //!< Index of the room on the z-axis (i.e., floor number)
265
266 Ptr<Building> bptr; //!< Pointer to the chosen building
267
268 /// Provides uniform random variables.
270};
271
272} // namespace ns3
273
274#endif /* BUILDING_POSITION_ALLOCATOR_H */
Generate a random position uniformly distributed in the volume of a chosen room inside a chosen build...
uint32_t floor
Index of the room on the z-axis (i.e., floor number)
uint32_t roomx
Index of the room on the x-axis.
uint32_t roomy
Index of the room on the y-axis.
Ptr< UniformRandomVariable > m_rand
Provides uniform random variables.
Ptr< Building > bptr
Pointer to the chosen building.
int64_t AssignStreams(int64_t) override
Assign a fixed random variable stream number to the random variables used by this model.
static TypeId GetTypeId()
Get the type ID.
keep track of a set of node pointers.
std::vector< Ptr< Node > >::const_iterator Iterator
Node container iterator.
void SetY(Ptr< RandomVariableStream > y)
Set the random variable stream object that generates y-positions.
uint32_t m_maxAttempts
maximum number of attempts before giving up
static TypeId GetTypeId()
Get the type ID.
void SetX(Ptr< RandomVariableStream > x)
Set the random variable stream object that generates x-positions.
Ptr< RandomVariableStream > m_x
pointer to x's random variable stream
Ptr< RandomVariableStream > m_z
pointer to z's random variable stream
Ptr< RandomVariableStream > m_y
pointer to y's random variable stream
void SetZ(Ptr< RandomVariableStream > z)
Set the random variable stream object that generates z-positions.
int64_t AssignStreams(int64_t stream) override
Assign a fixed random variable stream number to the random variables used by this model.
Allocate a set of positions.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
Allocate each position by randomly choosing a building from the list of all buildings,...
std::vector< Ptr< Building > > m_buildingListWithoutReplacement
List of building without replacement.
int64_t AssignStreams(int64_t stream) override
Assign a fixed random variable stream number to the random variables used by this model.
bool m_withReplacement
If true, the building will be randomly selected with replacement.
Ptr< UniformRandomVariable > m_rand
Provides uniform random variables.
Allocate each position by randomly choosing a room from the list of all buildings,...
int64_t AssignStreams(int64_t stream) override
Assign a fixed random variable stream number to the random variables used by this model.
std::vector< RoomInfo > m_roomListWithoutReplacement
Container of rooms.
static TypeId GetTypeId()
Get the type ID.
Ptr< UniformRandomVariable > m_rand
Provides uniform random variables.
Walks a given NodeContainer sequentially, and for each node allocate a new position randomly in the s...
NodeContainer m_nodes
Nodes container.
Ptr< UniformRandomVariable > m_rand
Provides uniform random variables.
int64_t AssignStreams(int64_t) override
Assign a fixed random variable stream number to the random variables used by this model.
NodeContainer::Iterator m_nodeIt
Nodes iterator.
static TypeId GetTypeId()
Get the type ID.
a unique identifier for an interface.
Definition: type-id.h:59
Every class exported by the ns3 library is enclosed in the ns3 namespace.