source: framspy/evolalg_steps/selection/selection.py @ 1302

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

Renamed a module; new name is "evolalg_steps"

File size: 683 bytes
Line 
1from abc import abstractmethod
2
3from evolalg_steps.base.step import Step
4import copy
5
6
7class Selection(Step):
8    def __init__(self, copy=False, *args, **kwargs):
9        super(Selection, self).__init__(*args, **kwargs)
10        self.copy = copy
11
12    @abstractmethod
13    def select_next(self, population):
14        pass
15
16    def call(self, population, count=None):
17        super(Selection, self).call(population)
18        res = []
19        if count is None:
20            count = len(population)
21
22        for _ in range(count):
23            sel = self.select_next(population)
24            if self.copy:
25                sel = copy.deepcopy(sel)
26            res.append(sel)
27        return res
Note: See TracBrowser for help on using the repository browser.