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

Last change on this file since 1113 was 1113, checked in by Maciej Komosinski, 4 years ago

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

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