This repository was archived by the owner on Feb 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 110
Expand file tree
/
Copy pathGilbertElliotModel.cc
More file actions
96 lines (83 loc) · 3.67 KB
/
Copy pathGilbertElliotModel.cc
File metadata and controls
96 lines (83 loc) · 3.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//
// Created by seba on 09.07.19.
//
#include <stdexcept>
#include <iostream>
#include "GilbertElliotModel.h"
#include "stack/phy/ChannelModel/LteGilbertElliotChannelModel.h"
GilbertElliotModel::GilbertElliotModel() {}
void GilbertElliotModel::setStartingState() {
double steady_state_good = getSteadyStateProbability(ChannelState::good);
double random_number = parent->getRandomNumber();
if (random_number <= steady_state_good)
current_channel_state = ChannelState::good;
else
current_channel_state = ChannelState::bad;
}
double GilbertElliotModel::update() {
double random_number = parent->getRandomNumber();
double current_transition_probability = current_channel_state == ChannelState::good ? good_state_transition_prob : bad_state_transition_prob;
if (random_number <= current_transition_probability)
current_channel_state = current_channel_state == ChannelState::good ? ChannelState::bad : ChannelState::good;
current_channel_state == ChannelState::good ? num_times_good_state_visited++ : num_times_bad_state_visited++;
return getCurrentErrorProbability();
}
void GilbertElliotModel::setErrorProbability(const int channel_state, double error_probability) {
if (channel_state == ChannelState::good)
this->good_state_packet_error_prob = error_probability;
else if (channel_state == ChannelState::bad)
this->bad_state_packet_error_prob = error_probability;
else
throw std::invalid_argument("Channel state is neither good nor bad.");
}
void GilbertElliotModel::setTransitionProbability(const int channel_state, double transition_probability) {
if (channel_state == ChannelState::good)
this->good_state_transition_prob = transition_probability;
else if (channel_state == ChannelState::bad)
this->bad_state_transition_prob = transition_probability;
else
throw std::invalid_argument("Channel state is neither good nor bad.");
}
double GilbertElliotModel::getErrorProbability(const int channel_state) const {
if (channel_state == ChannelState::good)
return this->good_state_packet_error_prob;
else if (channel_state == ChannelState::bad)
return this->bad_state_packet_error_prob;
else
throw std::invalid_argument("Channel state is neither good nor bad.");
}
double GilbertElliotModel::getTransitionProbability(const int channel_state) const {
if (channel_state == ChannelState::good)
return this->good_state_transition_prob;
else if (channel_state == ChannelState::bad)
return this->bad_state_transition_prob;
else
throw std::invalid_argument("Channel state is neither good nor bad.");
}
double GilbertElliotModel::getCurrentErrorProbability() const {
return current_channel_state == ChannelState::good ? good_state_packet_error_prob : bad_state_packet_error_prob;
}
double GilbertElliotModel::getSteadyStateProbability(const int channel_state) const {
const double& p12 = good_state_transition_prob;
const double& p21 = bad_state_transition_prob;
if (channel_state == ChannelState::good)
return p21 / (p12 + p21);
else if (channel_state == ChannelState::bad)
return p12 / (p21 + p12);
else
throw std::invalid_argument("Channel state is neither good nor bad.");
}
const GilbertElliotModel::ChannelState& GilbertElliotModel::getCurrentChannelState() const {
return this->current_channel_state;
}
void GilbertElliotModel::setParent(LteGilbertElliotChannelModel* parent) {
this->parent = parent;
}
unsigned long GilbertElliotModel::getNumTimesStateVisited(const int channel_state) const {
if (channel_state == ChannelState::good)
return num_times_good_state_visited;
else if (channel_state == ChannelState::bad)
return num_times_bad_state_visited;
else
throw std::invalid_argument("Channel state is neither good nor bad.");
}