Commit b82d4791 authored by Ashkan Taslimi's avatar Ashkan Taslimi

Add estimate_n_for_k method

Update some variable and method names
parent 09c0d081
Pipeline #3754 failed with stages
in 3 seconds
......@@ -3,6 +3,7 @@ import prrt
import math
import ric
class AbstractSearch(ABC):
@abstractmethod
def search(self):
......@@ -12,6 +13,7 @@ class AbstractSearch(ABC):
class HECFullSearch(AbstractSearch):
def __init__(self, n_p_max, prrtApplicationParameters, prrtChannelParameters, prrtSystemParameters):
self.n_max = 255
self.step_size = 2 # Step size in the estimation of the optimum code word length
self.n_p_max = n_p_max
self.prrtApplicationParameters = prrtApplicationParameters
self.prrtChannelParameters = prrtChannelParameters
......@@ -20,9 +22,9 @@ class HECFullSearch(AbstractSearch):
pass
def search(self):
ri_min = math.inf
ri_opt = math.inf
k_opt = 0
n_c_opt = 0
n_opt = 0
n_p_opt = []
# Eq.5.9, page 125
fec_delay_min = self.prrtSystemParameters.source_packet_interval + \
......@@ -37,35 +39,35 @@ class HECFullSearch(AbstractSearch):
n_c_max = math.ceil((self.prrtApplicationParameters.max_latency - fec_delay_min) / req_delay)
# self.k_lim = somewhat(prrtApplicationParameters.loss_tolerance, self.n_max)
for n_c in range(n_c_max + 1):
# n_c = 0 is the proactive packet
for n_c in range(n_c_max):
# Eq.5.11, k(Nc, D_T), page 125
k_max = min(self.get_k(n_c, req_delay), self.get_k_lim(1, self.n_max))
for k in range(1, k_max + 1):
n_p = ric.get_ric(self.n_max - k, n_c, 1, self.n_p_max)
for i in n_p:
coding_conf = prrt.PrrtCodingConfiguration(self.n_max, k, i)
n = self.estimate_n_for_k(k)
repair_schedules = ric.gen_repair_schedule(n - k, n_c, 1, self.n_p_max)
for repair_schedule in repair_schedules:
coding_conf = prrt.PrrtCodingConfiguration(n, k, repair_schedule)
ri = coding_conf.get_redundant_information(self.prrtChannelParameters)
if ri < ri_min:
if ri < ri_opt:
k_opt = k
n_c_opt = n_c
n_p_opt = i
return prrt.PrrtCodingConfiguration(k_opt, n_c_opt, n_p_opt)
n_opt = n
n_p_opt = repair_schedule
return prrt.PrrtCodingConfiguration(n_opt, k_opt, n_p_opt)
def get_k(self, n_c, req_delay):
math.ceil((self.prrtApplicationParameters.max_latency -
return math.ceil((self.prrtApplicationParameters.max_latency -
self.n_p_max * self.prrtSystemParameters.redundancy_packet_transmission_delay -
(self.prrtChannelParameters.rtt_prop_fwd + self.prrtSystemParameters.processing_delay) / 2 -
self.prrtSystemParameters.packet_loss_detection_delay -
n_c * req_delay) / self.prrtSystemParameters.source_packet_interval)
def get_k_lim(self, start, end):
mid_point = math.ceil((end - start) / 2)
p_r = self.get_max_coding_block_length(mid_point)
if (p_r == self.p_t):
if p_r == self.p_t:
return mid_point
elif (p_r > self.p_t):
elif p_r > self.p_t:
self.get_k_lim(start, mid_point - 1)
else:
self.get_k_lim(mid_point + 1, end)
......@@ -80,6 +82,24 @@ class HECFullSearch(AbstractSearch):
total_packet_erasure += packet_erasure_at_i
return (1 / k) * total_packet_erasure
def estimate_n_for_k(self, k):
n = k + 1
while self.residual_packet_erasure_rate(k, n, self.prrtApplicationParameters, self.prrtChannelParameters) > self.prrtApplicationParameters.max_residual_loss_rate\
and n <= self.n_max - self.step_size:
print("")
return 0
def residual_packet_erasure_rate(self, k, n, prrtApplicationParameters, prrtChannelParameters):
total_packet_erasure = 0
for i in range(1, k):
for j in range(max(n - k + 1, i), n - k + i):
packet_erasure_at_i = i * self.hypergeometric_distribution(n, k, i, j) * self.get_error_prob(j, n, prrtChannelParameters.loss_rate_fwd)
total_packet_erasure += packet_erasure_at_i
residual_packet_erasure_rate = (1 / k) * total_packet_erasure # Pr(k, n)
return residual_packet_erasure_rate
# Restricted Integer combinations
"""
......
import pyximport; pyximport.install()
import itertools
def gen_ric(redundancy, positions, min, max):
def generate_restricted_integer_compositions(redundancy, positions, min, max):
cdef c_redundancy = redundancy
cdef c_positions = positions
cdef c_min = min
......@@ -15,17 +15,17 @@ def gen_ric(redundancy, positions, min, max):
raise StopIteration
for i in range(c_min, c_redundancy + 1):
for result in gen_ric(c_redundancy - i, c_positions - 1, i, c_max):
for result in generate_restricted_integer_compositions(c_redundancy - i, c_positions - 1, i, c_max):
if (i <= c_max):
yield (i,) + result
def get_ric(redundancy, positions, min, max):
def gen_repair_schedule(redundancy, positions, min, max):
rawList = []
permuted = []
permuted = set()
f = gen_ric(redundancy, positions, min, max)
f = generate_restricted_integer_compositions(redundancy, positions, min, max)
for i in f:
rawList.append(i)
rawList.add(i)
for i in rawList:
permuted.append(itertools.permutations(i))
......
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