Rev | Line | |
---|
[1113] | 1 | import random |
---|
| 2 | |
---|
| 3 | from evolalg.base.frams_step import FramsStep |
---|
| 4 | from evolalg.base.individual import Individual |
---|
| 5 | |
---|
| 6 | |
---|
| 7 | class 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.