source: framspy/evolalg/mutation_cross/frams_mutation.py @ 1114

Last change on this file since 1114 was 1113, checked in by Maciej Komosinski, 3 years ago

Added a framework for evolutionary algorithms cooperating with FramsticksLib?.py

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