def switch_partition_and_controller_deployment(self,): assert self.pn assert self.level assert self.network assert self.network.sn assert self.network.s_wei assert self.network.path_cost #输入 sn = self.network.sn pn = self.pn s_wei = self.network.s_wei l_wei = self.network.l_wei path_cost = self.network.path_cost #划分算法开始 #1.粗化 #NULL #2.初始划分 partition = self.initial_partition(s_wei, l_wei, path_cost, 0, 1)#迭代二分当前层数0,区域编号从1开始 #3.细化 #NULL #划分算法结束 #放置算法开始 s_wei_2 = get_s_wei_2(l_wei, partition) #获取part_no part_no = {} #无法保证分区数量为pn #for i in range(sn): # part_no[partition[i]] = partition[i] #################### #修改如下 for i in xrange(pn): part_no[i+pn] = i+pn ################### ctr_place = {} part_cost = {} for pno in part_no.keys(): ctr_place[pno] = -1 part_cost[pno] = 0 for c_part_no in part_no.keys(): res = get_child_network(s_wei,s_wei_2,l_wei,path_cost,partition,c_part_no) if res == None: ctr_place[c_part_no] = -1 part_cost[c_part_no] = 0 continue c_s_wei = res[0] c_l_wei = res[1] c_path_cost = res[2] c_index = res[3] res = self.controller_deployment(c_s_wei,c_l_wei,c_path_cost) ctr_i = res[0] ctr_place[c_part_no] = c_index[ctr_i] part_cost[c_part_no] = res[1] tmp_res = tool.get_res(s_wei, l_wei, path_cost, partition, ctr_place) part_s_num = tmp_res[0] part_s_wei = tmp_res[1] inter_traffic = tmp_res[2] res = Result(self.network, self, pn, partition, ctr_place, part_cost, part_s_num, part_s_wei, inter_traffic) return res
def switch_partition_and_controller_deployment(self,): assert self.network assert self.network.sn assert self.pn assert self.network.s_wei assert self.network.path_cost #输入 sn = self.network.sn pn = self.pn s_wei = self.network.s_wei l_wei = self.network.l_wei path_cost = self.network.path_cost partition = [-1]*sn ctr_place = {} part_cost = {} #求出流请求总量 sum_s_wei = 0 for i in xrange(sn): sum_s_wei += s_wei[i] for k in xrange(pn): ctr_place[(k+1)] = -1 part_cost[(k+1)] = 0 #贪婪方式选出控制器位置 cost = sys.maxint ii = -1 for i in range(sn): #控制器位置可能和非它管控的交换机直接相连 if(partition[i] != -1): continue tmp_cost = 0 #选出未分配交换机与控制器通讯总花费最小的位置ii for j in range(sn): if(partition[j] != -1): #未分配交换机 tmp_cost += s_wei[j]*path_cost[i][j] if tmp_cost < cost: ii = i cost = tmp_cost ctr_place[(k+1)] = ii #该区域的交换机 domain_s_wei = 0 while True: jj = -1 cost = sys.maxint for j in xrange(sn): if(partition[j] != -1): continue tmp_cost = s_wei[j]*path_cost[ii][j] if tmp_cost < cost: jj = j cost = tmp_cost #表示所有交换机已经分配完成 if(jj == -1): break; #交换机jj分配给区域(k+1) partition[jj] = k+1 part_cost[(k+1)] += cost domain_s_wei += s_wei[jj] #区域负载是否已经达到 if(domain_s_wei*pn >= sum_s_wei): break; tmp_res = tool.get_res(s_wei, l_wei, path_cost, partition, ctr_place) part_sn = tmp_res[0] part_s_wei = tmp_res[1] inter_traffic = tmp_res[2] res = Result(self.network, self, pn, partition, ctr_place, part_cost, part_sn, part_s_wei, inter_traffic) return res