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 <map>
26 
27 namespace ns3
28 {
29 
30 NS_OBJECT_ENSURE_REGISTERED(SatMarkovConf);
31 NS_LOG_COMPONENT_DEFINE("SatMarkovConf");
32 
45  /* Elevation 30 degrees */
46  {{0.9684, 0.0316, 0.0000}, {0.4155, 0.5845, 0.0000}, {0.0000, 0.0000, 0.0000}}};
47 
55  0.9293,
56  0.0707,
57  0.0000};
58 
59 TypeId
61 {
62  static TypeId tid =
63  TypeId("ns3::SatMarkovConf")
64  .SetParent<Object>()
65  .AddConstructor<SatMarkovConf>()
66  .AddAttribute("ElevationCount",
67  "Number of elevation sets in the Markov model.",
69  MakeUintegerAccessor(&SatMarkovConf::m_elevationCount),
70  MakeUintegerChecker<uint32_t>())
71  .AddAttribute("StateCount",
72  "Number of states in the Markov model.",
74  MakeUintegerAccessor(&SatMarkovConf::m_stateCount),
75  MakeUintegerChecker<uint32_t>())
76  .AddAttribute(
77  "MinimumPositionChangeInMeters",
78  "Minimum position change in meters for Markov model state change cooldown.",
79  DoubleValue(100.0),
81  MakeDoubleChecker<double>())
82  .AddAttribute("CooldownPeriodLength",
83  "Cooldown period length for state change.",
84  TimeValue(Seconds(0.0001)),
85  MakeTimeAccessor(&SatMarkovConf::m_cooldownPeriodLength),
86  MakeTimeChecker())
87  .AddAttribute("UseDecibels",
88  "Defines whether the fading value should be in decibels or not.",
89  BooleanValue(false),
90  MakeBooleanAccessor(&SatMarkovConf::m_useDecibels),
91  MakeBooleanChecker());
92  return tid;
93 }
94 
96  : m_elevationCount(SatMarkovConf::DEFAULT_ELEVATION_COUNT),
97  m_stateCount(SatMarkovConf::DEFAULT_STATE_COUNT),
98  m_minimumPositionChangeInMeters(1000.0),
99  m_cooldownPeriodLength(Seconds(0.00005)),
100  m_useDecibels(false),
101  m_looConf(NULL),
102  m_rayleighConf(NULL),
103  m_faderType(SatMarkovConf::LOO_FADER)
104 {
105  NS_LOG_FUNCTION(this);
106 
107  for (uint32_t i = 0; i < m_elevationCount; i++)
108  {
109  std::vector<std::vector<double>> states;
110 
111  for (uint32_t j = 0; j < m_stateCount; j++)
112  {
113  std::vector<double> probabilities;
114 
115  for (uint32_t k = 0; k < m_stateCount; k++)
116  {
117  probabilities.push_back(g_MarkovElevationStateChangeProbabilities[i][j][k]);
118  }
119  states.push_back(probabilities);
120  }
121  m_markovProbabilities.push_back(states);
122  }
123 
124  for (uint32_t i = 0; i < m_stateCount; i++)
125  {
127  }
128 
129  std::pair<double, uint32_t> elevation;
130 
131  elevation.first = 30.0;
132  elevation.second = 0;
133  m_markovElevations.insert(elevation);
134 
135  m_looConf = CreateObject<SatLooConf>();
136  m_rayleighConf = CreateObject<SatRayleighConf>();
137 
138  if (m_markovElevations.size() != m_elevationCount)
139  {
140  NS_FATAL_ERROR("SatMarkovConf::SatMarkovConf - Markov elevations does not match");
141  }
142 }
143 
145 {
146  NS_LOG_FUNCTION(this);
147 
148  Reset();
149 }
150 
151 void
153 {
154  NS_LOG_FUNCTION(this);
155 
156  for (uint32_t i = 0; i < m_elevationCount; i++)
157  {
158  for (uint32_t j = 0; j < m_stateCount; j++)
159  {
160  m_markovProbabilities[i][j].clear();
161  }
162  }
163 
164  m_looConf = NULL;
165  m_rayleighConf = NULL;
166 
167  m_initialProbabilities.clear();
168  m_markovElevations.clear();
169 }
170 
171 void
173 {
174  NS_LOG_FUNCTION(this);
175 
176  Reset();
177  Object::DoDispose();
178 }
179 
180 std::vector<std::vector<double>>
182 {
183  NS_LOG_FUNCTION(this << set);
184 
185  if (set >= m_elevationCount)
186  {
187  NS_FATAL_ERROR("SatMarkovConf::GetElevationProbabilities - Invalid set");
188  }
189 
190  return m_markovProbabilities[set];
191 }
192 
193 uint32_t
195 {
196  NS_LOG_FUNCTION(this << elevation);
197 
198  if (elevation < 0.0 && elevation > 90.0)
199  {
200  NS_FATAL_ERROR("SatMarkovConf::GetProbabilitySetID - Invalid elevation");
201  }
202 
203  uint32_t smallestDifferenceIndex = 0;
204  double smallestDifference = 360;
205  double difference = 0;
206 
207  std::map<double, uint32_t>::iterator iter;
208 
209  for (iter = m_markovElevations.begin(); iter != m_markovElevations.end(); iter++)
210  {
211  difference = fabs(iter->first - elevation);
212  if (difference < smallestDifference)
213  {
214  smallestDifference = difference;
215  smallestDifferenceIndex = iter->second;
216  }
217  }
218 
219  NS_LOG_INFO("New ID for elevation " << elevation << " is " << smallestDifferenceIndex);
220  return smallestDifferenceIndex;
221 }
222 
223 uint32_t
225 {
226  NS_LOG_FUNCTION(this);
227 
228  return m_stateCount;
229 }
230 
231 Time
233 {
234  NS_LOG_FUNCTION(this);
235 
236  return m_cooldownPeriodLength;
237 }
238 
239 double
241 {
242  NS_LOG_FUNCTION(this);
243 
245 }
246 
247 uint32_t
249 {
250  NS_LOG_FUNCTION(this);
251 
252  return m_markovElevations.size();
253 }
254 
255 uint32_t
257 {
258  NS_LOG_FUNCTION(this);
259 
260  double total = 0;
261 
262  for (uint32_t i = 0; i < m_stateCount; ++i)
263  {
264  total += m_initialProbabilities[i];
265  }
266 
267  if (total != 1)
268  {
269  NS_FATAL_ERROR("SatMarkovConf::GetInitialState - Total sum doesn not match");
270  }
271 
272  double r = total * (std::rand() / double(RAND_MAX));
273  double acc = 0.0;
274 
275  for (uint32_t i = 0; i < m_stateCount; ++i)
276  {
277  acc += m_initialProbabilities[i];
278 
279  if (r <= acc)
280  {
281  return i;
282  }
283  }
284 
285  return m_stateCount - 1;
286 }
287 
288 Ptr<SatLooConf>
290 {
291  NS_LOG_FUNCTION(this);
292 
293  return m_looConf;
294 }
295 
296 Ptr<SatRayleighConf>
298 {
299  NS_LOG_FUNCTION(this);
300 
301  return m_rayleighConf;
302 }
303 
306 {
307  NS_LOG_FUNCTION(this);
308 
309  return m_faderType;
310 }
311 
312 bool
314 {
315  NS_LOG_FUNCTION(this);
316 
317  return m_useDecibels;
318 }
319 
320 } // 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]