def aimFunc1(self, pop):
     pop_values = pop.Phen
     # 对种群中的每一个个体求目标值的近似最小值及解集
     obj_val_list = []
     for one_pop in pop_values:
         # 给连接图的上半三角填充权重
         sdn_nodes = np.array(one_pop[:self.sdn_node_count]).astype(int)
         filled_weight_list = self.fill_graph_weights(one_pop[self.sdn_node_count:])
         total_bandwidth_used = np.zeros([self.node_size, self.node_size])
         # Dijkstra算法对每个顶点计算最短链路
         shortest_path_list = [gu.dijkstra_alg(filled_weight_list, i) for i in range(self.node_size)]
         for i in range(self.node_size):
             # 先将每个节点看成传统节点,以每个顶点为目标节点,构建有向无环图
             legacy_node_dag = gu.build_dag(filled_weight_list, i, shortest_path_list)
             # 针对每一个顶点的有向无环图查找sdn节点,增加可用链路并验证环路
             dag, sorted_nodes = gu.add_links(filled_weight_list, legacy_node_dag, i, sdn_nodes)
             near_optimal_bandwidth_used = nosr.execute(dag, sorted_nodes, np.array([self.traffic]), self.band_width,
                                                        sdn_nodes, scene_determined_split_ratio=True,
                                                        scene_verification=self.scene_verify)
             # print('sdn节点为%s, %d为目标的, 近似最优链路使用情况:\n' % (sdn_nodes, i),
             #       near_optimal_bandwidth_used)
             total_bandwidth_used = near_optimal_bandwidth_used + total_bandwidth_used
         max_utilization_formula_val = calculator.calc_utilization_formula(self.band_width,
                                                                           total_bandwidth_used, False)
         min_variance = calculator.calc_remaining_bandwidth_variance(self.band_width, total_bandwidth_used)
         obj_val_list.append([max_utilization_formula_val, min_variance])
         max_utilization, max_x_index, max_y_index = calculator.calc_max_utilization(self.band_width, total_bandwidth_used)
         # print(self.xml_name + ": ", max_utilization)
         # print("target_one: " + str(max_utilization_formula_val) + " min_variance: " + str(min_variance))
         return max_utilization, max_x_index, max_y_index, max_utilization_formula_val, min_variance
Exemplo n.º 2
0
 def get_target_values(self, ratio_matrix):
     link_band_width_used = self.parallel_route_flow_simulate(ratio_matrix)
     value_of_utilization_formula = calculator.calc_utilization_formula(
         self.band_width, link_band_width_used)
     # 这个需要计算有流量经过的链路的剩余带宽方差
     remaining_bandwidth_variance = calculator.calc_remaining_bandwidth_variance(
         self.band_width, link_band_width_used)
     return value_of_utilization_formula, remaining_bandwidth_variance
 def solve_one_pop(self, one_pop):
     # 给连接图的上半三角填充权重
     start_time = time.time()
     sdn_nodes = np.array(one_pop[:self.sdn_node_count]).astype(int)
     filled_weight_list = self.fill_graph_weights(one_pop[self.sdn_node_count:])
     total_bandwidth_used = np.zeros([self.node_size, self.node_size])
     # Dijkstra算法对每个顶点计算最短链路
     shortest_path_list = [gu.dijkstra_alg(filled_weight_list, i) for i in range(self.node_size)]
     with ProcessPoolExecutor(max_workers=2) as executor:
         jobs = []
         for index in range(self.node_size):
             jobs.append(executor.submit(self.solve_sub_problem_one_node, index, filled_weight_list,
                                         shortest_path_list, sdn_nodes))
         for job in as_completed(jobs):
             total_bandwidth_used = total_bandwidth_used + job.result()
     min_utilization_formula_val = calculator.calc_utilization_formula(self.band_width, total_bandwidth_used, True)
     min_variance = calculator.calc_remaining_bandwidth_variance(self.band_width, total_bandwidth_used)
     max_utilization = calculator.calc_max_utilization(self.band_width, total_bandwidth_used)
     print(self.xml_name + ": ", max_utilization)
     print("target_one: " + str(min_utilization_formula_val) + " min_variance: " + str(min_variance))
     # print('计算一个个体的总耗时:{}'.format(time.time() - start_time))
     return [min_utilization_formula_val, min_variance]
Exemplo n.º 4
0
 def solve_one_pop(self, one_pop, do_print=False):
     """
     尝试仿真流量计算链路的最大利用率函数和剩余带宽均方差的均值
     """
     # 给连接图的上半三角填充权重
     start_time = time.time()
     sdn_node_perm = np.array(one_pop).astype(int)
     print("sdn node permutation: ", sdn_node_perm)
     filled_weight_list = self.graph.copy()
     shortest_path_list = [
         gu.dijkstra_alg(filled_weight_list, i)
         for i in range(self.node_count)
     ]
     total_mean_utilization_formula = 0
     total_mean_variance = 0
     total_mean_max_utilization = 0
     for i in range(self.node_count):
         # 计算渐进升级策略升级过程中应对历史数据的链路性能平均表现
         sdn_nodes = sdn_node_perm[:i]
         total_bandwidth_used = np.zeros([self.node_count, self.node_count])
         # Dijkstra算法对每个顶点计算最短链路
         for index in range(self.node_count):
             total_bandwidth_used += self.solve_sub_problem_one_node(
                 index, filled_weight_list, shortest_path_list, sdn_nodes,
                 self.traffics)
         utilization_formula_val = calculator.calc_utilization_formula(
             self.band_width, total_bandwidth_used, do_print)
         variance = calculator.calc_remaining_bandwidth_variance(
             self.band_width, total_bandwidth_used)
         max_utilization = calculator.calc_max_utilization(
             self.band_width, total_bandwidth_used)[0]
         total_mean_utilization_formula += utilization_formula_val / self.node_count
         total_mean_variance += variance / self.node_count
         total_mean_max_utilization += max_utilization / self.node_count
     # for traffic in self.traffics:
     #     mean_traffic_formula_val = 0
     #     mean_variance = 0
     #     mean_max_utilization = 0
     #     for i in range(self.node_count):
     #         # 计算渐进升级策略升级过程中应对历史数据的链路性能平均表现
     #         sdn_nodes = sdn_node_perm[:i]
     #         total_bandwidth_used = np.zeros([self.node_count, self.node_count])
     #         # Dijkstra算法对每个顶点计算最短链路
     #         for index in range(self.node_count):
     #             total_bandwidth_used += self.solve_sub_problem_one_node(index, filled_weight_list,
     #                                                                     shortest_path_list, sdn_nodes, traffic)
     #         utilization_formula_val = calculator.calc_utilization_formula(self.band_width,
     #                                                                       total_bandwidth_used, do_print)
     #         variance = calculator.calc_remaining_bandwidth_variance(self.band_width, total_bandwidth_used)
     #         max_utilization = calculator.calc_max_utilization(self.band_width, total_bandwidth_used)[0]
     #         # print("sdn nodes: ", sdn_nodes, ": ", max_utilization)
     #         # print("target_one: " + str(utilization_formula_val) + " min_variance: " + str(variance))
     #         mean_traffic_formula_val += utilization_formula_val / self.node_count
     #         mean_variance += variance / self.node_count
     #         mean_max_utilization += max_utilization / self.node_count
     #     total_mean_utilization_formula += mean_traffic_formula_val / traffic_count
     #     total_mean_variance += mean_variance / traffic_count
     #     total_mean_max_utilization += mean_max_utilization / traffic_count
     print("sdn_node_permutation: ", sdn_node_perm, "result: ",
           (total_mean_utilization_formula, total_mean_variance,
            total_mean_max_utilization))
     # print('计算一个个体的总耗时:{}'.format(time.time() - start_time))
     return [total_mean_utilization_formula, total_mean_variance]
        bandwidth[4][9], bandwidth[5][6], bandwidth[6][7], bandwidth[6][8], bandwidth[7][8], bandwidth[8][9], \
        bandwidth[9][10], bandwidth[10][11] = [9920000] * 14
    bandwidth[3][10] = 2480000
    json_name = "../utilization/add_weight/abilene_TM_2004_05.json"
    traffic_dir = "../abilene/TM/2004/05/"
    traffics = get_traffics(json_name, traffic_dir)
    sdn_nodes = [10, 11]
    filled_weight_list = graph.copy()
    shortest_path_list = [
        gu.dijkstra_alg(filled_weight_list, i) for i in range(12)
    ]
    total_bandwidth_used = np.zeros([12, 12])
    for index in range(12):
        # 先将每个节点看成传统节点,以每个顶点为目标节点,构建有向无环图
        legacy_node_dag = gu.build_dag(filled_weight_list, index,
                                       shortest_path_list)
        # 针对每一个顶点的有向无环图查找sdn节点,增加可用链路并验证环路
        dag, sorted_nodes = gu.add_links(filled_weight_list, legacy_node_dag,
                                         index, sdn_nodes)
        near_optimal_bandwidth_used = nosr.execute(dag, sorted_nodes, traffics,
                                                   bandwidth, sdn_nodes)
        total_bandwidth_used += near_optimal_bandwidth_used
    utilization_formula_val = calculator.calc_utilization_formula(
        bandwidth, total_bandwidth_used, True)
    variance = calculator.calc_remaining_bandwidth_variance(
        bandwidth, total_bandwidth_used)
    max_utilization = calculator.calc_max_utilization(bandwidth,
                                                      total_bandwidth_used)[0]
    print("utilization_formula_val: %s, variance: %s, max_utilization: %s" %
          (utilization_formula_val, variance, max_utilization))