def test_simple_cases(self): p1 = ["capacity", "int", [1.0], [10.0], 1] p2 = ["amount_of_routes", "int", [3.0], [8.0], 1] p3 = ["arrival_rates", "float", [0.0], [0.0], "amount_of_routes"] p4 = ["service_rates", "float", [1.0], [1.0], "amount_of_routes"] p5 = [ "subset_amount_of_routes", "int", [2.0], ["amount_of_routes", "-", 1], 1 ] p6 = [ "requirements_of_routes", "int", [1.0], ["capacity", "/", 2], "amount_of_routes" ] input = generate_input([p1, p2, p3, p4, p5, p6]) bp = bp_v1(sum(input['arrival_rates']), input['capacity'], input['requirements_of_routes']) for i in range(input['amount_of_routes']): assert (not input['arrival_rates'][i] == 0) or bp[i] == 0, "arrival rate is " + str( input['arrival_rates'][i]) + "blocking prob is " + str( bp[i]) assert (not input['requirements_of_routes'][i] == 0) or bp[i] == 0, "requirement is " + str( input['requirements_of_routes'] [i]) + "blocking prob is " + str(bp[i])
def test_get_next(self): #s = S_x([[5, 6], [20, 20]], [20, 20]) p1 = ["capacity1", "int", [1.0], [10.0], 1] # capacity of link 1 p2 = ["capacity2", "int", [1.0], [10.0], 1] # capacity of link 2 p3 = ["amount_of_routes", "int", [3.0], [8.0], 1] # amount of routes p4 = [ "requirements_of_routes1", "int", [1.0], ["capacity1", "/", 2], "amount_of_routes" ] p5 = [ "requirements_of_routes2", "int", [1.0], ["capacity2", "/", 2], "amount_of_routes" ] input = generate_input([p1, p2, p3, p4, p5]) print(str(input)) A = [[ input["requirements_of_routes1"][i], input["requirements_of_routes2"][i] ] for i in range(input["amount_of_routes"])] print(str(A)) s = S_x(A, [input["capacity1"], input["capacity2"]]) current = s.get_next() while (not all(i == 0 for i in current)): print(current) current = s.get_next()
def test_redundant_lossRate_v2_v3(self): p1 = ["capacity", "int", [1.0], [10.0], 1] p2 = ["amount_of_routes", "int", [3.0], [8.0], 1] p3 = ["arrival_rates", "float", [0.0], [10.0], "amount_of_routes"] p4 = ["service_rates", "float", [1.0], [1.0], "amount_of_routes"] p5 = [ "subset_amount_of_routes", "int", [2.0], ["amount_of_routes", "-", 1], 1 ] p6 = [ "requirements_of_routes", "int", [1.0], ["capacity", "/", 2], "amount_of_routes" ] input = generate_input([p1, p2, p3, p4, p5, p6]) bp1 = bp_v1(sum(input['arrival_rates']), input['capacity'], input['requirements_of_routes']) bp2 = bp_v2(sum(input['arrival_rates']), input['capacity'], input['requirements_of_routes']) bp3 = bp_v3(sum(input['arrival_rates']), input['capacity'], input['requirements_of_routes']) lossRate1 = rl_v1(bp1, input["arrival_rates"], input["service_rates"]) lossRate2 = rl_v2(bp1, input["arrival_rates"], input["service_rates"]) lossRate3 = rl_v3(bp3, input["arrival_rates"], input["service_rates"]) assert lossRate1 == lossRate3, str(input) + "lossRate1: " + str( lossRate1) + ", lossRate3: " + str(lossRate3) assert lossRate1 == lossRate2, str(input) + "lossRate1: " + str( lossRate1) + ", lossRate2: " + str(lossRate2)
def get_general_input(): p0 = ["amount_of_routes", "int", [3.0], [8.0], 1] p1 = ["X1", "int", [2.0], [10.0], 1] p2 = ["X2", "int", [2.0], [10.0], 1] p3 = ["A1", "int", [1.0], ["X1", "/", 2], "amount_of_routes"] p4 = ["A2", "int", [1.0], ["X2", "/", 2], "amount_of_routes"] temp_result = generate_input([p0, p1, p2, p3, p4]) result = dict() result["X"] = [temp_result["X1"], temp_result["X2"]] result["A"] = [] for i in range(temp_result["amount_of_routes"]): result["A"].append([temp_result["A1"][i], temp_result["A2"][i]]) return result
def get_general_input(): p1 = ["capacity", "int", [1.0], [10.0], 1] p2 = ["amount_of_routes", "int", [3.0], [8.0], 1] p3 = ["arrival_rates", "float", [0.0], [10.0], "amount_of_routes"] p4 = ["service_rates", "float", [1.0], [1.0], "amount_of_routes"] p5 = [ "subset_amount_of_routes", "int", [2.0], ["amount_of_routes", "-", 1], 1 ] p6 = [ "requirements_of_routes", "int", [1.0], ["capacity", "/", 2], "amount_of_routes" ] return generate_input([p1, p2, p3, p4, p5, p6])
def main(): debug_print("Testing the input generation!!!") debug_print("Starting with one array.") debug_print(input_generator.generate_input()) debug_print("Now many arrays.") inputs = input_generator.generate_fake_inputs() debug_print(inputs) debug_print("Testing align_values.") inputs = thor.align_values(inputs) debug_print(inputs) debug_print("Testing choose_values.") inputs = thor.choose_values(inputs) debug_print(inputs) debug_print("Testing calculate_means.") inputs = thor.calculate_means(inputs) debug_print(inputs)
def get_more_than_half_input(): result = get_general_input() # randomly modify first three routes s.t. # first has requirement > X1/2 # second has requirement > X2/2 # third has requirement > X1/2 and >X2/2 p0 = [ "link1", "int", [result["X"][0], "/", 2, "+", 1], [result["X"][0]], 2 ] p1 = [ "link2", "int", [result["X"][1], "/", 2, "+", 1], [result["X"][1]], 2 ] sub_result = generate_input([p0, p1]) result["A"][0][0] = sub_result["link1"][0] result["A"][1][1] = sub_result["link2"][0] result["A"][2][0] = sub_result["link1"][1] result["A"][2][1] = sub_result["link2"][1] return result
def test_redundant_bp_v3(self): p1 = ["capacity", "int", [1.0], [10.0], 1] p2 = ["amount_of_routes", "int", [3.0], [8.0], 1] p3 = ["arrival_rates", "float", [0.0], [10.0], "amount_of_routes"] p4 = ["service_rates", "float", [1.0], [1.0], "amount_of_routes"] p5 = [ "subset_amount_of_routes", "int", [2.0], ["amount_of_routes", "-", 1], 1 ] p6 = [ "requirements_of_routes", "int", [1.0], ["capacity", "/", 2], "amount_of_routes" ] input = generate_input([p1, p2, p3, p4, p5, p6]) bp1 = bp_v1(sum(input['arrival_rates']), input['capacity'], input['requirements_of_routes']) bp3 = bp_v3(sum(input['arrival_rates']), input['capacity'], input['requirements_of_routes']) #assert bp1 == bp2, str(input) + "bp1: " + str(bp1) + "bp2: " + str(bp2) assert bp1 == bp3, str(input) + "bp1: " + str(bp1) + "bp3: " + str(bp3)
def create_inputs(range): input_generator.generate_input('inputs/50.in', 50, 25, range) input_generator.generate_input('inputs/100.in', 100, 50, range) input_generator.generate_input('inputs/200.in', 200, 100, range)
from blockProbs_v2 import blocking_probabilities as bp_v2 from blockProbs_v3 import blocking_probabilities as bp_v3 from rateLoss_v1 import rate_of_loss as rl_v1 from rateLoss_v2 import rate_of_loss as rl_v2 from rateLoss_v3 import rate_of_loss as rl_v3 from input_generator import generate_input p1 = ["capacity", "int", [1.0], [10.0], 1] p2 = ["amount_of_routes", "int", [3.0], [8.0], 1] p3 = ["arrival_rates", "float", [0.0], [10.0], "amount_of_routes"] p4 = ["service_rates", "float", [1.0], [1.0], "amount_of_routes"] p5 = ["subset_amount_of_routes", "int", [2.0], ["amount_of_routes", "-", 1], 1] p6 = ["requirements_of_routes", "int", [1.0], ["capacity", "/", 2], "amount_of_routes"] #input = get_general_input() input = generate_input([p1, p2, p3, p4, p5, p6]) bp1 = bp_v1(sum(input['arrival_rates']), input['capacity'], input['requirements_of_routes']) bp2 = bp_v2(sum(input['arrival_rates']), input['capacity'], input['requirements_of_routes']) bp3 = bp_v3(sum(input['arrival_rates']), input['capacity'], input['requirements_of_routes']) assert bp1 == bp2, str(input) + "bp1: " + str(bp1) + "bp2: " + str(bp2) assert bp1 == bp3, str(input) + "bp1: " + str(bp1) + "bp3: " + str(bp3) lossRate1 = rl_v1(bp1, input["arrival_rates"], input["service_rates"]) lossRate2 = rl_v2(bp2, input["arrival_rates"], input["service_rates"]) lossRate3 = rl_v3(bp3, input["arrival_rates"], input["service_rates"]) assert lossRate1 == lossRate3, str(input) + "lossRate1: " + str(lossRate1) + ", lossRate3: " + str(lossRate3) assert lossRate1 == lossRate2, str(input) + "lossRate1: " + str(lossRate1) + ", lossRate2: " + str(lossRate2)