Line | |
---|
1 | from collections import Iterable |
---|
2 | |
---|
3 | from evolalg.base.step import Step |
---|
4 | |
---|
5 | |
---|
6 | class UnionStep(Step): |
---|
7 | def __init__(self, steps, *args, **kwargs): |
---|
8 | super(UnionStep, self).__init__(*args, **kwargs) |
---|
9 | if isinstance(steps, Iterable): |
---|
10 | self.steps = steps |
---|
11 | else: |
---|
12 | self.steps = [steps] |
---|
13 | |
---|
14 | def init(self): |
---|
15 | for s in self.steps: |
---|
16 | if isinstance(s, Step): |
---|
17 | s.init() |
---|
18 | |
---|
19 | def call(self, population): |
---|
20 | super(UnionStep, self).call(population) |
---|
21 | for s in self.steps: |
---|
22 | population = s(population) |
---|
23 | return population |
---|
24 | |
---|
25 | def __len__(self): |
---|
26 | return len(self.steps) |
---|
27 | |
---|
28 | def __iter__(self): |
---|
29 | return iter(self.steps) |
---|
Note: See
TracBrowser
for help on using the repository browser.