Last change
on this file since 1139 was
1139,
checked in by Maciej Komosinski, 4 years ago
|
Added --debug mode that prints names of steps; final multiple evaluation now evaluates genotypes in hall of fame instead of the last population
|
File size:
865 bytes
|
Rev | Line | |
---|
[1113] | 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): |
---|
[1139] | 8 | def __init__(self, frams_lib, commands, cross_prob, *args, **kwargs): |
---|
| 9 | super().__init__(frams_lib, commands, *args, **kwargs) |
---|
[1113] | 10 | self.cross_prob = cross_prob |
---|
| 11 | |
---|
| 12 | def call(self, population): |
---|
[1139] | 13 | super(FramsCross, self).call(population) |
---|
[1113] | 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.