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

Last change on this file since 1113 was 1113, checked in by Maciej Komosinski, 19 months ago

Added a framework for evolutionary algorithms cooperating with FramsticksLib?.py

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