Commit 4b8e346d authored by Ashkan's avatar Ashkan

Update.

parent 6b95008c
Pipeline #4495 failed with stages
in 12 seconds
import math
import prrt
import numpy as np
import pandas as pd
import prrt_utils
import restricted_integer_composition as ric
import fec_balance_utils
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)
fec_balance_utils_obj = fec_balance_utils.FecBalanceUtils("/home/ashkan/Documents/deep-hec/code/test_input_with_predicted_fec_balance")
# ri = fec_balance_utils_obj.get_ri_single_input(35)
# print(ri)
fec_balance_utils_obj.get_all_ri()
\ No newline at end of file
import math
import prrt
import numpy as np
import pandas as pd
import prrt_utils
import restricted_integer_composition as ric
class FecBalanceUtils:
def __init__(self, predicted_table_path):
self.predicted_table_in_df = pd.read_csv(predicted_table_path, sep=',')
self.n_max = 255
self.n_min = 1
self.n_p_min = 1
self.k = 0
self.n = 0
self.repair_schedule = []
self.nc_cap = 10
self.nc = 0
self.columns_order = ["app_max_latency", "app_max_residual_loss_rate", "app_data_rate", "app_pkt_length",
"ch_loss_rate", "ch_rtt_prop_fwd", "ch_data_rate_btl_fwd",
"sys_red_pkt_trans_dly", "sys_src_pkt_interval",
"fec_balance", "config", "ri"]
print("FecBalanceUtils Class is initialized")
def get_arq_delay(self, index):
d_t = self.predicted_table_in_df["app_max_latency"][index]
fec_balance = self.predicted_table_in_df["fec_balance"][index]
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_in_df["ch_rtt_prop_fwd"][index]
sys_red_pkt_trans_dly = self.predicted_table_in_df["sys_red_pkt_trans_dly"][index]
nc = math.ceil(arq_delay / (ch_rtt_prop_fwd + sys_red_pkt_trans_dly))
return nc
def get_k(self, index):
d_t = self.predicted_table_in_df["app_max_latency"][index]
ch_rtt_prop_fwd = self.predicted_table_in_df["ch_rtt_prop_fwd"][index]
sys_red_pkt_trans_dly = self.predicted_table_in_df["sys_red_pkt_trans_dly"][index]
sys_src_pkt_interval = self.predicted_table_in_df["sys_src_pkt_interval"][index]
self.nc = min(self.get_nc(index), self.nc_cap)
k = (d_t - ch_rtt_prop_fwd - self.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_k_lim(self, index):
get_k_lim = prrt_utils.get_k_lim(self.n_min, self.n_max, self.predicted_table_in_df["ch_loss_rate"][index],
self.predicted_table_in_df["app_max_residual_loss_rate"][index])
return get_k_lim
def get_ri_single_input(self, index):
self.k = min(self.get_k_lim(index), self.get_k(index))
ch_rtt_prop_fwd = self.predicted_table_in_df["ch_rtt_prop_fwd"][index]
ch_data_rate_btl_fwd = self.predicted_table_in_df["ch_data_rate_btl_fwd"][index]
ch_loss_rate = self.predicted_table_in_df["ch_loss_rate"][index]
app_pkt_length = self.predicted_table_in_df["app_pkt_length"][index]
app_max_residual_loss_rate = self.predicted_table_in_df["app_max_residual_loss_rate"][index]
n_p_max = prrt_utils.get_n_p_max(ch_rtt_prop_fwd, app_pkt_length, ch_data_rate_btl_fwd)
self.n = prrt_utils.estimate_n_for_k(self.k, min(self.n_max, self.nc * n_p_max), ch_loss_rate, app_max_residual_loss_rate)
if (self.n - self.k) * self.n_p_min < self.nc or n_p_max == 0:
self.repair_schedule = []
return -1
self.repair_schedule = ric.gen_repair_schedule(self.n - self.k, self.nc, self.n_p_min, n_p_max)
appParams = prrt.PrrtApplicationParameters(self.predicted_table_in_df['app_max_latency'][index],
self.predicted_table_in_df['app_max_residual_loss_rate'][index],
self.predicted_table_in_df['app_data_rate'][index],
self.predicted_table_in_df['app_pkt_length'][index])
chnlParams = prrt.PrrtChannelParameters(self.predicted_table_in_df['ch_loss_rate'][index],
0,
self.predicted_table_in_df['ch_rtt_prop_fwd'][index],
0,
self.predicted_table_in_df['ch_data_rate_btl_fwd'][index],
0)
sysParams = prrt.PrrtSystemParameters(0,
np.round(self.predicted_table_in_df['sys_red_pkt_trans_dly'][index], 5),
0,
0,
self.predicted_table_in_df['sys_src_pkt_interval'][index])
coding_conf = prrt.PrrtCodingConfiguration(self.n, self.k, self.repair_schedule, appParams, chnlParams, sysParams)
return coding_conf.get_redundant_information()
def get_all_ri(self):
save_result_to = pd.DataFrame()
for index, row in self.predicted_table_in_df.iterrows():
if index < 150:
print(index)
ri = self.get_ri_single_input(index)
save_result_to = save_result_to.append({'app_max_latency': row['app_max_latency'],
'app_max_residual_loss_rate': row['app_max_residual_loss_rate'],
'app_data_rate': row['app_data_rate'],
'app_pkt_length': row['app_pkt_length'],
'ch_loss_rate': row['ch_loss_rate'],
'ch_rtt_prop_fwd': row['ch_rtt_prop_fwd'],
'ch_data_rate_btl_fwd': row['ch_data_rate_btl_fwd'],
'sys_red_pkt_trans_dly': np.round(row['sys_red_pkt_trans_dly'], 5),
'sys_src_pkt_interval': row['sys_src_pkt_interval'],
'fec_balance': row['fec_balance'],
'config': [self.k, self.n, self.nc, self.repair_schedule],
'ri':ri}, ignore_index=True, sort=False)
save_result_to.to_csv('ri_from_predicted_model', sep=',', index=False, columns = self.columns_order)
\ No newline at end of file
......@@ -67,6 +67,6 @@ cpdef bint is_maximum_loss_fulfilled(int k, int n, float loss_rate_fwd, float ma
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
cpdef get_n_p_max(float rtt_prop_fwd, int pkt_length, float data_rate_btl_fwd):
n_p_max = rtt_prop_fwd * data_rate_btl_fwd / pkt_length
return np.round(n_p_max,0)
\ No newline at end of file
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