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