Commit 6b95008c authored by Ashkan's avatar Ashkan

Created fec_balance class and moved n_p_max function to prrt_utils and some other minor changes.

parent a2397db2
Pipeline #4483 failed with stages
in 11 seconds
import math
import prrt
import numpy as np
import pandas as pd
import prrt_utils
import restricted_integer_composition as ric
class FecBalance:
def __init__(self, predicted_table_path):
self.predicted_table_in_df = pd.read_csv(predicted_table_path, sep=',')
self.predicted_table_row_indexed = self.predicted_table_in_df[0]
self.n_max = 255
self.n_min = 1
def get_arq_delay(self, index):
d_t = self.predicted_table_row_indexed[index]["app_max_latency"]
fec_balance = self.predicted_table_row_indexed[index]["fec_balance"]
return (1 - fec_balance) * d_t
def get_nc(self, index):
arq_delay = self.get_arq_delay(index)
ch_rtt_prop_fwd = self.predicted_table_row_indexed[index]["ch_rtt_prop_fwd"]
sys_red_pkt_trans_dly = self.predicted_table_row_indexed[index]["sys_red_pkt_trans_dly"]
return arq_delay / (ch_rtt_prop_fwd + sys_red_pkt_trans_dly)
def get_k(self, index):
d_t = self.predicted_table_row_indexed[index]["app_max_latency"]
ch_rtt_prop_fwd = self.predicted_table_row_indexed[index]["ch_rtt_prop_fwd"]
sys_red_pkt_trans_dly = self.predicted_table_row_indexed[index]["sys_red_pkt_trans_dly"]
sys_src_pkt_interval = self.predicted_table_row_indexed[index]["sys_src_pkt_interval"]
nc = self.get_nc(index)
k = (d_t - ch_rtt_prop_fwd - nc * (ch_rtt_prop_fwd + sys_red_pkt_trans_dly)) / max(sys_red_pkt_trans_dly, sys_src_pkt_interval)
return math.ceil(k)
def get_ri(self, index=None):
if index != None:
k = self.get_k(index)
nc = self.get_nc(index)
ch_rtt_prop_fwd = self.predicted_table_row_indexed[index]["ch_rtt_prop_fwd"]
ch_data_rate_btl_fwd = self.predicted_table_row_indexed[index]["ch_data_rate_btl_fwd"]
ch_loss_rate = self.predicted_table_row_indexed[index]["ch_loss_rate"]
app_pkt_length = self.predicted_table_row_indexed[index]["app_pkt_length"]
app_max_residual_loss_rate = self.predicted_table_row_indexed[index]["app_max_residual_loss_rate"]
n_p_max = prrt_utils.get_n_p_max(ch_rtt_prop_fwd, app_pkt_length, ch_data_rate_btl_fwd)
n = prrt_utils.estimate_n_for_k(k, min(self.n_max, nc * n_p_max), ch_loss_rate, app_max_residual_loss_rate)
repair_schedule = ric.gen_repair_schedule(n - k, nc, self.n_p_min, n_p_max)
appParams = prrt.PrrtApplicationParameters(self.predicted_table_row_indexed[index]['app_max_latency'],
self.predicted_table_row_indexed[index]['app_max_residual_loss_rate'],
self.predicted_table_row_indexed[index]['app_data_rate'],
self.predicted_table_row_indexed[index]['app_pkt_length'])
chnlParams = prrt.PrrtChannelParameters(self.predicted_table_row_indexed[index]['ch_loss_rate'],
0,
self.predicted_table_row_indexed[index]['ch_rtt_prop_fwd'],
0,
self.predicted_table_row_indexed[index]['ch_data_rate_btl_fwd'],
0)
sysParams = prrt.PrrtSystemParameters(0,
np.round(self.predicted_table_row_indexed[index]['sys_red_pkt_trans_dly'], 5),
0,
0,
self.predicted_table_row_indexed[index]['sys_src_pkt_interval'])
coding_conf = prrt.PrrtCodingConfiguration(n, k, repair_schedule, appParams,
chnlParams, sysParams)
......@@ -64,4 +64,9 @@ cpdef bint is_maximum_loss_fulfilled(int k, int n, float loss_rate_fwd, float ma
cdef float residual_packet_erasure_rate = total_packet_erasure / k # Pr(k, n)
if (residual_packet_erasure_rate <= max_residual_loss_rate):
return True
return False
\ No newline at end of file
return False
@cdivision(True)
cpdef cc(rtt_prop_fwd, pkt_length, data_rate_btl_fwd):
np = rtt_prop_fwd * data_rate_btl_fwd / pkt_length
return np.round(np,0)
\ No newline at end of file
......@@ -6,6 +6,7 @@ import datetime
import hec_search
import numpy as np
import pandas as pd
import prrt_utils
from multiprocessing import Pool
# --------------------------------------------------------------
......@@ -32,13 +33,10 @@ columns_order = ["app_max_latency", "app_max_residual_loss_rate", "app_data_rate
"sys_red_pkt_trans_dly", "sys_src_pkt_interval",
"time", "config", "fec_balance"]
def get_n_p_max(rtt_prop_fwd, pkt_length, data_rate_btl_fwd):
return rtt_prop_fwd * data_rate_btl_fwd / pkt_length
def evaluate(searchAlgorithm, appParams, channelParams, systemParams):
n_p_min = 1
n_p_max = np.round(get_n_p_max(channelParams.rtt_prop_fwd, appParams.pkt_length, channelParams.data_rate_btl_fwd), 0)
n_p_max = prrt_utils.get_n_p_max(channelParams.rtt_prop_fwd, appParams.pkt_length, channelParams.data_rate_btl_fwd)
if n_p_min <= n_p_max:
start = time.time()
search = hec_search.HECSearch(searchAlgorithm, n_p_min, n_p_max, appParams, channelParams, systemParams)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment