Line | |
---|
1 | from abc import abstractmethod |
---|
2 | from collections import Iterable |
---|
3 | |
---|
4 | from evolalg.base.step import Step |
---|
5 | |
---|
6 | |
---|
7 | class Repair(Step): |
---|
8 | def __init__(self, excepted_size): |
---|
9 | self.excepted_size = excepted_size |
---|
10 | |
---|
11 | @abstractmethod |
---|
12 | def generate_new(self, population, missing_count): |
---|
13 | pass |
---|
14 | |
---|
15 | def call(self, population): |
---|
16 | generated = [] |
---|
17 | while len(generated) + len(population) < self.excepted_size: |
---|
18 | gen = self.generate_new(population, self.excepted_size-len(population)-len(generated)) |
---|
19 | if isinstance(gen, Iterable): |
---|
20 | generated.extend(gen) |
---|
21 | else: |
---|
22 | generated.append(gen) |
---|
23 | population.extend(generated) |
---|
24 | return population[:self.excepted_size] |
---|
Note: See
TracBrowser
for help on using the repository browser.