source: framspy/evolalg/mutation_cross/frams_cross.py @ 1141

Last change on this file since 1141 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
Line 
1import random
2
3from evolalg.base.frams_step import FramsStep
4from evolalg.base.individual import Individual
5
6
7class 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.