def __init__(self, L, M, N, R, M_grid, pm, pc, pop_size, max_gen, file_path_name, Dth, k1, w1, w2, maxdis, GA_step, VF_step, seed_number, alpha1, alpha2, alpha3): ''' :param L: 场景变长,Km :param M: 基站总数 :param N: 待选数 :param R: 基站半径 :param M_grid: 栅格数 :param pm: 变异概率 :param pc: 交叉概率 :param pop_size: 种群大小 :param max_gen: 最大迭代次数 :param Dth: 两个点的距离等于这个时既无引力又无斥力 :param k1: 感知距离系数 :param w1: 引力系数 :param w2: 斥力系数 :param maxdis: 单次移动最大距离 :param GA_step: 每GA_step步进行虚拟力引导 :param VF_step: 每VF_step步离散化操作 ''' self.L = L self.M = M self.N = N self.R = R self.M_grid = M_grid self.pm = pm self.pc = pc self.pop_size = pop_size self.max_gen = max_gen self.scence = scence(L, M, N, R, M_grid) self.Dth = Dth self.k1 = k1 self.w1 = w1 self.w2 = w2 self.maxdis = maxdis self.GA_step = GA_step self.VF_step = VF_step self.Rs = k1 * R self.alpha1 = alpha1 self.alpha2 = alpha2 self.alpha3 = alpha3 self.kdtree = kdtree(self.scence.sum_sites) para_dict = {'L':L, 'M':M, 'N':N, 'R':R, 'M_grid':M_grid, 'pm':pm, 'pc':pc, 'pop_size':pop_size, 'max_gen':max_gen, 'Dth':Dth, 'k1':k1, 'w1':w1, 'w2':w2, 'maxdis':maxdis, 'GA_step':GA_step, 'VF_step':VF_step, 'seed_number':seed_number, 'alpha1':alpha1, 'alpha2':alpha2, 'alpha3':alpha3} self.record = record(file_path_name) self.record.write_scence_para(para_dict) self.pop = [] self.bests = [0] * max_gen self.g_best = 0
def __init__(self, L, M, N, R, M_grid, pm, pc, pop_size, max_gen, file_path_name): """ 算法初始化 :param L: 场景变长,Km :param M: 基站总数 :param N: 待选数 :param R: 基站半径 :param M_grid: 栅格数 :param pm: 变异概率 :param pc: 交叉概率 :param pop_size: 种群大小 :param max_gen: 最大迭代次数 :return: """ self.L = L self.M = M self.N = N self.R = R self.M_grid = M_grid self.pm = pm self.pc = pc self.pop_size = pop_size self.max_gen = max_gen self.scence = scence(L, M, N, R, M_grid) para_dict = {'L':L, 'M':M, 'N':N, 'R':R, 'M_grid':M_grid, 'pm':pm, 'pc':pc, 'pop_size':pop_size, 'max_gen':max_gen} self.record = record(file_path_name) self.record.write_scence_para(para_dict) self.pop = [] self.bests = [0] * max_gen self.g_best = 0
self.y2 = 0 self.y3 = 0 for i in self.x: self.y2 += self.scence.cost[i] self.y3 += self.scence.accept[i] self.y2 = self.alpha2 * self.y2 / len(self.x) self.y3 = self.alpha3 * self.y3 / len(self.x) self.y = self.y1 + self.y2 + self.y3 def coding(self): self.x.sort() self.code = [0] * self.all_BS for i in self.x: self.code[i] = 1 while self.choose_BS != sum(self.code): self.code[random.randint(0, self.all_BS - 1)] = 1 self.func() if __name__ == '__main__': for i in range(20): L, M, N, R, R_grid = 50, 200, 40, 5, 50 * 1 from scence import scence my_scence = scence(L, M, N, R, R_grid) chromosome = Chromosome(M, N, my_scence) print(chromosome.y)