def calBest(self): uniformPoint, ans = ea.crtup(self.M, 10000) # 生成10000个在各目标的单位维度上均匀分布的参考点 realBestObjV = uniformPoint / np.tile( np.sqrt(np.array([np.sum(uniformPoint**2, 1)]).T), (1, self.M)) return realBestObjV
def run(self, prophetPop=None): # prophetPop为先知种群(即包含先验知识的种群) # ==========================初始化配置=========================== population = self.population self.initialization() # 初始化算法模板的一些动态参数 # ===========================准备进化============================ uniformPoint, NIND = ea.crtup(self.problem.M, population.sizes) # 生成在单位目标维度上均匀分布的参考点集 population.initChrom( NIND ) # 初始化种群染色体矩阵,此时种群规模将调整为uniformPoint点集的大小,initChrom函数会把种群规模给重置 self.call_aimFunc(population) # 计算种群的目标函数值 # 插入先验知识(注意:这里不会对先知种群prophetPop的合法性进行检查,故应确保prophetPop是一个种群类且拥有合法的Chrom、ObjV、Phen等属性) if prophetPop is not None: population = (prophetPop + population)[:NIND] # 插入先知种群 # ===========================开始进化============================ while self.terminated(population) == False: # 进行差分进化操作 offspring = population.copy() # 存储子代种群 offspring.Chrom = self.mutOper.do(offspring.Encoding, offspring.Chrom, offspring.Field) # 变异 tempPop = population + offspring # 当代种群个体与变异个体进行合并(为的是后面用于重组) offspring.Chrom = self.recOper.do(tempPop.Chrom) # 重组 self.call_aimFunc(offspring) # 计算目标函数值 # 重插入生成新一代种群 population = self.reinsertion(population, offspring, NIND, uniformPoint) return self.finishing(population) # 调用finishing完成后续工作并返回结果
def run(self, prophetPop=None): # prophetPop为先知种群(即包含先验知识的种群) #==========================初始化配置=========================== population = self.population self.initialization() # 初始化算法模板的一些动态参数 #===========================准备进化============================ uniformPoint, NIND = ea.crtup(self.problem.M, population.sizes) # 生成在单位目标维度上均匀分布的参考点集 population.initChrom( NIND ) # 初始化种群染色体矩阵,此时种群规模将调整为uniformPoint点集的大小,initChrom函数会把种群规模给重置 self.call_aimFunc(population) # 计算种群的目标函数值 # 插入先验知识(注意:这里不会对先知种群prophetPop的合法性进行检查,故应确保prophetPop是一个种群类且拥有合法的Chrom、ObjV、Phen等属性) if prophetPop is not None: population = (prophetPop + population)[:NIND] # 插入先知种群 #===========================开始进化============================ while self.terminated(population) == False: # 选择个体参与进化 offspring = population[ea.selecting(self.selFunc, population.sizes, NIND)] # 进行进化操作,分别对各个种群染色体矩阵进行重组和变异 for i in range(population.ChromNum): offspring.Chroms[i] = self.recOpers[i].do( offspring.Chroms[i]) # 重组 offspring.Chroms[i] = self.mutOpers[i].do( offspring.Encodings[i], offspring.Chroms[i], offspring.Fields[i]) # 变异 self.call_aimFunc(offspring) # 求进化后个体的目标函数值 population = self.reinsertion(population, offspring, NIND, uniformPoint) # 重插入生成新一代种群 return self.finishing(population) # 调用finishing完成后续工作并返回结果
def run(self): #==========================初始化配置=========================== population = self.population self.initialization() # 初始化算法模板的一些动态参数 #===========================准备进化============================ uniformPoint, NIND = ea.crtup(self.problem.M, population.sizes) # 生成在单位目标维度上均匀分布的参考点集 refPoint = np.vstack([uniformPoint, np.random.rand(NIND, self.problem.M)]) # 初始化参考点(详见注释中的参考文献) if population.Chrom is None or population.sizes != NIND: population.initChrom(NIND) # 初始化种群染色体矩阵(内含解码,详见Population类的源码),此时种群规模将调整为uniformPoint点集的大小,initChrom函数会把种群规模给重置 else: population.Phen = population.decoding() # 染色体解码 self.problem.aimFunc(population) # 计算种群的目标函数值 self.evalsNum = population.sizes # 记录评价次数 #===========================开始进化============================ while self.terminated(population) == False: # 选择个体参与进化 offspring = population[ea.selecting(self.selFunc, population.FitnV, NIND)] # 对选出的个体进行进化操作 offspring.Chrom = self.recOper.do(offspring.Chrom) # 重组 offspring.Chrom = self.mutOper.do(offspring.Encoding, offspring.Chrom, offspring.Field) # 变异 offspring.Phen = offspring.decoding() # 解码 self.problem.aimFunc(offspring) # 求进化后个体的目标函数值 self.evalsNum += offspring.sizes # 更新评价次数 # 重插入生成新一代种群 population = self.reinsertion(population, offspring, refPoint) # 修改refPoint refPoint[NIND:, :] = self.renewRefPoint(population.ObjV, refPoint[NIND:, :]) if (self.currentGen) % np.ceil(self.fr * self.MAXGEN) == 0: refPoint[:NIND, :] = uniformPoint * (np.max(population.ObjV, 0) - np.min(population.ObjV, 0)) # 后续处理,限制种群规模(因为此时种群规模有可能大于NIND) [levels, criLevel] = self.ndSort(self.problem.maxormins * population.ObjV, NIND, None, population.CV) # 对NIND个个体进行非支配分层 population = population[ea.refselect(self.problem.maxormins * population.ObjV, levels, criLevel, NIND, uniformPoint)] # 根据参考点选择个体 return self.finishing(population) # 调用finishing完成后续工作并返回结果
def run(self): #==========================初始化配置=========================== population = self.population self.initialization() # 初始化算法模板的一些动态参数 #===========================准备进化============================ uniformPoint, NIND = ea.crtup(self.problem.M, population.sizes) # 生成在单位目标维度上均匀分布的参考点集 if population.Chrom is None or population.sizes != NIND: population.initChrom(NIND) # 初始化种群染色体矩阵(内含解码,详见Population类的源码),此时种群规模将调整为uniformPoint点集的大小,initChrom函数会把种群规模给重置 else: population.Phen = population.decoding() # 染色体解码 self.problem.aimFunc(population) # 计算种群的目标函数值 self.evalsNum = population.sizes # 记录评价次数 #===========================开始进化============================ while self.terminated(population) == False: # 选择个体参与进化 offspring = population[ea.selecting(self.selFunc, population.FitnV, NIND)] # 对选出的个体进行进化操作 offspring.Chrom = self.recOper.do(offspring.Chrom) # 重组 offspring.Chrom = self.mutOper.do(offspring.Encoding, offspring.Chrom, offspring.Field) # 变异 offspring.Phen = offspring.decoding() # 解码 self.problem.aimFunc(offspring) # 求进化后个体的目标函数值 self.evalsNum += offspring.sizes # 更新评价次数 # 重插入生成新一代种群 population = self.reinsertion(population, offspring, NIND, uniformPoint) return self.finishing(population) # 调用finishing完成后续工作并返回结果
def run(self): #==========================初始化配置=========================== population = self.population self.initialization() # 初始化算法模板的一些动态参数 #===========================准备进化============================ uniformPoint, NIND = ea.crtup(self.problem.M, population.sizes) # 生成在单位目标维度上均匀分布的参考点集 if population.Chrom is None or population.sizes != NIND: population.initChrom(NIND) # 初始化种群染色体矩阵(内含解码,详见Population类的源码),此时种群规模将调整为uniformPoint点集的大小,initChrom函数会把种群规模给重置 else: population.Phen = population.decoding() # 染色体解码 self.problem.aimFunc(population) # 计算种群的目标函数值 self.evalsNum = population.sizes # 记录评价次数 #===========================开始进化============================ while self.terminated(population) == False: # 进行差分进化操作 r0 = ea.selecting(self.selFunc, population.FitnV, NIND) # 得到基向量索引 offspring = population.copy() # 存储子代种群 offspring.Chrom = ea.mutate(self.mutFunc, offspring.Encoding, offspring.Chrom, offspring.Field, r0, self.F, 1) # 差分变异 tempPop = population + offspring # 当代种群个体与变异个体进行合并(为的是后面用于重组) offspring.Chrom = ea.recombin(self.recFunc, tempPop.Chrom, self.pc, True) # 重组 # 求进化后个体的目标函数值 offspring.Phen = offspring.decoding() # 染色体解码 self.problem.aimFunc(offspring) # 计算目标函数值 self.evalsNum += offspring.sizes # 更新评价次数 # 重插入生成新一代种群 population = self.reinsertion(population, offspring, NIND, uniformPoint) return self.finishing(population) # 调用finishing完成后续工作并返回结果
def calBest(self): # 计算全局最优解 uniformPoint, ans = ea.crtup(self.M, 10000) # 生成10000个在各目标的单位维度上均匀分布的参考点 globalBestObjV = uniformPoint / np.tile( np.sqrt(np.sum(uniformPoint**2, 1, keepdims=True)), (1, self.M)) return globalBestObjV
def run(self, prophetPop=None): # prophetPop为先知种群(即包含先验知识的种群) # ==========================初始化配置=========================== population = self.population self.initialization() # 初始化算法类的一些动态参数 # ===========================准备进化============================ uniformPoint, NIND = ea.crtup(self.problem.M, population.sizes) # 生成在单位目标维度上均匀分布的参考点集 refPoint = uniformPoint.copy() # 初始化参考点为uniformPoint population.initChrom( NIND ) # 初始化种群染色体矩阵,此时种群规模将调整为uniformPoint点集的大小,initChrom函数会把种群规模给重置 # 插入先验知识(注意:这里不会对先知种群prophetPop的合法性进行检查) if prophetPop is not None: print('本算法需谨慎使用先验知识,有可能会导致结果比先验知识差。') population = (prophetPop + population)[:NIND] # 插入先知种群 self.call_aimFunc(population) # 计算种群的目标函数值 # ===========================开始进化============================ while not self.terminated(population): # 选择个体参与进化 offspring = population[ea.selecting(self.selFunc, population.sizes, NIND)] # 对选出的个体进行进化操作 offspring.Chrom = self.recOper.do(offspring.Chrom) # 重组 offspring.Chrom = self.mutOper.do(offspring.Encoding, offspring.Chrom, offspring.Field) # 变异 self.call_aimFunc(offspring) # 求进化后个体的目标函数值 population = self.reinsertion(population, offspring, refPoint) # 重插入生成新一代种群 # 修改refPoint if (self.currentGen) % np.ceil(self.fr * self.MAXGEN) == 0: refPoint = uniformPoint * (np.max(population.ObjV, 0) - np.min(population.ObjV, 0)) self.Gamma = None # 重置Gamma为None return self.finishing(population) # 调用finishing完成后续工作并返回结果
def calBest(self): # 计算全局最优解 N = 10000 # 设置所要生成的全局最优解的个数 Point, num = ea.crtup(self.M, N) # 生成N个在各目标的单位维度上均匀分布的参考点 M = self.M c = np.ones((num, M)) for i in range(num): for j in range(1, M): temp = Point[i, j] / Point[i, 0] * np.prod(1 - c[i, M - j:M - 1]) c[i, M - j - 1] = (temp**2 - temp + np.sqrt(2 * temp)) / (temp**2 + 1) x = np.arccos(c) * 2 / np.pi temp = (1 - np.sin( np.pi / 2 * x[:, [1]])) * Point[:, [M - 1]] / Point[:, [M - 2]] a = np.linspace(0, 1, 10000 + 1) for i in range(num): E = np.abs(temp[i] * (1 - np.cos(np.pi / 2 * a)) - 1 + a * np.cos(5 * np.pi * a)**2) rank = np.argsort(E, kind='mergesort') x[i, 0] = a[np.min(rank[0:10])] Point = convex(x) Point[:, [M - 1]] = disc(x) [levels, criLevel] = ea.ndsortESS(Point, None, 1) # 非支配分层,只分出第一层即可 Point = Point[np.where(levels == 1)[0], :] # 只保留点集中的非支配点 globalBestObjV = np.tile(np.array([list(range(2, 2 * self.M + 1, 2))]), (Point.shape[0], 1)) * Point return globalBestObjV
def run(self, prophetPop=None): # prophetPop为先知种群(即包含先验知识的种群) #==========================初始化配置=========================== population = self.population self.initialization() # 初始化算法模板的一些动态参数 #===========================准备进化============================ uniformPoint, NIND = ea.crtup(self.problem.M, population.sizes) # 生成在单位目标维度上均匀分布的参考点集 if population.Chrom is None or population.sizes != NIND: # 如果种群染色体还没初始化或者规模与NIND不一致,则进行初始化 population.initChrom( NIND ) # 初始化种群染色体矩阵,此时种群规模将调整为uniformPoint点集的大小,initChrom函数会把种群规模给重置 self.call_aimFunc(population) # 计算种群的目标函数值 # 插入先验知识(注意:这里不会对先知种群prophetPop的合法性进行检查,故应确保prophetPop是一个种群类且拥有合法的Chrom、ObjV、Phen等属性) if prophetPop is not None: population = (prophetPop + population)[:NIND] # 插入先知种群 #===========================开始进化============================ while self.terminated(population) == False: # 选择个体参与进化 offspring = population[ea.selecting(self.selFunc, population.FitnV, NIND)] # 对选出的个体进行进化操作 offspring.Chrom = self.recOper.do(offspring.Chrom) # 重组 offspring.Chrom = self.mutOper.do(offspring.Encoding, offspring.Chrom, offspring.Field) # 变异 self.call_aimFunc(offspring) # 求进化后个体的目标函数值 # 重插入生成新一代种群 population = self.reinsertion(population, offspring, NIND, uniformPoint) return self.finishing(population) # 调用finishing完成后续工作并返回结果
def calReferObjV(self): # 设定目标数参考值(本问题目标函数参考值设定为理论最优值,即“真实帕累托前沿点”) N = 10000 # 设置所要生成的全局最优解的个数 Point, num = ea.crtup(self.M, N) # 生成N个在各目标的单位维度上均匀分布的参考点 M = self.M c = np.ones((num, M)) for i in range(num): for j in range(1, M): temp = Point[i, j] / Point[i, 0] * np.prod(1 - c[i, M - j:M - 1]) c[i, M - j - 1] = (temp**2 - temp + np.sqrt(2 * temp)) / (temp**2 + 1) x = np.arccos(c) * 2 / np.pi temp = (1 - np.sin( np.pi / 2 * x[:, [1]])) * Point[:, [M - 1]] / Point[:, [M - 2]] a = np.linspace(0, 1, 10000 + 1) for i in range(num): E = np.abs(temp[i] * (1 - np.cos(np.pi / 2 * a)) - 1 + a + np.cos(10 * np.pi * a + np.pi / 2) / 10 / np.pi) rank = np.argsort(E, kind='mergesort') x[i, 0] = a[np.min(rank[0:10])] Point = convex(x) Point[:, [M - 1]] = mixed(x) referenceObjV = np.tile(np.array([list(range(2, 2 * self.M + 1, 2))]), (num, 1)) * Point return referenceObjV
def calBest(self): # 计算全局最优解 globalBestObjV, ans = ea.crtup(self.M, 10000) # 生成10000个在各目标的单位维度上均匀分布的参考点 globalBestObjV /= np.sqrt( np.sum(globalBestObjV**2, 1, keepdims=True) - 3 / 4 * np.max(globalBestObjV**2, 1, keepdims=True)) return globalBestObjV
def run(self): #==========================初始化配置=========================== population = self.population self.initialization() # 初始化算法模板的一些动态参数 #===========================准备进化============================ uniformPoint, NIND = ea.crtup(self.problem.M, population.sizes) # 生成在单位目标维度上均匀分布的参考点集 refPoint = uniformPoint.copy() # 初始化参考点为uniformPoint if population.Chrom is None or population.sizes != NIND: population.initChrom(NIND) # 初始化种群染色体矩阵(内含解码,详见Population类的源码),此时种群规模将调整为uniformPoint点集的大小,initChrom函数会把种群规模给重置 self.problem.aimFunc(population) # 计算种群的目标函数值 self.evalsNum = population.sizes # 记录评价次数 #===========================开始进化============================ while self.terminated(population) == False: # 选择个体参与进化 offspring = population[ea.selecting(self.selFunc, population.FitnV, NIND)] # 对选出的个体进行进化操作 offspring.Chrom = ea.recombin(self.recFunc, offspring.Chrom, self.pc) # 重组 offspring.Chrom = ea.mutate(self.mutFunc, offspring.Encoding, offspring.Chrom, offspring.Field, self.pm) # 变异 offspring.Phen = offspring.decoding() # 解码 self.problem.aimFunc(offspring) # 求进化后个体的目标函数值 self.evalsNum += offspring.sizes # 更新评价次数 # 重插入生成新一代种群 population = self.reinsertion(population, offspring, refPoint) # 修改refPoint if (self.currentGen) % np.ceil(self.fr * self.MAXGEN) == 0: refPoint = uniformPoint * (np.max(population.ObjV, 0) - np.min(population.ObjV, 0)) self.Gamma = None # 重置Gamma为None return self.finishing(population) # 调用finishing完成后续工作并返回结果
def run(self, prophetPop = None): # prophetPop为先知种群(即包含先验知识的种群) #==========================初始化配置=========================== population = self.population self.initialization() # 初始化算法模板的一些动态参数 #===========================准备进化============================ uniformPoint, NIND = ea.crtup(self.problem.M, population.sizes) # 生成在单位目标维度上均匀分布的参考点集 refPoint = uniformPoint.copy() # 初始化参考点为uniformPoint if population.Chrom is None or population.sizes != NIND: population.initChrom(NIND) # 初始化种群染色体矩阵(内含解码,详见Population类的源码),此时种群规模将调整为uniformPoint点集的大小,initChrom函数会把种群规模给重置 else: population.Phen = population.decoding() # 染色体解码 self.problem.aimFunc(population) # 计算种群的目标函数值 self.evalsNum = population.sizes # 记录评价次数 # 插入先验知识(注意:这里不会对先知种群prophetPop的合法性进行检查,故应确保prophetPop是一个种群类且拥有合法的Chrom、ObjV、Phen等属性) if prophetPop is not None: print('本算法需谨慎使用先验知识,有可能会导致结果比先验知识差。') population = (prophetPop + population)[:NIND] # 插入先知种群 #===========================开始进化============================ while self.terminated(population) == False: # 选择个体参与进化 offspring = population[ea.selecting(self.selFunc, population.FitnV, NIND)] # 对选出的个体进行进化操作 offspring.Chrom = self.recOper.do(offspring.Chrom) # 重组 offspring.Chrom = self.mutOper.do(offspring.Encoding, offspring.Chrom, offspring.Field) # 变异 offspring.Phen = offspring.decoding() # 解码 self.problem.aimFunc(offspring) # 求进化后个体的目标函数值 self.evalsNum += offspring.sizes # 更新评价次数 # 重插入生成新一代种群 population = self.reinsertion(population, offspring, refPoint) # 修改refPoint if (self.currentGen) % np.ceil(self.fr * self.MAXGEN) == 0: refPoint = uniformPoint * (np.max(population.ObjV, 0) - np.min(population.ObjV, 0)) self.Gamma = None # 重置Gamma为None return self.finishing(population) # 调用finishing完成后续工作并返回结果
def calReferObjV(self): # 设定目标数参考值(本问题目标函数参考值设定为理论最优值,即“真实帕累托前沿点”) referenceObjV, ans = ea.crtup(self.M, 10000) # 生成10000个在各目标的单位维度上均匀分布的参考点 referenceObjV /= np.sqrt( np.sum(referenceObjV**2, 1, keepdims=True) - 3 / 4 * np.max(referenceObjV**2, 1, keepdims=True)) return referenceObjV
def run(self): #==========================初始化配置=========================== population = self.population self.initialization() # 初始化算法模板的一些动态参数 #===========================准备进化============================ uniformPoint, NIND = ea.crtup(self.problem.M, population.sizes) # 生成在单位目标维度上均匀分布的参考点集 population.initChrom( NIND ) # 初始化种群染色体矩阵(内含解码,详见Population类的源码),此时种群规模将调整为uniformPoint点集的大小,initChrom函数会把种群规模给重置 self.problem.aimFunc(population) # 计算种群的目标函数值 self.evalsNum = population.sizes # 记录评价次数 #===========================开始进化============================ while self.terminated(population) == False: # 选择个体参与进化 offspring = population[ea.selecting(self.selFunc, population.FitnV, NIND)] # 进行进化操作,分别对各个种群染色体矩阵进行重组和变异 for i in range(population.ChromNum): offspring.Chroms[i] = ea.recombin(self.recFuncs[i], offspring.Chroms[i], self.pcs[i]) #重组 offspring.Chroms[i] = ea.mutate(self.mutFuncs[i], offspring.Encodings[i], offspring.Chroms[i], offspring.Fields[i], self.pms[i]) # 变异 offspring.Phen = offspring.decoding() # 解码 self.problem.aimFunc(offspring) # 求进化后个体的目标函数值 self.evalsNum += offspring.sizes # 更新评价次数 # 重插入生成新一代种群 population = self.reinsertion(population, offspring, NIND, uniformPoint) return self.finishing(population) # 调用finishing完成后续工作并返回结果
def run(self, prophetPop = None): # prophetPop为先知种群(即包含先验知识的种群) #==========================初始化配置=========================== population = self.population self.initialization() # 初始化算法模板的一些动态参数 #===========================准备进化============================ uniformPoint, NIND = ea.crtup(self.problem.M, population.sizes) # 生成在单位目标维度上均匀分布的参考点集 population.initChrom(NIND) # 初始化种群染色体矩阵,此时种群规模将调整为uniformPoint点集的大小,initChrom函数会把种群规模给重置 self.call_aimFunc(population) # 计算种群的目标函数值 # 插入先验知识(注意:这里不会对先知种群prophetPop的合法性进行检查,故应确保prophetPop是一个种群类且拥有合法的Chrom、ObjV、Phen等属性) if prophetPop is not None: population = (prophetPop + population)[:NIND] # 插入先知种群 # 确定邻域大小 if self.neighborSize is None: self.neighborSize = population.sizes self.neighborSize = max(self.neighborSize, 2) # 确保不小于2 # 生成由所有邻居索引组成的矩阵 neighborIdx = np.argsort(cdist(uniformPoint, uniformPoint), axis=1, kind='mergesort')[:, :self.neighborSize] # 计算理想点 idealPoint = ea.crtidp(population.ObjV, population.CV, self.problem.maxormins) # 创建全局存档 if self.MAXSIZE is None: self.MAXSIZE = 10 * population.sizes # 默认为10倍的种群个体数 [levels, criLevel] = ea.ndsortDED(population.ObjV, NIND, None, population.CV, self.problem.maxormins) # 对NIND个个体进行非支配分层 globalNDSet = population[np.where(levels == 1)[0]] # 创建全局存档,该全局存档贯穿进化始终,随着进化不断更新 if globalNDSet.CV is not None: # CV不为None说明有设置约束条件 globalNDSet = globalNDSet[np.where(np.all(globalNDSet.CV <= 0, 1))[0]] # 排除非可行解 #===========================开始进化============================ while self.terminated(population) == False: select_rands = np.random.rand(population.sizes) # 生成一组随机数 for i in range(population.sizes): indices = neighborIdx[i, :] # 得到邻居索引 if select_rands[i] < self.Ps: chooseIdx = indices[ea.rps(self.neighborSize, 2)] # 只从邻域中选择 else: chooseIdx = ea.rps(population.sizes, 2) matting_Chrom = population.Chrom[chooseIdx, :] # 选出2条来自被选个体的染色体 offspring = ea.Population(population.Encoding, population.Field, 1) # 实例化一个种群对象用于存储进化的后代(这里只进化生成一个后代) # 对选出的个体进行进化操作 offspring.Chrom = self.recOper.do(matting_Chrom) # 重组 offspring.Chrom = self.mutOper.do(offspring.Encoding, offspring.Chrom, offspring.Field) # 变异 self.call_aimFunc(offspring) # 求进化后个体的目标函数值 # 更新理想点 idealPoint = ea.crtidp(offspring.ObjV, offspring.CV, self.problem.maxormins, idealPoint) # 重插入更新种群个体 self.reinsertion(indices, population, offspring, idealPoint, uniformPoint) # 完成当代的进化后,更新全局存档 globalNDSet = population + globalNDSet # 将population与全局归档集合并 [levels, criLevel] = ea.ndsortDED(globalNDSet.ObjV, None, None, globalNDSet.CV, self.problem.maxormins) # 非支配排序 globalNDSet = globalNDSet[np.where(levels == 1)[0]] if globalNDSet.CV is not None: # CV不为None说明有设置约束条件 globalNDSet = globalNDSet[np.where(np.all(globalNDSet.CV <= 0, 1))[0]] # 排除非可行解 if globalNDSet.sizes > self.MAXSIZE: globalNDSet = globalNDSet[ea.rps(globalNDSet.sizes, self.MAXSIZE)] # 采用rps随机排列选择,控制全局存档的大小 self.passTime += time.time() - self.timeSlot # 更新用时记录 #=========================绘图及输出结果========================= if self.drawing != 0: ea.moeaplot(globalNDSet.ObjV, 'Pareto Front', saveFlag = True, gridFlag = True) # 返回帕累托最优集 return globalNDSet
def calBest(self): # 计算全局最优解 N = 10000 # 设置所要生成的全局最优解的个数 Point, num = ea.crtup(self.M, N) # 生成N个在各目标的单位维度上均匀分布的参考点 Point = Point / np.tile(np.sqrt(np.array([np.sum(Point**2, 1)]).T), (1, self.M)) globalBestObjV = np.tile(np.array([list(range(2, 2 * self.M + 1, 2))]), (Point.shape[0], 1)) * Point return globalBestObjV
def calReferObjV(self): # 设定目标数参考值(本问题目标函数参考值设定为理论最优值,即“真实帕累托前沿点”) N = 10000 # 设置所要生成的全局最优解的个数 Point, num = ea.crtup(self.M, N) # 生成N个在各目标的单位维度上均匀分布的参考点 Point = Point / np.tile(np.sqrt(np.array([np.sum(Point**2, 1)]).T), (1, self.M)) referenceObjV = np.tile(np.array([list(range(2, 2 * self.M + 1, 2))]), (Point.shape[0], 1)) * Point return referenceObjV
def run(self, prophetPop=None): # prophetPop为先知种群(即包含先验知识的种群) # ==========================初始化配置=========================== population = self.population self.initialization() # 初始化算法类的一些动态参数 # ===========================准备进化============================ uniformPoint, NIND = ea.crtup(self.problem.M, population.sizes) # 生成在单位目标维度上均匀分布的参考点集 population.initChrom( NIND ) # 初始化种群染色体矩阵,此时种群规模将调整为uniformPoint点集的大小,initChrom函数会把种群规模给重置 # 插入先验知识(注意:这里不会对先知种群prophetPop的合法性进行检查) if prophetPop is not None: population = (prophetPop + population)[:NIND] # 插入先知种群 self.call_aimFunc(population) # 计算种群的目标函数值 # 确定邻域大小 if self.neighborSize is None: self.neighborSize = population.sizes // 10 self.neighborSize = max(self.neighborSize, 2) # 确保不小于2 # 生成由所有邻居索引组成的矩阵 neighborIdx = np.argsort(ea.cdist(uniformPoint, uniformPoint), axis=1, kind='mergesort')[:, :self.neighborSize] neighborIdx_list = [] for i in range(population.sizes): neighborIdx_list.append(neighborIdx[i, :]) offspring = ea.Population(population.Encoding, population.Field, 1) # 实例化一个种群对象用于存储进化的后代(每一代只进化生成一个后代) # 计算理想点 idealPoint = ea.crtidp(population.ObjV, population.CV, self.problem.maxormins) # ===========================开始进化============================ while not self.terminated(population): select_rands = np.random.rand(population.sizes) # 生成一组随机数 Masks = np.random.rand(population.sizes, population.Lind) < self.Cr for i in range(population.sizes): if select_rands[i] < self.Ps: indices = neighborIdx_list[i] else: indices = np.arange(population.sizes) r = indices[ea.rps(len(indices), 2)] # 随机选择两个索引作为差分向量的索引 r1, r2 = r[0], r[1] # 得到差分向量索引 offspring.Chrom = population.Chrom[[i], :] Mask = Masks[i] offspring.Chrom[0][Mask] = offspring.Chrom[0][ Mask] + self.F * (population.Chrom[r1][Mask] - population.Chrom[r2][Mask]) offspring.Chrom = self.mutOper.do(offspring.Encoding, offspring.Chrom, offspring.Field) # 多项式变异 self.call_aimFunc(offspring) # 求进化后个体的目标函数值 # 更新理想点 idealPoint = ea.crtidp(offspring.ObjV, offspring.CV, self.problem.maxormins, idealPoint) # 重插入更新种群个体 self.reinsertion(indices, population, offspring, idealPoint, uniformPoint) return self.finishing(population) # 调用finishing完成后续工作并返回结果
def run(self, prophetPop=None): # prophetPop为先知种群(即包含先验知识的种群) #==========================初始化配置=========================== population = self.population self.initialization() # 初始化算法模板的一些动态参数 #===========================准备进化============================ uniformPoint, NIND = ea.crtup(self.problem.M, population.sizes) # 生成在单位目标维度上均匀分布的参考点集 population.initChrom( NIND ) # 初始化种群染色体矩阵,此时种群规模将调整为uniformPoint点集的大小,initChrom函数会把种群规模给重置 self.call_aimFunc(population) # 计算种群的目标函数值 # 插入先验知识(注意:这里不会对先知种群prophetPop的合法性进行检查,故应确保prophetPop是一个种群类且拥有合法的Chrom、ObjV、Phen等属性) if prophetPop is not None: population = (prophetPop + population)[:NIND] # 插入先知种群 # 确定邻域大小 if self.neighborSize is None: self.neighborSize = population.sizes // 10 self.neighborSize = max(self.neighborSize, 2) # 确保不小于2 # 生成由所有邻居索引组成的矩阵 neighborIdx = np.argsort(cdist(uniformPoint, uniformPoint), axis=1, kind='mergesort')[:, :self.neighborSize] # 计算理想点 idealPoint = ea.crtidp(population.ObjV, population.CV, self.problem.maxormins) #===========================开始进化============================ while self.terminated(population) == False: select_rands = np.random.rand(population.sizes) # 生成一组随机数 for i in range(population.sizes): if select_rands[i] < self.Ps: indices = neighborIdx[i, :] else: indices = np.arange(population.sizes) offspring = ea.Population(population.Encoding, population.Field, 1) # 实例化一个种群对象用于存储进化的后代(这里只进化生成一个后代) r = indices[ea.rps(len(indices), 2)] r1, r2 = r[[0]], r[[1]] # 得到差分向量索引 pop_Chrom = population.Chrom[[i], :] # 进行进化操作 offspring.Chrom = pop_Chrom + self.F * ( population.Chrom[r1, :] - population.Chrom[r2, :]) # 差分变异 offspring.Chrom = self.recOper.do( np.vstack([pop_Chrom, offspring.Chrom])) # 重组 offspring.Chrom = self.mutOper.do(offspring.Encoding, offspring.Chrom, offspring.Field) # 多项式变异 self.call_aimFunc(offspring) # 求进化后个体的目标函数值 # 更新理想点 idealPoint = ea.crtidp(offspring.ObjV, offspring.CV, self.problem.maxormins, idealPoint) # 重插入更新种群个体 self.reinsertion(indices, population, offspring, idealPoint, uniformPoint) return self.finishing(population) # 调用finishing完成后续工作并返回结果
def run(self, prophetPop=None): # prophetPop为先知种群(即包含先验知识的种群) # ==========================初始化配置=========================== population = self.population self.initialization() # 初始化算法类的一些动态参数 # ===========================准备进化============================ uniformPoint, NIND = ea.crtup(self.problem.M, population.sizes) # 生成在单位目标维度上均匀分布的参考点集 population.initChrom( NIND ) # 初始化种群染色体矩阵,此时种群规模将调整为uniformPoint点集的大小,initChrom函数会把种群规模给重置 # 插入先验知识(注意:这里不会对先知种群prophetPop的合法性进行检查) if prophetPop is not None: population = (prophetPop + population)[:NIND] # 插入先知种群 self.call_aimFunc(population) # 计算种群的目标函数值 # 确定邻域大小 if self.neighborSize is None: self.neighborSize = population.sizes self.neighborSize = max(self.neighborSize, 2) # 确保不小于2 # 生成由所有邻居索引组成的矩阵 neighborIdx = np.argsort(ea.cdist(uniformPoint, uniformPoint), axis=1, kind='mergesort')[:, :self.neighborSize] neighborIdx_list = [] for i in range(population.sizes): neighborIdx_list.append(neighborIdx[i, :]) offspring = ea.Population(population.Encoding, population.Field, 1) # 实例化一个种群对象用于存储进化的后代(每一代只进化生成一个后代) # 计算理想点 idealPoint = ea.crtidp(population.ObjV, population.CV, self.problem.maxormins) # ===========================开始进化============================ while not self.terminated(population): select_rands = np.random.rand(population.sizes) # 生成一组随机数 for i in range(population.sizes): indices = neighborIdx_list[i] # 得到邻居索引 if select_rands[i] < self.Ps: chooseIdx = indices[ea.rps(self.neighborSize, 2)] # 只从邻域中选择 else: chooseIdx = ea.rps(population.sizes, 2) matting_Chrom = population.Chrom[ chooseIdx, :] # 选出2条来自被选个体的染色体 # 对选出的个体进行进化操作 offspring.Chrom = self.recOper.do(matting_Chrom) # 重组 offspring.Chrom = self.mutOper.do(offspring.Encoding, offspring.Chrom, offspring.Field) # 变异 self.call_aimFunc(offspring) # 求进化后个体的目标函数值 # 更新理想点 idealPoint = ea.crtidp(offspring.ObjV, offspring.CV, self.problem.maxormins, idealPoint) # 重插入更新种群个体 self.reinsertion(indices, population, offspring, idealPoint, uniformPoint) return self.finishing(population) # 调用finishing完成后续工作并返回结果
def run(self): #==========================初始化配置=========================== population = self.population self.timeSlot = time.time() # 开始计时 uniformPoint, NIND = ea.crtup(self.problem.M, population.sizes) # 生成在单位目标维度上均匀分布的参考点集 if population.Chrom is None or population.sizes != NIND: population.initChrom( NIND ) # 初始化种群染色体矩阵(内含解码,详见Population类的源码),此时种群规模将调整为uniformPoint点集的大小,initChrom函数会把种群规模给重置 population.ObjV, population.CV = self.problem.aimFuc( population.Phen, population.CV) # 计算种群的目标函数值 self.evalsNum = population.sizes # 记录评价次数 #===========================开始进化============================ self.currentGen = 0 while self.terminated(population) == False: population.shuffle() # 打乱个体顺序 # 进行差分进化操作 mutPop = population.copy() mutPop.Chrom = ea.mutate(self.mutFunc, mutPop.Encoding, mutPop.Chrom, mutPop.Field, self.F, 1) # 差分变异 tempPop = population + mutPop # 当代种群个体与变异个体进行合并(为的是后面用于重组) experimentPop = population.copy() # 试验种群 experimentPop.Chrom = ea.recombin(self.recFunc, tempPop.Chrom, self.pc, True) # 重组 # 求进化后个体的目标函数值 experimentPop.Phen = experimentPop.decoding() # 染色体解码 experimentPop.ObjV, experimentPop.CV = self.problem.aimFuc( experimentPop.Phen, experimentPop.CV) self.evalsNum += experimentPop.sizes # 更新评价次数 # 合并 population = population + experimentPop population.FitnV = self.calFitnV(population, NIND, uniformPoint) # 计算合并种群的适应度 population = population[ea.selecting('dup', population.FitnV, NIND)] # 选择操作,保留NIND个个体 # 得到非支配种群 [levels, criLevel] = self.ndSort(self.problem.maxormins * population.ObjV, NIND, 1, population.CV) # 非支配分层 NDSet = population[np.where(levels == 1)[0]] # 只保留种群中的非支配个体,形成一个非支配种群 NDSet = NDSet[np.where(np.all(NDSet.CV <= 0, 1))[0]] # 最后要彻底排除非可行解 self.passTime += time.time() - self.timeSlot # 更新用时记录 # 绘图 if self.drawing != 0: ea.moeaplot(NDSet.ObjV, True) # 返回帕累托最优集 return NDSet
def run(self, prophetPop=None): # prophetPop为先知种群(即包含先验知识的种群) #==========================初始化配置=========================== population = self.population self.initialization() # 初始化算法模板的一些动态参数 #===========================准备进化============================ uniformPoint, NIND = ea.crtup(self.problem.M, population.sizes) # 生成在单位目标维度上均匀分布的参考点集 refPoint = np.vstack( [uniformPoint, np.random.rand(NIND, self.problem.M)]) # 初始化参考点(详见注释中的参考文献) population.initChrom( NIND ) # 初始化种群染色体矩阵,此时种群规模将调整为uniformPoint点集的大小,initChrom函数会把种群规模给重置 self.call_aimFunc(population) # 计算种群的目标函数值 # 插入先验知识(注意:这里不会对先知种群prophetPop的合法性进行检查,故应确保prophetPop是一个种群类且拥有合法的Chrom、ObjV、Phen等属性) if prophetPop is not None: print('本算法需谨慎使用先验知识,有可能会导致结果比先验知识差。') population = (prophetPop + population)[:NIND] # 插入先知种群 #===========================开始进化============================ while self.terminated(population) == False: # 选择个体参与进化 offspring = population[ea.selecting(self.selFunc, population.FitnV, NIND)] # 进行进化操作,分别对各个种群染色体矩阵进行重组和变异 for i in range(population.ChromNum): offspring.Chroms[i] = self.recOpers[i].do( offspring.Chroms[i]) # 重组 offspring.Chroms[i] = self.mutOpers[i].do( offspring.Encodings[i], offspring.Chroms[i], offspring.Fields[i]) # 变异 self.call_aimFunc(offspring) # 求进化后个体的目标函数值 population = self.reinsertion(population, offspring, refPoint) # 重插入生成新一代种群 # 修改refPoint refPoint[NIND:, :] = self.renewRefPoint(population.ObjV, refPoint[NIND:, :]) if (self.currentGen) % np.ceil(self.fr * self.MAXGEN) == 0: refPoint[:NIND, :] = uniformPoint * ( np.max(population.ObjV, 0) - np.min(population.ObjV, 0)) # 后续处理,限制种群规模(因为此时种群规模有可能大于NIND) [levels, criLevel] = self.ndSort(self.problem.maxormins * population.ObjV, NIND, None, population.CV) # 对NIND个个体进行非支配分层 population = population[ea.refselect( self.problem.maxormins * population.ObjV, levels, criLevel, NIND, uniformPoint)] # 根据参考点选择个体 return self.finishing(population) # 调用finishing完成后续工作并返回结果
def calReferObjV(self): # 设定目标数参考值(本问题目标函数参考值设定为理论最优值,即“真实帕累托前沿点”) Point, ans = ea.crtup(self.M, 10000) # 生成10000个在各目标的单位维度上均匀分布的参考点 Point /= np.tile(np.sqrt(np.sum(Point**2, 1, keepdims=True)), (1, self.M)) r = 0.4 if self.M == 3 else 0.5 referenceObjV = Point[np.where( np.min([ np.min((Point - 1)**2 + np.sum(Point**2, 1, keepdims=True) - Point**2 - r**2, 1, keepdims=True), np.sum((Point - 1 / np.sqrt(self.M))**2, 1, keepdims=True) - r**2 ], 0) <= 0)[0], :] return referenceObjV
def run(self): #==========================初始化配置=========================== population = self.population self.timeSlot = time.time() # 开始计时 uniformPoint, NIND = ea.crtup(self.problem.M, population.sizes) # 生成在单位目标维度上均匀分布的参考点集 if population.Chrom is None or population.sizes != NIND: population.initChrom( NIND ) # 初始化种群染色体矩阵(内含解码,详见Population类的源码),此时种群规模将调整为uniformPoint点集的大小,initChrom函数会把种群规模给重置 population.ObjV, population.CV = self.problem.aimFuc( population.Phen, population.CV) # 计算种群的目标函数值 self.evalsNum = population.sizes # 记录评价次数 #===========================开始进化============================ self.currentGen = 0 while self.terminated(population) == False: # 选择个体参与进化 offspring = population[ea.selecting(self.selFunc, population.FitnV, NIND)] # 对基个体进行进化操作 offspring.Chrom = ea.recombin(self.recFunc, offspring.Chrom, self.pc) #重组 offspring.Chrom = ea.mutate(self.mutFunc, offspring.Encoding, offspring.Chrom, offspring.Field, self.pm) # 变异 offspring.Phen = offspring.decoding() # 解码 offspring.ObjV, offspring.CV = self.problem.aimFuc( offspring.Phen, offspring.CV) # 求进化后个体的目标函数值 self.evalsNum += offspring.sizes # 更新评价次数 # 合并 population = population + offspring population.FitnV = self.calFitnV(population, NIND, uniformPoint) # 计算合并种群的适应度 population = population[ea.selecting('dup', population.FitnV, NIND)] # 选择操作,保留NIND个个体 # 得到非支配种群 [levels, criLevel] = self.ndSort(self.problem.maxormins * population.ObjV, NIND, 1, population.CV) # 非支配分层 NDSet = population[np.where(levels == 1)[0]] # 只保留种群中的非支配个体,形成一个非支配种群 NDSet = NDSet[np.where(np.all(NDSet.CV <= 0, 1))[0]] # 最后要彻底排除非可行解 self.passTime += time.time() - self.timeSlot # 更新用时记录 # 绘图 if self.drawing != 0: ea.moeaplot(NDSet.ObjV, True) # 返回帕累托最优集 return NDSet
def run(self, prophetPop=None): # prophetPop为先知种群(即包含先验知识的种群) # ==========================初始化配置=========================== population = self.population self.initialization() # 初始化算法模板的一些动态参数 # ===========================准备进化============================ uniformPoint, NIND = ea.crtup(self.problem.M, population.sizes) # 生成在单位目标维度上均匀分布的参考点集 population.initChrom(NIND) # 初始化种群染色体矩阵,此时种群规模将调整为uniformPoint点集的大小,initChrom函数会把种群规模给重置 self.call_aimFunc(population) # 计算种群的目标函数值 # 插入先验知识(注意:这里不会对先知种群prophetPop的合法性进行检查,故应确保prophetPop是一个种群类且拥有合法的Chrom、ObjV、Phen等属性) if prophetPop is not None: population = (prophetPop + population)[:NIND] # 插入先知种群 # 确定邻域大小 if self.neighborSize is None: self.neighborSize = population.sizes self.neighborSize = max(self.neighborSize, 2) # 确保不小于2 # 生成由所有邻居索引组成的矩阵 neighborIdx = np.argsort(cdist(uniformPoint, uniformPoint), axis=1, kind='mergesort')[:, :self.neighborSize] # 计算理想点 idealPoint = ea.crtidp(population.ObjV, population.CV, self.problem.maxormins) # 创建全局存档 if self.MAXSIZE is None: self.MAXSIZE = 10 * population.sizes # 默认为10倍的种群个体数 globalNDSet = self.updateNDSet(population) # 创建全局存档,该全局存档贯穿进化始终,随着进化不断更新 # ===========================开始进化============================ while self.terminated(population) == False: select_rands = np.random.rand(population.sizes) # 生成一组随机数 for i in range(population.sizes): indices = neighborIdx[i, :] # 得到邻居索引 if select_rands[i] < self.Ps: chooseIdx = indices[ea.rps(self.neighborSize, 2)] # 只从邻域中选择 else: chooseIdx = ea.rps(population.sizes, 2) matting_Chrom = population.Chrom[chooseIdx, :] # 选出2条来自被选个体的染色体 offspring = ea.Population(population.Encoding, population.Field, 1) # 实例化一个种群对象用于存储进化的后代(这里只进化生成一个后代) # 对选出的个体进行进化操作 offspring.Chrom = self.recOper.do(matting_Chrom) # 重组 offspring.Chrom = self.mutOper.do(offspring.Encoding, offspring.Chrom, offspring.Field) # 变异 self.call_aimFunc(offspring) # 求进化后个体的目标函数值 # 更新理想点 idealPoint = ea.crtidp(offspring.ObjV, offspring.CV, self.problem.maxormins, idealPoint) # 重插入更新种群个体 self.reinsertion(indices, population, offspring, idealPoint, uniformPoint) # 完成当代的进化后,更新全局存档 globalNDSet = self.updateNDSet(population, globalNDSet) return self.finishing(population, globalNDSet) # 调用finishing完成后续工作并返回结果
def run(self, prophetPop=None): # prophetPop为先知种群(即包含先验知识的种群) # ==========================初始化配置=========================== population = self.population self.initialization() # 初始化算法类的一些动态参数 # ===========================准备进化============================ uniformPoint, NIND = ea.crtup(self.problem.M, population.sizes) # 生成在单位目标维度上均匀分布的参考点集 population.initChrom(NIND) # 初始化种群染色体矩阵,此时种群规模将调整为uniformPoint点集的大小,initChrom函数会把种群规模给重置 # 插入先验知识(注意:这里不会对先知种群prophetPop的合法性进行检查) if prophetPop is not None: population = (prophetPop + population)[:NIND] # 插入先知种群 self.call_aimFunc(population) # 计算种群的目标函数值 # ===========================开始进化============================ while not self.terminated(population): # 选择个体参与进化 offspring = population[ea.selecting(self.selFunc, population.sizes, NIND)] # 对选出的个体进行进化操作 offspring.Chrom = self.recOper.do(offspring.Chrom) # 重组 offspring.Chrom = self.mutOper.do(offspring.Encoding, offspring.Chrom, offspring.Field) # 变异 self.call_aimFunc(offspring) # 求进化后个体的目标函数值 # 重插入生成新一代种群 population = self.reinsertion(population, offspring, NIND, uniformPoint) return self.finishing(population) # 调用finishing完成后续工作并返回结果
def run(self, prophetPop=None): # prophetPop为先知种群(即包含先验知识的种群) #==========================初始化配置=========================== population = self.population self.initialization() # 初始化算法模板的一些动态参数 #===========================准备进化============================ uniformPoint, NIND = ea.crtup(self.problem.M, population.sizes) # 生成在单位目标维度上均匀分布的参考点集 if population.Chrom is None or population.sizes != NIND: # 如果种群染色体还没初始化或者规模与NIND不一致,则进行初始化 population.initChrom( NIND ) # 初始化种群染色体矩阵(内含解码,详见PsyPopulation类的源码),此时种群规模将调整为uniformPoint点集的大小,initChrom函数会把种群规模给重置 else: population.Phen = population.decoding() # 染色体解码 self.problem.aimFunc(population) # 计算种群的目标函数值 self.evalsNum = population.sizes # 记录评价次数 # 插入先验知识(注意:这里不会对先知种群prophetPop的合法性进行检查,故应确保prophetPop是一个种群类且拥有合法的Chrom、ObjV、Phen等属性) if prophetPop is not None: population = (prophetPop + population)[:NIND] # 插入先知种群 #===========================开始进化============================ while self.terminated(population) == False: # 选择个体参与进化 offspring = population[ea.selecting(self.selFunc, population.FitnV, NIND)] # 进行进化操作,分别对各个种群染色体矩阵进行重组和变异 for i in range(population.ChromNum): offspring.Chroms[i] = self.recOpers[i].do( offspring.Chroms[i]) # 重组 offspring.Chroms[i] = self.mutOpers[i].do( offspring.Encodings[i], offspring.Chroms[i], offspring.Fields[i]) # 变异 offspring.Phen = offspring.decoding() # 解码 self.problem.aimFunc(offspring) # 求进化后个体的目标函数值 self.evalsNum += offspring.sizes # 更新评价次数 # 重插入生成新一代种群 population = self.reinsertion(population, offspring, NIND, uniformPoint) return self.finishing(population) # 调用finishing完成后续工作并返回结果
def run(self, prophetPop=None): # prophetPop为先知种群(即包含先验知识的种群) #==========================初始化配置=========================== population = self.population self.initialization() # 初始化算法模板的一些动态参数 #===========================准备进化============================ uniformPoint, NIND = ea.crtup(self.problem.M, population.sizes) # 生成在单位目标维度上均匀分布的参考点集 if population.Chrom is None or population.sizes != NIND: # 如果种群染色体还没初始化或者规模与NIND不一致,则进行初始化 population.initChrom( NIND ) # 初始化种群染色体矩阵(内含解码,详见Population类的源码),此时种群规模将调整为uniformPoint点集的大小,initChrom函数会把种群规模给重置 else: population.Phen = population.decoding() # 染色体解码 self.problem.aimFunc(population) # 计算种群的目标函数值 self.evalsNum = population.sizes # 记录评价次数 # 插入先验知识(注意:这里不会对先知种群prophetPop的合法性进行检查,故应确保prophetPop是一个种群类且拥有合法的Chrom、ObjV、Phen等属性) if prophetPop is not None: population = (prophetPop + population)[:NIND] # 插入先知种群 #===========================开始进化============================ while self.terminated(population) == False: # 进行差分进化操作 r0 = ea.selecting(self.selFunc, population.FitnV, NIND) # 得到基向量索引 offspring = population.copy() # 存储子代种群 offspring.Chrom = self.mutOper.do(offspring.Encoding, offspring.Chrom, offspring.Field, [r0]) # 变异 tempPop = population + offspring # 当代种群个体与变异个体进行合并(为的是后面用于重组) offspring.Chrom = self.recOper.do(tempPop.Chrom) # 重组 # 求进化后个体的目标函数值 offspring.Phen = offspring.decoding() # 染色体解码 self.problem.aimFunc(offspring) # 计算目标函数值 self.evalsNum += offspring.sizes # 更新评价次数 # 重插入生成新一代种群 population = self.reinsertion(population, offspring, NIND, uniformPoint) return self.finishing(population) # 调用finishing完成后续工作并返回结果