Line | |
---|
1 | import random |
---|
2 | import copy |
---|
3 | |
---|
4 | from evolalg.repair.repair import Repair |
---|
5 | |
---|
6 | |
---|
7 | class 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.