source: framspy/evolalg_steps/repair/repair.py @ 1204

Last change on this file since 1204 was 1185, checked in by Maciej Komosinski, 2 years ago

Renamed a module; new name is "evolalg_steps"

File size: 859 bytes
Line 
1from abc import abstractmethod
2from collections import Iterable
3
4from evolalg_steps.base.step import Step
5
6
7class 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.