Last change
on this file since 1161 was
1139,
checked in by Maciej Komosinski, 4 years ago
|
Added --debug mode that prints names of steps; final multiple evaluation now evaluates genotypes in hall of fame instead of the last population
|
File size:
677 bytes
|
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, *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.