Last change
on this file since 1325 was
1185,
checked in by Maciej Komosinski, 2 years ago
|
Renamed a module; new name is "evolalg_steps"
|
File size:
877 bytes
|
Line | |
---|
1 | import random |
---|
2 | |
---|
3 | from evolalg_steps.base.frams_step import FramsStep |
---|
4 | from evolalg_steps.base.individual import Individual |
---|
5 | |
---|
6 | |
---|
7 | class FramsCross(FramsStep): |
---|
8 | def __init__(self, frams_lib, commands, cross_prob, *args, **kwargs): |
---|
9 | super().__init__(frams_lib, commands, *args, **kwargs) |
---|
10 | self.cross_prob = cross_prob |
---|
11 | |
---|
12 | def call(self, population): |
---|
13 | super(FramsCross, self).call(population) |
---|
14 | for i in range(1, len(population), 2): |
---|
15 | if random.random() < self.cross_prob: |
---|
16 | geno1 = population[i - 1].genotype |
---|
17 | geno2 = population[i].genotype |
---|
18 | |
---|
19 | cross_geno1 = self.frams.crossOver(geno1, geno2) |
---|
20 | cross_geno2 = self.frams.crossOver(geno1, geno2) |
---|
21 | |
---|
22 | population[i - 1] = Individual(cross_geno1) |
---|
23 | population[i] = Individual(cross_geno2) |
---|
24 | |
---|
25 | return population |
---|
Note: See
TracBrowser
for help on using the repository browser.