source: framspy/evolalg/repair/mutate.py @ 1127

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

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

File size: 584 bytes
Line 
1import random
2import copy
3
4from evolalg.repair.repair import Repair
5
6
7class MutateRepair(Repair):
8    def __init__(self, mutate_step, excepted_size, iterations=1):
9        super(MutateRepair, self).__init__(excepted_size)
10        self.mutate_step = mutate_step
11        self.iterations = iterations
12
13
14    def generate_new(self, population, missing_count):
15        selected = population[random.randint(0, len(population))]
16        selected = copy.deepcopy(selected)
17        for _ in range(self.iterations):
18            selected = self.mutate_step([selected])[0]
19        return selected
Note: See TracBrowser for help on using the repository browser.