Last change
on this file since 1165 was
1139,
checked in by Maciej Komosinski, 4 years ago
|
Added --debug mode that prints names of steps; final multiple evaluation now evaluates genotypes in hall of fame instead of the last population
|
File size:
853 bytes
|
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, *args, **kwargs): |
---|
9 | super(Repair, self).__init__(*args, **kwargs) |
---|
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): |
---|
17 | super(Repair, self).call(population) |
---|
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.