satellite-markov-conf.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013 Magister Solutions Ltd
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: Frans Laakso <frans.laakso@magister.fi>
19  */
20 
21 #include "satellite-markov-conf.h"
22 
23 #include <ns3/log.h>
24 
25 #include <cstdlib>
26 #include <map>
27 #include <utility>
28 #include <vector>
29 
30 namespace ns3
31 {
32 
33 NS_OBJECT_ENSURE_REGISTERED(SatMarkovConf);
34 NS_LOG_COMPONENT_DEFINE("SatMarkovConf");
35 
48  /* Elevation 30 degrees */
49  {{0.9684, 0.0316, 0.0000}, {0.4155, 0.5845, 0.0000}, {0.0000, 0.0000, 0.0000}}};
50 
58  0.9293,
59  0.0707,
60  0.0000};
61 
62 TypeId
64 {
65  static TypeId tid =
66  TypeId("ns3::SatMarkovConf")
67  .SetParent<Object>()
68  .AddConstructor<SatMarkovConf>()
69  .AddAttribute("ElevationCount",
70  "Number of elevation sets in the Markov model.",
72  MakeUintegerAccessor(&SatMarkovConf::m_elevationCount),
73  MakeUintegerChecker<uint32_t>())
74  .AddAttribute("StateCount",
75  "Number of states in the Markov model.",
77  MakeUintegerAccessor(&SatMarkovConf::m_stateCount),
78  MakeUintegerChecker<uint32_t>())
79  .AddAttribute(
80  "MinimumPositionChangeInMeters",
81  "Minimum position change in meters for Markov model state change cooldown.",
82  DoubleValue(100.0),
84  MakeDoubleChecker<double>())
85  .AddAttribute("CooldownPeriodLength",
86  "Cooldown period length for state change.",
87  TimeValue(Seconds(0.0001)),
88  MakeTimeAccessor(&SatMarkovConf::m_cooldownPeriodLength),
89  MakeTimeChecker())
90  .AddAttribute("UseDecibels",
91  "Defines whether the fading value should be in decibels or not.",
92  BooleanValue(false),
93  MakeBooleanAccessor(&SatMarkovConf::m_useDecibels),
94  MakeBooleanChecker());
95  return tid;
96 }
97 
99  : m_elevationCount(SatMarkovConf::DEFAULT_ELEVATION_COUNT),
100  m_stateCount(SatMarkovConf::DEFAULT_STATE_COUNT),
101  m_minimumPositionChangeInMeters(1000.0),
102  m_cooldownPeriodLength(Seconds(0.00005)),
103  m_useDecibels(false),
104  m_looConf(nullptr),
105  m_rayleighConf(nullptr),
106  m_faderType(SatMarkovConf::LOO_FADER)
107 {
108  NS_LOG_FUNCTION(this);
109 
110  for (uint32_t i = 0; i < m_elevationCount; i++)
111  {
112  std::vector<std::vector<double>> states;
113 
114  for (uint32_t j = 0; j < m_stateCount; j++)
115  {
116  std::vector<double> probabilities;
117 
118  for (uint32_t k = 0; k < m_stateCount; k++)
119  {
120  probabilities.push_back(g_MarkovElevationStateChangeProbabilities[i][j][k]);
121  }
122  states.push_back(probabilities);
123  }
124  m_markovProbabilities.push_back(states);
125  }
126 
127  for (uint32_t i = 0; i < m_stateCount; i++)
128  {
130  }
131 
132  std::pair<double, uint32_t> elevation;
133 
134  elevation.first = 30.0;
135  elevation.second = 0;
136  m_markovElevations.insert(elevation);
137 
138  m_looConf = CreateObject<SatLooConf>();
139  m_rayleighConf = CreateObject<SatRayleighConf>();
140 
141  if (m_markovElevations.size() != m_elevationCount)
142  {
143  NS_FATAL_ERROR("SatMarkovConf::SatMarkovConf - Markov elevations does not match");
144  }
145 }
146 
148 {
149  NS_LOG_FUNCTION(this);
150 
151  Reset();
152 }
153 
154 void
156 {
157  NS_LOG_FUNCTION(this);
158 
159  for (uint32_t i = 0; i < m_elevationCount; i++)
160  {
161  for (uint32_t j = 0; j < m_stateCount; j++)
162  {
163  m_markovProbabilities[i][j].clear();
164  }
165  }
166 
167  m_looConf = nullptr;
168  m_rayleighConf = nullptr;
169 
170  m_initialProbabilities.clear();
171  m_markovElevations.clear();
172 }
173 
174 void
176 {
177  NS_LOG_FUNCTION(this);
178 
179  Reset();
180  Object::DoDispose();
181 }
182 
183 std::vector<std::vector<double>>
185 {
186  NS_LOG_FUNCTION(this << set);
187 
188  if (set >= m_elevationCount)
189  {
190  NS_FATAL_ERROR("SatMarkovConf::GetElevationProbabilities - Invalid set");
191  }
192 
193  return m_markovProbabilities[set];
194 }
195 
196 uint32_t
198 {
199  NS_LOG_FUNCTION(this << elevation);
200 
201  if (elevation < 0.0 && elevation > 90.0)
202  {
203  NS_FATAL_ERROR("SatMarkovConf::GetProbabilitySetID - Invalid elevation");
204  }
205 
206  uint32_t smallestDifferenceIndex = 0;
207  double smallestDifference = 360;
208  double difference = 0;
209 
210  std::map<double, uint32_t>::iterator iter;
211 
212  for (iter = m_markovElevations.begin(); iter != m_markovElevations.end(); iter++)
213  {
214  difference = fabs(iter->first - elevation);
215  if (difference < smallestDifference)
216  {
217  smallestDifference = difference;
218  smallestDifferenceIndex = iter->second;
219  }
220  }
221 
222  NS_LOG_INFO("New ID for elevation " << elevation << " is " << smallestDifferenceIndex);
223  return smallestDifferenceIndex;
224 }
225 
226 uint32_t
228 {
229  NS_LOG_FUNCTION(this);
230 
231  return m_stateCount;
232 }
233 
234 Time
236 {
237  NS_LOG_FUNCTION(this);
238 
239  return m_cooldownPeriodLength;
240 }
241 
242 double
244 {
245  NS_LOG_FUNCTION(this);
246 
248 }
249 
250 uint32_t
252 {
253  NS_LOG_FUNCTION(this);
254 
255  return m_markovElevations.size();
256 }
257 
258 uint32_t
260 {
261  NS_LOG_FUNCTION(this);
262 
263  double total = 0;
264 
265  for (uint32_t i = 0; i < m_stateCount; ++i)
266  {
267  total += m_initialProbabilities[i];
268  }
269 
270  if (total != 1)
271  {
272  NS_FATAL_ERROR("SatMarkovConf::GetInitialState - Total sum doesn not match");
273  }
274 
275  double r = total * (std::rand() / double(RAND_MAX));
276  double acc = 0.0;
277 
278  for (uint32_t i = 0; i < m_stateCount; ++i)
279  {
280  acc += m_initialProbabilities[i];
281 
282  if (r <= acc)
283  {
284  return i;
285  }
286  }
287 
288  return m_stateCount - 1;
289 }
290 
291 Ptr<SatLooConf>
293 {
294  NS_LOG_FUNCTION(this);
295 
296  return m_looConf;
297 }
298 
299 Ptr<SatRayleighConf>
301 {
302  NS_LOG_FUNCTION(this);
303 
304  return m_rayleighConf;
305 }
306 
309 {
310  NS_LOG_FUNCTION(this);
311 
312  return m_faderType;
313 }
314 
315 bool
317 {
318  NS_LOG_FUNCTION(this);
319 
320  return m_useDecibels;
321 }
322 
323 } // namespace ns3
A configuration class for three state Markov model.
void DoDispose()
Do needed dispose actions.
std::vector< double > m_initialProbabilities
Initial Markov state probabilities.
std::vector< std::vector< double > > GetElevationProbabilities(uint32_t set)
Function for returning the probabilities.
bool m_useDecibels
Defines whether the calculations should return the fading value in decibels or not.
static const uint32_t DEFAULT_ELEVATION_COUNT
Default elevation count.
Ptr< SatRayleighConf > m_rayleighConf
Rayleigh configuration.
uint32_t GetProbabilitySetID(double elevation)
Function for returning the parameter set.
Time m_cooldownPeriodLength
Cooldown period lengthin seconds.
std::vector< std::vector< std::vector< double > > > m_markovProbabilities
Markov state change probabilities.
MarkovFaderType_t
Possible types of Markov state faders.
SatMarkovConf::MarkovFaderType_t GetFaderType()
Function for returning the selected fader type.
double m_minimumPositionChangeInMeters
Minimum position change in meters.
std::map< double, uint32_t > m_markovElevations
Markov elevations.
SatMarkovConf::MarkovFaderType_t m_faderType
Selected fader type.
Ptr< SatLooConf > m_looConf
Loo configuration.
Ptr< SatLooConf > GetLooConf()
Function for returning the Loo's model configuration.
void Reset()
Clear used variables.
uint32_t GetInitialState()
Function for returning the initial state.
Time GetCooldownPeriod()
Function for returning the cooldown period.
double GetMinimumPositionChange()
Function for returning the minimum position change distance.
static const uint32_t DEFAULT_STATE_COUNT
Default state count.
Ptr< SatRayleighConf > GetRayleighConf()
Function for returning the Loo's model configuration.
uint32_t GetStateCount()
Function for returning the number of states.
uint32_t m_elevationCount
Number of parameter sets.
static TypeId GetTypeId(void)
NS-3 function for type id.
uint32_t m_stateCount
Number of states.
bool AreDecibelsUsed()
Function for getting whether the calculations should return the fading value in decibels or not.
uint32_t GetNumOfSets()
Function for returning the number of parameter sets.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.
static const double g_MarkovElevationStateChangeProbabilities[SatMarkovConf::DEFAULT_ELEVATION_COUNT][SatMarkovConf::DEFAULT_STATE_COUNT][SatMarkovConf::DEFAULT_STATE_COUNT]
static const double g_MarkovInitialStateProbabilities[SatMarkovConf::DEFAULT_STATE_COUNT]