50 : TclClass(
"Module/UW/HMMPHYSICAL/MCLINK/EXTENDED")
54 create(
int argc,
const char *
const * argv)
57 if (argc == 14 || argc == 15) {
61 std::stod(argv[6]), std::stod(argv[7]), std::stod(argv[8]),
62 std::stod(argv[9]), std::stod(argv[10]), std::stod(argv[11]),
63 std::stod(argv[12]), std::stod(argv[13])));
67 if (strcasecmp(argv[14],
"GOOD") == 0) {
69 }
else if (strcasecmp(argv[14],
"MEDIUM") == 0) {
71 }
else if (strcasecmp(argv[14],
"BAD") == 0) {
74 std::cerr <<
"TCL: MCLinkExtended state must be GOOD, MEDIUM or BAD"
79 std::stod(argv[6]), std::stod(argv[7]), std::stod(argv[8]),
80 std::stod(argv[9]), std::stod(argv[10]), std::stod(argv[11]),
81 std::stod(argv[12]),std::stod(argv[13]), ch_state));
84 std::cerr <<
"TCL: check MCLinkExtended constructor args" << std::endl;
100 {p_bg, p_bm, 1.0 - p_bg - p_bm}}
105 double ber_bad,
double p_gb,
double p_gm,
double p_mg,
double p_mb,
double p_bg,
106 double p_bm,
double step_period,
ChState ch_state)
107 :
MCLink(ber_good, ber_bad, p_gb, p_bg, step_period, ch_state)
108 , ber_medium(ber_medium)
114 {p_bg, p_bm, 1.0 - p_bg - p_bm}}
116 assert(ber_good >=0.0 && ber_good <= 1.0 &&
117 ber_medium >= 0.0 && ber_medium <= 1.0 &&
118 ber_bad >= 0.0 && ber_bad <= 1.0 &&
119 p_gb >= 0.0 && p_gb <= 1.0 && p_gm >= 0.0 && p_gm <= 1.0 &&
120 p_mg >= 0.0 && p_mg <= 1.0 && p_mb >= 0.0 && p_mb <= 1.0 &&
121 p_bg >= 0.0 && p_bg <= 1.0 && p_bm >= 0.0 && p_bm <= 1.0);
127 double C[3][3] = {0};
129 for (
int i = 0; i < 3; i++) {
130 for (
int j = 0; j < 3; j++) {
131 for (
int k = 0; k < 3; k++) {
132 C[i][j] = (C[i][j] + A[i][k] * B[k][j]);
137 for (
int i = 0; i < 3; i++) {
138 for (
int j = 0; j < 3; j++) {
149 for (
int i = 0; i < 3; i++) {
150 for (
int j = 0; j < 3; j++) {
160 mul_matrix(R,
const_cast<double (&)[3][3]
>(B));
162 mul_matrix(B,
const_cast<double (&)[3][3]
>(B));
175 double P_n[3][3] = {0.0};
176 pow_matrix(
const_cast<double (&)[3][3]
>(
P), n_step, P_n);
179 double new_p_gg = P_n[0][0];
180 double new_p_gm = P_n[0][1];
181 double rng = RNG::defaultrng()->uniform_double();
182 if (rng > new_p_gg + new_p_gm) {
184 }
else if (rng > new_p_gg) {
188 double new_p_mg = P_n[1][0];
189 double new_p_mm = P_n[1][1];
190 double rng = RNG::defaultrng()->uniform_double();
191 if (rng > new_p_mm + new_p_mg) {
193 }
else if (rng > new_p_mm) {
197 double new_p_bg = P_n[2][0];
198 double new_p_bb = P_n[2][2];
199 double rng = RNG::defaultrng()->uniform_double();
200 if (rng > new_p_bb + new_p_bg) {
202 }
else if (rng > new_p_bb) {
226 Tcl &tcl = Tcl::instance();
229 if (strcasecmp(argv[1],
"getChState") == 0) {
233 if (strcasecmp(argv[1],
"getBER") == 0) {
234 tcl.resultf(
"%f",
getBER());
238 std::cerr <<
"TCL: unknown MCLinkExtended command" << std::endl;
TclObject * create(int argc, const char *const *argv)
MCLinkExtended class stores and updates the probabilities and the channel state for UnderwaterHMMPhys...
MCLinkExtended()
Default constructor of MCLinkExtended class.
virtual double getBER() override
double P[3][3]
Transition matrix for the channel.
virtual ChState updateChState() override
Called upon packet reception, decides and returns the new channel state updates the members state and...
double p_gm
Prob of transition from good to medium channel.
double ber_medium
BER with medium channel.
void pow_matrix(const double(&A)[3][3], int n, double(&R)[3][3])
Auxiliary function raising a 3x3 matrix to the power of n.
virtual int command(int, const char *const *) override
TCL command interpreter.
void mul_matrix(double(&A)[3][3], const double(&B)[3][3])
Auxiliary function calculating the result of a 3x3 matrix multiplication; result is stored in first a...
MCLink class models the BER of a directed link between two nodes.
ChState ch_state
last channel state
double p_gb
Prob of transition from good to bad channel.
double ber_good
BER with good channel.
double last_update
last time channel state has been updated
double ber_bad
BER with bad channel.
double step_period
period (s) for channel transition between states
MCLinkExtendedClass class_module_mclinkextended
Definition of MCLinkExtended class, extending MCLink.