Commit 35314212 authored by Ashkan Taslimi's avatar Ashkan Taslimi

Backup.

parent ee6ddf8b
This diff is collapsed.
import numpy as np
import pandas as pd
import prrt
from prrt.HecSearch import HECFullSearch
from prrt.HecSearch import HECGreadySearch
import time
def evaluate(searchAlgorithm, appParams, channelParams, systemParams):
n_p_min = 1
n_p_max = get_n_p_max(channelParams.rtt_prop_fwd, channelParams.pkt_length, channelParams.data_rate_btl_fwd)
if searchAlgorithm == "FullSearch":
full_search = HECFullSearch(n_p_min, n_p_max, appParams, channelParams, systemParams)
start = time.now()
full_search_result = full_search.search()
duration = time.now() - start
return [full_search_result, duration]
if searchAlgorithm == "GreedySearch":
greedy_search = HECGreadySearch(n_p_min, n_p_max, appParams, channelParams, systemParams)
start = time.now()
greedy_search_result = greedy_search.search()
duration = time.now() - start
return [greedy_search_result, duration]
def test_case(csv_file_path):
appParams = prrt.PrrtApplicationParameters(max_latency, max_residual_loss_rate, data_rate)
chnlParams = prrt.PrrtChannelParameters(...)
sysParams = prrt.PrrtSystemParameters(...)
for searchAlgorithm in ["FullSearch", "GreedySearch"]:
config, duration = evaluate(searchAlgorithm, appParams, chnlParams, sysParams)
rows.append(..., search, config, duration)
pd.DataFrame(rows).to_csv()
def get_n_p_max(rtt_prop_fwd, pkt_length, data_rate_btl_fwd):
return rtt_prop_fwd * data_rate_btl_fwd / pkt_length
\ No newline at end of file
import pyximport; pyximport.install()
import itertools
def generate_restricted_integer_compositions(redundancy, positions, min, max):
cdef c_redundancy = redundancy
cdef c_positions = positions
cdef c_min = min
cdef c_max = max
if c_positions < 1:
raise StopIteration
if c_positions == 1:
if c_redundancy >= c_min and c_redundancy <= c_max:
yield (c_redundancy,)
raise StopIteration
for i in range(c_min, c_redundancy + 1):
for result in generate_restricted_integer_compositions(c_redundancy - i, c_positions - 1, i, c_max):
if (i <= c_max):
yield (i,) + result
# is_order_ascending = False for full search and True for greedy search
def gen_repair_schedules(redundancy, positions, min, max, is_order_ascending):
arbitrary_schedules = []
ordered_schedules = set()
gen_rics = generate_restricted_integer_compositions(redundancy, positions, min, max)
for ric in gen_rics:
arbitrary_schedules.append(ric)
if not is_order_ascending:
for ric in arbitrary_schedules:
ordered_schedules.add(itertools.permutations(ric))
return list(ordered_schedules)
else:
return arbitrary_schedules
def gen_repair_schedule(redundancy, positions, min, max):
if(redundancy < positions * min or min > max):
raise Exception("Illegal input combinations. Make sure the min > max. And, number of total redundancy is greater that positions*min.")
opt_schedule = [min for p in range(positions)]
redundancy_left_over = redundancy - min * positions
last_index = positions - 1
while(redundancy_left_over > 0):
if(opt_schedule[last_index] < max):
opt_schedule[last_index] += 1
redundancy_left_over -= 1
else:
last_index -= 1
return opt_schedule
\ No newline at end of file
......@@ -4,7 +4,7 @@ import prrt
import time
import numpy as np
dataset_file_path = 'in_12_param_4_sz_mini_1000.csv'
dataset_file_path = 'documents/in_12_param_4_sz_mini_1000.csv'
def get_n_p_max(rtt_prop_fwd, pkt_length, data_rate_btl_fwd):
......
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