Last change
on this file since 1297 was
1185,
checked in by Maciej Komosinski, 2 years ago
|
Renamed a module; new name is "evolalg_steps"
|
File size:
683 bytes
|
Rev | Line | |
---|
[1113] | 1 | from abc import abstractmethod |
---|
| 2 | |
---|
[1185] | 3 | from evolalg_steps.base.step import Step |
---|
[1113] | 4 | import copy |
---|
| 5 | |
---|
| 6 | |
---|
| 7 | class Selection(Step): |
---|
[1139] | 8 | def __init__(self, copy=False, *args, **kwargs): |
---|
| 9 | super(Selection, self).__init__(*args, **kwargs) |
---|
[1113] | 10 | self.copy = copy |
---|
| 11 | |
---|
| 12 | @abstractmethod |
---|
| 13 | def select_next(self, population): |
---|
| 14 | pass |
---|
| 15 | |
---|
| 16 | def call(self, population, count=None): |
---|
[1139] | 17 | super(Selection, self).call(population) |
---|
[1113] | 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.