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

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

Renamed a module; new name is "evolalg_steps"

File size: 778 bytes
Line 
1import random
2
3from evolalg_steps.base.frams_step import FramsStep
4from evolalg_steps.base.individual import Individual
5
6
7class FramsMutation(FramsStep):
8    def __init__(self, frams_lib, commands, mutate_prob, *args, **kwargs):
9        super().__init__(frams_lib, commands, *args, **kwargs)
10        self.mutate_prob = mutate_prob
11
12    def call(self, population):
13        super(FramsMutation, self).call(population)
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.