Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Czw007 opened this issue Oct 18, 2022 · 0 comments
Closed

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

Czw007 opened this issue Oct 18, 2022 · 0 comments

Comments

@Czw007
Copy link

Czw007 commented Oct 18, 2022

def crossover_2point_bit(self): ''' 3 times faster than crossover_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,未起到交叉变异的作用

@Czw007 Czw007 closed this as completed Oct 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant