import random from evolalg.base.frams_step import FramsStep from evolalg.base.individual import Individual class FramsCross(FramsStep): def __init__(self, frams_lib, commands, cross_prob): super().__init__(frams_lib, commands) self.cross_prob = cross_prob def call(self, population): for i in range(1, len(population), 2): if random.random() < self.cross_prob: geno1 = population[i - 1].genotype geno2 = population[i].genotype cross_geno1 = self.frams.crossOver(geno1, geno2) cross_geno2 = self.frams.crossOver(geno1, geno2) population[i - 1] = Individual(cross_geno1) population[i] = Individual(cross_geno2) return population