Last change
on this file since 1324 was
1185,
checked in by Maciej Komosinski, 2 years ago
|
Renamed a module; new name is "evolalg_steps"
|
File size:
859 bytes
|
Rev | Line | |
---|
[1113] | 1 | from abc import abstractmethod |
---|
| 2 | from collections import Iterable |
---|
| 3 | |
---|
[1185] | 4 | from evolalg_steps.base.step import Step |
---|
[1113] | 5 | |
---|
| 6 | |
---|
| 7 | class Repair(Step): |
---|
[1139] | 8 | def __init__(self, excepted_size, *args, **kwargs): |
---|
| 9 | super(Repair, self).__init__(*args, **kwargs) |
---|
[1113] | 10 | self.excepted_size = excepted_size |
---|
| 11 | |
---|
| 12 | @abstractmethod |
---|
| 13 | def generate_new(self, population, missing_count): |
---|
| 14 | pass |
---|
| 15 | |
---|
| 16 | def call(self, population): |
---|
[1139] | 17 | super(Repair, self).call(population) |
---|
[1113] | 18 | generated = [] |
---|
| 19 | while len(generated) + len(population) < self.excepted_size: |
---|
| 20 | gen = self.generate_new(population, self.excepted_size-len(population)-len(generated)) |
---|
| 21 | if isinstance(gen, Iterable): |
---|
| 22 | generated.extend(gen) |
---|
| 23 | else: |
---|
| 24 | generated.append(gen) |
---|
| 25 | population.extend(generated) |
---|
| 26 | return population[:self.excepted_size] |
---|
Note: See
TracBrowser
for help on using the repository browser.