source: framspy/evolalg/base/lambda_step.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: 757 bytes
Line 
1from evolalg.base.step import Step
2
3
4class LambdaStep(Step):
5    """
6    Wrapper for lambda expressions. In "normal" mode each step is given whole population to work with. This class
7    helps with any Callable that accepts individuals.
8
9    """
10    def __init__(self, fun, in_place=True, *args, **kwargs):
11        """
12        @param fun: Callable callable that will be called for each individual
13        @param in_place: Bool
14        """
15        super(LambdaStep, self).__init__(*args, **kwargs)
16        self.fun = fun
17        self.in_place = in_place
18
19    def call(self, population):
20        if self.in_place:
21            [self.fun(_) for _ in population]
22        else:
23            population = [self.fun(_) for _ in population]
24        return population
Note: See TracBrowser for help on using the repository browser.