def csv_tandem_compare_perform( foi_arrival: ArrivalDistribution, cross_arrival: ArrivalDistribution, foi_arrival2: ArrivalDistribution, cross_arrival2: ArrivalDistribution, rate: float, number_servers: int, perform_param_list: PerformParamList, opt_method: OptMethod, nc_analysis: NCAnalysis) -> pd.DataFrame: """Write dataframe results into a csv file. Args: foi_arrival: flow of interest's arrival distribution foi_arrival2: competitor's flow of interest's arrival distribution cross_arrival: distribution of cross arrivals cross_arrival2: competitor's distribution of cross arrivals rate: service rate of servers number_servers: number of servers in tandem perform_param_list: list of performance parameter values opt_method: optimization method nc_analysis: Network Calculus analysis type Returns: csv file """ bounds = [0.0] * len(perform_param_list.values_list) bounds2 = [0.0] * len(perform_param_list.values_list) filename = "tandem_{0}".format(perform_param_list.to_name()) arr_list: List[ArrivalDistribution] = [foi_arrival] arr_list2: List[ArrivalDistribution] = [foi_arrival2] ser_list: List[ConstantRate] = [] for _i in range(number_servers): arr_list.append(cross_arrival) arr_list2.append(cross_arrival2) ser_list.append(ConstantRate(rate=rate)) for _i in range(len(perform_param_list.values_list)): bounds[_i], bounds2[_i] = tandem_compare( arr_list=arr_list, arr_list2=arr_list2, ser_list=ser_list, opt_method=opt_method, perform_param=perform_param_list.get_parameter_at_i(_i), nc_analysis=nc_analysis) results_df = pd.DataFrame({ "bounds": bounds, "bounds2": bounds2 }, index=perform_param_list.values_list) results_df = results_df[["bounds", "bounds2"]] filename += "_" + str(number_servers) + "servers_" + foi_arrival.to_value( ) + "_rate=" + str(rate) results_df.to_csv( filename + '.csv', index=True, quoting=csv.QUOTE_NONNUMERIC) return results_df
def csv_fat_cross_perform(foi_arrival: ArrivalDistribution, cross_arrival: ArrivalDistribution, foi_service: ConstantRate, cross_service: ConstantRate, number_servers: int, perform_param_list: PerformParamList, opt_method: OptMethod) -> pd.DataFrame: """Write dataframe results into a csv file. Args: foi_arrival: flow of interest's arrival distribution cross_arrival: Distribution of cross arrivals foi_service: service of the server at the foi cross_service: service of remaining servers number_servers: number of servers in fat tree perform_param_list: list of performance parameter values opt_method: optimization method Returns: csv file """ if number_servers == 2: filename = "simple_setting_{0}".format(perform_param_list.to_name()) else: filename = "fat_cross_{0}".format(perform_param_list.to_name()) arr_list: List[ArrivalDistribution] = [foi_arrival] ser_list: List[ConstantRate] = [foi_service] for _i in range(number_servers - 1): arr_list.append(cross_arrival) ser_list.append(cross_service) data_frame = fat_cross_df(arr_list=arr_list, ser_list=ser_list, opt_method=opt_method, perform_param_list=perform_param_list) filename += "_" + foi_arrival.to_name() + "_" + foi_arrival.to_value( number=1, show_n=False) + "_" + foi_service.to_value( number=1) + "_" + cross_arrival.to_value( number=2, show_n=False) + "_" + cross_service.to_value(number=2) data_frame.to_csv(filename + '.csv', index=True, quoting=csv.QUOTE_NONNUMERIC) return data_frame
def perform_param_list_to_csv(prefix: str, data_frame_creator: Callable, arr_list: List[ArrivalDistribution], ser_list: List[ConstantRateServer], perform_param_list: PerformParamList, opt_method: OptMethod = None, suffix="") -> pd.DataFrame: filename = prefix + perform_param_list.to_name() if opt_method is None: data_frame = data_frame_creator(arr_list=arr_list, ser_list=ser_list, perform_param_list=perform_param_list) else: data_frame = data_frame_creator(arr_list=arr_list, ser_list=ser_list, opt_method=opt_method, perform_param_list=perform_param_list) filename += "_" + arr_list[0].to_name() for i in range(len(arr_list)): filename += "_" filename += arr_list[i].to_value(number=i + 1) for j in range(len(ser_list)): filename += "_" filename += ser_list[j].to_value(number=j + 1) data_frame.to_csv(filename + suffix + '.csv', index=True, quoting=csv.QUOTE_NONNUMERIC) return data_frame
def csv_single_perform(arrival: ArrivalDistribution, service: ConstantRate, perform_param_list: PerformParamList, opt_method: OptMethod) -> pd.DataFrame: """Writes dataframe results into a csv file Args: arrival: flow of interest's arrival distribution service: service of the server at the foi perform_param_list: list of performance parameter values opt_method: optimization method Returns: csv file """ filename = "single_{0}".format(perform_param_list.to_name()) data_frame = single_server_df(arr1=arrival, ser1=service, opt_method=opt_method, perform_param_list=perform_param_list) filename += "_" + arrival.to_name() + "_" + arrival.to_value( number=1, show_n=False) + "_" + service.to_value(number=1) data_frame.to_csv(filename + '.csv', index=True, quoting=csv.QUOTE_NONNUMERIC) return data_frame
def single_server_df(arr_list: List[ArrivalDistribution], ser_list: List[ConstantRateServer], opt_method: OptMethod, perform_param_list: PerformParamList) -> pd.DataFrame: """ Compute output standard_bound for T in T_list and write into dataframe Args: arr_list: Arrival object list ser_list: Service object list opt_method: method name as string, GS or PS perform_param_list: list of performance parameter values Returns: dataframe """ standard_bound = [0.0] * len(perform_param_list) new_bound = [0.0] * len(perform_param_list) for _i in range(len(perform_param_list)): setting = SingleServerMitPerform( arr_list=arr_list, server=ser_list[0], perform_param=perform_param_list.get_parameter_at_i(_i)) if opt_method == OptMethod.GRID_SEARCH: standard_bound[_i] = Optimize(setting=setting, number_param=1).grid_search( grid_bounds=[(0.1, 4.0)], delta=0.1) new_bound[_i] = OptimizeMitigator(setting_h_mit=setting, number_param=2).grid_search( grid_bounds=[(0.1, 4.0), (0.9, 8.0)], delta=0.05) elif opt_method == OptMethod.PATTERN_SEARCH: standard_bound[_i] = Optimize(setting=setting, number_param=1).pattern_search( start_list=[0.5], delta=3.0, delta_min=0.01) new_bound[_i] = OptimizeMitigator(setting_h_mit=setting, number_param=2).pattern_search( start_list=[0.5, 2.0], delta=3.0, delta_min=0.01) else: raise NotImplementedError( f"Optimization parameter {opt_method} is infeasible") delay_bounds_df = pd.DataFrame( { "standard_bound": standard_bound, "h_mit_bound": new_bound }, index=perform_param_list.values_list) return delay_bounds_df
def overlapping_tandem_df( arr_list: List[ArrivalDistribution], ser_list: List[ConstantRateServer], perform_param_list: PerformParamList) -> pd.DataFrame: """Compute delay standard_bound for T in T_list and write into dataframe. Args: arr_list: Arrival object list ser_list: Service object list perform_param_list: list of performance parameter values Returns: dataframe """ delta_val = 0.05 one_param_bounds = [(0.1, 10.0)] two_param_bounds = [(0.1, 10.0), (1.1, 10.0)] standard_bound = [0.0] * len(perform_param_list) server_bound = [0.0] * len(perform_param_list) fp_bound = [0.0] * len(perform_param_list) for i in range(len(perform_param_list)): overlapping_tandem_setting = OverlappingTandemPerform( arr_list=arr_list, ser_list=ser_list, perform_param=perform_param_list.get_parameter_at_i(i)) standard_bound[i] = Optimize(setting=overlapping_tandem_setting, number_param=2).grid_search( grid_bounds=two_param_bounds, delta=delta_val) server_bound[i] = OptimizeServerBound( setting_msob_fp=overlapping_tandem_setting, number_param=1).grid_search(grid_bounds=one_param_bounds, delta=delta_val) fp_bound[i] = OptimizeFPBound( setting_msob_fp=overlapping_tandem_setting, number_param=1).grid_search(grid_bounds=one_param_bounds, delta=delta_val) results_df = pd.DataFrame( { "standard_bound": standard_bound, "server_bound": server_bound, "fp_bound": fp_bound, }, index=perform_param_list.values_list) results_df = results_df[["standard_bound", "server_bound", "fp_bound"]] print( f"utilization: {overlapping_tandem_setting.approximate_utilization()}") return results_df
def single_server_df(arr1: ArrivalDistribution, ser1: ConstantRate, opt_method: OptMethod, perform_param_list: PerformParamList) -> pd.DataFrame: """Compute output bound for T in T_list and write into dataframe Args: arr1: Arrival object ser1: Service object opt_method: method name as string, GS or PS perform_param_list: list of performance parameter values Returns: dataframe """ bound = [0.0] * len(perform_param_list.values_list) new_bound = [0.0] * len(perform_param_list.values_list) for _i in range(len(perform_param_list.values_list)): setting = SingleServerPerform( arr=arr1, const_rate=ser1, perform_param=perform_param_list.get_parameter_at_i(_i)) if opt_method == OptMethod.GRID_SEARCH: bound[_i] = Optimize(setting=setting).grid_search(bound_list=[ (0.1, 4.0) ], delta=0.1) new_bound[_i] = OptimizeNew(setting_new=setting, new=True).grid_search(bound_list=[ (0.1, 4.0), (0.9, 8.0) ], delta=0.05) elif opt_method == OptMethod.PATTERN_SEARCH: bound[_i] = Optimize(setting=setting).pattern_search( start_list=[0.5], delta=3.0, delta_min=0.01) new_bound[_i] = OptimizeNew(setting_new=setting, new=True).pattern_search( start_list=[0.5, 2.0], delta=3.0, delta_min=0.01) else: raise NameError( "Optimization parameter {0} is infeasible".format(opt_method)) delay_bounds_df = pd.DataFrame({ "bound": bound, "new_bound": new_bound }, index=perform_param_list.values_list) delay_bounds_df = delay_bounds_df[["bound", "new_bound"]] return delay_bounds_df
def compare_probability(aggregation: int, sigma_single: float, rho_single: float, service_rate: float, perform_list: PerformParamList, opt_method: OptMethod) -> pd.DataFrame: dnc_fifo_single = [0.0] * len(perform_list.values_list) const_opt = [0.0] * len(perform_list.values_list) leaky_mass_1 = [0.0] * len(perform_list.values_list) leaky_mass_2_opt = [0.0] * len(perform_list.values_list) exact_mass_2_opt = [0.0] * len(perform_list.values_list) for _i in range(len(perform_list.values_list)): dnc_fifo_single[_i], const_opt[_i], leaky_mass_1[_i], leaky_mass_2_opt[ _i], exact_mass_2_opt[_i] = single_hop_comparison( aggregation=aggregation, sigma_single=sigma_single, rho_single=rho_single, service_rate=service_rate * aggregation, perform_param=perform_list.get_parameter_at_i(_i), opt_method=opt_method) results_df = pd.DataFrame( { "DNCBound": dnc_fifo_single, "constBound": const_opt, "leakyMassOne": leaky_mass_1, "leakyMassTwo": leaky_mass_2_opt, "exactMassTwo": exact_mass_2_opt }, index=perform_list.values_list) filename = ( "regulated_single_{0}_n_{1}_sigma_{2}_rho_{3}_utilization_{4}_{5}" ).format(perform_list.to_name(), aggregation, str(sigma_single), str(rho_single), str("%.2f" % (rho_single / service_rate)), opt_method.name) results_df.to_csv(filename + '.csv', index=True, quoting=csv.QUOTE_NONNUMERIC) return results_df
"server_bound": server_bound, "fp_bound": fp_bound, }, index=perform_param_list.values_list) results_df = results_df[["standard_bound", "server_bound", "fp_bound"]] print( f"utilization: {overlapping_tandem_setting.approximate_utilization()}") return results_df if __name__ == '__main__': # DELAY_PROB_LIST = PerformParamList(perform_metric=PerformEnum.DELAY_PROB, # values_list=range(4, 11)) DELAY_LIST = PerformParamList(perform_metric=PerformEnum.DELAY, values_list=[10**(-x) for x in range(10)]) print( perform_param_list_to_csv( prefix="overlapping_tandem_", data_frame_creator=overlapping_tandem_df, arr_list=[DM1(lamb=2.0), DM1(lamb=1.0), DM1(lamb=2.0)], ser_list=[ ConstantRateServer(rate=3.5), ConstantRateServer(rate=5.0), ConstantRateServer(rate=6.0) ], perform_param_list=DELAY_LIST))
start_list=[0.5], delta=3.0, delta_min=0.01) else: raise NameError( f"Optimization parameter {opt_method} is infeasible") delay_bounds_df = pd.DataFrame({"standard_bound": bound}, index=perform_param_list.values_list) delay_bounds_df = delay_bounds_df[["standard_bound"]] return delay_bounds_df if __name__ == '__main__': DELAY_LIST = PerformParamList(perform_metric=PerformEnum.DELAY_PROB, values_list=list(range(15, 41))) CONST1 = ConstantRateServer(rate=1.0) print( perform_param_list_to_csv(prefix="single_", data_frame_creator=single_server_df, arr_list=[MD1(lamb=0.8, mu=1.0)], ser_list=[CONST1], perform_param_list=DELAY_LIST, opt_method=OptMethod.GRID_SEARCH)) print( perform_param_list_to_csv(prefix="single_", data_frame_creator=single_server_df, arr_list=[MM1(lamb=0.8, mu=1.0)], ser_list=[CONST1],
def fat_cross_df(arr_list: List[ArrivalDistribution], ser_list: List[ConstantRate], opt_method: OptMethod, perform_param_list: PerformParamList) -> pd.DataFrame: """Compute delay bound for T in T_list and write into dataframe. Args: arr_list: Arrival object list ser_list: Service object list opt_method: method to_name as string, PS or GS perform_param_list: list of performance parameter values Returns: dataframe """ bound = [0.0] * len(perform_param_list.values_list) new_bound = [0.0] * len(perform_param_list.values_list) for _i in range(len(perform_param_list.values_list)): perform_param = perform_param_list.get_parameter_at_i(_i) setting = FatCrossPerform(arr_list=arr_list, ser_list=ser_list, perform_param=perform_param) if opt_method == OptMethod.GRID_SEARCH: bound[_i] = Optimize(setting=setting).grid_search(bound_list=[ (0.1, 5.0) ], delta=0.1) new_bound[_i] = OptimizeNew(setting_new=setting, new=True).grid_search(bound_list=[ (0.1, 5.0), (0.9, 6.0) ], delta=0.05) elif opt_method == OptMethod.PATTERN_SEARCH: bound[_i] = Optimize(setting=setting).pattern_search( start_list=[0.5], delta=3.0, delta_min=0.01) new_bound[_i] = OptimizeNew(setting_new=setting, new=True).pattern_search( start_list=[0.5, 2.0], delta=3.0, delta_min=0.01) elif opt_method == OptMethod.GS_OLD: bound[_i] = Optimize(setting=setting).grid_search_old(bound_list=[ (0.1, 5.0) ], delta=0.1) new_bound[_i] = OptimizeNew(setting_new=setting, new=True).grid_search_old(bound_list=[ (0.1, 5.0), (0.9, 6.0) ], delta=0.1) else: raise ValueError( "Optimization parameter {0} is infeasible".format(opt_method)) results_df = pd.DataFrame({ "bound": bound, "new_bound": new_bound }, index=perform_param_list.values_list) results_df = results_df[["bound", "new_bound"]] return results_df
filename += "_" + foi_arrival.to_name() + "_" + foi_arrival.to_value( number=1, show_n=False) + "_" + foi_service.to_value( number=1) + "_" + cross_arrival.to_value( number=2, show_n=False) + "_" + cross_service.to_value(number=2) data_frame.to_csv(filename + '.csv', index=True, quoting=csv.QUOTE_NONNUMERIC) return data_frame if __name__ == '__main__': DELAY_PROB_LIST = PerformParamList(perform_metric=PerformEnum.DELAY_PROB, values_list=range(4, 11)) DM1_FOI1 = DM1(lamb=0.2) DM1_CROSS1 = DM1(lamb=8.0) RATE_FOI1 = ConstantRate(rate=8.0) RATE_CROSS1 = ConstantRate(rate=0.2) print( csv_fat_cross_perform(foi_arrival=DM1_FOI1, cross_arrival=DM1_CROSS1, foi_service=RATE_FOI1, cross_service=RATE_CROSS1, number_servers=2, perform_param_list=DELAY_PROB_LIST, opt_method=OptMethod.GRID_SEARCH))
else: raise NotImplementedError( f"Optimization parameter {opt_method} is infeasible") delay_bounds_df = pd.DataFrame( { "standard_bound": standard_bound, "h_mit_bound": new_bound }, index=perform_param_list.values_list) return delay_bounds_df if __name__ == '__main__': OUTPUT_LIST = PerformParamList(perform_metric=PerformEnum.OUTPUT, values_list=list(range(4, 15))) print( perform_param_list_to_csv(prefix="single_", data_frame_creator=single_server_df, arr_list=[DM1(lamb=3.8, m=1)], ser_list=[ConstantRateServer(rate=3.0)], perform_param_list=OUTPUT_LIST, opt_method=OptMethod.GRID_SEARCH)) print( perform_param_list_to_csv( prefix="single_", data_frame_creator=single_server_df, arr_list=[MMOOCont(mu=8.0, lamb=12.0, peak_rate=3.0, m=1)], ser_list=[ConstantRateServer(rate=1.5)],
SERVICE_RATE = 0.12 SIGMA_VALUES_1 = [0.0, 0.1, 0.5, 1.0, 2.0, 5.0, 10.0, 15.0, 18.0, 20.0] for SIGMA_1 in SIGMA_VALUES_1: print( compare_aggregation(aggregations=NUMBER_AGGREGATIONS, sigma_single=SIGMA_1, rho_single=RHO_SINGLE, service_rate=SERVICE_RATE, perform_param=DELAY6, opt_method=OptMethod.GRID_SEARCH)) PERFORM_LIST = PerformParamList(perform_metric=PerformEnum.DELAY, values_list=[ 10**(-3), 10**(-6), 10**(-9), 10**(-12), 10**(-15), 10**(-18), 10**(-21), 10**(-24), 10**(-27), 10**(-30) ]) SIGMA_VALUES_2 = [3.0, 5.0, 10.0, 15.0, 18.0, 20.0, 50.0, 100.0] for SIGMA_2 in SIGMA_VALUES_2: print( compare_probability(aggregation=20, sigma_single=SIGMA_2, rho_single=RHO_SINGLE, service_rate=SERVICE_RATE, perform_list=PERFORM_LIST, opt_method=OptMethod.GRID_SEARCH))
def fat_cross_perform_df(arr_list: List[ArrivalDistribution], ser_list: List[ConstantRateServer], opt_method: OptMethod, perform_param_list: PerformParamList) -> pd.DataFrame: """Compute delay standard_bound for T in T_list and write into dataframe. Args: arr_list: Arrival object list ser_list: Service object list opt_method: PS or GS perform_param_list: list of performance parameter values Returns: dataframe """ delta_val = 0.05 one_param_bounds = [(delta_val, 10.0)] standard_bound = [0.0] * len(perform_param_list) h_mit_bound = [0.0] * len(perform_param_list) print_x = False fat_cross_setting = FatCrossPerform( arr_list=arr_list, ser_list=ser_list, perform_param=PerformParameter(perform_metric=PerformEnum.DELAY_PROB, value=0)) print(f"utilization: {fat_cross_setting.approximate_utilization()}") print() for i in range(len(perform_param_list)): fat_cross_setting = FatCrossPerform( arr_list=arr_list, ser_list=ser_list, perform_param=perform_param_list.get_parameter_at_i(i)) if opt_method == OptMethod.GRID_SEARCH: standard_bound[i] = Optimize(setting=fat_cross_setting, number_param=1, print_x=print_x).grid_search( grid_bounds=one_param_bounds, delta=delta_val) h_mit_bound[i] = OptimizeMitigator( setting_h_mit=fat_cross_setting, number_param=2, print_x=print_x).grid_search(grid_bounds=[(delta_val, 10.0), (1 + delta_val, 8.0) ], delta=delta_val) elif opt_method == OptMethod.PATTERN_SEARCH: standard_bound[i] = Optimize(setting=fat_cross_setting, number_param=1, print_x=print_x).pattern_search( start_list=[0.5], delta=3.0, delta_min=0.01) h_mit_bound[i] = OptimizeMitigator(setting_h_mit=fat_cross_setting, number_param=2, print_x=print_x).pattern_search( start_list=[0.5, 2.0], delta=3.0, delta_min=0.01) else: raise NotImplementedError(f"Optimization parameter {opt_method} " f"is infeasible") results_df = pd.DataFrame( { "standard_bound": standard_bound, "h_mit_bound": h_mit_bound }, index=perform_param_list.values_list) return results_df
}, index=perform_param_list.values_list) results_df = results_df[["bounds", "bounds2"]] filename += "_" + str(number_servers) + "servers_" + foi_arrival.to_value( ) + "_rate=" + str(rate) results_df.to_csv( filename + '.csv', index=True, quoting=csv.QUOTE_NONNUMERIC) return results_df if __name__ == '__main__': DELAY_LIST = PerformParamList( perform_metric=PerformEnum.DELAY, values_list=[10**(-1), 10**(-2), 10**(-4), 10**(-8), 10**(-12)]) DELAY6 = PerformParameter(perform_metric=PerformEnum.DELAY, value=10**(-6)) NUMBER_AGGREGATIONS = 10 RHO_SINGLE = 3.0 SERVICE_RATE = 70.0 SIGMA_SINGLE = 10.0 ARRIVAL_FOI = LeakyBucketMassOne( sigma_single=SIGMA_SINGLE, rho_single=RHO_SINGLE, n=NUMBER_AGGREGATIONS) ARRIVAL_CROSS = LeakyBucketMassOne( sigma_single=SIGMA_SINGLE, rho_single=RHO_SINGLE,