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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Nicola Baldo <nbaldo@cttc.es>
7 * Michele Polese <michele.polese@gmail.com> for the OutdoorPositionAllocator class
8 */
9#ifndef BUILDING_POSITION_ALLOCATOR_H
10#define BUILDING_POSITION_ALLOCATOR_H
11
12#include "ns3/random-variable-stream.h"
13#include <ns3/node-container.h>
14#include <ns3/position-allocator.h>
15#include <ns3/ptr.h>
16
17namespace ns3
18{
19
20class Building;
21class UniformRandomVariable;
22
23/**
24 * \ingroup buildings
25 *
26 * Allocate each position by randomly choosing a building from the list
27 * of all buildings, and then randomly choosing a position inside the building.
28 */
30{
31 public:
33
34 /**
35 * \brief Get the type ID.
36 * \return The object TypeId.
37 */
38 static TypeId GetTypeId();
39
40 // inherited from PositionAllocator
41 Vector GetNext() const override;
42
43 /**
44 * Assign a fixed random variable stream number to the random variables
45 * used by this model. Return the number of streams (possibly zero) that
46 * have been assigned.
47 *
48 * \param stream first stream index to use
49 * \return the number of stream indices assigned by this model
50 */
51 int64_t AssignStreams(int64_t stream) override;
52
53 private:
54 bool m_withReplacement; //!< If true, the building will be randomly selected with replacement
55 mutable std::vector<Ptr<Building>>
56 m_buildingListWithoutReplacement; //!< List of building without replacement
57
58 /// Provides uniform random variables.
60};
61
62/**
63 * \ingroup buildings
64 * \brief allocate outdoor positions
65 *
66 * Allocate positions outside of existing buildings using rejection sampling.
67 * This class extracts a random position in a box defined by the three
68 * RandomVariableStreams for the X, Y and Z dimensions (similarly to
69 * RandomBoxPositionAllocator), until a position is found that is outdoors
70 * with respect to all of the buildings in the scenario, or a maximum number
71 * of attempts is reached. The RandomVariableStream and the maximum number
72 * of attempts can be set using attributes. If the maximum number of
73 * attempts is reached, then the simulation aborts due to failure of properly
74 * positioning the node.
75 */
77{
78 public:
80
81 /**
82 * \brief Get the type ID.
83 * \return The object TypeId.
84 */
85 static TypeId GetTypeId();
86
87 // inherited from PositionAllocator
88 Vector GetNext() const override;
89
90 /**
91 * \brief Set the random variable stream object that generates x-positions
92 * \param x pointer to a RandomVariableStream object
93 */
95 /**
96 * \brief Set the random variable stream object that generates y-positions
97 * \param y pointer to a RandomVariableStream object
98 */
100 /**
101 * \brief Set the random variable stream object that generates z-positions
102 * \param z pointer to a RandomVariableStream object
103 */
105
106 /**
107 * Assign a fixed random variable stream number to the random variables
108 * used by this model. Return the number of streams (possibly zero) that
109 * have been assigned.
110 *
111 * \param stream first stream index to use
112 * \return the number of stream indices assigned by this model
113 */
114 int64_t AssignStreams(int64_t stream) override;
115
116 private:
117 Ptr<RandomVariableStream> m_x; //!< pointer to x's random variable stream
118 Ptr<RandomVariableStream> m_y; //!< pointer to y's random variable stream
119 Ptr<RandomVariableStream> m_z; //!< pointer to z's random variable stream
120
121 uint32_t m_maxAttempts; //!< maximum number of attempts before giving up
122};
123
124/**
125 * Allocate each position by randomly choosing a room from the list
126 * of all buildings, and then randomly choosing a position inside the room.
127 * The selection of the room is always done without replacement.
128 *
129 */
131{
132 public:
134
135 /**
136 * \brief Get the type ID.
137 * \return The object TypeId.
138 */
139 static TypeId GetTypeId();
140
141 // inherited from PositionAllocator
142 Vector GetNext() const override;
143
144 /**
145 * Assign a fixed random variable stream number to the random variables
146 * used by this model. Return the number of streams (possibly zero) that
147 * have been assigned.
148 *
149 * \param stream first stream index to use
150 * \return the number of stream indices assigned by this model
151 */
152 int64_t AssignStreams(int64_t stream) override;
153
154 private:
155 /**
156 * Room information
157 */
158 struct RoomInfo
159 {
160 Ptr<Building> b; //!< Building
161 uint32_t roomx; //!< Room (x coord)
162 uint32_t roomy; //!< Room (y coord)
163 uint32_t floor; //!< Room (floor number)
164 };
165
166 mutable std::vector<RoomInfo> m_roomListWithoutReplacement; //!< Container of rooms
167
168 /// Provides uniform random variables.
170};
171
172/**
173 * Walks a given NodeContainer sequentially, and for each node allocate a new
174 * position randomly in the same room of that node
175 *
176 */
178{
179 public:
181
182 /**
183 * Constructor
184 * \param c Node container
185 */
187
188 /**
189 * \brief Get the type ID.
190 * \return The object TypeId.
191 */
192 static TypeId GetTypeId();
193
194 // inherited from PositionAllocator
195 Vector GetNext() const override;
196
197 /**
198 * Assign a fixed random variable stream number to the random variables
199 * used by this model. Return the number of streams (possibly zero) that
200 * have been assigned.
201 *
202 * \param stream first stream index to use
203 * \return the number of stream indices assigned by this model
204 */
205 int64_t AssignStreams(int64_t) override;
206
207 private:
208 NodeContainer m_nodes; //!< Nodes container
209 mutable NodeContainer::Iterator m_nodeIt; //!< Nodes iterator
210
211 /// Provides uniform random variables.
213};
214
215/**
216 * Generate a random position uniformly distributed in the volume of a
217 * chosen room inside a chosen building.
218 */
220{
221 public:
222 /**
223 *
224 *
225 * \param x index of the room on the x-axis
226 * \param y index of the room on the y-axis
227 * \param z index of the room on the z-axis (i.e., floor number)
228 * \param b pointer to the chosen building
229 *
230 */
232 /**
233 * \brief Get the type ID.
234 * \return The object TypeId.
235 */
236 static TypeId GetTypeId();
237 // inherited from PositionAllocator
238 Vector GetNext() const override;
239
240 /**
241 * Assign a fixed random variable stream number to the random variables
242 * used by this model. Return the number of streams (possibly zero) that
243 * have been assigned.
244 *
245 * \param stream first stream index to use
246 * \return the number of stream indices assigned by this model
247 */
248 int64_t AssignStreams(int64_t) override;
249
250 private:
251 uint32_t roomx; //!< Index of the room on the x-axis
252 uint32_t roomy; //!< Index of the room on the y-axis
253 uint32_t floor; //!< Index of the room on the z-axis (i.e., floor number)
254
255 Ptr<Building> bptr; //!< Pointer to the chosen building
256
257 /// Provides uniform random variables.
259};
260
261} // namespace ns3
262
263#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.
FixedRoomPositionAllocator(uint32_t x, uint32_t y, uint32_t z, Ptr< Building > b)
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.
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:48
Every class exported by the ns3 library is enclosed in the ns3 namespace.