guofei9987 / scikit-opt

Genetic Algorithm, Particle Swarm Optimization, Simulated Annealing, Ant Colony Optimization Algorithm,Immune Algorithm, Artificial Fish Swarm Algorithm, Differential Evolution and TSP(Traveling salesman)
https://scikit-opt.github.io/scikit-opt/#/en/
MIT License
5.31k stars 992 forks source link

crossover.py文件中crossover_2point_bit算子起作用吗 #200

Closed Czw007 closed 2 years ago

Czw007 commented 2 years ago

def crossover_2point_bit(self): ''' 3 times faster thancrossover_2point, but only use for 0/1 type of Chrom :param self: :return: ''' Chrom, size_pop, len_chrom = self.Chrom, self.size_pop, self.len_chrom half_size_pop = int(size_pop / 2) Chrom1, Chrom2 = Chrom[:half_size_pop], Chrom[half_size_pop:] mask = np.zeros(shape=(half_size_pop, len_chrom), dtype=int) for i in range(half_size_pop): n1, n2 = np.random.randint(0, self.len_chrom, 2) if n1 > n2: n1, n2 = n2, n1 mask[i, n1:n2] = 1 mask2 = (Chrom1 ^ Chrom2) & mask Chrom1 ^= mask2 Chrom2 ^= mask2 return self.Chrom

该函数似乎并没有改变self.Chrom,未起到交叉变异的作用