Commit 3bad3aa8 authored by Ashkan's avatar Ashkan
Browse files

Upload last changes.

parent 26ae1095
Pipeline #4615 failed with stages
in 17 seconds
...@@ -2,14 +2,16 @@ import os ...@@ -2,14 +2,16 @@ import os
import fec_balance_utils import fec_balance_utils
from multiprocessing import Pool from multiprocessing import Pool
IS_N_PREDICTED = True
IS_K_PREDICTED = True
ds_all_input = set(os.listdir("documents/ml/DATASET_NORMAL_DIST_TEST_DIR")) # TODO: Adjust dataset dir ds_all_input = set(os.listdir("documents/ml/DATASET_1408_UNIFORM_TEST_PREDICTED_FECB_K_N_DIR")) # TODO: Adjust dataset dir
print("Total inputs: " + str(len(ds_all_input))) print("Total inputs: " + str(len(ds_all_input)))
ds_calculated_output = set(os.listdir("documents/ml/DATASET_NORMAL_DIST_TEST_DIR_OUT")) ds_calculated_output = set(os.listdir("documents/ml/DATASET_1408_UNIFORM_TEST_PREDICTED_FECB_K_N_DIR_OUT"))
ds_basename = list(ds_all_input - ds_calculated_output) ds_basename = list(ds_all_input - ds_calculated_output)
print("Inputs left: " + str(len(ds_basename))) print("Inputs left: " + str(len(ds_basename)))
ds_rel_input_path = "documents/ml/DATASET_NORMAL_DIST_TEST_DIR/" # TODO: Adjust dataset dir ds_rel_input_path = "documents/ml/DATASET_1408_UNIFORM_TEST_PREDICTED_FECB_K_N_DIR/" # TODO: Adjust dataset dir
ds_rel_output_path = "documents/ml/DATASET_NORMAL_DIST_TEST_DIR_OUT/" ds_rel_output_path = "documents/ml/DATASET_1408_UNIFORM_TEST_PREDICTED_FECB_K_N_DIR_OUT/"
#fec_balance_utils_obj = fec_balance_utils.FecBalanceUtils("documents/ml/input_predicted_fec_balance") #fec_balance_utils_obj = fec_balance_utils.FecBalanceUtils("documents/ml/input_predicted_fec_balance")
# ri = fec_balance_utils_obj.get_ri_single_input(35) # ri = fec_balance_utils_obj.get_ri_single_input(35)
...@@ -21,12 +23,12 @@ ds_rel_output_path = "documents/ml/DATASET_NORMAL_DIST_TEST_DIR_OUT/" ...@@ -21,12 +23,12 @@ ds_rel_output_path = "documents/ml/DATASET_NORMAL_DIST_TEST_DIR_OUT/"
# fec_balance_utils_obj.get_all_ri() # fec_balance_utils_obj.get_all_ri()
def init_constructor(base_name): def init_constructor(base_name):
fec_balance_utils_obj = fec_balance_utils.FecBalanceUtils(base_name, ds_rel_input_path, ds_rel_output_path) fec_balance_utils_obj = fec_balance_utils.FecBalanceUtils(base_name, ds_rel_input_path, ds_rel_output_path, IS_N_PREDICTED, IS_K_PREDICTED)
fec_balance_utils_obj.get_all_ri() fec_balance_utils_obj.get_all_ri()
if __name__ == '__main__': if __name__ == '__main__':
pool = Pool(processes=6) # TODO: Adjust number of cores pool = Pool(processes=7) # TODO: Adjust number of cores
pool.map(init_constructor, ds_basename, chunksize=1) pool.map(init_constructor, ds_basename, chunksize=1)
...@@ -5,11 +5,15 @@ import pandas as pd ...@@ -5,11 +5,15 @@ import pandas as pd
import prrt_utils import prrt_utils
import restricted_integer_composition as ric import restricted_integer_composition as ric
import time import time
class FecBalanceUtils: class FecBalanceUtils:
def __init__(self, base_name, ds_rel_input_path, ds_rel_output_path): def __init__(self, base_name, ds_rel_input_path, ds_rel_output_path, is_n_predicted, is_k_predicted):
self.base_name = base_name self.base_name = base_name
self.ds_rel_output_path = ds_rel_output_path self.ds_rel_output_path = ds_rel_output_path
self.predicted_table_in_df = pd.read_csv(ds_rel_input_path + base_name, sep=',') self.predicted_table_in_df = pd.read_csv(ds_rel_input_path + base_name, sep=',', index_col=0)
self.IS_N_PREDICTED = is_n_predicted
self.IS_K_PREDICTED = is_k_predicted
self.n_max = 255 self.n_max = 255
self.n_min = 1 self.n_min = 1
self.n_p_min = 1 self.n_p_min = 1
...@@ -19,19 +23,18 @@ class FecBalanceUtils: ...@@ -19,19 +23,18 @@ class FecBalanceUtils:
self.nc_cap = 10 self.nc_cap = 10
self.nc = 0 self.nc = 0
self.columns_order = ["app_max_latency", "app_max_residual_loss_rate", "app_data_rate", "app_pkt_length", 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", "ch_loss_rate", "ch_rtt_prop_fwd", "ch_data_rate_btl_fwd",
"sys_red_pkt_trans_dly", "sys_src_pkt_interval", "sys_red_pkt_trans_dly", "sys_src_pkt_interval", "fec_balance_star", "config_star",
"fec_balance_star", "config_star", "nc_star","time_star", "ri_star", "k_star", "n_star", "np_star"] "nc_star", "time_star", "ri_star",
"k_star", "n_star", "np_star"]
#print("FecBalanceUtils Class is initialized")
# print("FecBalanceUtils Class is initialized")
def get_arq_delay(self, index): def get_arq_delay(self, index):
d_t = self.predicted_table_in_df["app_max_latency"][index] d_t = self.predicted_table_in_df["app_max_latency"][index]
fec_balance_star = self.predicted_table_in_df["fec_balance_star"][index] fec_balance_star = self.predicted_table_in_df["fec_balance_star"][index]
return (1 - fec_balance_star) * d_t return (1 - fec_balance_star) * d_t
def get_nc(self, index): def get_nc(self, index):
arq_delay = self.get_arq_delay(index) arq_delay = self.get_arq_delay(index)
ch_rtt_prop_fwd = self.predicted_table_in_df["ch_rtt_prop_fwd"][index] ch_rtt_prop_fwd = self.predicted_table_in_df["ch_rtt_prop_fwd"][index]
...@@ -39,29 +42,36 @@ class FecBalanceUtils: ...@@ -39,29 +42,36 @@ class FecBalanceUtils:
nc = math.floor(arq_delay / (ch_rtt_prop_fwd + sys_red_pkt_trans_dly)) nc = math.floor(arq_delay / (ch_rtt_prop_fwd + sys_red_pkt_trans_dly))
return nc return nc
def get_k(self, index): def get_k(self, index):
d_t = self.predicted_table_in_df["app_max_latency"][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] 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_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] 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,
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) sys_src_pkt_interval)
return math.floor(k) return math.floor(k)
def get_ri_single_input(self, index): def get_ri_single_input(self, index):
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]) self.nc = min(self.get_nc(index), self.nc_cap)
k_loss = self.get_k(index) if not self.IS_K_PREDICTED:
self.k = min(k_lim, k_loss) 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])
k_loss = self.get_k(index)
self.k = min(k_lim, k_loss)
else:
self.k = int(self.predicted_table_in_df['k_star'][index])
ch_rtt_prop_fwd = self.predicted_table_in_df["ch_rtt_prop_fwd"][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_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_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) n_p_max = prrt_utils.get_n_p_max(ch_rtt_prop_fwd, app_pkt_length, ch_data_rate_btl_fwd)
n_of_nmax = min(self.n_max, self.nc * n_p_max) if not self.IS_N_PREDICTED:
self.n = prrt_utils.estimate_n_for_k(self.k, n_of_nmax, ch_loss_rate, app_max_residual_loss_rate) ch_loss_rate = self.predicted_table_in_df["ch_loss_rate"][index]
app_max_residual_loss_rate = self.predicted_table_in_df["app_max_residual_loss_rate"][index]
n_of_nmax = min(self.n_max, self.nc * n_p_max)
self.n = prrt_utils.estimate_n_for_k(self.k, n_of_nmax, ch_loss_rate, app_max_residual_loss_rate)
else:
self.n = int(self.predicted_table_in_df['n_star'][index])
if n_p_max == 0: if n_p_max == 0:
self.repair_schedule = [] self.repair_schedule = []
...@@ -69,7 +79,6 @@ class FecBalanceUtils: ...@@ -69,7 +79,6 @@ class FecBalanceUtils:
self.repair_schedule = ric.gen_repair_schedule(self.n - self.k, self.nc, self.n_p_min, n_p_max) 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], 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_max_residual_loss_rate'][index],
self.predicted_table_in_df['app_data_rate'][index], self.predicted_table_in_df['app_data_rate'][index],
...@@ -86,7 +95,8 @@ class FecBalanceUtils: ...@@ -86,7 +95,8 @@ class FecBalanceUtils:
0, 0,
self.predicted_table_in_df['sys_src_pkt_interval'][index]) self.predicted_table_in_df['sys_src_pkt_interval'][index])
coding_conf = prrt.PrrtCodingConfiguration(self.n, self.k, self.repair_schedule, appParams, chnlParams, sysParams) coding_conf = prrt.PrrtCodingConfiguration(self.n, self.k, self.repair_schedule, appParams, chnlParams,
sysParams)
if not (coding_conf.is_maximum_latency_fulfilled() and if not (coding_conf.is_maximum_latency_fulfilled() and
prrt_utils.is_maximum_loss_fulfilled(self.k, prrt_utils.is_maximum_loss_fulfilled(self.k,
...@@ -97,13 +107,12 @@ class FecBalanceUtils: ...@@ -97,13 +107,12 @@ class FecBalanceUtils:
return coding_conf.get_redundant_information() return coding_conf.get_redundant_information()
def get_all_ri(self): def get_all_ri(self):
save_result_to = pd.DataFrame() save_result_to = pd.DataFrame()
for index, row in self.predicted_table_in_df.iterrows(): for index, row in self.predicted_table_in_df.iterrows():
if index == 3: if index != -1 :
print(index) # print(index)
start_time = time.time() start_time = time.time()
ri = self.get_ri_single_input(index) ri = self.get_ri_single_input(index)
duration = time.time() - start_time duration = time.time() - start_time
...@@ -115,18 +124,20 @@ class FecBalanceUtils: ...@@ -115,18 +124,20 @@ class FecBalanceUtils:
'ch_loss_rate': row['ch_loss_rate'], 'ch_loss_rate': row['ch_loss_rate'],
'ch_rtt_prop_fwd': row['ch_rtt_prop_fwd'], 'ch_rtt_prop_fwd': row['ch_rtt_prop_fwd'],
'ch_data_rate_btl_fwd': row['ch_data_rate_btl_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_red_pkt_trans_dly': np.round(row['sys_red_pkt_trans_dly'],
5),
'sys_src_pkt_interval': row['sys_src_pkt_interval'], 'sys_src_pkt_interval': row['sys_src_pkt_interval'],
'fec_balance_star': row['fec_balance_star'], 'fec_balance_star': row['fec_balance_star'],
'config_star': [self.k, self.n, self.repair_schedule], 'config_star': [self.k, self.n, self.repair_schedule],
'nc_star' : len(self.repair_schedule) - 1, 'nc_star': len(self.repair_schedule) - 1,
'time_star' : duration, 'time_star': duration,
'ri_star':ri, 'ri_star': ri,
'k_star' : self.k, 'k_star': self.k,
'n_star' : self.n, 'n_star': self.n,
'np_star' : self.repair_schedule}, ignore_index=True, sort=False) 'np_star': self.repair_schedule}, ignore_index=True,
sort=False)
save_result_to.to_csv(self.ds_rel_output_path + self.base_name, sep=',', columns = self.columns_order)
save_result_to.to_csv(self.ds_rel_output_path + self.base_name, sep=',', columns=self.columns_order, index= True)
print(self.base_name + " saved!") print(self.base_name + " saved!")
def get_ri_residual_single_input(self, index): def get_ri_residual_single_input(self, index):
...@@ -148,5 +159,4 @@ class FecBalanceUtils: ...@@ -148,5 +159,4 @@ class FecBalanceUtils:
save_result_to = save_result_to.append({'time': duration, save_result_to = save_result_to.append({'time': duration,
'ri': ri}, ignore_index=True, sort=False) 'ri': ri}, ignore_index=True, sort=False)
save_result_to.to_csv('documents/ml/ri_res_from_predicted_model', sep=',', index=True, columns=["time","ri"]) save_result_to.to_csv('documents/ml/ri_res_from_predicted_model', sep=',', index=True, columns=["time", "ri"])
...@@ -58,7 +58,7 @@ class HECSearch: ...@@ -58,7 +58,7 @@ class HECSearch:
get_k_lim = prrt_utils.get_k_lim(self.n_min, self.n_max, self.prrtChannelParameters.loss_rate_fwd, self.prrtApplicationParameters.max_residual_loss_rate) # Bottleneck get_k_lim = prrt_utils.get_k_lim(self.n_min, self.n_max, self.prrtChannelParameters.loss_rate_fwd, self.prrtApplicationParameters.max_residual_loss_rate) # Bottleneck
# if self.searchType == "GreedySearch": # if self.searchType == "GreedySearch":
for n_c in range(1, min(n_c_max, n_c_cap) + 1): for n_c in range(0, min(n_c_max, n_c_cap) + 1):
get_k = self.get_k(n_c, arq_delay_i) get_k = self.get_k(n_c, arq_delay_i)
# print(str(get_k) + " " + str(get_k_lim)) # print(str(get_k) + " " + str(get_k_lim))
k_max = min(get_k, get_k_lim) k_max = min(get_k, get_k_lim)
...@@ -71,8 +71,8 @@ class HECSearch: ...@@ -71,8 +71,8 @@ class HECSearch:
self.prrtChannelParameters.loss_rate_fwd, self.prrtChannelParameters.loss_rate_fwd,
self.prrtApplicationParameters.max_residual_loss_rate) # Bottleneck self.prrtApplicationParameters.max_residual_loss_rate) # Bottleneck
redundancy = n - k redundancy = n - k
if redundancy * self.n_p_min < n_c: # if redundancy * self.n_p_min < n_c:
continue # continue
repair_schedule = ric.gen_repair_schedule(redundancy, n_c, self.n_p_min, self.n_p_max) repair_schedule = ric.gen_repair_schedule(redundancy, n_c, self.n_p_min, self.n_p_max)
# print("k=" + str(k) + " r=" + str(redundancy) + " n_c=" + str(n_c) + " n_p=" + str(repair_schedule)) # print("k=" + str(k) + " r=" + str(redundancy) + " n_c=" + str(n_c) + " n_p=" + str(repair_schedule))
......
Supports Markdown
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