def newPolyList(self): choose_id = int(random.random() * len(self.new_poly_list)) '''进行交换和旋转的操作,暂时不允许旋转''' if random.random()<=1: self.new_poly_list=PolyListProcessor.randomSwap(self.cur_poly_list,choose_id) else: self.new_poly_list=PolyListProcessor.randomRotate(self.cur_poly_list,self.min_angle,choose_id)
def mutate(self,individual): for swapped in range(len(individual)): if(random.random() < self.mutate_rate): # 首先是交换位置 if random.random()<=0.5: individual=PolyListProcessor.randomSwap(individual,swapped) else: individual=PolyListProcessor.randomRotate(individual,self.minimal_rotation,swapped) return individual