source: framspy/evolalg_steps/mutation_cross/frams_mutation.py @ 1296

Last change on this file since 1296 was 1185, checked in by Maciej Komosinski, 2 years ago

Renamed a module; new name is "evolalg_steps"

File size: 778 bytes
RevLine 
[1113]1import random
2
[1185]3from evolalg_steps.base.frams_step import FramsStep
4from evolalg_steps.base.individual import Individual
[1113]5
6
7class FramsMutation(FramsStep):
[1139]8    def __init__(self, frams_lib, commands, mutate_prob, *args, **kwargs):
9        super().__init__(frams_lib, commands, *args, **kwargs)
[1113]10        self.mutate_prob = mutate_prob
11
12    def call(self, population):
[1139]13        super(FramsMutation, self).call(population)
[1113]14        idx = []
15        for i in range(len(population)):
16            if random.random() < self.mutate_prob:
17                idx.append(i)
18        mutated = [population[_].genotype for _ in idx]
19        mutated = self.frams.mutate([_ for _ in mutated])
20
21        for i, m in zip(idx, mutated):
22            population[i] = Individual(m)
23
24        return population
Note: See TracBrowser for help on using the repository browser.