Line | |
---|
1 | import random |
---|
2 | |
---|
3 | from evolalg.base.frams_step import FramsStep |
---|
4 | from evolalg.base.individual import Individual |
---|
5 | |
---|
6 | |
---|
7 | class FramsCross(FramsStep): |
---|
8 | def __init__(self, frams_lib, commands, cross_prob): |
---|
9 | super().__init__(frams_lib, commands) |
---|
10 | self.cross_prob = cross_prob |
---|
11 | |
---|
12 | def call(self, population): |
---|
13 | for i in range(1, len(population), 2): |
---|
14 | if random.random() < self.cross_prob: |
---|
15 | geno1 = population[i - 1].genotype |
---|
16 | geno2 = population[i].genotype |
---|
17 | |
---|
18 | cross_geno1 = self.frams.crossOver(geno1, geno2) |
---|
19 | cross_geno2 = self.frams.crossOver(geno1, geno2) |
---|
20 | |
---|
21 | population[i - 1] = Individual(cross_geno1) |
---|
22 | population[i] = Individual(cross_geno2) |
---|
23 | |
---|
24 | return population |
---|
Note: See
TracBrowser
for help on using the repository browser.