source: framspy/evolalg/repair/repair.py @ 1174

Last change on this file since 1174 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
RevLine 
[1113]1from abc import abstractmethod
2from collections import Iterable
3
4from evolalg.base.step import Step
5
6
7class 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.